1
0
forked from 0ad/0ad

Replaces global g_VSync state by VideoMode property.

This was SVN commit r25504.
This commit is contained in:
Vladislav Belov 2021-05-21 21:33:43 +00:00
parent b2d0bd9a81
commit 7ae43c149e
5 changed files with 45 additions and 41 deletions

View File

@ -267,7 +267,7 @@ static void PumpEvents()
*/
inline static void LimitFPS()
{
if (g_VSync)
if (g_VideoMode.IsVSyncEnabled())
return;
double fpsLimit = 0.0;

View File

@ -35,7 +35,6 @@ bool g_PauseOnFocusLoss = false;
int g_xres, g_yres;
float g_GuiScale = 1.0f;
bool g_VSync = false;
bool g_Quickstart = false;
bool g_DisableAudio = false;
@ -47,8 +46,6 @@ bool g_DisableAudio = false;
// Fill in the globals from the config files.
static void LoadGlobals()
{
CFG_GET_VAL("vsync", g_VSync);
CFG_GET_VAL("pauseonfocusloss", g_PauseOnFocusLoss);
CFG_GET_VAL("gui.scale", g_GuiScale);

View File

@ -25,7 +25,6 @@ extern bool g_PauseOnFocusLoss;
extern int g_xres, g_yres;
extern float g_GuiScale;
extern bool g_VSync;
extern bool g_Quickstart;
extern bool g_DisableAudio;

View File

@ -23,8 +23,8 @@
#include "graphics/GameView.h"
#include "gui/GUIManager.h"
#include "lib/config2.h"
#include "lib/ogl.h"
#include "lib/external_libraries/libsdl.h"
#include "lib/ogl.h"
#include "lib/sysdep/gfx.h"
#include "lib/tex/tex.h"
#include "ps/CConsole.h"
@ -33,15 +33,14 @@
#include "ps/CStr.h"
#include "ps/Filesystem.h"
#include "ps/Game.h"
#include "ps/Pyrogenesis.h"
#include "ps/GameSetup/Config.h"
#include "ps/Pyrogenesis.h"
#include "renderer/Renderer.h"
#if OS_MACOSX
# include "lib/sysdep/os/osx/osx_sys_version.h"
#endif
static int DEFAULT_WINDOW_W = 1024;
static int DEFAULT_WINDOW_H = 768;
@ -51,13 +50,8 @@ static int DEFAULT_FULLSCREEN_H = 768;
CVideoMode g_VideoMode;
CVideoMode::CVideoMode() :
m_IsFullscreen(false), m_IsInitialised(false), m_Window(NULL),
m_PreferredW(0), m_PreferredH(0), m_PreferredBPP(0), m_PreferredFreq(0),
m_ConfigW(0), m_ConfigH(0), m_ConfigBPP(0), m_ConfigFullscreen(false),
m_WindowedW(DEFAULT_WINDOW_W), m_WindowedH(DEFAULT_WINDOW_H), m_WindowedX(0), m_WindowedY(0)
{
// (m_ConfigFullscreen defaults to false, so users don't get stuck if
// e.g. half the filesystem is missing and the config files aren't loaded)
}
void CVideoMode::ReadConfig()
@ -70,6 +64,8 @@ void CVideoMode::ReadConfig()
CFG_GET_VAL("yres", m_ConfigH);
CFG_GET_VAL("bpp", m_ConfigBPP);
CFG_GET_VAL("display", m_ConfigDisplay);
CFG_GET_VAL("vsync", m_ConfigVSync);
}
bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen)
@ -265,7 +261,7 @@ bool CVideoMode::InitSDL()
return false;
}
SDL_GL_SetSwapInterval(g_VSync ? 1 : 0);
SDL_GL_SetSwapInterval(m_ConfigVSync ? 1 : 0);
// Work around a bug in the proprietary Linux ATI driver (at least versions 8.16.20 and 8.14.13).
// The driver appears to register its own atexit hook on context creation.
@ -457,43 +453,49 @@ int CVideoMode::GetBestBPP()
return 32;
}
int CVideoMode::GetXRes()
int CVideoMode::GetXRes() const
{
ENSURE(m_IsInitialised);
return m_CurrentW;
}
int CVideoMode::GetYRes()
int CVideoMode::GetYRes() const
{
ENSURE(m_IsInitialised);
return m_CurrentH;
}
int CVideoMode::GetBPP()
int CVideoMode::GetBPP() const
{
ENSURE(m_IsInitialised);
return m_CurrentBPP;
}
int CVideoMode::GetDesktopXRes()
bool CVideoMode::IsVSyncEnabled() const
{
ENSURE(m_IsInitialised);
return m_ConfigVSync;
}
int CVideoMode::GetDesktopXRes() const
{
ENSURE(m_IsInitialised);
return m_PreferredW;
}
int CVideoMode::GetDesktopYRes()
int CVideoMode::GetDesktopYRes() const
{
ENSURE(m_IsInitialised);
return m_PreferredH;
}
int CVideoMode::GetDesktopBPP()
int CVideoMode::GetDesktopBPP() const
{
ENSURE(m_IsInitialised);
return m_PreferredBPP;
}
int CVideoMode::GetDesktopFreq()
int CVideoMode::GetDesktopFreq() const
{
ENSURE(m_IsInitialised);
return m_PreferredFreq;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2020 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -73,14 +73,16 @@ public:
*/
static void UpdateRenderer(int w, int h);
int GetXRes();
int GetYRes();
int GetBPP();
int GetXRes() const;
int GetYRes() const;
int GetBPP() const;
int GetDesktopXRes();
int GetDesktopYRes();
int GetDesktopBPP();
int GetDesktopFreq();
bool IsVSyncEnabled() const;
int GetDesktopXRes() const;
int GetDesktopYRes() const;
int GetDesktopBPP() const;
int GetDesktopFreq() const;
SDL_Window* GetWindow();
@ -96,23 +98,27 @@ private:
* important, just for verifying that the callers call our methods in
* the right order.)
*/
bool m_IsInitialised;
bool m_IsInitialised = false;
SDL_Window* m_Window;
SDL_Window* m_Window = nullptr;
// Initial desktop settings.
// Frequency is in Hz, and BPP means bits per pixels (not bytes per pixels).
int m_PreferredW;
int m_PreferredH;
int m_PreferredBPP;
int m_PreferredFreq;
int m_PreferredW = 0;
int m_PreferredH = 0;
int m_PreferredBPP = 0;
int m_PreferredFreq = 0;
// Config file settings (0 if unspecified)
int m_ConfigW;
int m_ConfigH;
int m_ConfigBPP;
int m_ConfigDisplay;
bool m_ConfigFullscreen;
int m_ConfigW = 0;
int m_ConfigH = 0;
int m_ConfigBPP = 0;
int m_ConfigDisplay = 0;
bool m_ConfigVSync = false;
// (m_ConfigFullscreen defaults to false, so users don't get stuck if
// e.g. half the filesystem is missing and the config files aren't loaded).
bool m_ConfigFullscreen = false;
// If we're fullscreen, size/position of window when we were last windowed (or the default window
// size/position if we started fullscreen), to support switching back to the old window size/position
@ -122,7 +128,7 @@ private:
int m_WindowedY;
// Whether we're currently being displayed fullscreen
bool m_IsFullscreen;
bool m_IsFullscreen = false;
// The last mode selected
int m_CurrentW;