Browse Source

engine: move vid cvars to static allocation

pull/2/head
Alibek Omarov 2 years ago
parent
commit
d4470402ee
  1. 4
      engine/client/ref_common.c
  2. 89
      engine/client/vid_common.c
  3. 9
      engine/client/vid_common.h
  4. 19
      engine/platform/linux/vid_fbdev.c
  5. 17
      engine/platform/sdl/events.c
  6. 40
      engine/platform/sdl/vid_sdl.c

4
engine/client/ref_common.c

@ -557,11 +557,11 @@ static void SetFullscreenModeFromCommandLine( void )
#if !XASH_MOBILE_PLATFORM #if !XASH_MOBILE_PLATFORM
if( Sys_CheckParm( "-fullscreen" )) if( Sys_CheckParm( "-fullscreen" ))
{ {
Cvar_DirectSet( vid_fullscreen, "1" ); Cvar_DirectSet( &vid_fullscreen, "1" );
} }
else if( Sys_CheckParm( "-windowed" )) else if( Sys_CheckParm( "-windowed" ))
{ {
Cvar_DirectSet( vid_fullscreen, "0" ); Cvar_DirectSet( &vid_fullscreen, "0" );
} }
#endif #endif
} }

89
engine/client/vid_common.c

@ -20,21 +20,21 @@ GNU General Public License for more details.
#include "vid_common.h" #include "vid_common.h"
#include "platform/platform.h" #include "platform/platform.h"
#define WINDOW_NAME XASH_ENGINE_NAME " Window" // Half-Life static CVAR_DEFINE( window_width, "width", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen width" );
convar_t *vid_fullscreen; static CVAR_DEFINE( window_height, "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" );
convar_t *vid_mode; static CVAR_DEFINE( vid_brightness, "brightness", "0.0", FCVAR_ARCHIVE, "brightness factor" );
convar_t *vid_brightness; static CVAR_DEFINE( vid_gamma, "gamma", "2.5", FCVAR_ARCHIVE, "gamma amount" );
convar_t *vid_gamma; static CVAR_DEFINE_AUTO( vid_mode, "0", FCVAR_RENDERINFO, "current video mode index (used only for storage)" );
convar_t *vid_highdpi; static CVAR_DEFINE_AUTO( vid_rotate, "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen rotation (0-3)" );
static CVAR_DEFINE_AUTO( vid_scale, "1.0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "pixel scale" );
CVAR_DEFINE_AUTO( vid_highdpi, "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" );
CVAR_DEFINE( vid_fullscreen, "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" );
CVAR_DEFINE( window_xpos, "_window_xpos", "-1", FCVAR_RENDERINFO, "window position by horizontal" );
CVAR_DEFINE( window_ypos, "_window_ypos", "-1", FCVAR_RENDERINFO, "window position by vertical" );
glwstate_t glw_state; glwstate_t glw_state;
convar_t *window_xpos;
convar_t *window_ypos;
convar_t *vid_rotate;
convar_t *vid_scale;
/* /*
================= =================
VID_StartupGamma VID_StartupGamma
@ -42,10 +42,10 @@ VID_StartupGamma
*/ */
void VID_StartupGamma( void ) void VID_StartupGamma( void )
{ {
BuildGammaTable( vid_gamma->value, vid_brightness->value ); BuildGammaTable( vid_gamma.value, vid_brightness.value );
Con_Reportf( "VID_StartupGamma: gamma %g brightness %g\n", vid_gamma->value, vid_brightness->value ); Con_Reportf( "VID_StartupGamma: gamma %g brightness %g\n", vid_gamma.value, vid_brightness.value );
ClearBits( vid_brightness->flags, FCVAR_CHANGED ); ClearBits( vid_brightness.flags, FCVAR_CHANGED );
ClearBits( vid_gamma->flags, FCVAR_CHANGED ); ClearBits( vid_gamma.flags, FCVAR_CHANGED );
} }
/* /*
@ -145,6 +145,36 @@ void VID_CheckChanges( void )
} }
} }
/*
===============
VID_SetDisplayTransform
notify ref dll about screen transformations
===============
*/
void VID_SetDisplayTransform( int *render_w, int *render_h )
{
uint rotate = vid_rotate.value;
if( ref.dllFuncs.R_SetDisplayTransform( rotate, 0, 0, vid_scale.value, vid_scale.value ))
{
if( rotate & 1 )
{
int swap = *render_w;
*render_w = *render_h;
*render_h = swap;
}
*render_h /= vid_scale.value;
*render_w /= vid_scale.value;
}
else
{
Con_Printf( S_WARN "failed to setup screen transform\n" );
}
}
static void VID_Mode_f( void ) static void VID_Mode_f( void )
{ {
int w, h; int w, h;
@ -177,25 +207,24 @@ static void VID_Mode_f( void )
return; return;
} }
R_ChangeDisplaySettings( w, h, Cvar_VariableInteger( "fullscreen" ) ); R_ChangeDisplaySettings( w, h, !!vid_fullscreen.value );
} }
void VID_Init( void ) void VID_Init( void )
{ {
// system screen width and height (don't suppose for change from console at all) // system screen width and height (don't suppose for change from console at all)
Cvar_Get( "width", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen width" ); Cvar_RegisterVariable( &window_width );
Cvar_Get( "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" ); Cvar_RegisterVariable( &window_height );
window_xpos = Cvar_Get( "_window_xpos", "-1", FCVAR_RENDERINFO, "window position by horizontal" ); Cvar_RegisterVariable( &vid_mode );
window_ypos = Cvar_Get( "_window_ypos", "-1", FCVAR_RENDERINFO, "window position by vertical" ); Cvar_RegisterVariable( &vid_highdpi );
Cvar_RegisterVariable( &vid_rotate );
vid_gamma = Cvar_Get( "gamma", "2.5", FCVAR_ARCHIVE, "gamma amount" ); Cvar_RegisterVariable( &vid_scale );
vid_brightness = Cvar_Get( "brightness", "0.0", FCVAR_ARCHIVE, "brightness factor" ); Cvar_RegisterVariable( &vid_fullscreen );
vid_fullscreen = Cvar_Get( "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" ); Cvar_RegisterVariable( &vid_brightness );
vid_mode = Cvar_Get( "vid_mode", "0", FCVAR_RENDERINFO, "current video mode index (used just for storage)" ); Cvar_RegisterVariable( &vid_gamma );
vid_highdpi = Cvar_Get( "vid_highdpi", "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" ); Cvar_RegisterVariable( &window_xpos );
vid_rotate = Cvar_Get( "vid_rotate", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen rotation (0-3)" ); Cvar_RegisterVariable( &window_ypos );
vid_scale = Cvar_Get( "vid_scale", "1.0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "pixel scale" );
// a1ba: planned to be named vid_mode for compability // a1ba: planned to be named vid_mode for compability
// but supported mode list is filled by backends, so numbers are not portable any more // but supported mode list is filled by backends, so numbers are not portable any more

9
engine/client/vid_common.h

@ -30,13 +30,14 @@ extern glwstate_t glw_state;
#define VID_MIN_HEIGHT 200 #define VID_MIN_HEIGHT 200
#define VID_MIN_WIDTH 320 #define VID_MIN_WIDTH 320
extern convar_t *vid_fullscreen; extern convar_t vid_fullscreen;
extern convar_t *vid_highdpi; extern convar_t vid_highdpi;
extern convar_t *vid_rotate; extern convar_t window_xpos;
extern convar_t *vid_scale; 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 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 ); void VID_CheckChanges( void );
const char *VID_GetModeString( int vid_mode ); const char *VID_GetModeString( int vid_mode );
void VID_StartupGamma( void ); void VID_StartupGamma( void );

19
engine/platform/linux/vid_fbdev.c

@ -122,7 +122,6 @@ qboolean VID_SetMode( void )
rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
{ {
int render_w, render_h; int render_w, render_h;
uint rotate = vid_rotate->value;
FB_GetScreenRes( &width, &height ); FB_GetScreenRes( &width, &height );
@ -131,23 +130,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
Con_Reportf( "R_ChangeDisplaySettings: forced resolution to %dx%d)\n", width, height ); Con_Reportf( "R_ChangeDisplaySettings: forced resolution to %dx%d)\n", width, height );
if( ref.dllFuncs.R_SetDisplayTransform( rotate, 0, 0, vid_scale->value, vid_scale->value ) ) VID_SetDisplayTransform( &render_w, &render_h );
{
if( rotate & 1 )
{
int swap = render_w;
render_w = render_h;
render_h = swap;
}
render_h /= vid_scale->value;
render_w /= vid_scale->value;
}
else
{
Con_Printf( S_WARN "failed to setup screen transform\n" );
}
R_SaveVideoMode( width, height, render_w, render_h ); R_SaveVideoMode( width, height, render_w, render_h );
return rserr_ok; return rserr_ok;

17
engine/platform/sdl/events.c

@ -374,7 +374,7 @@ static void SDLash_ActiveEvent( int gain )
SNDDMA_Activate( true ); SNDDMA_Activate( true );
} }
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
if( vid_fullscreen->value ) if( vid_fullscreen.value )
VID_SetMode(); VID_SetMode();
} }
else else
@ -611,10 +611,15 @@ static void SDLash_EventFilter( SDL_Event *event )
switch( event->window.event ) switch( event->window.event )
{ {
case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_MOVED:
if( !vid_fullscreen->value ) if( !vid_fullscreen.value )
{ {
Cvar_SetValue( "_window_xpos", (float)event->window.data1 ); char val[32];
Cvar_SetValue( "_window_ypos", (float)event->window.data2 );
Q_snprintf( val, sizeof( val ), "%d", event->window.data1 );
Cvar_DirectSet( &window_xpos, val );
Q_snprintf( val, sizeof( val ), "%d", event->window.data2 );
Cvar_DirectSet( &window_ypos, val );
} }
break; break;
case SDL_WINDOWEVENT_MINIMIZED: case SDL_WINDOWEVENT_MINIMIZED:
@ -624,7 +629,7 @@ static void SDLash_EventFilter( SDL_Event *event )
case SDL_WINDOWEVENT_RESTORED: case SDL_WINDOWEVENT_RESTORED:
host.status = HOST_FRAME; host.status = HOST_FRAME;
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
if( vid_fullscreen->value ) if( vid_fullscreen.value )
VID_SetMode(); VID_SetMode();
break; break;
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
@ -635,7 +640,7 @@ static void SDLash_EventFilter( SDL_Event *event )
break; break;
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
{ {
if( vid_fullscreen->value ) if( vid_fullscreen.value )
break; break;
VID_SaveWindowSize( event->window.data1, event->window.data2 ); VID_SaveWindowSize( event->window.data1, event->window.data2 );

40
engine/platform/sdl/vid_sdl.c

@ -523,7 +523,6 @@ static qboolean GL_UpdateContext( void )
void VID_SaveWindowSize( int width, int height ) void VID_SaveWindowSize( int width, int height )
{ {
int render_w = width, render_h = height; int render_w = width, render_h = height;
uint rotate = vid_rotate->value;
#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( !glw_state.software ) if( !glw_state.software )
@ -532,24 +531,7 @@ void VID_SaveWindowSize( int width, int height )
SDL_RenderSetLogicalSize( sw.renderer, width, height ); SDL_RenderSetLogicalSize( sw.renderer, width, height );
#endif #endif
if( ref.dllFuncs.R_SetDisplayTransform( rotate, 0, 0, vid_scale->value, vid_scale->value ) ) VID_SetDisplayTransform( &render_w, &render_h );
{
if( rotate & 1 )
{
int swap = render_w;
render_w = render_h;
render_h = swap;
}
render_h /= vid_scale->value;
render_w /= vid_scale->value;
}
else
{
Con_Printf( S_WARN "failed to setup screen transform\n" );
}
R_SaveVideoMode( width, height, render_w, render_h ); R_SaveVideoMode( width, height, render_w, render_h );
} }
@ -561,7 +543,7 @@ static qboolean VID_SetScreenResolution( int width, int height )
static string wndname; static string wndname;
#if !XASH_APPLE #if !XASH_APPLE
if( vid_highdpi->value ) wndFlags |= SDL_WINDOW_ALLOW_HIGHDPI; if( vid_highdpi.value ) wndFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif #endif
Q_strncpy( wndname, GI->title, sizeof( wndname )); Q_strncpy( wndname, GI->title, sizeof( wndname ));
@ -596,7 +578,7 @@ static qboolean VID_SetScreenResolution( int width, int height )
void VID_RestoreScreenResolution( void ) void VID_RestoreScreenResolution( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( !vid_fullscreen->value ) if( !vid_fullscreen.value )
{ {
SDL_SetWindowBordered( host.hWnd, SDL_TRUE ); SDL_SetWindowBordered( host.hWnd, SDL_TRUE );
} }
@ -641,7 +623,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
int xpos, ypos; int xpos, ypos;
const char *localIcoPath; const char *localIcoPath;
if( vid_highdpi->value ) wndFlags |= SDL_WINDOW_ALLOW_HIGHDPI; if( vid_highdpi.value ) wndFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
Q_strncpy( wndname, GI->title, sizeof( wndname )); Q_strncpy( wndname, GI->title, sizeof( wndname ));
if( glw_state.software ) if( glw_state.software )
wndFlags &= ~SDL_WINDOW_OPENGL; wndFlags &= ~SDL_WINDOW_OPENGL;
@ -665,8 +647,8 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
} }
else else
{ {
xpos = Cvar_VariableInteger( "_window_xpos" ); xpos = window_xpos.value;
ypos = Cvar_VariableInteger( "_window_ypos" ); ypos = window_ypos.value;
// don't create window outside of usable display space // don't create window outside of usable display space
if( xpos < r.x || xpos + width > r.x + r.w ) if( xpos < r.x || xpos + width > r.x + r.w )
@ -1144,14 +1126,14 @@ qboolean VID_SetMode( void )
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 ) #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
if( !FBitSet( vid_fullscreen->flags, FCVAR_CHANGED ) ) if( !FBitSet( vid_fullscreen.flags, FCVAR_CHANGED ) )
Cvar_DirectSet( vid_fullscreen, DEFAULT_FULLSCREEN ); Cvar_DirectSet( &vid_fullscreen, DEFAULT_FULLSCREEN );
else else
ClearBits( vid_fullscreen->flags, FCVAR_CHANGED ); 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 ) if(( err = R_ChangeDisplaySettings( iScreenWidth, iScreenHeight, vid_fullscreen.value )) == rserr_ok )
{ {
sdlState.prev_width = iScreenWidth; sdlState.prev_width = iScreenWidth;
sdlState.prev_height = iScreenHeight; sdlState.prev_height = iScreenHeight;
@ -1160,7 +1142,7 @@ qboolean VID_SetMode( void )
{ {
if( err == rserr_invalid_fullscreen ) if( err == rserr_invalid_fullscreen )
{ {
Cvar_DirectSet( vid_fullscreen, "0" ); Cvar_DirectSet( &vid_fullscreen, "0" );
Con_Reportf( S_ERROR "VID_SetMode: fullscreen unavailable in this mode\n" ); Con_Reportf( S_ERROR "VID_SetMode: fullscreen unavailable in this mode\n" );
Sys_Warn("fullscreen unavailable in this mode!"); Sys_Warn("fullscreen unavailable in this mode!");
if(( err = R_ChangeDisplaySettings( iScreenWidth, iScreenHeight, false )) == rserr_ok ) if(( err = R_ChangeDisplaySettings( iScreenWidth, iScreenHeight, false )) == rserr_ok )

Loading…
Cancel
Save