window defaults&persistent
authorhgn <hgodden00@gmail.com>
Fri, 29 Dec 2023 11:10:12 +0000 (11:10 +0000)
committerhgn <hgodden00@gmail.com>
Fri, 29 Dec 2023 11:10:12 +0000 (11:10 +0000)
vg.h
vg_console.h

diff --git a/vg.h b/vg.h
index 919f6f3b878049b68f55afb749eddf904d7c37c1..7822a9595c8e7ae9ec5c87f91f9f25d191909584 100644 (file)
--- a/vg.h
+++ b/vg.h
@@ -758,47 +758,45 @@ static void _vg_init_window( const char *window_name )
    vg.window_x = video_mode.w;
    vg.window_y = video_mode.h;
 
-#ifdef VG_DEVWINDOW
-   vg.window_x = 1280;
-   vg.window_y = 720;
-#endif
-
 #ifndef _WIN32
        SDL_SetHint( "SDL_VIDEO_X11_XINERAMA", "1" );
        SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "0" );
        SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "0" );
 #endif
 
-   vg_info( "CreateWindow( %d %d @%dhz )\n", vg.window_x, vg.window_y,
-                                             vg.display_refresh_rate );
+   u32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_GRABBED;
+
+#ifdef VG_DEVWINDOW
+   flags |= SDL_WINDOW_BORDERLESS;
+   vg.screen_mode = 2;
+   vg.window_x = 1280;
+   vg.window_y = 720;
+#else
+
+   if( vg.screen_mode == 2 )
+      flags |= SDL_WINDOW_RESIZABLE;
+   else if( vg.screen_mode == 1 )
+      flags |= SDL_WINDOW_FULLSCREEN;
+   else
+      flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+
+#endif
+
+   vg_info( "CreateWindow( %d %d %u )\n", vg.window_x, vg.window_y, flags );
 
-   /* TODO: Allow selecting closest video mode from launch opts */
    if((vg.window = SDL_CreateWindow( window_name,
+         0, 0, vg.window_x, vg.window_y, flags ))){
 
 #ifdef VG_DEVWINDOW
-         0, 0, vg.window_x, vg.window_y, 
-         SDL_WINDOW_BORDERLESS|SDL_WINDOW_OPENGL|SDL_WINDOW_INPUT_GRABBED
-      ))){
       SDL_SetWindowPosition( vg.window, video_mode.w-vg.window_x, 0 );
-      vg.screen_mode = 2;
-   }
-#else
-                                     0, 0,
-                                     vg.window_x, vg.window_y,
-
-                                     SDL_WINDOW_FULLSCREEN_DESKTOP | 
-                                     SDL_WINDOW_OPENGL |
-                                     SDL_WINDOW_INPUT_GRABBED |
-                                     SDL_WINDOW_RESIZABLE
-                                     )))
-   {
+#endif
+      
       if( SDL_SetWindowDisplayMode( vg.window, &video_mode ) ){
          vg_error( "SDL_SetWindowDisplayMode failed: %s", SDL_GetError() );
          SDL_Quit();
          exit(0);
       }
    }
-#endif
    else{
       vg_error( "SDL_CreateWindow failed: %s", SDL_GetError() );
       exit(0);
@@ -850,12 +848,7 @@ static void _vg_init_window( const char *window_name )
    }
 
    vg_info( "Display refresh rate: %d\n", dispmode.refresh_rate );
-   vg.fps_limit = vg.display_refresh_rate;
-
-#if defined(_WIN32) || defined(VG_DEVWINDOW)
-#else
-   //vg.vsync = 1;
-#endif
+   if( !vg.fps_limit) vg.fps_limit = vg.display_refresh_rate;
 }
 
 static void _vg_terminate(void)
@@ -884,8 +877,16 @@ static void vg_enter( int argc, char *argv[], const char *window_name ){
    vg_alloc_quota();
    _vg_console_init();
    
-   vg_console_reg_var( "fps_limit", &vg.fps_limit, k_var_dtype_i32, 0 );
-   vg_console_reg_var( "vsync", &vg.vsync, k_var_dtype_i32, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "vg_fps_limit", &vg.fps_limit, 
+                        k_var_dtype_i32, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "vg_vsync", &vg.vsync, 
+                        k_var_dtype_i32, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "vg_quality", &vg.quality_profile, 
+                        k_var_dtype_i32, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "vg_screen_mode", &vg.screen_mode,
+                        k_var_dtype_i32, VG_VAR_PERSISTENT );
+   vg_console_load_autos();
+
    vg_console_reg_cmd( "vg_settings", cmd_vg_settings_toggle, NULL );
    _vg_init_window( window_name );
 
index 3112cde10ea7a86383a75eb2f00d0a17ca052d5c..42f79e4f35e7c62582bad750798f19cc126b8082 100644 (file)
@@ -79,7 +79,7 @@ static int  _vg_console_list( int argc, char const *argv[] );
 static void _vg_console_init(void);
 static void _vg_console_write_persistent(void);
 static void _vg_console_free(void);
-static void  vg_execute_console_input( const char *cmd );
+static void  vg_execute_console_input( const char *cmd, bool silent );
 
 /*
  * Console interface
@@ -154,6 +154,9 @@ int _test_break( int argc, const char *argv[] ){
 int _vg_console_exec( int argc, const char *argv[] ){
    if( argc < 1 ) return 0;
 
+   int silent=0;
+   if( argc == 2 ) silent=1;
+
    char path[256];
    strcpy( path, "cfg/" );
    strncat( path, argv[0], 250 );
@@ -166,7 +169,7 @@ int _vg_console_exec( int argc, const char *argv[] ){
                        line[ strcspn( line, "\r\n#" ) ] = 0x00;
 
                        if( line[0] != 0x00 ){
-                               vg_execute_console_input( line );
+                               vg_execute_console_input( line, silent );
                        }
                }
 
@@ -209,7 +212,7 @@ static void _vg_console_init(void){
 }
 
 static void vg_console_load_autos(void){
-   _vg_console_exec( 1, (const char *[]){ "auto.conf" } );
+   _vg_console_exec( 2, (const char *[]){ "auto.conf", "silent" } );
 }
 
 static void _vg_console_write_persistent(void){
@@ -310,7 +313,7 @@ static vg_cmd *vg_console_match_cmd( const char *kw )
    return NULL;
 }
 
-static void vg_execute_console_input( const char *cmd )
+static void vg_execute_console_input( const char *cmd, bool silent )
 {
        char temp[512];
        char const *args[8];
@@ -328,7 +331,7 @@ static void vg_execute_console_input( const char *cmd )
       /* Cvar Matched, try get value */
       if( arg_count >= 2 ){
          if( cv->flags & VG_VAR_CHEAT ){
-            if( !vg_console.cheats ){
+            if( !vg_console.cheats && !silent ){
                vg_error( "variable is cheat protected\n" );
                return;
             }
@@ -367,7 +370,8 @@ static void vg_execute_console_input( const char *cmd )
       return;
    }
        
-       vg_error( "No command/var named '%s'. Use 'list' to view all\n", args[0] );
+   if( !silent )
+      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 ){
@@ -671,7 +675,7 @@ static void _vg_console_on_enter( char *buf, u32 len )
       }
 
       vg_console.history_pos = -1;
-      vg_execute_console_input( vg_console.input );
+      vg_execute_console_input( vg_console.input, 0 );
       _ui_textbox_move_cursor( &vg_ui.textbox.cursor_user,
                                &vg_ui.textbox.cursor_pos, -10000, 1 );