From 40b7ddda058da4e632315bb5f8d0d8314198dfec Mon Sep 17 00:00:00 2001 From: Misa Date: Thu, 12 Nov 2020 16:45:51 -0800 Subject: [PATCH] Remove duplicate screen configuration variables There were some duplicate Screen configuration variables that were on Game, when there didn't need to be. - game.fullScreenEffect_badSignal is a duplicate of graphics.screenbuffer->badSignalEffect - game.fullscreen is a duplicate of !graphics.screenbuffer->isWindowed - game.stretchMode is a duplicate of graphics.screenbuffer->stretchMode - game.useLinearFilter is a duplicate of graphics.screenbuffer->isFiltered These duplicate variables have been removed now. I put indentation when handling the ScreenSettings struct in main() so the local doesn't live for the entirety of main() (which is the entirety of the program). --- desktop_version/src/Game.cpp | 37 ++++++++++++++------------------ desktop_version/src/Game.h | 12 +++++------ desktop_version/src/Input.cpp | 4 ---- desktop_version/src/Render.cpp | 39 ++++++++++++++++++++++------------ desktop_version/src/editor.cpp | 2 +- desktop_version/src/main.cpp | 28 +++++++----------------- 6 files changed, 55 insertions(+), 67 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 4fba2687..5a162758 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -167,17 +167,12 @@ void Game::init(void) oldcreditposition = 0; bestgamedeaths = -1; - fullScreenEffect_badSignal = false; - //Accessibility Options colourblindmode = false; noflashingmode = false; slowdown = 30; gameframerate=34; - fullscreen = false;// true; //Assumed true at first unless overwritten at some point! - stretchMode = 0; - useLinearFilter = false; // 0..5 controllerSensitivity = 2; @@ -4473,7 +4468,7 @@ void Game::unlocknum( int t ) #define LOAD_ARRAY(ARRAY_NAME) LOAD_ARRAY_RENAME(ARRAY_NAME, ARRAY_NAME) -void Game::loadstats(int *width, int *height, bool *vsync) +void Game::loadstats(ScreenSettings* screen_settings) { tinyxml2::XMLDocument doc; if (!FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc)) @@ -4549,10 +4544,10 @@ void Game::loadstats(int *width, int *height, bool *vsync) } } - deserializesettings(dataNode, width, height, vsync); + deserializesettings(dataNode, screen_settings); } -void Game::deserializesettings(tinyxml2::XMLElement* dataNode, int* width, int* height, bool* vsync) +void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* screen_settings) { // Don't duplicate controller buttons! controllerButton_flip.clear(); @@ -4569,26 +4564,26 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, int* width, int* if (pKey == "fullscreen") { - fullscreen = help.Int(pText); + screen_settings->fullscreen = help.Int(pText); } if (pKey == "stretch") { - stretchMode = help.Int(pText); + screen_settings->stretch = help.Int(pText); } if (pKey == "useLinearFilter") { - useLinearFilter = help.Int(pText); + screen_settings->linearFilter = help.Int(pText); } if (pKey == "window_width") { - *width = help.Int(pText); + screen_settings->windowWidth = help.Int(pText); } if (pKey == "window_height") { - *height = help.Int(pText); + screen_settings->windowHeight = help.Int(pText); } @@ -4638,7 +4633,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, int* width, int* if (pKey == "advanced_smoothing") { - fullScreenEffect_badSignal = help.Int(pText); + screen_settings->badSignal = help.Int(pText); } if (pKey == "usingmmmmmm") @@ -4677,7 +4672,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, int* width, int* if (pKey == "vsync") { - *vsync = help.Int(pText); + screen_settings->useVsync = help.Int(pText); } if (pKey == "notextoutline") @@ -4853,11 +4848,11 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode) { tinyxml2::XMLDocument& doc = xml::get_document(dataNode); - xml::update_tag(dataNode, "fullscreen", fullscreen); + xml::update_tag(dataNode, "fullscreen", !graphics.screenbuffer->isWindowed); - xml::update_tag(dataNode, "stretch", stretchMode); + xml::update_tag(dataNode, "stretch", graphics.screenbuffer->stretchMode); - xml::update_tag(dataNode, "useLinearFilter", useLinearFilter); + xml::update_tag(dataNode, "useLinearFilter", graphics.screenbuffer->isFiltered); int width, height; if (graphics.screenbuffer != NULL) @@ -4884,7 +4879,7 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode) xml::update_tag(dataNode, "slowdown", slowdown); - xml::update_tag(dataNode, "advanced_smoothing", fullScreenEffect_badSignal); + xml::update_tag(dataNode, "advanced_smoothing", graphics.screenbuffer->badSignalEffect); xml::update_tag(dataNode, "usingmmmmmm", usingmmmmmm); @@ -4974,7 +4969,7 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode) xml::update_tag(dataNode, "controllerSensitivity", controllerSensitivity); } -void Game::loadsettings(int* width, int* height, bool* vsync) +void Game::loadsettings(ScreenSettings* screen_settings) { tinyxml2::XMLDocument doc; if (!FILESYSTEM_loadTiXml2Document("saves/settings.vvv", doc)) @@ -5001,7 +4996,7 @@ void Game::loadsettings(int* width, int* height, bool* vsync) tinyxml2::XMLElement* dataNode = hRoot.FirstChildElement("Data").FirstChild().ToElement(); - deserializesettings(dataNode, width, height, vsync); + deserializesettings(dataNode, screen_settings); } void Game::savesettings() diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 434a0950..f8649775 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -5,6 +5,8 @@ #include #include +#include "ScreenSettings.h" + // Forward decl without including all of namespace tinyxml2 { @@ -128,17 +130,17 @@ public: void unlocknum(int t); - void loadstats(int *width, int *height, bool *vsync); + void loadstats(ScreenSettings* screen_settings); void savestats(const bool stats_only = false); void deletestats(); - void deserializesettings(tinyxml2::XMLElement* dataNode, int* width, int* height, bool* vsync); + void deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* screen_settings); void serializesettings(tinyxml2::XMLElement* dataNode); - void loadsettings(int* width, int* height, bool* vsync); + void loadsettings(ScreenSettings* screen_settings); void savesettings(); @@ -308,7 +310,6 @@ public: bool unlocknotify[numunlock]; bool anything_unlocked(); int stat_trinkets; - bool fullscreen; int bestgamedeaths; @@ -368,9 +369,6 @@ public: bool savemystats; - bool fullScreenEffect_badSignal; - bool useLinearFilter; - int stretchMode; int controllerSensitivity; bool quickrestartkludge; diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 31e0b55d..79111595 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -385,7 +385,6 @@ void menuactionpress() case 0: music.playef(11); graphics.screenbuffer->toggleFullScreen(); - game.fullscreen = !game.fullscreen; game.savestats(); // Recreate menu to update "resize to nearest" @@ -395,7 +394,6 @@ void menuactionpress() case 1: music.playef(11); graphics.screenbuffer->toggleStretchMode(); - game.stretchMode = (game.stretchMode + 1) % 3; game.savestats(); break; case 2: @@ -414,13 +412,11 @@ void menuactionpress() case 3: music.playef(11); graphics.screenbuffer->toggleLinearFilter(); - game.useLinearFilter = !game.useLinearFilter; game.savestats(); break; case 4: //change smoothing music.playef(11); - game.fullScreenEffect_badSignal = !game.fullScreenEffect_badSignal; graphics.screenbuffer->badSignalEffect= !graphics.screenbuffer->badSignalEffect; game.savestats(); break; diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index c6e5d5e6..da7a6bcc 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -173,10 +173,13 @@ void menurender() graphics.bigprint( -1, 30, "Toggle Fullscreen", tr, tg, tb, true); graphics.Print( -1, 65, "Change to fullscreen/windowed mode.", tr, tg, tb, true); - if(game.fullscreen){ - graphics.Print( -1, 85, "Current mode: FULLSCREEN", tr, tg, tb, true); - }else{ - graphics.Print( -1, 85, "Current mode: WINDOWED", tr, tg, tb, true); + if (graphics.screenbuffer->isWindowed) + { + graphics.Print( -1, 85, "Current mode: WINDOWED", tr, tg, tb, true); + } + else + { + graphics.Print( -1, 85, "Current mode: FULLSCREEN", tr, tg, tb, true); } break; @@ -184,12 +187,17 @@ void menurender() graphics.bigprint( -1, 30, "Scaling Mode", tr, tg, tb, true); graphics.Print( -1, 65, "Choose letterbox/stretch/integer mode.", tr, tg, tb, true); - if(game.stretchMode == 2){ - graphics.Print( -1, 85, "Current mode: INTEGER", tr, tg, tb, true); - }else if (game.stretchMode == 1){ - graphics.Print( -1, 85, "Current mode: STRETCH", tr, tg, tb, true); - }else{ - graphics.Print( -1, 85, "Current mode: LETTERBOX", tr, tg, tb, true); + switch (graphics.screenbuffer->stretchMode) + { + case 2: + graphics.Print( -1, 85, "Current mode: INTEGER", tr, tg, tb, true); + break; + case 1: + graphics.Print( -1, 85, "Current mode: STRETCH", tr, tg, tb, true); + break; + default: + graphics.Print( -1, 85, "Current mode: LETTERBOX", tr, tg, tb, true); + break; } break; case 2: @@ -206,10 +214,13 @@ void menurender() graphics.bigprint( -1, 30, "Toggle Filter", tr, tg, tb, true); graphics.Print( -1, 65, "Change to nearest/linear filter.", tr, tg, tb, true); - if(game.useLinearFilter){ - graphics.Print( -1, 85, "Current mode: LINEAR", tr, tg, tb, true); - }else{ - graphics.Print( -1, 85, "Current mode: NEAREST", tr, tg, tb, true); + if (graphics.screenbuffer->isFiltered) + { + graphics.Print( -1, 85, "Current mode: LINEAR", tr, tg, tb, true); + } + else + { + graphics.Print( -1, 85, "Current mode: NEAREST", tr, tg, tb, true); } break; diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 5f326202..67f1d1f6 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -3906,7 +3906,7 @@ void editorinput() game.my = (float) key.my; ed.tilex=(game.mx - (game.mx%8))/8; ed.tiley=(game.my - (game.my%8))/8; - if (game.stretchMode == 1) { + if (graphics.screenbuffer->stretchMode == 1) { // In this mode specifically, we have to fix the mouse coordinates int winwidth, winheight; graphics.screenbuffer->GetWindowSize(&winwidth, &winheight); diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index e2a133de..2b0b1052 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -213,25 +213,14 @@ int main(int argc, char *argv[]) graphics.towerbg.bypos = map.ypos / 2; graphics.titlebg.bypos = map.ypos / 2; - //Moved screensetting init here from main menu V2.1 - int width = 320; - int height = 240; - bool vsync = false; - - // Prioritize unlock.vvv first (2.2 and below), - // but settings have been migrated to settings.vvv (2.3 and up) - game.loadstats(&width, &height, &vsync); - game.loadsettings(&width, &height, &vsync); - - gameScreen.init( - width, - height, - game.fullscreen, - vsync, - game.stretchMode, - game.useLinearFilter, - game.fullScreenEffect_badSignal - ); + { + // Prioritize unlock.vvv first (2.2 and below), + // but settings have been migrated to settings.vvv (2.3 and up) + ScreenSettings screen_settings; + game.loadstats(&screen_settings); + game.loadsettings(&screen_settings); + gameScreen.init(screen_settings); + } graphics.screenbuffer = &gameScreen; const SDL_PixelFormat* fmt = gameScreen.GetFormat(); @@ -490,7 +479,6 @@ void inline fixedloop() if(key.toggleFullscreen) { gameScreen.toggleFullScreen(); - game.fullscreen = !game.fullscreen; key.toggleFullscreen = false; key.keymap.clear(); //we lost the input due to a new window.