1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 06:28:30 +02:00

Extern gameScreen, remove screenbuffer

I know earlier I removed the gameScreen extern in favor of using
screenbuffer, but that was only to be consistent. After further
consideration, I have found that it's actually really stupid.

There's no reason to be accessing it through screenbuffer, and it's
probably an artifact of 2.0-2.2 passing stack-allocated otherwise-global
classes everywhere through function arguments. Also, it leads to stupid
bugs where screenbuffer could potentially be NULL, which has already
resulted in various annoying crashes in the past. Although those could
be fixed by simply initializing screenbuffer at the very top of main(),
but, why not just scrap the whole thing anyway?

So that's what I'm doing.

As a nice side effect, I've removed the transitive include of Screen.h
from Graphics.h. This could've been done already since it only includes
it for the pointer anyway, but it's still good to do it now.
This commit is contained in:
Misa 2021-12-24 23:56:47 -08:00
parent b7cbdfe8f9
commit d0ffafe117
10 changed files with 37 additions and 64 deletions

View File

@ -16,6 +16,7 @@
#include "KeyPoll.h" #include "KeyPoll.h"
#include "Map.h" #include "Map.h"
#include "Music.h" #include "Music.h"
#include "Screen.h"
#include "Script.h" #include "Script.h"
#include "UtilityClass.h" #include "UtilityClass.h"
@ -1921,10 +1922,10 @@ void editorinput(void)
game.my = (float) key.my; game.my = (float) key.my;
ed.tilex=(game.mx - (game.mx%8))/8; ed.tilex=(game.mx - (game.mx%8))/8;
ed.tiley=(game.my - (game.my%8))/8; ed.tiley=(game.my - (game.my%8))/8;
if (graphics.screenbuffer->scalingMode == 1) { if (gameScreen.scalingMode == 1) {
// In this mode specifically, we have to fix the mouse coordinates // In this mode specifically, we have to fix the mouse coordinates
int winwidth, winheight; int winwidth, winheight;
graphics.screenbuffer->GetWindowSize(&winwidth, &winheight); gameScreen.GetWindowSize(&winwidth, &winheight);
ed.tilex = ed.tilex * 320 / winwidth; ed.tilex = ed.tilex * 320 / winwidth;
ed.tiley = ed.tiley * 240 / winheight; ed.tiley = ed.tiley * 240 / winheight;
} }

View File

@ -20,6 +20,7 @@
#include "Map.h" #include "Map.h"
#include "Music.h" #include "Music.h"
#include "Network.h" #include "Network.h"
#include "Screen.h"
#include "Script.h" #include "Script.h"
#include "UtilityClass.h" #include "UtilityClass.h"
#include "Vlogging.h" #include "Vlogging.h"
@ -4326,13 +4327,8 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s
bool Game::savestats(bool sync /*= true*/) bool Game::savestats(bool sync /*= true*/)
{ {
if (graphics.screenbuffer == NULL)
{
return false;
}
ScreenSettings screen_settings; ScreenSettings screen_settings;
graphics.screenbuffer->GetSettings(&screen_settings); gameScreen.GetSettings(&screen_settings);
return savestats(&screen_settings, sync); return savestats(&screen_settings, sync);
} }
@ -4596,13 +4592,8 @@ void Game::loadsettings(ScreenSettings* screen_settings)
bool Game::savesettings(void) bool Game::savesettings(void)
{ {
if (graphics.screenbuffer == NULL)
{
return false;
}
ScreenSettings screen_settings; ScreenSettings screen_settings;
graphics.screenbuffer->GetSettings(&screen_settings); gameScreen.GetSettings(&screen_settings);
return savesettings(&screen_settings); return savesettings(&screen_settings);
} }
@ -6094,7 +6085,7 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
case Menu::graphicoptions: case Menu::graphicoptions:
option("toggle fullscreen"); option("toggle fullscreen");
option("scaling mode"); option("scaling mode");
option("resize to nearest", graphics.screenbuffer->isWindowed); option("resize to nearest", gameScreen.isWindowed);
option("toggle filter"); option("toggle filter");
option("toggle analogue"); option("toggle analogue");
option("toggle vsync"); option("toggle vsync");

View File

