minor stuff
authorhgn <hgodden00@gmail.com>
Fri, 23 Jun 2023 13:42:33 +0000 (14:42 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 23 Jun 2023 13:42:33 +0000 (14:42 +0100)
vg_build.h
vg_console.h
vg_imgui.h
vg_msg.h

index 873eb3981e41464b486026581762dad063e2c286..c3ca828c6ba1f45f3005505559621b0fa377b887 100644 (file)
@@ -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 ){
index 208b5b392b9245887583b6f7b34ebc32cb35f2b3..6f3c2bad7128e2650073138a6b8ed97137298101 100644 (file)
@@ -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; i<vg_console.function_count; i ++ ){
                struct vg_cmd *cmd = &vg_console.functions[ i ];
                vg_info( "* %s\n", cmd->name );
@@ -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; i<vg_console.var_count; i ++ ){
+               struct vg_var *cv = &vg_console.vars[i];
+
+      enum vg_var_dtype type = cv->data_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<vg_console.var_count; i ++ ){
@@ -301,11 +316,24 @@ VG_STATIC void vg_execute_console_input( const char *cmd )
    if( cv ){
       /* Cvar Matched, try get value */
       if( arg_count >= 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 ) );
 
index 10f93aaac29a893404c243db45ad3bcee333c457..7e16b3fc865b12cd6a5f4ec6ee6144932f9b9aae 100644 (file)
@@ -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;
index 28ae5c8c52e0f6ad0233851017c6cd758eb21484..ce012a6fc7bc6e0883b4df78b66a07992c613b45 100644 (file)
--- 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 ){