From 22d3d2590f773e3dfe6f2f6ebb2c35415ebe6a8d Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Fri, 26 Jan 2018 01:45:49 +0100 Subject: [PATCH] some work on the savemem feature --- blizzard.cpp | 3 +++ complex.cpp | 23 ++++++++++++++++++++++- hyper.h | 13 ++++++++++++- language-pl.cpp | 11 +++++++++++ mapeditor.cpp | 6 +++++- shmup.cpp | 15 +++++++++++++-- system.cpp | 10 +++++++++- yendor.cpp | 9 +++++++++ 8 files changed, 84 insertions(+), 6 deletions(-) diff --git a/blizzard.cpp b/blizzard.cpp index a900e1f5..81289578 100644 --- a/blizzard.cpp +++ b/blizzard.cpp @@ -234,4 +234,7 @@ auto ccm_blizzard = addHook(clearmemory, 0, [] () { arrowtraps.clear(); blizzardcells.clear(); bcells.clear(); + }) + +addHook(hooks_removecells, 0, [] () { + eliminate_if(arrowtraps, is_cell_removed); }); diff --git a/complex.cpp b/complex.cpp index a92abdd7..915d58a0 100644 --- a/complex.cpp +++ b/complex.cpp @@ -3025,7 +3025,28 @@ auto ccm = addHook(clearmemory, 0, [] () { prairie::tchoices.clear(); prairie::beaststogen.clear(); mirror::clearcache(); - }); + }) + + addHook(hooks_removecells, 0, [] () { + eliminate_if(heat::offscreen_heat, is_cell_removed); + eliminate_if(heat::offscreen_fire, is_cell_removed); + eliminate_if(princess::infos, [] (princess::info*& i) { + if(is_cell_removed(i->princess) || is_cell_removed(i->prison)) { + DEBSM(printf("removing a princess\n");) + if(i->princess && !is_cell_removed(i->princess)) { + DEBSM(printf("faking a princess\n");) + princess::newFakeInfo(i->princess); + } + delete i; + return true; + } + return false; + }); + set_if_removed(prairie::lasttreasure, NULL); + set_if_removed(prairie::enter, NULL); + eliminate_if(prairie::tchoices, is_cell_removed); + eliminate_if(prairie::beaststogen, is_cell_removed); + for(auto& bpd: clearing::bpdata) set_if_removed(bpd.second.root, NULL); + }); // windcode arrays precomputed for speed diff --git a/hyper.h b/hyper.h index 4635655a..68822919 100644 --- a/hyper.h +++ b/hyper.h @@ -28,6 +28,8 @@ typedef long double ld; #define DEBMEM(x) // { x fflush(stdout); } +#define DEBSM(x) + struct hyperpoint { ld tab[3]; ld& operator [] (int i) { return tab[i]; } @@ -1722,7 +1724,7 @@ template int addHook(hookset*& m, int prio, const U& hook) return 0; } -extern purehookset hooks_frame, hooks_stats, clearmemory, hooks_config, hooks_tests; +extern purehookset hooks_frame, hooks_stats, clearmemory, hooks_config, hooks_tests, hooks_removecells; template void callhooks(hookset *h, U... args) { if(h) for(auto& p: *h) p.second(args...); @@ -2497,3 +2499,12 @@ transmatrix rotmatrix(double rotation, int c0, int c1); void destroycellcontents(cell *c); extern heptagon *last_cleared; + +template void eliminate_if(vector& data, U pred) { + for(int i=0; ifirst)) { + monstersAt.insert(make_pair(nullptr, it->second)); + auto it0 = it; it++; + monstersAt.erase(it0); + } + else it++; + } + }); + } diff --git a/system.cpp b/system.cpp index 1b52ca1f..f19cf390 100644 --- a/system.cpp +++ b/system.cpp @@ -1224,5 +1224,13 @@ auto cgm = addHook(clearmemory, 40, [] () { buggycells.clear(); crush_next.clear(); crush_now.clear(); - }); + }) + +addHook(hooks_removecells, 0, [] () { + eliminate_if(crush_next, is_cell_removed); + eliminate_if(crush_now, is_cell_removed); + eliminate_if(buggycells, is_cell_removed); + eliminate_if(butterflies, [] (pair& p) { return is_cell_removed(p.first); }); + for(int i=0; i