From 65225680c12f4bd6617019d84736764ac5459376 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 30 Dec 2018 00:43:57 +0000 Subject: [PATCH] Move Num_vertices into d_level_shared_vertex_state --- common/main/fwd-segment.h | 3 +-- common/main/segment.h | 6 ++++++ similar/editor/info.cpp | 7 ++++--- similar/editor/meddraw.cpp | 7 ++++--- similar/editor/mine.cpp | 14 +++++++------- similar/editor/segment.cpp | 18 +++++++++++------- similar/main/gamemine.cpp | 16 ++++++++-------- similar/main/gamesave.cpp | 2 +- similar/main/mglobal.cpp | 2 +- 9 files changed, 43 insertions(+), 32 deletions(-) diff --git a/common/main/fwd-segment.h b/common/main/fwd-segment.h index c660822f1..280c82e45 100644 --- a/common/main/fwd-segment.h +++ b/common/main/fwd-segment.h @@ -123,10 +123,9 @@ DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(vertex, vert); struct count_segment_array_t; struct group; +struct d_level_shared_vertex_state; struct d_level_shared_segment_state; struct d_level_unique_segment_state; -extern unsigned Num_vertices; - #define Side_to_verts Side_to_verts_int extern const array, MAX_SIDES_PER_SEGMENT> Side_to_verts_int; // Side_to_verts[my_side] is list of vertices forming side my_side. diff --git a/common/main/segment.h b/common/main/segment.h index 8dcf3f9c1..4c170cc73 100644 --- a/common/main/segment.h +++ b/common/main/segment.h @@ -297,6 +297,12 @@ DXX_VALPTRIDX_DEFINE_GLOBAL_FACTORIES(dl_index, dlindex, Dl_indices); namespace dcx { #ifdef dsx +struct d_level_shared_vertex_state +{ + unsigned Num_vertices; +}; +extern d_level_shared_vertex_state LevelSharedVertexState; + struct d_level_shared_segment_state { unsigned Num_segments; diff --git a/similar/editor/info.cpp b/similar/editor/info.cpp index 7f0a91404..751d2225e 100644 --- a/similar/editor/info.cpp +++ b/similar/editor/info.cpp @@ -233,9 +233,10 @@ static void info_display_default(grs_canvas &canvas, int show_all) //---------------- Number of vertics ----------------- - if ( old_Num_vertices != Num_vertices ) { - old_Num_vertices = Num_vertices; - gr_uprintf(canvas, *canvas.cv_font, 0, 16, "Vertices: %4d/%4" PRIuFAST32, Num_vertices, static_cast(MAX_VERTICES)); + if (old_Num_vertices != LevelSharedVertexState.Num_vertices) + { + old_Num_vertices = LevelSharedVertexState.Num_vertices; + gr_uprintf(canvas, *canvas.cv_font, 0, 16, "Vertices: %4d/%4" PRIuFAST32, LevelSharedVertexState.Num_vertices, static_cast(MAX_VERTICES)); } //---------------- Number of objects ----------------- diff --git a/similar/editor/meddraw.cpp b/similar/editor/meddraw.cpp index 8bf654d7b..9daffe43f 100644 --- a/similar/editor/meddraw.cpp +++ b/similar/editor/meddraw.cpp @@ -665,13 +665,14 @@ static int alloc_vert() { int vn; - Assert(Num_vertices < MAX_SEGMENT_VERTICES); + const auto Num_vertices = LevelSharedVertexState.Num_vertices; + assert(Num_vertices < MAX_SEGMENT_VERTICES); for (vn=0; (vn < Num_vertices) && Vertex_active[vn]; vn++) ; Vertex_active[vn] = 1; - Num_vertices++; + ++LevelSharedVertexState.Num_vertices; return vn; } @@ -680,7 +681,7 @@ static int alloc_vert() static void free_vert(int vert_num) { Vertex_active[vert_num] = 0; - Num_vertices--; + --LevelSharedVertexState.Num_vertices; } // ----------------------------------------------------------------------------- diff --git a/similar/editor/mine.cpp b/similar/editor/mine.cpp index 9c5cee306..86579ae03 100644 --- a/similar/editor/mine.cpp +++ b/similar/editor/mine.cpp @@ -367,7 +367,7 @@ static int save_mine_data(PHYSFS_File * SaveFile) editor_offset = header_offset + sizeof(mine_header); texture_offset = editor_offset + sizeof(mine_editor); vertex_offset = texture_offset + (13*NumTextures); - segment_offset = vertex_offset + (sizeof(vms_vector)*Num_vertices); + segment_offset = vertex_offset + (sizeof(vms_vector) * LevelSharedVertexState.Num_vertices); newsegment_offset = segment_offset + (sizeof(segment) * LevelSharedSegmentState.Num_segments); newseg_verts_offset = newsegment_offset + sizeof(segment); walls_offset = newseg_verts_offset + (sizeof(vms_vector)*8); @@ -383,7 +383,7 @@ static int save_mine_data(PHYSFS_File * SaveFile) mine_fileinfo.editor_offset = editor_offset; mine_fileinfo.editor_size = sizeof(mine_editor); mine_fileinfo.vertex_offset = vertex_offset; - mine_fileinfo.vertex_howmany = Num_vertices; + mine_fileinfo.vertex_howmany = LevelSharedVertexState.Num_vertices; mine_fileinfo.vertex_sizeof = sizeof(vms_vector); mine_fileinfo.segment_offset = segment_offset; mine_fileinfo.segment_howmany = LevelSharedSegmentState.Num_segments; @@ -406,7 +406,7 @@ static int save_mine_data(PHYSFS_File * SaveFile) //===================== SAVE HEADER INFO ======================== - mine_header.num_vertices = Num_vertices; + mine_header.num_vertices = LevelSharedVertexState.Num_vertices; mine_header.num_segments = LevelSharedSegmentState.Num_segments; // Write the editor info @@ -447,7 +447,7 @@ static int save_mine_data(PHYSFS_File * SaveFile) if (vertex_offset != PHYSFS_tell(SaveFile)) Error( "OFFSETS WRONG IN MINE.C!" ); - PHYSFS_write( SaveFile, Vertices, sizeof(vms_vector), Num_vertices ); + PHYSFS_write(SaveFile, Vertices, sizeof(vms_vector), LevelSharedVertexState.Num_vertices); //===================== SAVE SEGMENT INFO ========================= @@ -570,16 +570,16 @@ int save_mine_data_compiled(PHYSFS_File *SaveFile) PHYSFSX_writeU8(SaveFile, version); // 1 byte = compiled version if (New_file_format_save) { - PHYSFS_writeSLE16(SaveFile, Num_vertices); // 2 bytes = Num_vertices + PHYSFS_writeSLE16(SaveFile, LevelSharedVertexState.Num_vertices); // 2 bytes = Num_vertices PHYSFS_writeSLE16(SaveFile, LevelSharedSegmentState.Num_segments); // 2 bytes = Num_segments } else { - PHYSFS_writeSLE32(SaveFile, Num_vertices); // 4 bytes = Num_vertices + PHYSFS_writeSLE32(SaveFile, LevelSharedVertexState.Num_vertices); // 4 bytes = Num_vertices PHYSFS_writeSLE32(SaveFile, LevelSharedSegmentState.Num_segments); // 4 bytes = Num_segments } - range_for (auto &i, partial_const_range(Vertices, Num_vertices)) + range_for (auto &i, partial_const_range(Vertices, LevelSharedVertexState.Num_vertices)) PHYSFSX_writeVector(SaveFile, i); const auto Num_segments = LevelSharedSegmentState.Num_segments; diff --git a/similar/editor/segment.cpp b/similar/editor/segment.cpp index 412af86f0..25d536635 100644 --- a/similar/editor/segment.cpp +++ b/similar/editor/segment.cpp @@ -115,6 +115,7 @@ int med_add_vertex(const vertex &vp) // set_vertex_counts(); + const auto Num_vertices = LevelSharedVertexState.Num_vertices; Assert(Num_vertices < MAX_SEGMENT_VERTICES); count = 0; @@ -139,7 +140,7 @@ int med_add_vertex(const vertex &vp) *vmvertptr(free_index) = vp; Vertex_active[free_index] = 1; - Num_vertices++; + ++LevelSharedVertexState.Num_vertices; if (free_index > Highest_vertex_index) Vertices.set_count(free_index + 1); @@ -187,6 +188,7 @@ segnum_t med_create_duplicate_segment(segment_array &Segments, const segment &sp // This is the same as med_add_vertex, except that it does not search for the presence of the vertex. int med_create_duplicate_vertex(const vertex &vp) { + const auto Num_vertices = LevelSharedVertexState.Num_vertices; Assert(Num_vertices < MAX_SEGMENT_VERTICES); Do_duplicate_vertex_check = 1; @@ -201,7 +203,7 @@ int med_create_duplicate_vertex(const vertex &vp) *vmvertptr(free_index) = vp; Vertex_active[free_index] = 1; - Num_vertices++; + ++LevelSharedVertexState.Num_vertices; if (free_index > Highest_vertex_index) Vertices.set_count(free_index + 1); @@ -219,7 +221,7 @@ int med_set_vertex(const unsigned vnum, const vertex &vp) // Just in case this vertex wasn't active, mark it as active. if (!Vertex_active[vnum]) { Vertex_active[vnum] = 1; - Num_vertices++; + ++LevelSharedVertexState.Num_vertices; if ((vnum > Highest_vertex_index) && (vnum < NEW_SEGMENT_VERTICES)) { Vertices.set_count(vnum + 1); } @@ -414,6 +416,7 @@ static void change_vertex_occurrences(int dest, int src) // -------------------------------------------------------------------------------------------------- static void compress_vertices(void) { + const auto Num_vertices = LevelSharedVertexState.Num_vertices; if (Highest_vertex_index == Num_vertices - 1) return; @@ -750,7 +753,7 @@ static void update_num_vertices(void) range_for (const auto v, partial_range(Vertex_active, Highest_vertex_index + 1)) if (v) ++n; - Num_vertices = n; + LevelSharedVertexState.Num_vertices = n; } namespace dsx { @@ -760,7 +763,7 @@ namespace dsx { // Set Num_vertices. void set_vertex_counts(void) { - Num_vertices = 0; + unsigned Num_vertices = 0; Vertex_active = {}; @@ -775,6 +778,7 @@ void set_vertex_counts(void) ++ Vertex_active[v]; } } + LevelSharedVertexState.Num_vertices = Num_vertices; } // ------------------------------------------------------------------------------- @@ -1263,7 +1267,7 @@ void med_create_new_segment(const vms_vector &scale) sp->segnum = 1; // What to put here? I don't know. // Create relative-to-center vertices, which are the points on the box defined by length, width, height - t = Num_vertices; + t = LevelSharedVertexState.Num_vertices; sp->verts[0] = med_set_vertex(NEW_SEGMENT_VERTICES+0,{+width/2,+height/2,-length/2}); sp->verts[1] = med_set_vertex(NEW_SEGMENT_VERTICES+1,{+width/2,-height/2,-length/2}); sp->verts[2] = med_set_vertex(NEW_SEGMENT_VERTICES+2,{-width/2,-height/2,-length/2}); @@ -1272,7 +1276,7 @@ void med_create_new_segment(const vms_vector &scale) sp->verts[5] = med_set_vertex(NEW_SEGMENT_VERTICES+5,{+width/2,-height/2,+length/2}); sp->verts[6] = med_set_vertex(NEW_SEGMENT_VERTICES+6,{-width/2,-height/2,+length/2}); sp->verts[7] = med_set_vertex(NEW_SEGMENT_VERTICES+7,{-width/2,+height/2,+length/2}); - Num_vertices = t; + LevelSharedVertexState.Num_vertices = t; // sp->scale = *scale; diff --git a/similar/main/gamemine.cpp b/similar/main/gamemine.cpp index 6eea7d838..7e709d719 100644 --- a/similar/main/gamemine.cpp +++ b/similar/main/gamemine.cpp @@ -777,8 +777,8 @@ int load_mine_data(PHYSFS_File *LoadFile) #endif - Num_vertices = mine_fileinfo.vertex_howmany; - Vertices.set_count(Num_vertices); + LevelSharedVertexState.Num_vertices = mine_fileinfo.vertex_howmany; + Vertices.set_count(LevelSharedVertexState.Num_vertices); LevelSharedSegmentState.Num_segments = mine_fileinfo.segment_howmany; Segments.set_count(LevelSharedSegmentState.Num_segments); @@ -788,7 +788,7 @@ int load_mine_data(PHYSFS_File *LoadFile) Vertices.set_count(MAX_SEGMENT_VERTICES); Segments.set_count(MAX_SEGMENTS); set_vertex_counts(); - Vertices.set_count(Num_vertices); + Vertices.set_count(LevelSharedVertexState.Num_vertices); Segments.set_count(LevelSharedSegmentState.Num_segments); warn_if_concave_segments(); @@ -881,10 +881,10 @@ int load_mine_data_compiled(PHYSFS_File *LoadFile) DXX_POISON_VAR(Vertices, 0xfc); if (New_file_format_load) - Num_vertices = PHYSFSX_readShort(LoadFile); + LevelSharedVertexState.Num_vertices = PHYSFSX_readShort(LoadFile); else - Num_vertices = PHYSFSX_readInt(LoadFile); - Assert( Num_vertices <= MAX_VERTICES ); + LevelSharedVertexState.Num_vertices = PHYSFSX_readInt(LoadFile); + assert(LevelSharedVertexState.Num_vertices <= MAX_VERTICES); DXX_POISON_VAR(Segments, 0xfc); if (New_file_format_load) @@ -893,7 +893,7 @@ int load_mine_data_compiled(PHYSFS_File *LoadFile) LevelSharedSegmentState.Num_segments = PHYSFSX_readInt(LoadFile); assert(LevelSharedSegmentState.Num_segments <= MAX_SEGMENTS); - range_for (auto &i, partial_range(Vertices, Num_vertices)) + range_for (auto &i, partial_range(Vertices, LevelSharedVertexState.Num_vertices)) PHYSFSX_readVector(LoadFile, i); const auto Num_segments = LevelSharedSegmentState.Num_segments; @@ -1004,7 +1004,7 @@ int load_mine_data_compiled(PHYSFS_File *LoadFile) } } - Vertices.set_count(Num_vertices); + Vertices.set_count(LevelSharedVertexState.Num_vertices); Segments.set_count(Num_segments); validate_segment_all(LevelSharedSegmentState); // Fill in side type and normals. diff --git a/similar/main/gamesave.cpp b/similar/main/gamesave.cpp index b1528f573..d9ecdac6b 100644 --- a/similar/main/gamesave.cpp +++ b/similar/main/gamesave.cpp @@ -1519,7 +1519,7 @@ int create_new_mine(void) current_group = -1; - Num_vertices = 0; // Number of vertices in global array. + LevelSharedVertexState.Num_vertices = 0; // Number of vertices in global array. Vertices.set_count(1); LevelSharedSegmentState.Num_segments = 0; // Number of segments in global array, will get increased in med_create_segment Segments.set_count(1); diff --git a/similar/main/mglobal.cpp b/similar/main/mglobal.cpp index 9ec739399..2f33ece23 100644 --- a/similar/main/mglobal.cpp +++ b/similar/main/mglobal.cpp @@ -38,6 +38,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "wall.h" namespace dcx { +d_level_shared_vertex_state LevelSharedVertexState; d_level_shared_segment_state LevelSharedSegmentState; d_level_unique_segment_state LevelUniqueSegmentState; // Global array of vertices, common to one mine. @@ -62,7 +63,6 @@ int d_tick_step = 0; // true once every 33.33ms // Translate table to get opposite side of a face on a segment. -unsigned Num_vertices; const array Side_opposite{{ WRIGHT, WBOTTOM, WLEFT, WTOP, WFRONT, WBACK }};