From faf127ff8860e18c5cba47572ca629527b0e4779 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sat, 4 Jan 2020 10:39:45 +0100 Subject: [PATCH] Add vertex slope spawning function. Rename P_ResetDynamicSlopes() to P_SpawnSlopes(). --- src/p_setup.c | 2 +- src/p_slopes.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++--- src/p_slopes.h | 2 +- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 0a802583a..a1aaeb4ba 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3582,7 +3582,7 @@ boolean P_LoadLevel(boolean fromnetsave) P_InitSpecials(); #ifdef ESLOPE - P_ResetDynamicSlopes(fromnetsave); + P_SpawnSlopes(fromnetsave); #endif P_SpawnMapThings(!fromnetsave); diff --git a/src/p_slopes.c b/src/p_slopes.c index e66d7ed21..5c47c7226 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -507,6 +507,56 @@ static void line_SpawnViaVertexes(const int linenum, const boolean spawnthinker) side->sector->hasslope = true; } +/// Spawn textmap vertex slopes. +void SpawnVertexSlopes (void) +{ + line_t *l1, *l2; + sector_t* sc; + vertex_t *v1, *v2, *v3; + size_t i; + for (i = 0, sc = sectors; i < numsectors; i++, sc++) + { + // The vertex slopes only work for 3-vertex sectors (and thus 3-sided sectors). + if (sc->linecount != 3) + continue; + + l1 = sc->lines[0]; + l2 = sc->lines[1]; + + // Determine the vertexes. + v1 = l1->v1; + v2 = l1->v2; + if ((l2->v1 != v1) && (l2->v1 != v2)) + v3 = l2->v1; + else + v3 = l2->v2; + + if (v1->floorzset || v2->floorzset || v3->floorzset) + { + vector3_t vtx[3] = { + {v1->x, v1->y, v1->floorzset == true ? v1->floorz : sc->floorheight}, + {v2->x, v2->y, v2->floorzset == true ? v2->floorz : sc->floorheight}, + {v3->x, v3->y, v3->floorzset == true ? v3->floorz : sc->floorheight}}; + pslope_t* slop = Slope_Add(0); + sc->f_slope = slop; + sc->hasslope = true; + ReconfigureViaVertexes(slop, vtx[0], vtx[1], vtx[2]); + } + + if (v1->ceilingzset || v2->ceilingzset || v3->ceilingzset) + { + vector3_t vtx[3] = { + {v1->x, v1->y, v1->ceilingzset == true ? v1->ceilingz : sc->ceilingheight}, + {v2->x, v2->y, v2->ceilingzset == true ? v2->ceilingz : sc->ceilingheight}, + {v3->x, v3->y, v3->ceilingzset == true ? v3->ceilingz : sc->ceilingheight}}; + pslope_t* slop = Slope_Add(0); + sc->c_slope = slop; + sc->hasslope = true; + ReconfigureViaVertexes(slop, vtx[0], vtx[1], vtx[2]); + } + + } +} // // P_CopySectorSlope @@ -551,12 +601,16 @@ pslope_t *P_SlopeById(UINT16 id) return ret; } -/// Reset slopes and read them from special lines. -void P_ResetDynamicSlopes(const boolean fromsave) { +/// Initializes and reads the slopes from the map data. +void P_SpawnSlopes(const boolean fromsave) { size_t i; + slopelist = NULL; slopecount = 0; + /// Generates vertex slopes. + SpawnVertexSlopes(); + /// Generates line special-defined slopes. for (i = 0; i < numlines; i++) { @@ -577,7 +631,7 @@ void P_ResetDynamicSlopes(const boolean fromsave) { case 705: case 714: case 715: - line_SpawnViaVertexes(i, !fromsave); + line_SpawnViaVertexes(i, !fromsave); // Mapthing-based vertex slopes. break; default: diff --git a/src/p_slopes.h b/src/p_slopes.h index 96764051b..0bf03f26d 100644 --- a/src/p_slopes.h +++ b/src/p_slopes.h @@ -23,7 +23,7 @@ extern UINT16 slopecount; void P_LinkSlopeThinkers (void); void P_CalculateSlopeNormal(pslope_t *slope); -void P_ResetDynamicSlopes(const boolean fromsave); +void P_SpawnSlopes(const boolean fromsave); // // P_CopySectorSlope