From 70f3d457dddf3aaf818909fca5b0b5d198a3125f Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 2 Nov 2020 15:23:53 -0800 Subject: [PATCH] Move title usages of towerbg to titlebg With the previous commit in place, we can now simply move some usages of the previous towerbg to use a separate object instead. That way, we don't have to mess with a monolithic state, or some better way to phrase what I just said, and we instead have two separate objects that can coexist side-by-side. --- desktop_version/src/Game.cpp | 12 ++++++------ desktop_version/src/Graphics.cpp | 1 + desktop_version/src/Graphics.h | 1 + desktop_version/src/Input.cpp | 17 +++++++++-------- desktop_version/src/Logic.cpp | 24 ++++++++++++------------ desktop_version/src/Map.cpp | 20 ++++++++++---------- desktop_version/src/Render.cpp | 4 ++-- desktop_version/src/Script.cpp | 2 +- desktop_version/src/editor.cpp | 10 +++++----- desktop_version/src/main.cpp | 7 +++++++ 10 files changed, 54 insertions(+), 44 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 415304ad..3c500683 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -1373,7 +1373,7 @@ void Game::updatestate() gamestate = TITLEMODE; graphics.fademode = 4; graphics.backgrounddrawn = true; - graphics.towerbg.tdrawback = true; + graphics.titlebg.tdrawback = true; createmenu(Menu::timetrialcomplete); state = 0; break; @@ -2942,7 +2942,7 @@ void Game::updatestate() gamestate = TITLEMODE; graphics.fademode = 4; graphics.backgrounddrawn = true; - graphics.towerbg.tdrawback = true; + graphics.titlebg.tdrawback = true; music.play(6); state = 0; break; @@ -3278,7 +3278,7 @@ void Game::updatestate() gamestate = TITLEMODE; graphics.fademode = 4; graphics.backgrounddrawn = true; - graphics.towerbg.tdrawback = true; + graphics.titlebg.tdrawback = true; createmenu(Menu::nodeathmodecomplete); state = 0; break; @@ -7129,7 +7129,7 @@ void Game::quittomenu() FILESYSTEM_unmountassets(); // should be before music.play(6) music.play(6); graphics.backgrounddrawn = false; - graphics.towerbg.tdrawback = true; + graphics.titlebg.tdrawback = true; graphics.flipmode = false; //Don't be stuck on the summary screen, //or "who do you want to play the level with?" @@ -7223,7 +7223,7 @@ void Game::returntoeditor() ed.level[i+(j*ed.maxwidth)].warpdir=ed.kludgewarpdir[i+(j*ed.maxwidth)]; } } - graphics.towerbg.scrolldir = 0; + graphics.titlebg.scrolldir = 0; } #endif @@ -7233,7 +7233,7 @@ void Game::returntopausemenu() returntomenu(kludge_ingametemp); gamestate = MAPMODE; map.kludge_to_bg(); - graphics.towerbg.tdrawback = true; + graphics.titlebg.tdrawback = true; graphics.backgrounddrawn = false; mapheld = true; graphics.flipmode = graphics.setflipmode; diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 06c318e0..44852861 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -118,6 +118,7 @@ void Graphics::init() footerbuffer = NULL; ghostbuffer = NULL; towerbg = TowerBG(); + titlebg = TowerBG(); trinketr = 0; trinketg = 0; trinketb = 0; diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index c443d1bc..f5f36c05 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -230,6 +230,7 @@ public: SDL_Surface* tempBuffer; TowerBG towerbg; + TowerBG titlebg; SDL_Rect bfont_rect; SDL_Rect tiles_rect; diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 4255226e..8d7fa32a 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -580,6 +580,7 @@ void menuactionpress() game.colourblindmode = !game.colourblindmode; game.savestats(); graphics.towerbg.tdrawback = true; + graphics.titlebg.tdrawback = true; music.playef(11); break; case 1: @@ -1683,7 +1684,7 @@ void titleinput() music.playef(18); game.screenshake = 10; game.flashlight = 5; - graphics.towerbg.colstate = 10; + graphics.titlebg.colstate = 10; map.nexttowercolour(); } else @@ -2381,13 +2382,13 @@ void mapmenuactionpress() map.bg_to_kludge(); game.kludge_ingametemp = game.currentmenuname; - graphics.towerbg.scrolldir = 0; - graphics.towerbg.colstate = ((int) (graphics.towerbg.colstate / 5)) * 5; - graphics.towerbg.bypos = 0; + graphics.titlebg.scrolldir = 0; + graphics.titlebg.colstate = ((int) (graphics.titlebg.colstate / 5)) * 5; + graphics.titlebg.bypos = 0; map.nexttowercolour(); // Fix delta rendering glitch - graphics.updatetowerbackground(graphics.towerbg); + graphics.updatetowerbackground(graphics.titlebg); titleupdatetextcol(); break; } @@ -2536,11 +2537,11 @@ void gamecompleteinput() //Do this before we update map.bypos if (!game.colourblindmode) { - graphics.updatetowerbackground(graphics.towerbg); + graphics.updatetowerbackground(graphics.titlebg); } //Do these here because input comes first - graphics.towerbg.bypos += graphics.towerbg.bscroll; + graphics.titlebg.bypos += graphics.titlebg.bscroll; game.oldcreditposition = game.creditposition; if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip)) @@ -2556,7 +2557,7 @@ void gamecompleteinput() } else { - graphics.towerbg.bscroll = +7; + graphics.titlebg.bscroll = +7; } game.press_action = true; } diff --git a/desktop_version/src/Logic.cpp b/desktop_version/src/Logic.cpp index eebb839f..6adac513 100644 --- a/desktop_version/src/Logic.cpp +++ b/desktop_version/src/Logic.cpp @@ -27,15 +27,15 @@ void titleupdatetextcol() void titlelogic() { //Misc - //map.updatetowerglow(graphics.towerbg); + //map.updatetowerglow(graphics.titlebg); help.updateglow(); - graphics.towerbg.bypos -= 2; - graphics.towerbg.bscroll = -2; + graphics.titlebg.bypos -= 2; + graphics.titlebg.bscroll = -2; if (!game.colourblindmode) { - graphics.updatetowerbackground(graphics.towerbg); + graphics.updatetowerbackground(graphics.titlebg); } if (!game.menustart) @@ -149,10 +149,10 @@ void maplogic() void gamecompletelogic() { //Misc - map.updatetowerglow(graphics.towerbg); + map.updatetowerglow(graphics.titlebg); help.updateglow(); graphics.crewframe = 0; - graphics.towerbg.scrolldir = 1; + graphics.titlebg.scrolldir = 1; graphics.updatetitlecolours(); graphics.col_tr = map.r - (help.glow / 4) - fRandom() * 4; @@ -169,11 +169,11 @@ void gamecompletelogic() if (game.creditposition <= -Credits::creditmaxposition) { game.creditposition = -Credits::creditmaxposition; - graphics.towerbg.bscroll = 0; + graphics.titlebg.bscroll = 0; } else if (!game.press_action) { - graphics.towerbg.bscroll = +1; + graphics.titlebg.bscroll = +1; } if (graphics.fademode == 1) @@ -182,8 +182,8 @@ void gamecompletelogic() graphics.showcutscenebars = false; graphics.cutscenebarspos = 0; graphics.oldcutscenebarspos = 0; - graphics.towerbg.scrolldir = 0; - graphics.towerbg.bypos = 0; + graphics.titlebg.scrolldir = 0; + graphics.titlebg.bypos = 0; //Return to game game.gamestate = GAMECOMPLETE2; graphics.fademode = 4; @@ -193,7 +193,7 @@ void gamecompletelogic() void gamecompletelogic2() { //Misc - map.updatetowerglow(graphics.towerbg); + map.updatetowerglow(graphics.titlebg); help.updateglow(); game.creditposdelay--; @@ -222,7 +222,7 @@ void gamecompletelogic2() game.savetele(); music.currentsong=tmp; //Return to game - graphics.towerbg.colstate = 10; + graphics.titlebg.colstate = 10; game.gamestate = TITLEMODE; graphics.fademode = 4; FILESYSTEM_unmountassets(); // should be before music.playef(18) diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 99f83b4b..04118187 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -628,10 +628,10 @@ void mapclass::updatetowerglow(TowerBG& bg_obj) void mapclass::nexttowercolour() { - graphics.towerbg.colstate+=5; - if (graphics.towerbg.colstate >= 30) graphics.towerbg.colstate = 0; - int check = graphics.towerbg.colstate % 5; //current state of phase - int cmode = (graphics.towerbg.colstate - check) / 5; // current colour transition + graphics.titlebg.colstate+=5; + if (graphics.titlebg.colstate >= 30) graphics.titlebg.colstate = 0; + int check = graphics.titlebg.colstate % 5; //current state of phase + int cmode = (graphics.titlebg.colstate - check) / 5; // current colour transition switch(cmode) { @@ -655,15 +655,15 @@ void mapclass::nexttowercolour() break; } - graphics.towerbg.tdrawback = true; + graphics.titlebg.tdrawback = true; } void mapclass::settowercolour(int t) { - graphics.towerbg.colstate=t*5; - if (graphics.towerbg.colstate >= 30) graphics.towerbg.colstate = 0; - int check = graphics.towerbg.colstate % 5; //current state of phase - int cmode = (graphics.towerbg.colstate - check) / 5; // current colour transition + graphics.titlebg.colstate=t*5; + if (graphics.titlebg.colstate >= 30) graphics.titlebg.colstate = 0; + int check = graphics.titlebg.colstate % 5; //current state of phase + int cmode = (graphics.titlebg.colstate - check) / 5; // current colour transition switch(cmode) { @@ -687,7 +687,7 @@ void mapclass::settowercolour(int t) break; } - graphics.towerbg.tdrawback = true; + graphics.titlebg.tdrawback = true; } bool mapclass::spikecollide(int x, int y) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index f34c0519..8ab45775 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -1182,7 +1182,7 @@ void titlerender() } else { - if(!game.colourblindmode) graphics.drawtowerbackground(graphics.towerbg); + if(!game.colourblindmode) graphics.drawtowerbackground(graphics.titlebg); tr = graphics.col_tr; tg = graphics.col_tg; @@ -1211,7 +1211,7 @@ void gamecompleterender() { FillRect(graphics.backBuffer, 0x000000); - if(!game.colourblindmode) graphics.drawtowerbackground(graphics.towerbg); + if(!game.colourblindmode) graphics.drawtowerbackground(graphics.titlebg); tr = graphics.col_tr; tg = graphics.col_tg; diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index bae49049..83eacbc6 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -2642,7 +2642,7 @@ void scriptclass::resetgametomenu() graphics.flipmode = false; obj.entities.clear(); graphics.fademode = 4; - graphics.towerbg.tdrawback = true; + graphics.titlebg.tdrawback = true; game.createmenu(Menu::gameover); } diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 94ce0d6c..ad81d35f 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -3292,7 +3292,7 @@ void editorrender() { if(!game.colourblindmode) { - graphics.drawtowerbackground(graphics.towerbg); + graphics.drawtowerbackground(graphics.titlebg); } else { @@ -3679,8 +3679,8 @@ void editorlogic() game.shouldreturntoeditor = false; } - graphics.towerbg.bypos -= 2; - graphics.towerbg.bscroll = -2; + graphics.titlebg.bypos -= 2; + graphics.titlebg.bscroll = -2; ed.entframedelay--; if(ed.entframedelay<=0) @@ -3740,14 +3740,14 @@ void editorlogic() } else if (!game.colourblindmode) { - graphics.updatetowerbackground(graphics.towerbg); + graphics.updatetowerbackground(graphics.titlebg); } if (graphics.fademode == 1) { //Return to game map.nexttowercolour(); - graphics.towerbg.colstate = 10; + graphics.titlebg.colstate = 10; game.gamestate = TITLEMODE; script.hardreset(); graphics.fademode = 4; diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index ce7f52da..c8717720 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -211,6 +211,7 @@ int main(int argc, char *argv[]) map.ypos = (700-29) * 8; graphics.towerbg.bypos = map.ypos / 2; + graphics.titlebg.bypos = map.ypos / 2; //Moved screensetting init here from main menu V2.1 int width = 320; @@ -262,6 +263,12 @@ int main(int argc, char *argv[]) graphics.towerbg.buffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16); SDL_SetSurfaceBlendMode(graphics.towerbg.buffer_lerp, SDL_BLENDMODE_NONE); + graphics.titlebg.buffer = CREATE_SURFACE(320 + 16, 240 + 16); + SDL_SetSurfaceBlendMode(graphics.titlebg.buffer, SDL_BLENDMODE_NONE); + + graphics.titlebg.buffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16); + SDL_SetSurfaceBlendMode(graphics.titlebg.buffer_lerp, SDL_BLENDMODE_NONE); + graphics.tempBuffer = CREATE_SURFACE(320, 240); SDL_SetSurfaceBlendMode(graphics.tempBuffer, SDL_BLENDMODE_NONE);