From 5d7d5319fdd7b63c5a161364d740394ef2f5f8db Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 19 May 2023 05:55:06 +0300 Subject: [PATCH] engine: move ref cvars to static allocation --- engine/client/cl_main.c | 8 +++---- engine/client/cl_parse.c | 6 +++--- engine/client/cl_qparse.c | 6 +++--- engine/client/cl_scrn.c | 6 +++--- engine/client/cl_view.c | 4 ++-- engine/client/client.h | 4 ++-- engine/client/keys.c | 4 ++-- engine/client/ref_common.c | 36 +++++++++++++++---------------- engine/client/ref_common.h | 6 +++--- engine/client/vid_common.h | 2 +- engine/common/common.h | 2 +- engine/common/host.c | 6 +++--- engine/platform/linux/vid_fbdev.c | 6 +++--- engine/platform/sdl/vid_sdl.c | 14 ++++++------ engine/ref_api.h | 4 ++-- ref/gl/gl_backend.c | 10 ++++----- ref/gl/gl_local.h | 1 - ref/gl/gl_opengl.c | 2 -- ref/soft/r_local.h | 1 - 19 files changed, 62 insertions(+), 66 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 8c2412d1..f899555c 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -480,7 +480,7 @@ qboolean CL_ProcessShowTexturesCmds( usercmd_t *cmd ) int changed; int pressed, released; - if( !gl_showtextures->value || CL_IsDevOverviewMode( )) + if( !r_showtextures.value || CL_IsDevOverviewMode( )) return false; changed = (oldbuttons ^ cmd->buttons); @@ -488,9 +488,9 @@ qboolean CL_ProcessShowTexturesCmds( usercmd_t *cmd ) released = changed & (~cmd->buttons); if( released & ( IN_RIGHT|IN_MOVERIGHT )) - Cvar_SetValue( "r_showtextures", gl_showtextures->value + 1 ); + Cvar_SetValue( "r_showtextures", r_showtextures.value + 1 ); if( released & ( IN_LEFT|IN_MOVELEFT )) - Cvar_SetValue( "r_showtextures", Q_max( 1, gl_showtextures->value - 1 )); + Cvar_SetValue( "r_showtextures", Q_max( 1, r_showtextures.value - 1 )); oldbuttons = cmd->buttons; return true; @@ -511,7 +511,7 @@ qboolean CL_ProcessOverviewCmds( usercmd_t *cmd ) float step = (2.0f / size) * host.realframetime; float step2 = step * 100.0f * (2.0f / ov->flZoom); - if( !CL_IsDevOverviewMode() || gl_showtextures->value ) + if( !CL_IsDevOverviewMode() || r_showtextures.value ) return false; if( ov->flZoom < 0.0f ) sign = -1; diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 7471d80c..0f7b6395 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -931,10 +931,10 @@ void CL_ParseServerData( sizebuf_t *msg, qboolean legacy ) // loading user settings CSCR_LoadDefaultCVars( "user.scr" ); - if( r_decals->value > mp_decals.value ) - Cvar_SetValue( "r_decals", mp_decals.value ); + if( r_decals.value > mp_decals.value ) + Cvar_DirectSet( &r_decals, mp_decals.string ); } - else Cvar_Reset( "r_decals" ); + else Cvar_DirectSet( &r_decals, NULL ); // set the background state if( cls.demoplayback && ( cls.demonum != -1 )) diff --git a/engine/client/cl_qparse.c b/engine/client/cl_qparse.c index be6752a0..e9da6024 100644 --- a/engine/client/cl_qparse.c +++ b/engine/client/cl_qparse.c @@ -232,10 +232,10 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg ) // loading user settings CSCR_LoadDefaultCVars( "user.scr" ); - if( r_decals->value > mp_decals.value ) - Cvar_SetValue( "r_decals", mp_decals.value ); + if( r_decals.value > mp_decals.value ) + Cvar_DirectSet( &r_decals, mp_decals.string ); } - else Cvar_Reset( "r_decals" ); + else Cvar_DirectSet( &r_decals, NULL ); if( cl.background ) // tell the game parts about background state Cvar_FullSet( "cl_background", "1", FCVAR_READ_ONLY ); diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index f476b162..9d70ae73 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -366,7 +366,7 @@ void SCR_BeginLoadingPlaque( qboolean is_background ) cl.video_prepped = false; if( !Host_IsDedicated() ) - oldclear = gl_clear->value; + oldclear = gl_clear.value; if( CL_IsInMenu( ) && !cls.changedemo && !is_background ) { @@ -382,7 +382,7 @@ void SCR_BeginLoadingPlaque( qboolean is_background ) return; if( !Host_IsDedicated() ) - gl_clear->value = 0.0f; + gl_clear.value = 0.0f; if( is_background ) IN_MouseSavePos( ); cls.draw_changelevel = !is_background; @@ -391,7 +391,7 @@ void SCR_BeginLoadingPlaque( qboolean is_background ) cl.background = is_background; // set right state before svc_serverdata is came if( !Host_IsDedicated() ) - gl_clear->value = oldclear; + gl_clear.value = oldclear; // SNDDMA_LockSound(); } diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index fca79f63..8fd5a29b 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -311,7 +311,7 @@ void V_GetRefParams( ref_params_t *fd, ref_viewpass_t *rvp ) rvp->fov_y = V_CalcFov( &rvp->fov_x, clgame.viewport[2], clgame.viewport[3] ); // adjust FOV for widescreen - if( refState.wideScreen && r_adjust_fov->value ) + if( refState.wideScreen && r_adjust_fov.value ) V_AdjustFov( &rvp->fov_x, &rvp->fov_y, clgame.viewport[2], clgame.viewport[3], false ); rvp->flags = 0; @@ -472,7 +472,7 @@ void R_ShowTree( void ) float y = NODE_INTERVAL_Y(1.0f); mleaf_t *viewleaf; - if( !cl.worldmodel || !CVAR_TO_BOOL( r_showtree )) + if( !cl.worldmodel || !r_showtree.value ) return; world.recursion_level = 0; diff --git a/engine/client/client.h b/engine/client/client.h index c4f6aa4f..984cca61 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -683,7 +683,7 @@ extern convar_t *cl_clockreset; extern convar_t *cl_fixtimerate; extern convar_t *hud_fontscale; extern convar_t *hud_scale; -extern convar_t *gl_showtextures; +extern convar_t r_showtextures; extern convar_t *cl_bmodelinterp; extern convar_t *cl_lw; // local weapons extern convar_t *cl_charset; @@ -697,7 +697,7 @@ extern convar_t *v_dark; // start from dark extern convar_t *net_graph; extern convar_t *rate; extern convar_t *m_ignore; -extern convar_t *r_showtree; +extern convar_t r_showtree; extern convar_t *ui_renderworld; //============================================================================= diff --git a/engine/client/keys.c b/engine/client/keys.c index 16d0f839..2022a191 100644 --- a/engine/client/keys.c +++ b/engine/client/keys.c @@ -719,10 +719,10 @@ void GAME_EXPORT Key_Event( int key, int down ) switch( cls.key_dest ) { case key_game: - if( CVAR_TO_BOOL( gl_showtextures )) + if( r_showtextures.value ) { // close texture atlas - Cvar_SetValue( "r_showtextures", 0.0f ); + Cvar_DirectSet( &r_showtextures, "0" ); return; } else if( host.mouse_visible && cls.state != ca_cinematic ) diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index 79a120d6..707852be 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -8,14 +8,14 @@ struct ref_state_s ref; ref_globals_t refState; -convar_t *gl_vsync; -convar_t *gl_showtextures; -convar_t *r_decals; -convar_t *r_adjust_fov; -convar_t *r_showtree; -convar_t *gl_msaa_samples; -convar_t *gl_clear; -convar_t *r_refdll; +CVAR_DEFINE_AUTO( gl_vsync, "0", FCVAR_ARCHIVE, "enable vertical syncronization" ); +CVAR_DEFINE_AUTO( r_showtextures, "0", FCVAR_CHEAT, "show all uploaded textures" ); +CVAR_DEFINE_AUTO( r_adjust_fov, "1", FCVAR_ARCHIVE, "making FOV adjustment for wide-screens" ); +CVAR_DEFINE_AUTO( r_decals, "4096", FCVAR_ARCHIVE, "sets the maximum number of decals" ); +CVAR_DEFINE_AUTO( gl_msaa_samples, "0", FCVAR_GLCONFIG, "samples number for multisample anti-aliasing" ); +CVAR_DEFINE_AUTO( gl_clear, "0", FCVAR_ARCHIVE, "clearing screen after each frame" ); +CVAR_DEFINE_AUTO( r_showtree, "0", FCVAR_ARCHIVE, "build the graph of visible BSP tree" ); +static CVAR_DEFINE_AUTO( r_refdll, "", FCVAR_RENDERINFO, "choose renderer implementation, if supported" ); void R_GetTextureParms( int *w, int *h, int texnum ) { @@ -618,14 +618,14 @@ qboolean R_Init( void ) qboolean success = false; string requested; - gl_vsync = Cvar_Get( "gl_vsync", "0", FCVAR_ARCHIVE, "enable vertical syncronization" ); - gl_showtextures = Cvar_Get( "r_showtextures", "0", FCVAR_CHEAT, "show all uploaded textures" ); - r_adjust_fov = Cvar_Get( "r_adjust_fov", "1", FCVAR_ARCHIVE, "making FOV adjustment for wide-screens" ); - r_decals = Cvar_Get( "r_decals", "4096", FCVAR_ARCHIVE, "sets the maximum number of decals" ); - gl_msaa_samples = Cvar_Get( "gl_msaa_samples", "0", FCVAR_GLCONFIG, "samples number for multisample anti-aliasing" ); - gl_clear = Cvar_Get( "gl_clear", "0", FCVAR_ARCHIVE, "clearing screen after each frame" ); - r_showtree = Cvar_Get( "r_showtree", "0", FCVAR_ARCHIVE, "build the graph of visible BSP tree" ); - r_refdll = Cvar_Get( "r_refdll", "", FCVAR_RENDERINFO, "choose renderer implementation, if supported" ); + Cvar_RegisterVariable( &gl_vsync ); + Cvar_RegisterVariable( &r_showtextures ); + Cvar_RegisterVariable( &r_adjust_fov ); + Cvar_RegisterVariable( &r_decals ); + Cvar_RegisterVariable( &gl_msaa_samples ); + Cvar_RegisterVariable( &gl_clear ); + Cvar_RegisterVariable( &r_showtree ); + Cvar_RegisterVariable( &r_refdll ); // cvars that are expected to exist Cvar_Get( "r_speeds", "0", FCVAR_ARCHIVE, "shows renderer speeds" ); @@ -669,9 +669,9 @@ qboolean R_Init( void ) if( !success && Sys_GetParmFromCmdLine( "-ref", requested )) success = R_LoadRenderer( requested ); - if( !success && COM_CheckString( r_refdll->string )) + if( !success && COM_CheckString( r_refdll.string )) { - Q_strncpy( requested, r_refdll->string, sizeof( requested )); + Q_strncpy( requested, r_refdll.string, sizeof( requested )); success = R_LoadRenderer( requested ); } diff --git a/engine/client/ref_common.h b/engine/client/ref_common.h index 3904d58b..7c7d9387 100644 --- a/engine/client/ref_common.h +++ b/engine/client/ref_common.h @@ -46,9 +46,9 @@ void R_GetTextureParms( int *w, int *h, int texnum ); void GL_RenderFrame( const struct ref_viewpass_s *rvp ); // common engine and renderer cvars -extern convar_t *r_decals; -extern convar_t *r_adjust_fov; -extern convar_t *gl_clear; +extern convar_t r_decals; +extern convar_t r_adjust_fov; +extern convar_t gl_clear; qboolean R_Init( void ); void R_Shutdown( void ); diff --git a/engine/client/vid_common.h b/engine/client/vid_common.h index 36be09cf..12420bc5 100644 --- a/engine/client/vid_common.h +++ b/engine/client/vid_common.h @@ -34,8 +34,8 @@ extern convar_t vid_fullscreen; extern convar_t vid_highdpi; extern convar_t window_xpos; extern convar_t window_ypos; +extern convar_t gl_msaa_samples; -extern convar_t *gl_msaa_samples; void R_SaveVideoMode( int w, int h, int render_w, int render_h ); void VID_SetDisplayTransform( int *render_w, int *render_h ); void VID_CheckChanges( void ); diff --git a/engine/common/common.h b/engine/common/common.h index b6579c46..92123280 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -153,7 +153,7 @@ void DBG_AssertFunction( qboolean fExpr, const char* szExpr, const char* szFile, #define Assert( f ) #endif -extern convar_t *gl_vsync; +extern convar_t gl_vsync; extern convar_t *scr_loading; extern convar_t *scr_download; extern convar_t *cmd_scripting; diff --git a/engine/common/host.c b/engine/common/host.c index 53b295b0..e836c4e5 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -278,7 +278,7 @@ static int Host_CalcSleep( void ) #ifndef XASH_DEDICATED // never sleep in timedemo for benchmarking purposes // also don't sleep with vsync for less lag - if( CL_IsTimeDemo( ) || CVAR_TO_BOOL( gl_vsync )) + if( CL_IsTimeDemo( ) || gl_vsync.value ) return 0; #endif @@ -599,12 +599,12 @@ double Host_CalcFPS( void ) } else if( Host_IsLocalGame( )) { - if( !CVAR_TO_BOOL( gl_vsync )) + if( !gl_vsync.value ) fps = host_maxfps->value; } else { - if( !CVAR_TO_BOOL( gl_vsync )) + if( !gl_vsync.value ) { fps = host_maxfps->value; if( fps == 0.0 ) fps = MAX_FPS; diff --git a/engine/platform/linux/vid_fbdev.c b/engine/platform/linux/vid_fbdev.c index fe1d823e..c616cc09 100644 --- a/engine/platform/linux/vid_fbdev.c +++ b/engine/platform/linux/vid_fbdev.c @@ -168,11 +168,11 @@ void GL_UpdateSwapInterval( void ) { // setup fb vsync here fb.vsync = false; - SetBits( gl_vsync->flags, FCVAR_CHANGED ); + SetBits( gl_vsync.flags, FCVAR_CHANGED ); } - else if( FBitSet( gl_vsync->flags, FCVAR_CHANGED )) + else if( FBitSet( gl_vsync.flags, FCVAR_CHANGED )) { - ClearBits( gl_vsync->flags, FCVAR_CHANGED ); + ClearBits( gl_vsync.flags, FCVAR_CHANGED ); fb.vsync = true; } } diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index bfe43aec..4cf7873b 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -455,13 +455,13 @@ void GL_UpdateSwapInterval( void ) if( cls.state < ca_active ) { SDL_GL_SetSwapInterval( 0 ); - SetBits( gl_vsync->flags, FCVAR_CHANGED ); + SetBits( gl_vsync.flags, FCVAR_CHANGED ); } - else if( FBitSet( gl_vsync->flags, FCVAR_CHANGED )) + else if( FBitSet( gl_vsync.flags, FCVAR_CHANGED )) { - ClearBits( gl_vsync->flags, FCVAR_CHANGED ); + ClearBits( gl_vsync.flags, FCVAR_CHANGED ); - if( SDL_GL_SetSwapInterval( gl_vsync->value ) ) + if( SDL_GL_SetSwapInterval( gl_vsync.value ) ) Con_Reportf( S_ERROR "SDL_GL_SetSwapInterval: %s\n", SDL_GetError( ) ); } #endif // SDL_VERSION_ATLEAST( 2, 0, 0 ) @@ -676,7 +676,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) glw_state.safe++; - if( !gl_msaa_samples->value && glw_state.safe == SAFE_NOMSAA ) + if( !gl_msaa_samples.value && glw_state.safe == SAFE_NOMSAA ) glw_state.safe++; // no need to skip msaa, if we already disabled it GL_SetupAttributes(); // re-choose attributes @@ -816,7 +816,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) glw_state.safe++; - if( !gl_msaa_samples->value && glw_state.safe == SAFE_NOMSAA ) + if( !gl_msaa_samples.value && glw_state.safe == SAFE_NOMSAA ) glw_state.safe++; // no need to skip msaa, if we already disabled it GL_SetupAttributes(); // re-choose attributes @@ -1131,7 +1131,7 @@ qboolean VID_SetMode( void ) else ClearBits( vid_fullscreen.flags, FCVAR_CHANGED ); - SetBits( gl_vsync->flags, FCVAR_CHANGED ); + SetBits( gl_vsync.flags, FCVAR_CHANGED ); if(( err = R_ChangeDisplaySettings( iScreenWidth, iScreenHeight, vid_fullscreen.value )) == rserr_ok ) { diff --git a/engine/ref_api.h b/engine/ref_api.h index 944afbd7..18cea090 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -627,7 +627,7 @@ typedef int (*REFAPI)( int version, ref_interface_t *pFunctionTable, ref_api_t* #define DECLARE_ENGINE_SHARED_CVAR( x, y ) extern cvar_t *x; #define RETRIEVE_ENGINE_SHARED_CVAR( x, y ) \ if(!( x = gEngfuncs.pfnGetCvarPointer( #y, 0 ) )) \ - gEngfuncs.Host_Error( S_ERROR "engine betrayed us and didn't gave us %s cvar pointer\n", #y ); + gEngfuncs.Host_Error( S_ERROR "engine didn't gave us %s cvar pointer\n", #y ); #define ENGINE_SHARED_CVAR_NAME( f, x, y ) f( x, y ) #define ENGINE_SHARED_CVAR( f, x ) ENGINE_SHARED_CVAR_NAME( f, x, x ) @@ -638,7 +638,7 @@ typedef int (*REFAPI)( int version, ref_interface_t *pFunctionTable, ref_api_t* #define ENGINE_SHARED_CVAR_LIST( f ) \ ENGINE_SHARED_CVAR_NAME( f, vid_gamma, gamma ) \ ENGINE_SHARED_CVAR_NAME( f, vid_brightness, brightness ) \ - ENGINE_SHARED_CVAR_NAME( f, gl_showtextures, r_showtextures ) \ + ENGINE_SHARED_CVAR( f, r_showtextures ) \ ENGINE_SHARED_CVAR( f, r_speeds ) \ ENGINE_SHARED_CVAR( f, r_fullbright ) \ ENGINE_SHARED_CVAR( f, r_norefresh ) \ diff --git a/ref/gl/gl_backend.c b/ref/gl/gl_backend.c index c4250509..9d595d20 100644 --- a/ref/gl/gl_backend.c +++ b/ref/gl/gl_backend.c @@ -611,7 +611,7 @@ void R_ShowTextures( void ) static qboolean showHelp = true; string shortname; - if( !CVAR_TO_BOOL( gl_showtextures )) + if( !r_showtextures->value ) return; if( showHelp ) @@ -629,8 +629,8 @@ void R_ShowTextures( void ) rebuild_page: total = base_w * base_h; - start = total * (gl_showtextures->value - 1); - end = total * gl_showtextures->value; + start = total * (r_showtextures->value - 1); + end = total * r_showtextures->value; if( end > MAX_TEXTURES ) end = MAX_TEXTURES; w = gpGlobals->width / base_w; @@ -645,10 +645,10 @@ rebuild_page: if( pglIsTexture( image->texnum )) j++; } - if( i == MAX_TEXTURES && gl_showtextures->value != 1 ) + if( i == MAX_TEXTURES && r_showtextures->value != 1 ) { // bad case, rewind to one and try again - gEngfuncs.Cvar_SetValue( "r_showtextures", Q_max( 1, gl_showtextures->value - 1 )); + gEngfuncs.Cvar_SetValue( "r_showtextures", Q_max( 1, r_showtextures->value - 1 )); if( ++numTries < 2 ) goto rebuild_page; // to prevent infinite loop } diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index 877cd70e..d252e779 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -736,7 +736,6 @@ extern cvar_t *r_lighting_ambient; extern cvar_t *r_studio_lambert; extern cvar_t *r_detailtextures; extern cvar_t *r_drawentities; -extern cvar_t *r_decals; extern cvar_t *r_novis; extern cvar_t *r_nocull; extern cvar_t *r_lockpvs; diff --git a/ref/gl/gl_opengl.c b/ref/gl/gl_opengl.c index d16738fd..16664ac8 100644 --- a/ref/gl/gl_opengl.c +++ b/ref/gl/gl_opengl.c @@ -25,8 +25,6 @@ cvar_t *r_lighting_extended; cvar_t *r_lighting_modulate; cvar_t *r_lighting_ambient; cvar_t *r_detailtextures; -cvar_t *r_adjust_fov; -cvar_t *r_decals; cvar_t *r_novis; cvar_t *r_nocull; cvar_t *r_lockpvs; diff --git a/ref/soft/r_local.h b/ref/soft/r_local.h index 2940d6fe..4b2120a1 100644 --- a/ref/soft/r_local.h +++ b/ref/soft/r_local.h @@ -1103,7 +1103,6 @@ extern cvar_t *sw_stipplealpha; extern cvar_t *sw_surfcacheoverride; extern cvar_t *sw_waterwarp; extern cvar_t *sw_texfilt; -extern cvar_t *r_decals; extern cvar_t *r_traceglow; extern cvar_t *sw_notransbrushes; extern cvar_t *sw_noalphabrushes;