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

89
engine/client/vid_common.c

@ -20,21 +20,21 @@ GNU General Public License for more details. @@ -20,21 +20,21 @@ GNU General Public License for more details.
#include "vid_common.h"
#include "platform/platform.h"
#define WINDOW_NAME XASH_ENGINE_NAME " Window" // Half-Life
convar_t *vid_fullscreen;
convar_t *vid_mode;
convar_t *vid_brightness;
convar_t *vid_gamma;
convar_t *vid_highdpi;
static CVAR_DEFINE( window_width, "width", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen width" );
static CVAR_DEFINE( window_height, "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" );
static CVAR_DEFINE( vid_brightness, "brightness", "0.0", FCVAR_ARCHIVE, "brightness factor" );
static CVAR_DEFINE( vid_gamma, "gamma", "2.5", FCVAR_ARCHIVE, "gamma amount" );
static CVAR_DEFINE_AUTO( vid_mode, "0", FCVAR_RENDERINFO, "current video mode index (used only for storage)" );
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;
convar_t *window_xpos;
convar_t *window_ypos;
convar_t *vid_rotate;
convar_t *vid_scale;
/*
=================
VID_StartupGamma
@ -42,10 +42,10 @@ VID_StartupGamma @@ -42,10 +42,10 @@ VID_StartupGamma
*/
void VID_StartupGamma( void )
{
BuildGammaTable( 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_gamma->flags, FCVAR_CHANGED );
BuildGammaTable( 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_gamma.flags, FCVAR_CHANGED );
}
/*
@ -145,6 +145,36 @@ void VID_CheckChanges( void ) @@ -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 )
{
int w, h;
@ -177,25 +207,24 @@ static void VID_Mode_f( void ) @@ -177,25 +207,24 @@ static void VID_Mode_f( void )
return;
}
R_ChangeDisplaySettings( w, h, Cvar_VariableInteger( "fullscreen" ) );
R_ChangeDisplaySettings( w, h, !!vid_fullscreen.value );
}
void VID_Init( void )
{
// 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_Get( "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" );
window_xpos = Cvar_Get( "_window_xpos", "-1", FCVAR_RENDERINFO, "window position by horizontal" );
window_ypos = Cvar_Get( "_window_ypos", "-1", FCVAR_RENDERINFO, "window position by vertical" );
vid_gamma = Cvar_Get( "gamma", "2.5", FCVAR_ARCHIVE, "gamma amount" );
vid_brightness = Cvar_Get( "brightness", "0.0", FCVAR_ARCHIVE, "brightness factor" );
vid_fullscreen = Cvar_Get( "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" );
vid_mode = Cvar_Get( "vid_mode", "0", FCVAR_RENDERINFO, "current video mode index (used just for storage)" );
vid_highdpi = Cvar_Get( "vid_highdpi", "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" );
vid_rotate = Cvar_Get( "vid_rotate", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen rotation (0-3)" );
vid_scale = Cvar_Get( "vid_scale", "1.0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "pixel scale" );
Cvar_RegisterVariable( &window_width );
Cvar_RegisterVariable( &window_height );
Cvar_RegisterVariable( &vid_mode );
Cvar_RegisterVariable( &vid_highdpi );
Cvar_RegisterVariable( &vid_rotate );
Cvar_RegisterVariable( &vid_scale );
Cvar_RegisterVariable( &vid_fullscreen );
Cvar_RegisterVariable( &vid_brightness );
Cvar_RegisterVariable( &vid_gamma );
Cvar_RegisterVariable( &window_xpos );
Cvar_RegisterVariable( &window_ypos );
// a1ba: planned to be named vid_mode for compability
// 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; @@ -30,13 +30,14 @@ extern glwstate_t glw_state;
#define VID_MIN_HEIGHT 200
#define VID_MIN_WIDTH 320
extern convar_t *vid_fullscreen;
extern convar_t *vid_highdpi;
extern convar_t *vid_rotate;
extern convar_t *vid_scale;
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;
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 );
const char *VID_GetModeString( int vid_mode );
void VID_StartupGamma( void );

19
engine/platform/linux/vid_fbdev.c

@ -122,7 +122,6 @@ qboolean VID_SetMode( void ) @@ -122,7 +122,6 @@ qboolean VID_SetMode( void )
rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
{
int render_w, render_h;
uint rotate = vid_rotate->value;
FB_GetScreenRes( &width, &height );
@ -131,23 +130,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) @@ -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 );
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" );
}
VID_SetDisplayTransform( &render_w, &render_h );
R_SaveVideoMode( width, height, render_w, render_h );
return rserr_ok;

17
engine/platform/sdl/events.c

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

40
engine/platform/sdl/vid_sdl.c

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

Loading…
Cancel
Save