From 11c1052e4f820d3002d2096f931bca70a4f3ef08 Mon Sep 17 00:00:00 2001 From: hgn Date: Fri, 23 Jun 2023 14:42:33 +0100 Subject: [PATCH] minor stuff --- vg_build.h | 4 +-- vg_console.h | 74 +++++++++++++++++++++++++++++++++++----------------- vg_imgui.h | 4 ++- vg_msg.h | 2 +- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/vg_build.h b/vg_build.h index 873eb39..c3ca828 100644 --- a/vg_build.h +++ b/vg_build.h @@ -231,8 +231,8 @@ void vg_build(void) /* Warnings */ strcat( cmd, " -Wall\\\n" - " -Wno-unused-function -Wno-unused-variable\\\n" - " -Wno-unused-command-line-argument -Wno-unused-but-set-variable\\\n" + " -Wno-unused-function -Wno-unused-variable -Wno-format-truncation\\\n" + " -Wno-unused-command-line-argument -Wno-unused-but-set-variable\\\n" ); if( vg_compiler.compiler == k_compiler_clang ){ diff --git a/vg_console.h b/vg_console.h index 208b5b3..6f3c2ba 100644 --- a/vg_console.h +++ b/vg_console.h @@ -18,8 +18,9 @@ { u32 flags=0x00; __VA_ARGS__ ;\ vg_console_reg_var( #NAME, &NAME, k_var_dtype_i32, flags ); } -#define VG_VAR_PERSISTENT 0x1 -#define VG_VAR_CHEAT 0x2 +#define VG_VAR_PERSISTENT 0x1 +#define VG_VAR_CHEAT 0x2 +#define VG_VAR_CHEATTOGGLE 0x4 typedef struct vg_var vg_var; typedef struct vg_cmd vg_cmd; @@ -35,8 +36,9 @@ struct vg_console{ k_var_dtype_f32 } data_type; - u32 flags; + + union{ u32 _u32; f32 _f32; i32 _i32; } defaults; } vars[ 128 ]; @@ -67,10 +69,9 @@ struct vg_console{ char history[32][96]; int history_last, history_pos, history_count; - int enabled; + i32 enabled, cheats; } -vg_console; - +static vg_console; VG_STATIC void _vg_console_draw( void ); void _vg_console_println( const char *str ); @@ -90,8 +91,7 @@ VG_STATIC void console_proc_key( SDL_Keysym ev ); /* * Implementation */ -VG_STATIC int _vg_console_enabled(void) -{ +VG_STATIC int _vg_console_enabled(void){ return vg_console.enabled; } @@ -108,6 +108,10 @@ void vg_console_reg_var( const char *alias, void *ptr, enum vg_var_dtype type, var->data_type = type; var->flags = flags; + if ( type == k_var_dtype_f32 ) var->defaults._f32 = *((f32 *)ptr); + else if( type == k_var_dtype_i32 ) var->defaults._i32 = *((i32 *)ptr); + else if( type == k_var_dtype_u32 ) var->defaults._u32 = *((u32 *)ptr); + vg_info( "Console variable '%s' registered\n", alias ); } @@ -128,8 +132,7 @@ void vg_console_reg_cmd( const char *alias, vg_info( "Console function '%s' registered\n", alias ); } -VG_STATIC int _vg_console_list( int argc, char const *argv[] ) -{ +VG_STATIC int _vg_console_list( int argc, char const *argv[] ){ for( int i=0; iname ); @@ -143,14 +146,12 @@ VG_STATIC int _vg_console_list( int argc, char const *argv[] ) return 0; } -int _test_break( int argc, const char *argv[] ) -{ +int _test_break( int argc, const char *argv[] ){ vg_fatal_error( "Test crash from main, after loading (console)" ); return 0; } -int _vg_console_exec( int argc, const char *argv[] ) -{ +int _vg_console_exec( int argc, const char *argv[] ){ if( argc < 1 ) return 0; char path[256]; @@ -178,20 +179,34 @@ int _vg_console_exec( int argc, const char *argv[] ) return 0; } -VG_STATIC void _vg_console_init(void) -{ +int _ccmd_vg_console_defaults( int argc, const char *argv[] ){ + for( int i=0; idata_type; + void *ptr = cv->data; + + if ( type == k_var_dtype_f32 ) *((f32 *)ptr) = cv->defaults._f32; + else if( type == k_var_dtype_i32 ) *((i32 *)ptr) = cv->defaults._i32; + else if( type == k_var_dtype_u32 ) *((u32 *)ptr) = cv->defaults._u32; + } + + return 0; +} + +VG_STATIC void _vg_console_init(void){ vg_console_reg_cmd( "list", _vg_console_list, NULL ); vg_console_reg_cmd( "crash", _test_break, NULL ); vg_console_reg_cmd( "exec", _vg_console_exec, NULL ); + vg_console_reg_cmd( "defaults", _ccmd_vg_console_defaults, NULL ); + vg_console_reg_var( "cheats", &vg_console.cheats, k_var_dtype_i32, 0 ); } -VG_STATIC void vg_console_load_autos(void) -{ +VG_STATIC void vg_console_load_autos(void){ _vg_console_exec( 1, (const char *[]){ "auto.conf" } ); } -VG_STATIC void _vg_console_write_persistent(void) -{ +VG_STATIC void _vg_console_write_persistent(void){ FILE *fp = fopen( "cfg/auto.conf", "w" ); for( int i=0; i= 2 ){ + if( cv->flags & VG_VAR_CHEAT ){ + if( !vg_console.cheats ){ + vg_error( "variable is cheat protected\n" ); + return; + } + } + if( (cv->data_type == k_var_dtype_u32) || (cv->data_type == k_var_dtype_i32) ) { int *ptr = cv->data; *ptr = atoi( args[1] ); + + if( cv->flags & VG_VAR_CHEATTOGGLE ){ + if( *ptr ){ + _ccmd_vg_console_defaults( 0, NULL ); + } + } } else if( cv->data_type == k_var_dtype_f32 ){ float *ptr = cv->data; @@ -331,8 +359,7 @@ VG_STATIC void vg_execute_console_input( const char *cmd ) vg_error( "No command/var named '%s'. Use 'list' to view all\n", args[0] ); } -u32 str_lev_distance( const char *s1, const char *s2 ) -{ +u32 str_lev_distance( const char *s1, const char *s2 ){ u32 m = strlen( s1 ), n = strlen( s2 ); @@ -369,8 +396,7 @@ u32 str_lev_distance( const char *s1, const char *s2 ) return costs[n]; } -u32 str_lcs( const char *s1, const char *s2 ) -{ +u32 str_lcs( const char *s1, const char *s2 ){ u32 m = VG_MIN( 31, strlen( s1 ) ), n = VG_MIN( 31, strlen( s2 ) ); diff --git a/vg_imgui.h b/vg_imgui.h index 10f93aa..7e16b3f 100644 --- a/vg_imgui.h +++ b/vg_imgui.h @@ -1113,7 +1113,9 @@ static void ui_postrender(void) ui_rect row0, row1, btn; ui_split_ratio( message, k_ui_axis_h, 0.5f, 0, row0, row1 ); - ui_text( row0, vg_ui.modal.message, 1, k_ui_align_middle_center, colour ); + row0[0] += UI_GLYPH_SPACING_X; + ui_ntext( row0, vg_ui.modal.message, (box[2]/UI_GLYPH_SPACING_X)-2, 1, + k_ui_align_left, colour ); rect_copy( row1, btn ); btn[2] = 86; diff --git a/vg_msg.h b/vg_msg.h index 28ae5c8..ce012a6 100644 --- a/vg_msg.h +++ b/vg_msg.h @@ -305,7 +305,7 @@ static int vg_msg_next( vg_msg *msg, vg_msg_cmd *cmd ){ */ if( cmd->code == 0x44 ) cmd->code = 0x82; #endif - + cmd->key_djb2 = 0; if( msg->error != k_vg_msg_error_OK ) return 0; if( cmd->code == k_vg_msg_frame ){ -- 2.25.1