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).
This commit is contained in:
Misa 2020-11-12 16:45:51 -08:00 committed by Ethan Lee
parent af11f6936a
commit 40b7ddda05
6 changed files with 55 additions and 67 deletions

View File

@ -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()

View File

@ -5,6 +5,8 @@
#include <string>
#include <vector>
#include "ScreenSettings.h"
// Forward decl without including all of <tinyxml2.h>
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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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.