Move Num_vertices into d_level_shared_vertex_state

This commit is contained in:
Kp 2018-12-30 00:43:57 +00:00
parent f87c503618
commit 65225680c1
9 changed files with 43 additions and 32 deletions

View file

@ -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<array<unsigned, 4>, MAX_SIDES_PER_SEGMENT> Side_to_verts_int; // Side_to_verts[my_side] is list of vertices forming side my_side.

View file

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

View file

@ -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<uint_fast32_t>(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<uint_fast32_t>(MAX_VERTICES));
}
//---------------- Number of objects -----------------

View file

@ -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;
}
// -----------------------------------------------------------------------------

View file

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

View file

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

View file

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

View file

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

View file

@ -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<uint8_t, MAX_SIDES_PER_SEGMENT> Side_opposite{{
WRIGHT, WBOTTOM, WLEFT, WTOP, WFRONT, WBACK
}};