From d695aee00d8d09ba7cf3d82d73379aacb96a422b Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 7 Apr 2020 14:06:00 +0200 Subject: [PATCH] tour:: a system for easier restoration of slide-changed values --- tour.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tour.cpp b/tour.cpp index f4763c6b..3971a0b8 100644 --- a/tour.cpp +++ b/tour.cpp @@ -63,23 +63,40 @@ static const flagtype SIDESCREEN = 64; static const flagtype USE_SLIDE_NAME = 128; #endif +EX vector restorers; + +#if HDR +template void slide_backup(T& what, T value) { + T backup = what; + restorers.push_back([&what, backup] { what = backup; }); + what = value; + } +#endif + +EX void on_restore(const reaction_t& t) { + restorers.push_back(t); + } + +EX void slide_restore_all() { + while(!restorers.empty()) { + restorers.back()(); + restorers.pop_back(); + } + } + /** \brief an auxiliary function to enable a visualization in the Canvas land */ EX void setCanvas(presmode mode, char canv) { - static char wc; - static eLand ld; if(mode == pmStart) { gamestack::push(); - wc = patterns::whichCanvas; - patterns::whichCanvas = canv; - ld = firstland; - firstland = laCanvas; + slide_backup(patterns::whichCanvas, canv); + slide_backup(firstland, laCanvas); + slide_backup(specialland, laCanvas); start_game(); resetview(); } if(mode == pmStop) { gamestack::pop(); - patterns::whichCanvas = wc; - firstland = ld; + slide_restore_all(); } }