From 9bfc3ba400f17df6240193b174c05a8ee8c17e7c Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 16 Apr 2026 19:02:07 +0200 Subject: [PATCH] stuff affected by on_dim_change now implements the dim_listener interface --- aperiodic-hat.cpp | 2 +- cell.cpp | 7 ++++--- fake.cpp | 4 ++-- geometry.cpp | 21 ++++++++++++++++++++- shmup.cpp | 12 ++++-------- sphere.cpp | 6 ++++-- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/aperiodic-hat.cpp b/aperiodic-hat.cpp index e3fb562e..f3cdc128 100644 --- a/aperiodic-hat.cpp +++ b/aperiodic-hat.cpp @@ -784,7 +784,7 @@ vector spectre_rules_recursive = { rule_recursive EX ld hat_param = 1; EX ld hat_param_imag = 0; -struct hrmap_hat : hrmap { +struct hrmap_hat : hrmap, dim_listener { // always generate the same way std::mt19937 hatrng; diff --git a/cell.cpp b/cell.cpp index 2a9b7e88..3330f09a 100644 --- a/cell.cpp +++ b/cell.cpp @@ -29,7 +29,6 @@ struct hrmap { virtual ~hrmap() { } virtual vector& allcells(); virtual void verify() { } - virtual void on_dim_change() { } virtual bool link_alt(heptagon *h, heptagon *alt, hstate firststate, int dir); virtual void extend_altmap(heptagon *h, int levs = default_levs(), bool link_cdata = true); heptagon *may_create_step(heptagon *h, int direction) { @@ -37,6 +36,8 @@ struct hrmap { return create_step(h, direction); } virtual heptagon *create_step(heptagon *h, int direction); + /** reinitialize the map after swapping dimensions */ + virtual void reinit() {} protected: virtual transmatrix relative_matrixh(heptagon *h2, heptagon *h1, const hyperpoint& hint); virtual transmatrix relative_matrixc(cell *c2, cell *c1, const hyperpoint& hint); @@ -103,7 +104,7 @@ public: * Liskov substitution warning: maps which produce both tiling like above and 3D tilings * (e.g. Euclidean and Crystal) also inherit from hrmap_standard **/ -struct hrmap_standard : hrmap { +struct hrmap_standard : hrmap, dim_listener { void draw_at(cell *at, const shiftmatrix& where) override; transmatrix relative_matrixh(heptagon *h2, heptagon *h1, const hyperpoint& hint) override; transmatrix relative_matrixc(cell *c2, cell *c1, const hyperpoint& hint) override; @@ -592,7 +593,7 @@ EX void initcells() { check_cgi(); geom3::swap_direction = +1; for(auto& m: cgi.heptmove) swapmatrix(m); - currentmap->on_dim_change(); + currentmap->reinit(); return; } diff --git a/fake.cpp b/fake.cpp index 78c32628..c9b3d132 100644 --- a/fake.cpp +++ b/fake.cpp @@ -25,8 +25,8 @@ EX namespace fake { EX bool in_ext() { return in() || (mhybrid && PIU(in())); } - EX void on_dim_change() { pmap->on_dim_change(); } - + EX void reinit() override { pmap->reinit(); } + /** like in() but takes slided arb into account */ EX bool split() { return in() || arb::in_slided(); } diff --git a/geometry.cpp b/geometry.cpp index 663a0cda..22982dad 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -986,6 +986,25 @@ void geometry_information::prepare_basics() { EX purehookset hooks_swapdim; +#if HDR +extern struct dim_listener *dl_list; + +struct dim_listener { + dim_listener *next, **prev; + dim_listener() { + dl_list->prev = &next; + next = dl_list; + dl_list = this; + } + ~dim_listener() { + *prev = next; next->prev = prev; + } + virtual void on_dim_change() {} + }; +#endif + +dim_listener *dl_list; + EX hookset hooks_scalefactor; EX namespace geom3 { @@ -1210,7 +1229,7 @@ EX namespace geom3 { swapmatrix_view(NLP, View); swapmatrix_view(NLP, current_display->which_copy); callhooks(hooks_swapdim); - for(auto m: allmaps) m->on_dim_change(); + auto dl = dl_list; while(dl) { dl->on_dim_change(); dl = dl->next; } } #if MAXMDIM >= 4 diff --git a/shmup.cpp b/shmup.cpp index ee0f8169..8c327369 100644 --- a/shmup.cpp +++ b/shmup.cpp @@ -34,7 +34,8 @@ ld sqdist(shiftpoint a, shiftpoint b) { EX namespace shmup { #if HDR -struct monster { + +struct monster : dim_listener { eMonster type; cell *base; ///< on which base cell this monster currently is cell *torigin; ///< tortoises: origin, butterflies: last position @@ -92,7 +93,8 @@ struct monster { parent->refs++; } - }; + void on_dim_change() override { swapmatrix(at); } + }; #endif void monster::reset() { @@ -3056,12 +3058,6 @@ EX void switch_shmup() { start_game(); } -#if MAXMDIM >= 4 -auto hooksw = addHook(hooks_swapdim, 100, [] { - for(auto& p: monstersAt) swapmatrix(p.second->at); - }); -#endif - EX shiftmatrix at_missile_level(const shiftmatrix& T) { if(WDIM == 3) return T; if(GDIM == 3) return orthogonal_move(T, cgi.BODY); diff --git a/sphere.cpp b/sphere.cpp index d66617e6..104a706b 100644 --- a/sphere.cpp +++ b/sphere.cpp @@ -172,11 +172,13 @@ struct hrmap_spherical : hrmap_standard { return Id; } - void on_dim_change() override { - hrmap_standard::on_dim_change(); + void reinit() override { + hrmap_standard::reinit(); where.clear(); } + void on_dim_change() override { reinit(); } + transmatrix relative_matrixc(cell *c2, cell *c1, const hyperpoint& hint) override { if(IRREGULAR) return relative_matrix_via_masters(c2, c1, hint); transmatrix T = iso_inverse(get_where(c1)) * get_where(c2);