From 47ebbf15ab621d8a415eeb56276de4b1dba0e2ef Mon Sep 17 00:00:00 2001 From: Info Teddy Date: Mon, 27 Jan 2020 14:46:11 -0800 Subject: [PATCH] Don't redraw H/V warp BG if gotorooming to same room in customs This has two benefits: (1) The game uses less resources when it is asked to gotoroom to the same room because it is no longer redrawing the warp background every single frame, which is very wasteful. (2) The warp background no longer freezes or flickers if the player is standing inside a gotoroom script box (which calls gotoroom every frame or every other frame, because every time the gotoroom happens the script box gets reloaded). --- desktop_version/src/Game.h | 1 + desktop_version/src/Map.cpp | 16 ++++++++++++++-- desktop_version/src/Script.cpp | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index c52f4deb..08ee639c 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -121,6 +121,7 @@ public: int door_up; int door_down; int roomx, roomy, roomchangedir; + int prevroomx, prevroomy; int temp, j, k; int savex, savey, saverx, savery; diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 27505aae..b6fbfe3a 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -1059,9 +1059,18 @@ void mapclass::gotoroom(int rx, int ry, Graphics& dwgfx, Game& game, entityclass loadlevel(game.roomx, game.roomy, dwgfx, game, obj, music); - dwgfx.backgrounddrawn = false; //Used for background caching speedup + //Do we need to reload the background? + bool redrawbg = game.roomx != game.prevroomx || game.roomy != game.prevroomy; + + if(redrawbg) + { + dwgfx.backgrounddrawn = false; //Used for background caching speedup + } dwgfx.foregrounddrawn = false; //Used for background caching speedup + game.prevroomx = game.roomx; + game.prevroomy = game.roomy; + //a very special case: if entering the communication room, room 13,4 before tag 5 is set, set the game state to a background //textbox thingy. if tag five is not set when changing room, reset the game state. (tag 5 is set when you get back to the ship) if(!game.intimetrial && !custommode) @@ -1605,7 +1614,10 @@ void mapclass::loadlevel(int rx, int ry, Graphics& dwgfx, Game& game, entityclas } //If screen warping, then override all that: - dwgfx.backgrounddrawn = false; + bool redrawbg = game.roomx != game.prevroomx || game.roomy != game.prevroomy; + if(redrawbg){ + dwgfx.backgrounddrawn = false; + } if(ed.level[curlevel].warpdir>0){ if(ed.level[curlevel].warpdir==1){ warpx=true; diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index bd87bdfe..5a09c8fd 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -3427,6 +3427,8 @@ void scriptclass::hardreset( KeyPoll& key, Graphics& dwgfx, Game& game,mapclass& game.roomchange = false; game.roomx = 0; game.roomy = 0; + game.prevroomx = 0; + game.prevroomy = 0; game.teleport_to_new_area = false; game.teleport_to_x = 0; game.teleport_to_y = 0;