1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01: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 "Map.h"
#include "Music.h"
#include "Screen.h"
#include "Script.h"
#include "UtilityClass.h"
@ -1921,10 +1922,10 @@ void editorinput(void)
game.my = (float) key.my;
ed.tilex=(game.mx - (game.mx%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
int winwidth, winheight;
graphics.screenbuffer->GetWindowSize(&winwidth, &winheight);
gameScreen.GetWindowSize(&winwidth, &winheight);
ed.tilex = ed.tilex * 320 / winwidth;
ed.tiley = ed.tiley * 240 / winheight;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -14,6 +14,7 @@
#include "Map.h"
#include "Maths.h"
#include "Music.h"
#include "Screen.h"
#include "Script.h"
#include "UtilityClass.h"
#include "Version.h"
@ -288,19 +289,13 @@ static void menurender(void)
}
break;
case Menu::graphicoptions:
if (graphics.screenbuffer == NULL)
{
SDL_assert(0 && "Screenbuffer is NULL!");
break;
}
switch (game.currentmenuoption)
{
case 0:
graphics.bigprint( -1, 30, "Toggle Fullscreen", 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);
}
@ -314,7 +309,7 @@ static void menurender(void)
graphics.bigprint( -1, 30, "Scaling 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:
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.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);
if (!graphics.screenbuffer->isWindowed)
if (!gameScreen.isWindowed)
{
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);
@ -341,7 +336,7 @@ static void menurender(void)
graphics.bigprint( -1, 30, "Toggle 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);
}
@ -367,7 +362,7 @@ static void menurender(void)
graphics.Print(-1, 75, "Edit the config file.", tr, tg, tb, true);
#endif
if (!graphics.screenbuffer->vsync)
if (!gameScreen.vsync)
{
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 <SDL.h>

View file

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

View file

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