mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-09-06 04:17:58 +00:00
major rewrite: unified the common parts of heptagon and cell via struct connection<T> and struct walker<T>
This commit is contained in:
44
savemem.cpp
44
savemem.cpp
@@ -32,8 +32,8 @@ void slow_delete_cell(cell *c) {
|
||||
while(c->mpdist < BARLEV)
|
||||
degrade(c);
|
||||
for(int i=0; i<c->type; i++)
|
||||
if(c->mov[i])
|
||||
c->mov[i]->mov[c->spn(i)] = NULL;
|
||||
if(c->move(i))
|
||||
c->move(i)->move(c->c.spin(i)) = NULL;
|
||||
removed_cells.push_back(c);
|
||||
delete c;
|
||||
}
|
||||
@@ -42,20 +42,20 @@ void delete_heptagon(heptagon *h2) {
|
||||
cell *c = h2->c7;
|
||||
if(!nonbitrunc) {
|
||||
for(int i=0; i<c->type; i++)
|
||||
if(c->mov[i])
|
||||
slow_delete_cell(c->mov[i]);
|
||||
if(c->move(i))
|
||||
slow_delete_cell(c->move(i));
|
||||
}
|
||||
slow_delete_cell(c);
|
||||
for(int i=0; i<S7; i++)
|
||||
if(h2->move[i])
|
||||
h2->move[i]->move[h2->spin(i)] = NULL;
|
||||
if(h2->move(i))
|
||||
h2->move(i)->move(h2->c.spin(i)) = NULL;
|
||||
delete h2;
|
||||
}
|
||||
|
||||
void recursive_delete(heptagon *h, int i) {
|
||||
heptagon *h2 = h->move[i];
|
||||
heptagon *h2 = h->move(i);
|
||||
{ for(int i=1; i<S7; i++)
|
||||
if(h2->move[i] && h2->move[i]->move[0] == h2)
|
||||
if(h2->move(i) && h2->move(i)->move(0) == h2)
|
||||
recursive_delete(h2, i); }
|
||||
if(h2->alt && h2->alt->alt == h2->alt) {
|
||||
DEBSM(printf("destroying alternate map %p\n", h2->alt);)
|
||||
@@ -74,7 +74,7 @@ void recursive_delete(heptagon *h, int i) {
|
||||
h2->alt->cdata = NULL;
|
||||
}
|
||||
delete_heptagon(h2);
|
||||
h->move[i] = NULL;
|
||||
h->move(i) = NULL;
|
||||
}
|
||||
|
||||
bool unsafeLand(cell *c) {
|
||||
@@ -86,11 +86,11 @@ bool unsafeLand(cell *c) {
|
||||
void save_memory() {
|
||||
if(quotient || !hyperbolic) return;
|
||||
if(!memory_saving_mode) return;
|
||||
if(unsafeLand(cwt.c)) return;
|
||||
int d = celldist(cwt.c);
|
||||
if(unsafeLand(cwt.at)) return;
|
||||
int d = celldist(cwt.at);
|
||||
if(d < LIM+10) return;
|
||||
|
||||
heptagon *at = cwt.c->master;
|
||||
heptagon *at = cwt.at->master;
|
||||
heptagon *orig = currentmap->gamestart()->master;
|
||||
|
||||
if(recallCell) {
|
||||
@@ -100,13 +100,13 @@ void save_memory() {
|
||||
while(at != at2) {
|
||||
t++; if(t > 10000) return;
|
||||
if(celldist(at->c7) > celldist(at2->c7))
|
||||
at = at->move[0];
|
||||
at = at->move(0);
|
||||
else
|
||||
at2 = at2->move[0];
|
||||
at2 = at2->move(0);
|
||||
}
|
||||
}
|
||||
|
||||
while(celldist(at->c7) > d-LIM) at = at->move[0];
|
||||
while(celldist(at->c7) > d-LIM) at = at->move(0);
|
||||
|
||||
// go back to such a point X that all the heptagons adjacent to the current 'at'
|
||||
// are the children of X. This X becomes the new 'at'
|
||||
@@ -115,8 +115,8 @@ void save_memory() {
|
||||
int hcount = 0;
|
||||
allh[hcount++] = at;
|
||||
for(int j=0; j<S7; j++)
|
||||
if(allh[0]->move[j])
|
||||
allh[hcount++] = at->move[j];
|
||||
if(allh[0]->move(j))
|
||||
allh[hcount++] = at->move(j);
|
||||
|
||||
int deuniq_steps = 0;
|
||||
|
||||
@@ -125,10 +125,10 @@ void save_memory() {
|
||||
if(allh[i] == allh[0])
|
||||
allh[i] = allh[hcount-1], hcount--;
|
||||
else if(celldist(allh[i]->c7) > celldist(allh[0]->c7))
|
||||
allh[i] = allh[i]->move[0];
|
||||
allh[i] = allh[i]->move(0);
|
||||
else {
|
||||
if(allh[0] == orig) return;
|
||||
allh[0] = allh[0]->move[0];
|
||||
allh[0] = allh[0]->move(0);
|
||||
i = 1;
|
||||
deuniq_steps++;
|
||||
if(deuniq_steps == 10) return;
|
||||
@@ -141,15 +141,15 @@ void save_memory() {
|
||||
if(last_cleared && celldist(at->c7) < celldist(last_cleared->c7))
|
||||
return;
|
||||
|
||||
DEBSM(printf("celldist = %d, %d\n", celldist(cwt.c), celldist(at->c7));)
|
||||
DEBSM(printf("celldist = %d, %d\n", celldist(cwt.at), celldist(at->c7));)
|
||||
|
||||
heptagon *at1 = at;
|
||||
while(at != last_cleared && at != orig) {
|
||||
heptagon *atn = at;
|
||||
at = at->move[0];
|
||||
at = at->move(0);
|
||||
|
||||
for(int i=1; i<S7; i++)
|
||||
if(at->move[i] && at->move[i] != atn)
|
||||
if(at->move(i) && at->move(i) != atn)
|
||||
recursive_delete(at, i);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user