diff --git a/common/main/wall.h b/common/main/wall.h index 7208d5c95..4b961cbd9 100644 --- a/common/main/wall.h +++ b/common/main/wall.h @@ -176,7 +176,10 @@ struct active_door : public prohibit_void_ptr fix time; // how long been opening, closing, waiting }; -DXX_VALPTRIDX_DEFINE_GLOBAL_FACTORIES(active_door, actdoor, ActiveDoors); +struct d_level_unique_active_door_state +{ + active_door_array ActiveDoors; +}; } @@ -203,6 +206,7 @@ struct d_level_unique_wall_state }; struct d_level_unique_wall_subsystem_state : + d_level_unique_active_door_state, d_level_unique_wall_state #if defined(DXX_BUILD_DESCENT_II) , d_level_unique_cloaking_wall_state diff --git a/similar/editor/medwall.cpp b/similar/editor/medwall.cpp index 3383bd4c7..eb8869b28 100644 --- a/similar/editor/medwall.cpp +++ b/similar/editor/medwall.cpp @@ -641,7 +641,8 @@ int wall_restore_all() w.flags &= ~(WALL_BLASTED | WALL_DOOR_OPENED | WALL_DOOR_OPENING | WALL_EXPLODING); } - range_for (auto &&i, vmactdoorptr) + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; + range_for (auto &&i, ActiveDoors.vmptr) wall_close_door_ref(Segments.vmptridx, Walls, WallAnims, i); range_for (auto &&i, vmsegptr) diff --git a/similar/main/dumpmine.cpp b/similar/main/dumpmine.cpp index 169c367f9..0399a7ec3 100644 --- a/similar/main/dumpmine.cpp +++ b/similar/main/dumpmine.cpp @@ -656,6 +656,7 @@ void write_game_text_file(const char *filename) auto &Walls = LevelUniqueWallSubsystemState.Walls; auto &vcwallptridx = Walls.vcptridx; PHYSFSX_printf(my_file, "Number of walls: %4i\n", Walls.get_count()); + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; PHYSFSX_printf(my_file, "Number of open doors: %4i\n", ActiveDoors.get_count()); PHYSFSX_printf(my_file, "Number of triggers: %4i\n", Triggers.get_count()); PHYSFSX_printf(my_file, "Number of matcens: %4i\n", Num_robot_centers); diff --git a/similar/main/gamesave.cpp b/similar/main/gamesave.cpp index 6c86e444f..4b3f6c549 100644 --- a/similar/main/gamesave.cpp +++ b/similar/main/gamesave.cpp @@ -1105,6 +1105,7 @@ static int load_game_data( validate_segment_wall(i, side, eside.idx); } + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; ActiveDoors.set_count(0); //go through all walls, killing references to invalid triggers @@ -1545,6 +1546,7 @@ int create_new_mine(void) } Num_robot_centers = 0; + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; ActiveDoors.set_count(0); wall_init(); trigger_init(); @@ -1616,6 +1618,7 @@ static int save_game_data( WRITE_HEADER_ENTRY(object, Highest_object_index + 1); auto &Walls = LevelUniqueWallSubsystemState.Walls; WRITE_HEADER_ENTRY(wall, Walls.get_count()); + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; WRITE_HEADER_ENTRY(active_door, ActiveDoors.get_count()); WRITE_HEADER_ENTRY(trigger, Triggers.get_count()); WRITE_HEADER_ENTRY(0, 0); // links (removed by Parallax) diff --git a/similar/main/mglobal.cpp b/similar/main/mglobal.cpp index b4e744576..33678d242 100644 --- a/similar/main/mglobal.cpp +++ b/similar/main/mglobal.cpp @@ -41,7 +41,6 @@ namespace dcx { d_level_shared_vertex_state LevelSharedVertexState; d_level_unique_segment_state LevelUniqueSegmentState; // Global array of vertices, common to one mine. -valptridx::array_managed_type ActiveDoors; valptridx::array_managed_type Players; valptridx::array_managed_type Segments; } diff --git a/similar/main/state.cpp b/similar/main/state.cpp index 9be40137a..2b41ec8fe 100644 --- a/similar/main/state.cpp +++ b/similar/main/state.cpp @@ -1117,12 +1117,15 @@ int state_save_all_sub(const char *filename, const char *desc) } //Save door info + { + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; { const int i = ActiveDoors.get_count(); PHYSFS_write(fp, &i, sizeof(int), 1); } - range_for (auto &&ad, vcactdoorptr) + range_for (auto &&ad, ActiveDoors.vcptr) active_door_write(fp, ad); + } #if defined(DXX_BUILD_DESCENT_II) //Save cloaking wall info @@ -1716,9 +1719,12 @@ int state_restore_all_sub(const d_level_shared_destructible_light_state &LevelSh } //Restore door info + { + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; ActiveDoors.set_count(PHYSFSX_readSXE32(fp, swap)); - range_for (auto &&ad, vmactdoorptr) + range_for (auto &&ad, ActiveDoors.vmptr) active_door_read(fp, ad); + } #if defined(DXX_BUILD_DESCENT_II) if (version >= 14) { //Restore cloaking wall info diff --git a/similar/main/wall.cpp b/similar/main/wall.cpp index 213f1dbb3..941fd7e34 100644 --- a/similar/main/wall.cpp +++ b/similar/main/wall.cpp @@ -244,6 +244,7 @@ void wall_init() w.clip_num = -1; w.linked_wall = -1; } + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; ActiveDoors.set_count(0); #if defined(DXX_BUILD_DESCENT_II) auto &CloakingWalls = LevelUniqueWallSubsystemState.CloakingWalls; @@ -408,6 +409,8 @@ void wall_open_door(const vmsegptridx_t seg, int side) return; #endif + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; + auto &vmactdoorptr = ActiveDoors.vmptr; if (w->state == WALL_DOOR_CLOSING) { //closing, so reuse door const auto &&r = make_range(vmactdoorptr); const auto &&i = std::find_if(r.begin(), r.end(), find_active_door_predicate(wall_num)); @@ -745,6 +748,8 @@ void wall_close_door(wall_array &Walls, const vmsegptridx_t seg, const unsigned if (is_door_obstructed(vcobjptridx, vcsegptr, seg, side)) return; + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; + auto &vmactdoorptr = ActiveDoors.vmptr; if (w->state == WALL_DOOR_OPENING) { //reuse door const auto &&r = make_range(vmactdoorptr); const auto &&i = std::find_if(r.begin(), r.end(), find_active_door_predicate(wall_num)); @@ -1342,6 +1347,7 @@ void wall_frame_process() { process_exploding_walls(); { + auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; const auto &&r = partial_range(ActiveDoors, ActiveDoors.get_count()); auto &&i = std::remove_if(r.begin(), r.end(), ad_removal_predicate()); ActiveDoors.set_count(std::distance(r.begin(), i));