@ -109,7 +109,6 @@ void Graphics::init(void)
m = 0; m = 0;
linedelay = 0; linedelay = 0;
menubuffer = NULL; menubuffer = NULL;
screenbuffer = NULL;
tempBuffer = NULL; tempBuffer = NULL;
warpbuffer = NULL; warpbuffer = NULL;
warpbuffer_lerp = NULL; warpbuffer_lerp = NULL;
@ -3014,7 +3013,7 @@ void Graphics::menuoffrender(void)
BlitSurfaceStandard(tempBuffer, NULL, backBuffer, NULL); BlitSurfaceStandard(tempBuffer, NULL, backBuffer, NULL);
BlitSurfaceStandard(menubuffer, NULL, backBuffer, &offsetRect); BlitSurfaceStandard(menubuffer, NULL, backBuffer, &offsetRect);
screenbuffer->UpdateScreen(backBuffer, NULL); gameScreen.UpdateScreen(backBuffer, NULL);
ClearSurface(backBuffer); ClearSurface(backBuffer);
} }
@ -3135,7 +3134,7 @@ void Graphics::flashlight(void)
void Graphics::screenshake(void) void Graphics::screenshake(void)
{ {
SDL_Rect shakeRect = {screenshake_x, screenshake_y, backBuffer->w, backBuffer->h}; SDL_Rect shakeRect = {screenshake_x, screenshake_y, backBuffer->w, backBuffer->h};
screenbuffer->UpdateScreen(backBuffer, &shakeRect); gameScreen.UpdateScreen(backBuffer, &shakeRect);
ClearSurface(backBuffer); ClearSurface(backBuffer);
} }
@ -3148,12 +3147,7 @@ void Graphics::updatescreenshake(void)
void Graphics::render(void) void Graphics::render(void)
{ {
if (screenbuffer == NULL) gameScreen.UpdateScreen(backBuffer, NULL);
{
return;
}
screenbuffer->UpdateScreen(backBuffer, NULL);
} }
void Graphics::renderwithscreeneffects(void) void Graphics::renderwithscreeneffects(void)
@ -3180,7 +3174,7 @@ void Graphics::renderfixedpre(void)
updatescreenshake(); updatescreenshake();
} }
if (screenbuffer != NULL && screenbuffer->badSignalEffect) if (gameScreen.badSignalEffect)
{ {
UpdateFilter(); UpdateFilter();
} }
@ -3414,10 +3408,7 @@ bool Graphics::reloadresources(void)
images.push_back(grphx.im_image11); images.push_back(grphx.im_image11);
images.push_back(grphx.im_image12); images.push_back(grphx.im_image12);
if (screenbuffer != NULL) gameScreen.LoadIcon();
{
screenbuffer->LoadIcon();
}
music.destroy(); music.destroy();
music.init(); music.init();

View File

@ -8,7 +8,6 @@
#include "GraphicsResources.h" #include "GraphicsResources.h"
#include "GraphicsUtil.h" #include "GraphicsUtil.h"
#include "Maths.h" #include "Maths.h"
#include "Screen.h"
#include "Textbox.h" #include "Textbox.h"
#include "TowerBG.h" #include "TowerBG.h"
@ -258,7 +257,6 @@ public:
bool notextoutline; bool notextoutline;
//buffer objects. //TODO refactor buffer objects //buffer objects. //TODO refactor buffer objects
SDL_Surface* backBuffer; SDL_Surface* backBuffer;
Screen* screenbuffer;
SDL_Surface* menubuffer; SDL_Surface* menubuffer;
SDL_Surface* foregroundBuffer; SDL_Surface* foregroundBuffer;
SDL_Surface* tempBuffer; SDL_Surface* tempBuffer;

View File

