From 70d55c010d25b7aa82297115763f4690d344d482 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 26 Dec 2020 21:17:29 +0000 Subject: [PATCH] Move Num_vertices into if(DXX_USE_EDITOR) Non-editor builds only need Num_vertices as a local during mine loading. --- common/main/segment.h | 6 ++++++ similar/main/gamemine.cpp | 16 +++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/common/main/segment.h b/common/main/segment.h index dcae2b468..fa67f83e7 100644 --- a/common/main/segment.h +++ b/common/main/segment.h @@ -397,7 +397,13 @@ namespace dcx { #ifdef dsx struct d_level_shared_vertex_state { +#if DXX_USE_EDITOR + /* Number of elements in Vertex_active which have a nonzero value. + * This can be less than the index of the highest defined vertex if + * there are unused vertices. + */ unsigned Num_vertices; +#endif private: vertex_array Vertices; #if DXX_USE_EDITOR diff --git a/similar/main/gamemine.cpp b/similar/main/gamemine.cpp index d2aa04457..215698786 100644 --- a/similar/main/gamemine.cpp +++ b/similar/main/gamemine.cpp @@ -442,11 +442,13 @@ int load_mine_data_compiled(PHYSFS_File *LoadFile, const char *const Gamesave_cu (void)compiled_version; DXX_POISON_VAR(Vertices, 0xfc); - if (New_file_format_load) - LevelSharedVertexState.Num_vertices = PHYSFSX_readShort(LoadFile); - else - LevelSharedVertexState.Num_vertices = PHYSFSX_readInt(LoadFile); - assert(LevelSharedVertexState.Num_vertices <= MAX_VERTICES); + const unsigned Num_vertices = New_file_format_load + ? PHYSFSX_readShort(LoadFile) + : PHYSFSX_readInt(LoadFile); + assert(Num_vertices <= MAX_VERTICES); +#if DXX_USE_EDITOR + LevelSharedVertexState.Num_vertices = Num_vertices; +#endif DXX_POISON_VAR(Segments, 0xfc); if (New_file_format_load) @@ -455,7 +457,7 @@ int load_mine_data_compiled(PHYSFS_File *LoadFile, const char *const Gamesave_cu LevelSharedSegmentState.Num_segments = PHYSFSX_readInt(LoadFile); assert(LevelSharedSegmentState.Num_segments <= MAX_SEGMENTS); - range_for (auto &i, partial_range(Vertices, LevelSharedVertexState.Num_vertices)) + range_for (auto &i, partial_range(Vertices, Num_vertices)) PHYSFSX_readVector(LoadFile, i); const auto Num_segments = LevelSharedSegmentState.Num_segments; @@ -561,7 +563,7 @@ int load_mine_data_compiled(PHYSFS_File *LoadFile, const char *const Gamesave_cu } } - Vertices.set_count(LevelSharedVertexState.Num_vertices); + Vertices.set_count(Num_vertices); Segments.set_count(Num_segments); validate_segment_all(LevelSharedSegmentState); // Fill in side type and normals.