tour:: a system for easier restoration of slide-changed values

This commit is contained in:
Zeno Rogue 2020-04-07 14:06:00 +02:00
parent 7438fbf4c8
commit d695aee00d
1 changed files with 25 additions and 8 deletions

View File

@ -63,23 +63,40 @@ static const flagtype SIDESCREEN = 64;
static const flagtype USE_SLIDE_NAME = 128; static const flagtype USE_SLIDE_NAME = 128;
#endif #endif
EX vector<reaction_t> restorers;
#if HDR
template<class T> 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 */ /** \brief an auxiliary function to enable a visualization in the Canvas land */
EX void setCanvas(presmode mode, char canv) { EX void setCanvas(presmode mode, char canv) {
static char wc;
static eLand ld;
if(mode == pmStart) { if(mode == pmStart) {
gamestack::push(); gamestack::push();
wc = patterns::whichCanvas; slide_backup(patterns::whichCanvas, canv);
patterns::whichCanvas = canv; slide_backup(firstland, laCanvas);
ld = firstland; slide_backup(specialland, laCanvas);
firstland = laCanvas;
start_game(); start_game();
resetview(); resetview();
} }
if(mode == pmStop) { if(mode == pmStop) {
gamestack::pop(); gamestack::pop();
patterns::whichCanvas = wc; slide_restore_all();
firstland = ld;
} }
} }