@ -13,6 +13,7 @@
#include "MakeAndPlay.h" #include "MakeAndPlay.h"
#include "Map.h" #include "Map.h"
#include "Music.h" #include "Music.h"
#include "Screen.h"
#include "Script.h" #include "Script.h"
#include "UtilityClass.h" #include "UtilityClass.h"
#include "Vlogging.h" #include "Vlogging.h"
@ -559,7 +560,7 @@ static void menuactionpress(void)
&& FILESYSTEM_openDirectory(FILESYSTEM_getUserLevelDirectory())) && FILESYSTEM_openDirectory(FILESYSTEM_getUserLevelDirectory()))
{ {
music.playef(11); music.playef(11);
SDL_MinimizeWindow(graphics.screenbuffer->m_window); SDL_MinimizeWindow(gameScreen.m_window);
} }
else else
{ {
@ -604,30 +605,24 @@ static void menuactionpress(void)
map.nexttowercolour(); map.nexttowercolour();
break; break;
case Menu::graphicoptions: case Menu::graphicoptions:
if (graphics.screenbuffer == NULL)
{
SDL_assert(0 && "Screenbuffer is NULL!");
break;
}
switch (game.currentmenuoption) switch (game.currentmenuoption)
{ {
case 0: case 0:
music.playef(11); music.playef(11);
graphics.screenbuffer->toggleFullScreen(); gameScreen.toggleFullScreen();
game.savestatsandsettings_menu(); game.savestatsandsettings_menu();
break; break;
case 1: case 1:
music.playef(11); music.playef(11);
graphics.screenbuffer->toggleScalingMode(); gameScreen.toggleScalingMode();
game.savestatsandsettings_menu(); game.savestatsandsettings_menu();
break; break;
case 2: case 2:
// resize to nearest multiple // resize to nearest multiple
if (graphics.screenbuffer->isWindowed) if (gameScreen.isWindowed)
{ {
music.playef(11); music.playef(11);
graphics.screenbuffer->ResizeToNearestMultiple(); gameScreen.ResizeToNearestMultiple();
game.savestatsandsettings_menu(); game.savestatsandsettings_menu();
} }
else else
@ -637,13 +632,13 @@ static void menuactionpress(void)
break; break;
case 3: case 3:
music.playef(11); music.playef(11);
graphics.screenbuffer->toggleLinearFilter(); gameScreen.toggleLinearFilter();
game.savestatsandsettings_menu(); game.savestatsandsettings_menu();
break; break;
case 4: case 4:
//change smoothing //change smoothing
music.playef(11); music.playef(11);
graphics.screenbuffer->badSignalEffect= !graphics.screenbuffer->badSignalEffect; gameScreen.badSignalEffect= !gameScreen.badSignalEffect;
game.savestatsandsettings_menu(); game.savestatsandsettings_menu();
break; break;
case 5: case 5:
@ -651,7 +646,7 @@ static void menuactionpress(void)
#if SDL_VERSION_ATLEAST(2, 0, 17) #if SDL_VERSION_ATLEAST(2, 0, 17)
//toggle vsync //toggle vsync
music.playef(11); music.playef(11);
graphics.screenbuffer->toggleVSync(); gameScreen.toggleVSync();
game.savestatsandsettings_menu(); game.savestatsandsettings_menu();
#endif #endif
break; break;

View File

@ -9,6 +9,7 @@
#include "GlitchrunnerMode.h" #include "GlitchrunnerMode.h"
#include "Graphics.h" #include "Graphics.h"
#include "Music.h" #include "Music.h"
#include "Screen.h"
#include "Vlogging.h" #include "Vlogging.h"
int inline KeyPoll::getThreshold(void) int inline KeyPoll::getThreshold(void)
@ -67,10 +68,7 @@ bool KeyPoll::textentry(void)
void KeyPoll::toggleFullscreen(void) void KeyPoll::toggleFullscreen(void)
{ {
if (graphics.screenbuffer != NULL) gameScreen.toggleFullScreen();
{
graphics.screenbuffer->toggleFullScreen();
}
keymap.clear(); /* we lost the input due to a new window. */ keymap.clear(); /* we lost the input due to a new window. */
if (GlitchrunnerMode_less_than_or_equal(Glitchrunner2_2)) if (GlitchrunnerMode_less_than_or_equal(Glitchrunner2_2))
@ -337,7 +335,7 @@ void KeyPoll::Poll(void)
{ {
if (wasFullscreen) if (wasFullscreen)
{ {
graphics.screenbuffer->isWindowed = false; gameScreen.isWindowed = false;
SDL_SetWindowFullscreen( SDL_SetWindowFullscreen(
SDL_GetWindowFromID(evt.window.windowID), SDL_GetWindowFromID(evt.window.windowID),
SDL_WINDOW_FULLSCREEN_DESKTOP SDL_WINDOW_FULLSCREEN_DESKTOP
@ -359,8 +357,8 @@ void KeyPoll::Poll(void)
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0)
{ {
wasFullscreen = !graphics.screenbuffer->isWindowed; wasFullscreen = !gameScreen.isWindowed;
graphics.screenbuffer->isWindowed = true; gameScreen.isWindowed = true;
SDL_SetWindowFullscreen( SDL_SetWindowFullscreen(
SDL_GetWindowFromID(evt.window.windowID), SDL_GetWindowFromID(evt.window.windowID),
0 0

View File

@ -14,6 +14,7 @@
#include "Map.h" #include "Map.h"
#include "Maths.h" #include "Maths.h"
#include "Music.h" #include "Music.h"
#include "Screen.h"
#include "Script.h" #include "Script.h"
#include "UtilityClass.h" #include "UtilityClass.h"
#include "Version.h" #include "Version.h"
@ -288,19 +289,13 @@ static void menurender(void)
} }
break; break;
case Menu::graphicoptions: case Menu::graphicoptions:
if (graphics.screenbuffer == NULL)
{
SDL_assert(0 && "Screenbuffer is NULL!");
break;
}
switch (game.currentmenuoption) switch (game.currentmenuoption)
{ {
case 0: case 0:
graphics.bigprint( -1, 30, "Toggle Fullscreen", tr, tg, tb, true); graphics.bigprint( -1, 30, "Toggle Fullscreen", tr, tg, tb, true);
graphics.Print( -1, 65, "Change to fullscreen/windowed mode.", tr, tg, tb, true); graphics.Print( -1, 65, "Change to fullscreen/windowed mode.", tr, tg, tb, true);
if (graphics.screenbuffer->isWindowed) if (gameScreen.isWindowed)
{ {
graphics.Print( -1, 85, "Current mode: WINDOWED", tr, tg, tb, true); graphics.Print( -1, 85, "Current mode: WINDOWED", tr, tg, tb, true);
} }
@ -314,7 +309,7 @@ static void menurender(void)
graphics.bigprint( -1, 30, "Scaling Mode", tr, tg, tb, true); graphics.bigprint( -1, 30, "Scaling Mode", tr, tg, tb, true);
graphics.Print( -1, 65, "Choose letterbox/stretch/integer mode.", tr, tg, tb, true); graphics.Print( -1, 65, "Choose letterbox/stretch/integer mode.", tr, tg, tb, true);
switch (graphics.screenbuffer->scalingMode) switch (gameScreen.scalingMode)
{ {
case 2: case 2:
graphics.Print( -1, 85, "Current mode: INTEGER", tr, tg, tb, true); graphics.Print( -1, 85, "Current mode: INTEGER", tr, tg, tb, true);
@ -331,7 +326,7 @@ static void menurender(void)
graphics.bigprint(-1, 30, "Resize to Nearest", tr, tg, tb, true); graphics.bigprint(-1, 30, "Resize to Nearest", tr, tg, tb, true);
graphics.Print(-1, 65, "Resize to the nearest window size", tr, tg, tb, true); graphics.Print(-1, 65, "Resize to the nearest window size", tr, tg, tb, true);
graphics.Print(-1, 75, "that is of an integer multiple.", tr, tg, tb, true); graphics.Print(-1, 75, "that is of an integer multiple.", tr, tg, tb, true);
if (!graphics.screenbuffer->isWindowed) if (!gameScreen.isWindowed)
{ {
graphics.Print(-1, 95, "You must be in windowed mode", tr, tg, tb, true); graphics.Print(-1, 95, "You must be in windowed mode", tr, tg, tb, true);
graphics.Print(-1, 105, "to use this option.", tr, tg, tb, true); graphics.Print(-1, 105, "to use this option.", tr, tg, tb, true);
@ -341,7 +336,7 @@ static void menurender(void)
graphics.bigprint( -1, 30, "Toggle Filter", tr, tg, tb, true); graphics.bigprint( -1, 30, "Toggle Filter", tr, tg, tb, true);
graphics.Print( -1, 65, "Change to nearest/linear filter.", tr, tg, tb, true); graphics.Print( -1, 65, "Change to nearest/linear filter.", tr, tg, tb, true);
if (graphics.screenbuffer->isFiltered) if (gameScreen.isFiltered)
{ {
graphics.Print( -1, 85, "Current mode: LINEAR", tr, tg, tb, true); graphics.Print( -1, 85, "Current mode: LINEAR", tr, tg, tb, true);
} }
@ -367,7 +362,7 @@ static void menurender(void)
graphics.Print(-1, 75, "Edit the config file.", tr, tg, tb, true); graphics.Print(-1, 75, "Edit the config file.", tr, tg, tb, true);
#endif #endif
if (!graphics.screenbuffer->vsync) if (!gameScreen.vsync)
{ {
graphics.Print(-1, 85, "Current mode: VSYNC OFF", tr/2, tg/2, tb/2, true); graphics.Print(-1, 85, "Current mode: VSYNC OFF", tr/2, tg/2, tb/2, true);
} }

View File

@ -1,3 +1,4 @@
#define GAMESCREEN_DEFINITION
#include "Screen.h" #include "Screen.h"
#include <SDL.h> #include <SDL.h>

View File

@ -41,4 +41,8 @@ public:
SDL_Surface* m_screen; SDL_Surface* m_screen;
}; };
#ifndef GAMESCREEN_DEFINITION
extern Screen gameScreen;
#endif
#endif /* SCREEN_H */ #endif /* SCREEN_H */

View File

@ -576,7 +576,6 @@ int main(int argc, char *argv[])
game.loadsettings(&screen_settings); game.loadsettings(&screen_settings);
gameScreen.init(screen_settings); gameScreen.init(screen_settings);
} }
graphics.screenbuffer = &gameScreen;
graphics.create_buffers(gameScreen.GetFormat()); graphics.create_buffers(gameScreen.GetFormat());