mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-03-13 23:18:16 +00:00
intra:: optimize saved maps
This commit is contained in:
parent
5d5f93e1bc
commit
6db94b134d
23
intra.cpp
23
intra.cpp
@ -726,6 +726,29 @@ EX void kill(int id) {
|
||||
println(hlog, isize(to_remove), " connections and ", isize(to_erase_cell), " cells erased");
|
||||
}
|
||||
|
||||
EX set<cell*> need_to_save;
|
||||
|
||||
EX void prepare_need_to_save() {
|
||||
need_to_save.clear();
|
||||
map<cell*, cell*> parent;
|
||||
vector<cell*> q;
|
||||
cell *s = mapstream::save_start();
|
||||
parent[s] = s;
|
||||
q = {s};
|
||||
for(int i=0; i<isize(q); i++) {
|
||||
cell *c = q[i];
|
||||
forCellEx(c2, c)
|
||||
if(!parent.count(c2)) { parent[c2] = c; q.push_back(c2); }
|
||||
}
|
||||
for(int i=isize(q)-1; i>=0; i--) {
|
||||
cell *c = q[i];
|
||||
if(c == cwt.at) need_to_save.insert(c);
|
||||
for(auto& p: connections) if(p.first.at == c) need_to_save.insert(c);
|
||||
if(need_to_save.count(c)) need_to_save.insert(parent[c]);
|
||||
}
|
||||
println(hlog, "need to save ", isize(need_to_save), " out of ", isize(q), " cells");
|
||||
}
|
||||
|
||||
auto hooks1 =
|
||||
addHook(hooks_o_key, 90, [] (o_funcs& v) {
|
||||
if(intra::in) v.push_back(named_dialog(XLAT("manage portals"), show_portals));
|
||||
|
@ -702,6 +702,7 @@ EX namespace mapstream {
|
||||
}
|
||||
|
||||
addToQueue(save_start());
|
||||
if(intra::in) intra::prepare_need_to_save();
|
||||
for(int i=0; i<isize(cellbyid); i++) {
|
||||
cell *c = cellbyid[i];
|
||||
if(i) {
|
||||
@ -743,6 +744,9 @@ EX namespace mapstream {
|
||||
// f.write_char(c->bardir);
|
||||
f.write(c->wparam); f.write(c->landparam);
|
||||
f.write_char(c->stuntime); f.write_char(c->hitpoints);
|
||||
bool blocked = false;
|
||||
if(intra::in && isWall3(c) && !intra::need_to_save.count(c)) blocked = true;
|
||||
if(!blocked)
|
||||
for(int j=0; j<c->type; j++) {
|
||||
cell *c2 = c->move(j);
|
||||
if(c2 && c2->land != laNone) addToQueue(c2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user