Move ActiveDoors to d_level_unique_active_door_state

This commit is contained in:
Kp 2018-12-30 00:43:58 +00:00
parent 865bad8607
commit 4b125af449
7 changed files with 25 additions and 5 deletions

View file

@ -176,7 +176,10 @@ struct active_door : public prohibit_void_ptr<active_door>
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

View file

@ -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)

View file

@ -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);

View file

@ -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)

View file

@ -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<active_door>::array_managed_type ActiveDoors;
valptridx<player>::array_managed_type Players;
valptridx<segment>::array_managed_type Segments;
}

View file

@ -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

View file

@ -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));