Replaces global g_VSync state by VideoMode property.
This was SVN commit r25504.
This commit is contained in:
parent
b2d0bd9a81
commit
7ae43c149e
@ -267,7 +267,7 @@ static void PumpEvents()
|
|||||||
*/
|
*/
|
||||||
inline static void LimitFPS()
|
inline static void LimitFPS()
|
||||||
{
|
{
|
||||||
if (g_VSync)
|
if (g_VideoMode.IsVSyncEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
double fpsLimit = 0.0;
|
double fpsLimit = 0.0;
|
||||||
|
@ -35,7 +35,6 @@ bool g_PauseOnFocusLoss = false;
|
|||||||
|
|
||||||
int g_xres, g_yres;
|
int g_xres, g_yres;
|
||||||
float g_GuiScale = 1.0f;
|
float g_GuiScale = 1.0f;
|
||||||
bool g_VSync = false;
|
|
||||||
|
|
||||||
bool g_Quickstart = false;
|
bool g_Quickstart = false;
|
||||||
bool g_DisableAudio = false;
|
bool g_DisableAudio = false;
|
||||||
@ -47,8 +46,6 @@ bool g_DisableAudio = false;
|
|||||||
// Fill in the globals from the config files.
|
// Fill in the globals from the config files.
|
||||||
static void LoadGlobals()
|
static void LoadGlobals()
|
||||||
{
|
{
|
||||||
CFG_GET_VAL("vsync", g_VSync);
|
|
||||||
|
|
||||||
CFG_GET_VAL("pauseonfocusloss", g_PauseOnFocusLoss);
|
CFG_GET_VAL("pauseonfocusloss", g_PauseOnFocusLoss);
|
||||||
|
|
||||||
CFG_GET_VAL("gui.scale", g_GuiScale);
|
CFG_GET_VAL("gui.scale", g_GuiScale);
|
||||||
|
@ -25,7 +25,6 @@ extern bool g_PauseOnFocusLoss;
|
|||||||
|
|
||||||
extern int g_xres, g_yres;
|
extern int g_xres, g_yres;
|
||||||
extern float g_GuiScale;
|
extern float g_GuiScale;
|
||||||
extern bool g_VSync;
|
|
||||||
|
|
||||||
extern bool g_Quickstart;
|
extern bool g_Quickstart;
|
||||||
extern bool g_DisableAudio;
|
extern bool g_DisableAudio;
|
||||||
|
@ -23,8 +23,8 @@
|
|||||||
#include "graphics/GameView.h"
|
#include "graphics/GameView.h"
|
||||||
#include "gui/GUIManager.h"
|
#include "gui/GUIManager.h"
|
||||||
#include "lib/config2.h"
|
#include "lib/config2.h"
|
||||||
#include "lib/ogl.h"
|
|
||||||
#include "lib/external_libraries/libsdl.h"
|
#include "lib/external_libraries/libsdl.h"
|
||||||
|
#include "lib/ogl.h"
|
||||||
#include "lib/sysdep/gfx.h"
|
#include "lib/sysdep/gfx.h"
|
||||||
#include "lib/tex/tex.h"
|
#include "lib/tex/tex.h"
|
||||||
#include "ps/CConsole.h"
|
#include "ps/CConsole.h"
|
||||||
@ -33,15 +33,14 @@
|
|||||||
#include "ps/CStr.h"
|
#include "ps/CStr.h"
|
||||||
#include "ps/Filesystem.h"
|
#include "ps/Filesystem.h"
|
||||||
#include "ps/Game.h"
|
#include "ps/Game.h"
|
||||||
#include "ps/Pyrogenesis.h"
|
|
||||||
#include "ps/GameSetup/Config.h"
|
#include "ps/GameSetup/Config.h"
|
||||||
|
#include "ps/Pyrogenesis.h"
|
||||||
#include "renderer/Renderer.h"
|
#include "renderer/Renderer.h"
|
||||||
|
|
||||||
#if OS_MACOSX
|
#if OS_MACOSX
|
||||||
# include "lib/sysdep/os/osx/osx_sys_version.h"
|
# include "lib/sysdep/os/osx/osx_sys_version.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static int DEFAULT_WINDOW_W = 1024;
|
static int DEFAULT_WINDOW_W = 1024;
|
||||||
static int DEFAULT_WINDOW_H = 768;
|
static int DEFAULT_WINDOW_H = 768;
|
||||||
|
|
||||||
@ -51,13 +50,8 @@ static int DEFAULT_FULLSCREEN_H = 768;
|
|||||||
CVideoMode g_VideoMode;
|
CVideoMode g_VideoMode;
|
||||||
|
|
||||||
CVideoMode::CVideoMode() :
|
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_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()
|
void CVideoMode::ReadConfig()
|
||||||
@ -70,6 +64,8 @@ void CVideoMode::ReadConfig()
|
|||||||
CFG_GET_VAL("yres", m_ConfigH);
|
CFG_GET_VAL("yres", m_ConfigH);
|
||||||
CFG_GET_VAL("bpp", m_ConfigBPP);
|
CFG_GET_VAL("bpp", m_ConfigBPP);
|
||||||
CFG_GET_VAL("display", m_ConfigDisplay);
|
CFG_GET_VAL("display", m_ConfigDisplay);
|
||||||
|
|
||||||
|
CFG_GET_VAL("vsync", m_ConfigVSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen)
|
bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen)
|
||||||
@ -265,7 +261,7 @@ bool CVideoMode::InitSDL()
|
|||||||
return false;
|
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).
|
// 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.
|
// The driver appears to register its own atexit hook on context creation.
|
||||||
@ -457,43 +453,49 @@ int CVideoMode::GetBestBPP()
|
|||||||
return 32;
|
return 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVideoMode::GetXRes()
|
int CVideoMode::GetXRes() const
|
||||||
{
|
{
|
||||||
ENSURE(m_IsInitialised);
|
ENSURE(m_IsInitialised);
|
||||||
return m_CurrentW;
|
return m_CurrentW;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVideoMode::GetYRes()
|
int CVideoMode::GetYRes() const
|
||||||
{
|
{
|
||||||
ENSURE(m_IsInitialised);
|
ENSURE(m_IsInitialised);
|
||||||
return m_CurrentH;
|
return m_CurrentH;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVideoMode::GetBPP()
|
int CVideoMode::GetBPP() const
|
||||||
{
|
{
|
||||||
ENSURE(m_IsInitialised);
|
ENSURE(m_IsInitialised);
|
||||||
return m_CurrentBPP;
|
return m_CurrentBPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVideoMode::GetDesktopXRes()
|
bool CVideoMode::IsVSyncEnabled() const
|
||||||
|
{
|
||||||
|
ENSURE(m_IsInitialised);
|
||||||
|
return m_ConfigVSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CVideoMode::GetDesktopXRes() const
|
||||||
{
|
{
|
||||||
ENSURE(m_IsInitialised);
|
ENSURE(m_IsInitialised);
|
||||||
return m_PreferredW;
|
return m_PreferredW;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVideoMode::GetDesktopYRes()
|
int CVideoMode::GetDesktopYRes() const
|
||||||
{
|
{
|
||||||
ENSURE(m_IsInitialised);
|
ENSURE(m_IsInitialised);
|
||||||
return m_PreferredH;
|
return m_PreferredH;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVideoMode::GetDesktopBPP()
|
int CVideoMode::GetDesktopBPP() const
|
||||||
{
|
{
|
||||||
ENSURE(m_IsInitialised);
|
ENSURE(m_IsInitialised);
|
||||||
return m_PreferredBPP;
|
return m_PreferredBPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVideoMode::GetDesktopFreq()
|
int CVideoMode::GetDesktopFreq() const
|
||||||
{
|
{
|
||||||
ENSURE(m_IsInitialised);
|
ENSURE(m_IsInitialised);
|
||||||
return m_PreferredFreq;
|
return m_PreferredFreq;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2020 Wildfire Games.
|
/* Copyright (C) 2021 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 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);
|
static void UpdateRenderer(int w, int h);
|
||||||
|
|
||||||
int GetXRes();
|
int GetXRes() const;
|
||||||
int GetYRes();
|
int GetYRes() const;
|
||||||
int GetBPP();
|
int GetBPP() const;
|
||||||
|
|
||||||
int GetDesktopXRes();
|
bool IsVSyncEnabled() const;
|
||||||
int GetDesktopYRes();
|
|
||||||
int GetDesktopBPP();
|
int GetDesktopXRes() const;
|
||||||
int GetDesktopFreq();
|
int GetDesktopYRes() const;
|
||||||
|
int GetDesktopBPP() const;
|
||||||
|
int GetDesktopFreq() const;
|
||||||
|
|
||||||
SDL_Window* GetWindow();
|
SDL_Window* GetWindow();
|
||||||
|
|
||||||
@ -96,23 +98,27 @@ private:
|
|||||||
* important, just for verifying that the callers call our methods in
|
* important, just for verifying that the callers call our methods in
|
||||||
* the right order.)
|
* the right order.)
|
||||||
*/
|
*/
|
||||||
bool m_IsInitialised;
|
bool m_IsInitialised = false;
|
||||||
|
|
||||||
SDL_Window* m_Window;
|
SDL_Window* m_Window = nullptr;
|
||||||
|
|
||||||
// Initial desktop settings.
|
// Initial desktop settings.
|
||||||
// Frequency is in Hz, and BPP means bits per pixels (not bytes per pixels).
|
// Frequency is in Hz, and BPP means bits per pixels (not bytes per pixels).
|
||||||
int m_PreferredW;
|
int m_PreferredW = 0;
|
||||||
int m_PreferredH;
|
int m_PreferredH = 0;
|
||||||
int m_PreferredBPP;
|
int m_PreferredBPP = 0;
|
||||||
int m_PreferredFreq;
|
int m_PreferredFreq = 0;
|
||||||
|
|
||||||
// Config file settings (0 if unspecified)
|
// Config file settings (0 if unspecified)
|
||||||
int m_ConfigW;
|
int m_ConfigW = 0;
|
||||||
int m_ConfigH;
|
int m_ConfigH = 0;
|
||||||
int m_ConfigBPP;
|
int m_ConfigBPP = 0;
|
||||||
int m_ConfigDisplay;
|
int m_ConfigDisplay = 0;
|
||||||
bool m_ConfigFullscreen;
|
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
|
// 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
|
// size/position if we started fullscreen), to support switching back to the old window size/position
|
||||||
@ -122,7 +128,7 @@ private:
|
|||||||
int m_WindowedY;
|
int m_WindowedY;
|
||||||
|
|
||||||
// Whether we're currently being displayed fullscreen
|
// Whether we're currently being displayed fullscreen
|
||||||
bool m_IsFullscreen;
|
bool m_IsFullscreen = false;
|
||||||
|
|
||||||
// The last mode selected
|
// The last mode selected
|
||||||
int m_CurrentW;
|
int m_CurrentW;
|
||||||
|
Loading…
Reference in New Issue
Block a user