mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-04-05 18:27:01 +00:00
moved the RogueViz cleanup system to core HyperRogue
This commit is contained in:
parent
03890caf1e
commit
a064c20b94
@ -897,15 +897,6 @@ void init(flagtype _vizflags) {
|
||||
|
||||
int search_for = -1;
|
||||
|
||||
vector<reaction_t> cleanup;
|
||||
|
||||
void do_cleanup() {
|
||||
while(!cleanup.empty()) {
|
||||
cleanup.back()();
|
||||
cleanup.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void close() {
|
||||
search_for = -1;
|
||||
for(int i=0; i<isize(vdata); i++)
|
||||
@ -917,7 +908,6 @@ void close() {
|
||||
edgeinfos.clear();
|
||||
callhooks(hooks_close);
|
||||
edgetypes.clear();
|
||||
do_cleanup();
|
||||
relmatrices.clear();
|
||||
}
|
||||
|
||||
|
@ -121,37 +121,6 @@ namespace rogueviz {
|
||||
|
||||
void storeall(int from = 0);
|
||||
|
||||
extern vector<reaction_t> 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<class T> void rv_change(T& variable, const T& value) {
|
||||
T backup = variable;
|
||||
variable = value;
|
||||
on_cleanup_or_next([backup, &variable] { variable = backup; });
|
||||
}
|
||||
|
||||
template<class T> void rv_keep(T& variable) {
|
||||
T backup = variable;
|
||||
on_cleanup_or_next([backup, &variable] { variable = backup; });
|
||||
}
|
||||
|
||||
template<class T, class U> void rv_hook(hookset<T>& 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<bool()> hooks_rvmenu_replace;
|
||||
inline hookset<bool(int&, string&, FILE*)> hooks_readcolor;
|
||||
inline purehookset hooks_close;
|
||||
|
||||
void readcolor(const string& cfname);
|
||||
|
||||
|
44
tour.cpp
44
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<reaction_t> 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<class T> void rv_change(T& variable, const T& value) {
|
||||
T backup = variable;
|
||||
variable = value;
|
||||
on_cleanup_or_next([backup, &variable] { variable = backup; });
|
||||
}
|
||||
|
||||
template<class T> void rv_keep(T& variable) {
|
||||
T backup = variable;
|
||||
on_cleanup_or_next([backup, &variable] { variable = backup; });
|
||||
}
|
||||
|
||||
template<class T, class U> void rv_hook(hookset<T>& 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
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user