From 472ac1b07cf5a8b0cb4f140cc97ceccf54a4cc22 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 21 Feb 2012 21:52:42 +0000 Subject: [PATCH] - Fixed: The nodebuilder is highly likely to renumber vertices, so we need to remember how the original vertices map to the new ones until after vertex slopes are handled. SVN r3380 (trunk) --- src/nodebuild.cpp | 8 ++++++-- src/nodebuild.h | 2 ++ src/nodebuild_utility.cpp | 13 ++++++++++++- src/p_setup.cpp | 12 +++++++++--- src/p_slopes.cpp | 16 +++++++++------- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/nodebuild.cpp b/src/nodebuild.cpp index 9fa95d9cf..5ac860bef 100644 --- a/src/nodebuild.cpp +++ b/src/nodebuild.cpp @@ -65,8 +65,8 @@ const int AAPreference = 16; FNodeBuilder::FNodeBuilder(FLevel &level) : Level(level), GLNodes(false), SegsStuffed(0) { - VertexMap = NULL; + OldVertexTable = NULL; } FNodeBuilder::FNodeBuilder (FLevel &level, @@ -84,10 +84,14 @@ FNodeBuilder::FNodeBuilder (FLevel &level, FNodeBuilder::~FNodeBuilder() { - if (VertexMap != 0) + if (VertexMap != NULL) { delete VertexMap; } + if (OldVertexTable != NULL) + { + delete OldVertexTable; + } } void FNodeBuilder::BuildMini(bool makeGLNodes) diff --git a/src/nodebuild.h b/src/nodebuild.h index da82e26a2..a6f0459a0 100644 --- a/src/nodebuild.h +++ b/src/nodebuild.h @@ -209,6 +209,7 @@ public: seg_t *&segs, glsegextra_t *&glsegextras, int &segCount, subsector_t *&ssecs, int &subCount, vertex_t *&verts, int &vertCount); + const int *GetOldVertexTable(); // These are used for building sub-BSP trees for polyobjects. void Clear(); @@ -227,6 +228,7 @@ public: private: IVertexMap *VertexMap; + int *OldVertexTable; TArray Nodes; TArray Subsectors; diff --git a/src/nodebuild_utility.cpp b/src/nodebuild_utility.cpp index ac4671075..b37533921 100644 --- a/src/nodebuild_utility.cpp +++ b/src/nodebuild_utility.cpp @@ -75,7 +75,7 @@ angle_t FNodeBuilder::PointToAngle (fixed_t x, fixed_t y) void FNodeBuilder::FindUsedVertices (vertex_t *oldverts, int max) { - int *map = (int *)alloca (max*sizeof(int)); + int *map = new int[max]; int i; FPrivVert newvert; @@ -102,6 +102,17 @@ void FNodeBuilder::FindUsedVertices (vertex_t *oldverts, int max) Level.Lines[i].v1 = (vertex_t *)(size_t)map[v1]; Level.Lines[i].v2 = (vertex_t *)(size_t)map[v2]; } + OldVertexTable = map; +} + +// Retrieves the original vertex -> current vertex table. +// Doing so prevents the node builder from freeing it. + +const int *FNodeBuilder::GetOldVertexTable() +{ + int *table = OldVertexTable; + OldVertexTable = NULL; + return table; } // For every sidedef in the map, create a corresponding seg. diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 340b6df63..ce8a72da3 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -73,7 +73,7 @@ #define MISSING_TEXTURE_WARN_LIMIT 20 -void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt); +void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable); void P_SetSlopes (); void P_CopySlopes(); void BloodCrypt (void *data, int key, int len); @@ -3444,6 +3444,7 @@ void P_SetupLevel (char *lumpname, int position) int numbuildthings; int i; bool buildmap; + const int *oldvertextable = NULL; // This is motivated as follows: @@ -3758,7 +3759,7 @@ void P_SetupLevel (char *lumpname, int position) bool BuildGLNodes; if (ForceNodeBuild) { - BuildGLNodes = Renderer->RequireGLNodes() || am_textured || multiplayer || demoplayback || demorecording || genglnodes; + BuildGLNodes = RequireGLNodes || multiplayer || demoplayback || demorecording || genglnodes; startTime = I_FPSTime (); TArray polyspots, anchors; @@ -3782,6 +3783,7 @@ void P_SetupLevel (char *lumpname, int position) vertexes, numvertexes); endTime = I_FPSTime (); DPrintf ("BSP generation took %.3f sec (%d segs)\n", (endTime - startTime) * 0.001, numsegs); + oldvertextable = builder.GetOldVertexTable(); reloop = true; } else @@ -3868,7 +3870,7 @@ void P_SetupLevel (char *lumpname, int position) if (!buildmap) { // [RH] Spawn slope creating things first. - P_SpawnSlopeMakers (&MapThingsConverted[0], &MapThingsConverted[MapThingsConverted.Size()]); + P_SpawnSlopeMakers (&MapThingsConverted[0], &MapThingsConverted[MapThingsConverted.Size()], oldvertextable); P_CopySlopes(); // Spawn 3d floors - must be done before spawning things so it can't be done in P_SpawnSpecials @@ -3898,6 +3900,10 @@ void P_SetupLevel (char *lumpname, int position) delete[] buildthings; } delete map; + if (oldvertextable != NULL) + { + delete[] oldvertextable; + } // set up world state P_SpawnSpecials (); diff --git a/src/p_slopes.cpp b/src/p_slopes.cpp index 5ac7cf704..07ddf2e0d 100644 --- a/src/p_slopes.cpp +++ b/src/p_slopes.cpp @@ -280,7 +280,7 @@ enum // //========================================================================== -static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt) +static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable) { TMap vt_heights[2]; FMapThing *mt; @@ -311,15 +311,17 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt) for(int i = 0; i < numvertexdatas; i++) { + int ii = oldvertextable == NULL ? i : oldvertextable[i]; + if (vertexdatas[i].flags & VERTEXFLAG_ZCeilingEnabled) { - vt_heights[1][i] = vertexdatas[i].zCeiling; + vt_heights[1][ii] = vertexdatas[i].zCeiling; vt_found = true; } if (vertexdatas[i].flags & VERTEXFLAG_ZFloorEnabled) { - vt_heights[0][i] = vertexdatas[i].zFloor; + vt_heights[0][ii] = vertexdatas[i].zFloor; vt_found = true; } } @@ -413,7 +415,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt) // //=========================================================================== -void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt) +void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable) { FMapThing *mt; @@ -421,7 +423,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt) { if ((mt->type >= THING_SlopeFloorPointLine && mt->type <= THING_SetCeilingSlope) || - mt->type==THING_VavoomFloor || mt->type==THING_VavoomCeiling) + mt->type == THING_VavoomFloor || mt->type == THING_VavoomCeiling) { fixed_t x, y, z; secplane_t *refplane; @@ -439,7 +441,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt) refplane = &sec->floorplane; } z = refplane->ZatPoint (x, y) + (mt->z); - if (mt->type==THING_VavoomFloor || mt->type==THING_VavoomCeiling) + if (mt->type == THING_VavoomFloor || mt->type == THING_VavoomCeiling) { P_VavoomSlope(sec, mt->thingid, x, y, mt->z, mt->type & 1); } @@ -465,7 +467,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt) } } - P_SetSlopesFromVertexHeights(firstmt, lastmt); + P_SetSlopesFromVertexHeights(firstmt, lastmt, oldvertextable); }