diff --git a/rogueviz/graphs.cpp b/rogueviz/graphs.cpp index 89128ab0..1a74b961 100644 --- a/rogueviz/graphs.cpp +++ b/rogueviz/graphs.cpp @@ -897,15 +897,6 @@ void init(flagtype _vizflags) { int search_for = -1; -vector cleanup; - -void do_cleanup() { - while(!cleanup.empty()) { - cleanup.back()(); - cleanup.pop_back(); - } - } - void close() { search_for = -1; for(int i=0; i cleanup; - - void do_cleanup(); - - inline void on_cleanup_or_next(const reaction_t& del) { - #if CAP_TOUR - if(tour::on) tour::on_restore(del); - else - #endif - cleanup.push_back(del); - } - - template void rv_change(T& variable, const T& value) { - T backup = variable; - variable = value; - on_cleanup_or_next([backup, &variable] { variable = backup; }); - } - - template void rv_keep(T& variable) { - T backup = variable; - on_cleanup_or_next([backup, &variable] { variable = backup; }); - } - - template void rv_hook(hookset& m, int prio, U&& hook) { - int p = addHook(m, prio, hook); - auto del = [&m, p] { - delHook(m, p); - }; - on_cleanup_or_next(del); - } - extern bool showlabels; extern bool rog3; @@ -164,7 +133,6 @@ namespace rogueviz { inline purehookset hooks_rvmenu; inline hookset hooks_rvmenu_replace; inline hookset hooks_readcolor; - inline purehookset hooks_close; void readcolor(const string& cfname); diff --git a/tour.cpp b/tour.cpp index a7738b93..5eb0f9f0 100644 --- a/tour.cpp +++ b/tour.cpp @@ -1068,5 +1068,49 @@ auto a2 = addHook(hooks_handleKey, 100, handleKeyTour); auto a3 = addHook(hooks_nextland, 100, [] (eLand l) { return tour::on ? getNext(l) : laNone; }); EX } + +/* these were originally in RogueViz, but useful enough to be moved to main */ + +EX vector cleanup; + +EX void do_cleanup() { + while(!cleanup.empty()) { + cleanup.back()(); + cleanup.pop_back(); + } + } + +EX void on_cleanup_or_next(const reaction_t& del) { + #if CAP_TOUR + if(tour::on) tour::on_restore(del); + else + #endif + cleanup.push_back(del); + } + +#if HDR +template void rv_change(T& variable, const T& value) { + T backup = variable; + variable = value; + on_cleanup_or_next([backup, &variable] { variable = backup; }); + } + +template void rv_keep(T& variable) { + T backup = variable; + on_cleanup_or_next([backup, &variable] { variable = backup; }); + } + +template void rv_hook(hookset& m, int prio, U&& hook) { + int p = addHook(m, prio, hook); + auto del = [&m, p] { + delHook(m, p); + }; + on_cleanup_or_next(del); + } #endif + +int ah_cleanup = addHook(hooks_clearmemory, 500, [] { do_cleanup(); }); + +#endif + }