From c80d6134e3cb9cd020fab0cadc9ce98ec6ae5a67 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 21 May 2022 16:38:39 +0200 Subject: [PATCH] adj_minefields_cells_with_orientation upgraded to adj_minefield_cells_full --- attack.cpp | 8 ++++---- cell.cpp | 35 +++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/attack.cpp b/attack.cpp index c128247a..dc016a39 100644 --- a/attack.cpp +++ b/attack.cpp @@ -326,8 +326,8 @@ EX void prespill(cell* c, eWall t, int rad, cell *from) { // block spill if(t == waTemporary) return; // cwt.at->item = itNone; - if(rad) for(auto p: adj_minefield_cells_with_orientation(c)) { - prespill(p.first, conditional_flip_slime(p.second, t), rad-1, c); + if(rad) for(auto p: adj_minefield_cells_full(c)) { + prespill(p.c, conditional_flip_slime(p.mirrored, t), rad-1, c); } } @@ -342,8 +342,8 @@ EX void spillfix(cell* c, eWall t, int rad) { changes.ccell(c); c->wall = t; } - if(rad) for(auto p: adj_minefield_cells_with_orientation(c)) { - spillfix(p.first, conditional_flip_slime(p.second, t), rad-1); + if(rad) for(auto p: adj_minefield_cells_full(c)) { + spillfix(p.c, conditional_flip_slime(p.mirrored, t), rad-1); } } diff --git a/cell.cpp b/cell.cpp index 6b5ce6dc..914ff0b7 100644 --- a/cell.cpp +++ b/cell.cpp @@ -1355,7 +1355,15 @@ EX int neighborId(cell *ofWhat, cell *whichOne) { EX int mine_adjacency_rule = 0; -EX map>> adj_memo; +#if HDR +struct adj_data { + cell *c; + bool mirrored; + transmatrix T; + }; +#endif + +EX map> adj_memo; EX bool geometry_has_alt_mine_rule() { if(S3 >= OINF) return false; @@ -1364,24 +1372,29 @@ EX bool geometry_has_alt_mine_rule() { return true; } -EX vector> adj_minefield_cells_with_orientation(cell *c) { - vector> res; - if(mine_adjacency_rule == 0 || !geometry_has_alt_mine_rule()) - forCellIdCM(c2, i, c) res.emplace_back(c2, c->c.mirror(i)); +EX vector adj_minefield_cells_full(cell *c) { + if(adj_memo.count(c)) return adj_memo[c]; + if(isize(adj_memo) > 10000) adj_memo.clear(); + auto& res = adj_memo[c]; + if(mine_adjacency_rule == 0 || !geometry_has_alt_mine_rule()) { + forCellIdCM(c2, i, c) res.emplace_back(adj_data{c2, c->c.mirror(i), currentmap->adj(c, i)}); + } else if(WDIM == 2) { cellwalker cw(c, 0); + transmatrix T = Id; + T = T * currentmap->adj(c, 0); cw += wstep; cw++; cellwalker cw1 = cw; do { - res.emplace_back(cw.at, cw.mirrored); + res.emplace_back(adj_data{cw.at, cw.mirrored, T}); + T = T * currentmap->adj(c, cw.spin); cw += wstep; cw++; if(cw.cpeek() == c) cw++; } while(cw != cw1); } - else if(adj_memo.count(c)) return adj_memo[c]; else { auto& ss = currentmap->get_cellshape(c); const vector& vertices = ss.vertices_only_local; @@ -1397,7 +1410,7 @@ EX vector> adj_minefield_cells_with_orientation(cell *c) { auto& vertices1 = ss1.vertices_only_local; for(hyperpoint h: vertices) for(hyperpoint h2: vertices1) if(hdist(h, T * h2) < 1e-6) shares = true; - if(shares) res.emplace_back(c1, det(T) < 0); + if(shares) res.emplace_back(adj_data{c1, det(T) < 0, T}); } if(shares || c == c1) forCellIdEx(c2, i, c1) { if(cl.listed(c2)) continue; @@ -1405,16 +1418,14 @@ EX vector> adj_minefield_cells_with_orientation(cell *c) { M.push_back(T * currentmap->adj(c1, i)); } } - // println(hlog, "adjacent to ", c, " = ", isize(res), " of ", isize(M)); - adj_memo[c] = res; } return res; } EX vector adj_minefield_cells(cell *c) { vector res; - auto ori = adj_minefield_cells_with_orientation(c); - for(auto p: ori) res.push_back(p.first); + auto ori = adj_minefield_cells_full(c); + for(auto p: ori) res.push_back(p.c); return res; }