prevent stored games from having their cgi destroyed

This commit is contained in:
Zeno Rogue 2022-08-05 20:06:05 +02:00
parent 1c01cc7f94
commit 1f832faeba
2 changed files with 15 additions and 4 deletions

View File

@ -524,8 +524,8 @@ hpcshape
/** contains the texture point coordinates for 3D models */ /** contains the texture point coordinates for 3D models */
basic_textureinfo models_texture; basic_textureinfo models_texture;
geometry_information() { last = NULL; } geometry_information() { last = NULL; use_count = 0; }
void require_basics() { if(state & 1) return; state |= 1; prepare_basics(); } void require_basics() { if(state & 1) return; state |= 1; prepare_basics(); }
void require_shapes() { if(state & 2) return; state |= 2; prepare_shapes(); } void require_shapes() { if(state & 2) return; state |= 2; prepare_shapes(); }
@ -535,6 +535,9 @@ hpcshape
hpcshape& generate_pipe(ld length, ld width, ePipeEnd endtype = ePipeEnd::sharp); hpcshape& generate_pipe(ld length, ld width, ePipeEnd endtype = ePipeEnd::sharp);
map<string, unique_ptr<gi_extension>> ext; map<string, unique_ptr<gi_extension>> ext;
/** prevent from being destroyed */
int use_count;
}; };
#endif #endif
@ -1238,9 +1241,11 @@ EX void check_cgi() {
if(arcm::alt_cgip) arcm::alt_cgip->timestamp = ntimestamp; if(arcm::alt_cgip) arcm::alt_cgip->timestamp = ntimestamp;
#endif #endif
if(isize(cgis) > 4 && IFINTRA(intra::data.empty(), true)) { int limit = 4;
for(auto& t: cgis) if(t.second.use_count) limit++;
if(isize(cgis) > limit) {
vector<pair<int, string>> timestamps; vector<pair<int, string>> timestamps;
for(auto& t: cgis) timestamps.emplace_back(-t.second.timestamp, t.first); for(auto& t: cgis) if(!t.second.use_count) timestamps.emplace_back(-t.second.timestamp, t.first);
sort(timestamps.begin(), timestamps.end()); sort(timestamps.begin(), timestamps.end());
while(isize(timestamps) > 4) { while(isize(timestamps) > 4) {
DEBB(DF_GEOM, ("erasing geometry ", timestamps.back().second)); DEBB(DF_GEOM, ("erasing geometry ", timestamps.back().second));

View File

@ -60,8 +60,14 @@ void gamedata_all(gamedata& gd) {
gd.store(land_structure); gd.store(land_structure);
gd.store(*current_display); gd.store(*current_display);
gd.store(cgip); gd.store(cgip);
if(gd.mode == 0) cgip->use_count++;
if(gd.mode != 0) cgip->use_count--;
gd.store(hybrid::underlying); gd.store(hybrid::underlying);
gd.store(hybrid::csteps); gd.store(hybrid::csteps);
if(hybri && hybrid::underlying_cgip) {
if(gd.mode == 0) hybrid::underlying_cgip->use_count++;
if(gd.mode != 0) hybrid::underlying_cgip->use_count--;
}
gd.store(hybrid::underlying_cgip); gd.store(hybrid::underlying_cgip);
gd.store_ptr(vid.projection_config); gd.store_ptr(vid.projection_config);
gd.store_ptr(vid.rug_config); gd.store_ptr(vid.rug_config);