#include "foundation.h"
#include "console_system.h"
-struct console_command
+struct console_item
{
const c8 *alias;
- i32 (*fn)( struct console_arguments *args );
+ enum console_item_type
+ {
+ k_console_item_ccmd,
+ k_console_item_cvar_i32,
+ k_console_item_cvar_f32
+ }
+ type;
+
+ union
+ {
+ i32 (*fn)( struct console_arguments *args );
+ i32 *_i32;
+ f32 *_f32;
+ };
};
#include "generated/console.c"
args.count = 0;
u32 temp_frame = _start_temporary_frame();
- struct console_command *target_command = NULL;
+ struct console_item *target_command = NULL;
// TODO: warning if we put to many or to few arguments & required ones.
for( u32 i=0; i<ARRAY_COUNT(args.arguments)+1; i ++ )
{
if( i == 0 )
{
- for( u32 j=0; j<ARRAY_COUNT(_console_commands); j ++ )
+ for( u32 j=0; j<ARRAY_COUNT(_console_items); j ++ )
{
- struct console_command *cmd = &_console_commands[j];
+ struct console_item *cmd = &_console_items[j];
if( compare_buffers( cmd->alias, 0, command+start, length ) )
{
target_command = cmd;
}
if( target_command )
- target_command->fn( &args );
+ {
+ if( target_command->type == k_console_item_ccmd )
+ target_command->fn( &args );
+ else
+ {
+ const c8 *set_to = console_get_argument( &args, 0 );
+ if( set_to )
+ {
+ struct stream string;
+ stream_open_buffer_read( &string, set_to, buffer_last_index( set_to, 0, 0 ), 0 );
+
+ if( target_command->type == k_console_item_cvar_f32 )
+ {
+ f64 f;
+ if( string_parse_f64( &string, &f ) == k_string_parse_ok )
+ *target_command->_f32 = f;
+ }
+ if( target_command->type == k_console_item_cvar_i32 )
+ {
+ i64 i;
+ if( string_parse_i64( &string, &i ) == k_string_parse_ok )
+ *target_command->_i32 = i;
+ }
+
+ $log( $info, {"Value set"} );
+ }
+ else
+ {
+ if( target_command->type == k_console_item_cvar_f32 )
+ {
+ $log( $info, {"The value of "}, {target_command->alias}, {"(f32) is: "}, $float( *target_command->_f32 ) );
+ }
+ else if( target_command->type == k_console_item_cvar_i32 )
+ {
+ $log( $info, {"The value of "}, {target_command->alias}, {"(i32) is: "}, $signed( *target_command->_i32 ) );
+ }
+ }
+ }
+ }
_end_temporary_frame( temp_frame );
}
const c8 *type;
const c8 *alias;
const c8 *shader_name;
+ const c8 *count;
};
struct stretchy_allocator uniforms;
stretchy_init( &uniforms, sizeof(struct uniform_info) );
{ "mat3", "f32 m[3][3]", "glUniformMatrix3fv", "1,GL_FALSE,(f32*)m" },
{ "mat4", "f32 m[4][4]", "glUniformMatrix4fv", "1,GL_FALSE,(f32*)m" },
{ "float", "f32 f", "glUniform1f", "f" },
- { "mat4x3", "f32 m[4][3]", "glUniformMatrix4x3fv", "1,GL_FALSE,(f32*)m" },
+ { "mat4x3", "f32 (*m)[4][3], u32 c","glUniformMatrix4x3fv", "c,GL_FALSE,(f32*)m" },
{ "sampler2D", "i32 i", "glUniform1i", "i" },
{ "usampler3D", "i32 i", "glUniform1i", "i" },
{ "samplerCube", "i32 i", "glUniform1i", "i" },
uniform->glsl_index = -1;
uniform->type = keyvalues_read_string( &_assembly, uniform_it, "type", NULL );
uniform->alias = keyvalues_read_string( &_assembly, uniform_it, "alias", NULL );
+ uniform->count = keyvalues_read_string( &_assembly, uniform_it, "count", NULL );
uniform->shader_name = shader_name;
ASSERT_CRITICAL( uniform->type && uniform->alias );
ASSERT_CRITICAL( uniform->glsl_index != -1 );
uniform_count ++;
- $v_string( &C, {"uniform "}, {uniform->type}, {" "}, {uniform->alias}, {";\\n"} );
+ if( uniform->count )
+ {
+ $v_string( &C, {"uniform "}, {uniform->type}, {" "}, {uniform->alias}, {"["},{uniform->count},{"];\\n"} );
+ }
+ else
+ {
+ $v_string( &C, {"uniform "}, {uniform->type}, {" "}, {uniform->alias}, {";\\n"} );
+ }
}
$v_string( &C, {"\",\n"}, {" },\n"} );
subshader_count ++;
stream_open_file( &H, "generated/console.h", k_stream_write );
stream_open_file( &C, "generated/console.c", k_stream_write );
- $v_string( &C, {"static struct console_command _console_commands[] = \n{\n"} );
+ $v_string( &C, {"static struct console_item _console_items[] = \n{\n"} );
u32 ccmd_it = 0;
while( keyvalues_foreach( &_assembly, &ccmd_it, 0, "ccmd" ) )
ASSERT_CRITICAL( name && function );
$v_string( &H, {"i32 "}, {function}, {"( struct console_arguments *args );\n"} );
- $v_string( &C, {" {\n .alias = \""}, {name}, {"\",\n .fn = "}, {function}, {"\n },\n"} );
+ $v_string( &C, {" {\n .alias = \""}, {name}, {"\",\n .type = k_console_item_ccmd,\n .fn = "}, {function}, {"\n },\n"} );
+ }
+
+ u32 cvar_it = 0;
+ while( keyvalues_foreach( &_assembly, &cvar_it, 0, "cvar" ) )
+ {
+ const c8 *name = keyvalues_read_string( &_assembly, cvar_it, "name", NULL );
+ const c8 *type = keyvalues_read_string( &_assembly, cvar_it, "type", NULL );
+ const c8 *value = keyvalues_read_string( &_assembly, cvar_it, "default", NULL );
+ const c8 *cheat = keyvalues_read_string( &_assembly, cvar_it, "cheat", NULL );
+ ASSERT_CRITICAL( name && type && value );
+ $v_string( &H, {"extern "}, {type}, {" _cvar_"}, {name}, {";\n"} );
+ $v_string( &C, {" {\n .alias = \""}, {name}, {"\",\n .type = k_console_item_cvar_"},{type},
+ {",\n ._"},{type},{" = &_cvar_"}, {name}, {"\n },\n"} );
}
$v_string( &C, {"};\n\n"} );
+ cvar_it = 0;
+ while( keyvalues_foreach( &_assembly, &cvar_it, 0, "cvar" ) )
+ {
+ const c8 *name = keyvalues_read_string( &_assembly, cvar_it, "name", NULL );
+ const c8 *type = keyvalues_read_string( &_assembly, cvar_it, "type", NULL );
+ const c8 *value = keyvalues_read_string( &_assembly, cvar_it, "default", NULL );
+ const c8 *cheat = keyvalues_read_string( &_assembly, cvar_it, "cheat", NULL );
+ ASSERT_CRITICAL( name && type && value );
+ $v_string( &C, {type}, {" _cvar_"}, {name}, {" = "}, {value}, {";\n"} );
+ }
+
stream_close( &H );
stream_close( &C );
}