diff --git a/common/main/automap.h b/common/main/automap.h index 05f1e0a6b..54318255a 100644 --- a/common/main/automap.h +++ b/common/main/automap.h @@ -43,9 +43,6 @@ void do_automap(); extern void automap_clear_visited(); } #endif -namespace dcx { -extern array Automap_visited; -} #if defined(DXX_BUILD_DESCENT_II) #include "object.h" diff --git a/common/main/segment.h b/common/main/segment.h index 557298a92..ffd429b00 100644 --- a/common/main/segment.h +++ b/common/main/segment.h @@ -349,6 +349,11 @@ struct d_level_shared_segment_state } }; +struct d_level_unique_automap_state +{ + array Automap_visited; +}; + struct d_level_unique_segment_state { auto &get_segments() @@ -361,6 +366,7 @@ struct d_level_unique_segment_state } }; +extern d_level_unique_automap_state LevelUniqueAutomapState; extern d_level_unique_segment_state LevelUniqueSegmentState; #endif diff --git a/similar/main/automap.cpp b/similar/main/automap.cpp index 8f5eac328..fac960015 100644 --- a/similar/main/automap.cpp +++ b/similar/main/automap.cpp @@ -188,6 +188,15 @@ namespace dcx { int Automap_active = 0; static int Automap_debug_show_all_segments; + +static void automap_clear_visited() +{ +#ifndef NDEBUG + Automap_debug_show_all_segments = 0; +#endif + LevelUniqueAutomapState.Automap_visited = {}; +} + } namespace dsx { @@ -208,11 +217,6 @@ static void init_automap_colors(automap *am) am->blue_48 = gr_find_closest_color_current(0,0,48); am->red_48 = gr_find_closest_color_current(48,0,0); } -} - -namespace dcx { -array Automap_visited; // Segment visited list -} // Map movement defines #define PITCH_DEFAULT 9000 @@ -220,9 +224,7 @@ array Automap_visited; // Segment visited list #define ZOOM_MIN_VALUE i2f(20*5) #define ZOOM_MAX_VALUE i2f(20*100) - // Function Prototypes -namespace dsx { static void adjust_segment_limit(automap *am, int SegmentLimit); static void automap_build_edge_list(automap *am, int add_all_edges); } @@ -462,10 +464,7 @@ static void ClearMarkers() void automap_clear_visited() { - Automap_visited = {}; -#ifndef NDEBUG - Automap_debug_show_all_segments = 0; -#endif + ::dcx::automap_clear_visited(); ClearMarkers(); } @@ -745,7 +744,7 @@ static void draw_automap(fvcobjptr &vcobjptr, automap *am) } break; case OBJ_POWERUP: - if (Automap_visited[objp->segnum] || Automap_debug_show_all_segments) + if (LevelUniqueAutomapState.Automap_visited[objp->segnum] || Automap_debug_show_all_segments) { ubyte id = get_powerup_id(objp); unsigned r, g, b; @@ -828,7 +827,7 @@ static void recompute_automap_segment_visibility(const object &plrobj, automap * if (Automap_debug_show_all_segments) compute_depth_all_segments = 1; automap_build_edge_list(am, compute_depth_all_segments); - am->max_segments_away = set_segment_depths(plrobj.segnum, compute_depth_all_segments ? nullptr : &Automap_visited, am->depth_array); + am->max_segments_away = set_segment_depths(plrobj.segnum, compute_depth_all_segments ? nullptr : &LevelUniqueAutomapState.Automap_visited, am->depth_array); am->segment_limit = am->max_segments_away; adjust_segment_limit(am, am->segment_limit); } @@ -1427,7 +1426,7 @@ static void add_segment_edges(fvcsegptr &vcsegptr, fvcwallptr &vcwallptr, automa if (!Automap_debug_show_all_segments) { auto &player_info = get_local_plrobj().ctype.player_info; - if ((cheats.fullautomap || player_info.powerup_flags & PLAYER_FLAGS_MAP_ALL) && (!Automap_visited[segnum])) + if ((cheats.fullautomap || player_info.powerup_flags & PLAYER_FLAGS_MAP_ALL) && !LevelUniqueAutomapState.Automap_visited[segnum]) color = am->wall_revealed_color; } Here: @@ -1498,7 +1497,8 @@ void automap_build_edge_list(automap *am, int add_all_edges) #if DXX_USE_EDITOR if (segp->segnum != segment_none) #endif - if (Automap_visited[segp]) { + if (LevelUniqueAutomapState.Automap_visited[segp]) + { add_segment_edges(vcsegptr, vcwallptr, am, segp); } } @@ -1507,7 +1507,8 @@ void automap_build_edge_list(automap *am, int add_all_edges) #if DXX_USE_EDITOR if (segp->segnum != segment_none) #endif - if (!Automap_visited[segp]) { + if (!LevelUniqueAutomapState.Automap_visited[segp]) + { add_unknown_segment_edges(am, segp); } } diff --git a/similar/main/mglobal.cpp b/similar/main/mglobal.cpp index 7c7637042..ae1294c1f 100644 --- a/similar/main/mglobal.cpp +++ b/similar/main/mglobal.cpp @@ -53,6 +53,7 @@ static void reconstruct_global_variable(T &t) d_interface_unique_state InterfaceUniqueState; d_game_unique_state GameUniqueState; d_level_shared_vertex_state LevelSharedVertexState; +d_level_unique_automap_state LevelUniqueAutomapState; d_level_unique_fuelcenter_state LevelUniqueFuelcenterState; d_level_unique_segment_state LevelUniqueSegmentState; // Global array of vertices, common to one mine. diff --git a/similar/main/render.cpp b/similar/main/render.cpp index bfd8327a6..2a420ccc8 100644 --- a/similar/main/render.cpp +++ b/similar/main/render.cpp @@ -762,7 +762,7 @@ static void render_segment(fvcvertptr &vcvertptr, fvcwallptr &vcwallptr, const v if (Viewer->type != OBJ_ROBOT) #endif { - Automap_visited[seg]=1; + LevelUniqueAutomapState.Automap_visited[seg] = 1; } range_for (const uint_fast32_t sn, xrange(MAX_SIDES_PER_SEGMENT)) @@ -1567,7 +1567,7 @@ void render_mine(grs_canvas &canvas, const vms_vector &Viewer_eye, const vcsegid { //all off screen? if (Viewer->type!=OBJ_ROBOT) - Automap_visited[segnum]=1; + LevelUniqueAutomapState.Automap_visited[segnum] = 1; range_for (const uint_fast32_t sn, xrange(MAX_SIDES_PER_SEGMENT)) { @@ -1616,7 +1616,7 @@ void render_mine(grs_canvas &canvas, const vms_vector &Viewer_eye, const vcsegid { //all off screen? if (Viewer->type!=OBJ_ROBOT) - Automap_visited[segnum]=1; + LevelUniqueAutomapState.Automap_visited[segnum] = 1; range_for (const uint_fast32_t sn, xrange(MAX_SIDES_PER_SEGMENT)) { diff --git a/similar/main/state.cpp b/similar/main/state.cpp index 700c64214..94cb29f50 100644 --- a/similar/main/state.cpp +++ b/similar/main/state.cpp @@ -1237,7 +1237,7 @@ int state_save_all_sub(const char *filename, const char *desc) ai_save_state( fp ); // Save the automap visited info - PHYSFS_write(fp, &Automap_visited[0], sizeof(uint8_t), std::max(Highest_segment_index + 1, MAX_SEGMENTS_ORIGINAL)); + PHYSFS_write(fp, LevelUniqueAutomapState.Automap_visited.data(), sizeof(uint8_t), std::max(Highest_segment_index + 1, MAX_SEGMENTS_ORIGINAL)); PHYSFS_write(fp, &state_game_id, sizeof(unsigned), 1); { @@ -1861,14 +1861,13 @@ int state_restore_all_sub(const d_level_shared_destructible_light_state &LevelSh // Restore the AI state ai_restore_state( fp, version, swap ); - // Restore the automap visited info - if ( Highest_segment_index+1 > MAX_SEGMENTS_ORIGINAL ) { + auto &Automap_visited = LevelUniqueAutomapState.Automap_visited; + // Restore the automap visited info Automap_visited = {}; - PHYSFS_read(fp, &Automap_visited[0], sizeof(ubyte), Highest_segment_index + 1); + DXX_MAKE_MEM_UNDEFINED(Automap_visited.begin(), Automap_visited.end()); + PHYSFS_read(fp, Automap_visited.data(), sizeof(uint8_t), std::max(Highest_segment_index + 1, MAX_SEGMENTS_ORIGINAL)); } - else - PHYSFS_read(fp, &Automap_visited[0], sizeof(ubyte), MAX_SEGMENTS_ORIGINAL); { // Restore hacked up weapon system stuff.