More cleanup, and made dynamic sloping more efficient/fixed memory leak

This commit is contained in:
RedEnchilada 2015-04-26 21:50:50 -05:00
parent d0a726c00b
commit 6fa1448f59
5 changed files with 134 additions and 35 deletions

View file

@ -2544,6 +2544,7 @@ boolean P_SetupLevel(boolean skipprecip)
break;
// set up world state
P_ResetDynamicSlopes();
P_SpawnSpecials(fromnetsave);
if (loadprecip) // ugly hack for P_NetUnArchiveMisc (and P_LoadNetGame)

View file

@ -40,27 +40,79 @@
#ifdef ESLOPE
static pslope_t *dynslopes = NULL;
// Reset the dynamic slopes pointer
void P_ResetDynamicSlopes(void) {
dynslopes = NULL;
}
// Calculate line normal
void P_CalculateSlopeNormal(pslope_t *slope) {
slope->normal.z = FINECOSINE(slope->zangle>>ANGLETOFINESHIFT);
slope->normal.x = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.x);
slope->normal.y = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.y);
}
// Recalculate dynamic slopes
void P_RunDynamicSlopes(void) {
pslope_t *slope;
for (slope = dynslopes; slope; slope = slope->next) {
fixed_t zdelta;
switch(slope->refpos) {
case 1: // front floor
zdelta = slope->sourceline->backsector->floorheight - slope->sourceline->frontsector->floorheight;
break;
case 2: // front ceiling
zdelta = slope->sourceline->backsector->ceilingheight - slope->sourceline->frontsector->ceilingheight;
break;
case 3: // back floor
zdelta = slope->sourceline->frontsector->floorheight - slope->sourceline->backsector->floorheight;
break;
case 4: // back ceiling
zdelta = slope->sourceline->frontsector->ceilingheight - slope->sourceline->backsector->ceilingheight;
break;
default:
I_Error("P_RunDynamicSlopes: slope has invalid type!");
}
if (slope->zdelta != FixedDiv(zdelta, slope->extent)) {
slope->zdeltaf = FIXED_TO_FLOAT(slope->zdelta = FixedDiv(zdelta, slope->extent));
slope->zangle = R_PointToAngle2(0, 0, slope->extent, zdelta);
P_CalculateSlopeNormal(slope);
}
}
}
//
// P_MakeSlope
//
// Alocates and fill the contents of a slope structure.
//
static pslope_t *P_MakeSlope(const v3fixed_t *o, const v2fixed_t *d,
const fixed_t zdelta, boolean isceiling)
const fixed_t zdelta, boolean dynamic)
{
pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL);
memset(ret, 0, sizeof(*ret));
pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL);
memset(ret, 0, sizeof(*ret));
ret->of.x = FIXED_TO_FLOAT(ret->o.x = o->x);
ret->of.y = FIXED_TO_FLOAT(ret->o.y = o->y);
ret->of.z = FIXED_TO_FLOAT(ret->o.z = o->z);
ret->of.x = FIXED_TO_FLOAT(ret->o.x = o->x);
ret->of.y = FIXED_TO_FLOAT(ret->o.y = o->y);
ret->of.z = FIXED_TO_FLOAT(ret->o.z = o->z);
ret->df.x = FIXED_TO_FLOAT(ret->d.x = d->x);
ret->df.y = FIXED_TO_FLOAT(ret->d.y = d->y);
ret->df.x = FIXED_TO_FLOAT(ret->d.x = d->x);
ret->df.y = FIXED_TO_FLOAT(ret->d.y = d->y);
ret->zdeltaf = FIXED_TO_FLOAT(ret->zdelta = zdelta);
ret->zdeltaf = FIXED_TO_FLOAT(ret->zdelta = zdelta);
return ret;
if (dynamic) { // Add to the dynamic slopes list
ret->next = dynslopes;
dynslopes = ret;
}
return ret;
}
//
@ -195,7 +247,11 @@ void P_SpawnSlope_Line(int linenum)
// In P_SpawnSlopeLine the origin is the centerpoint of the sourcelinedef
fslope = line->frontsector->f_slope =
P_MakeSlope(&point, &direction, dz, false);
P_MakeSlope(&point, &direction, dz, true);
// Set up some shit
fslope->extent = extent;
fslope->refpos = 1;
// Now remember that f_slope IS a vector
// fslope->o = origin 3D point 1 of the vector
@ -235,8 +291,10 @@ void P_SpawnSlope_Line(int linenum)
fslope->highz = highest;
fslope->lowz = lowest;
fslope->zangle = R_PointToAngle2(0, origin.z, R_PointToDist2(origin.x, origin.y, point.x, point.y), point.z);
fslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z);
fslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
P_CalculateSlopeNormal(fslope);
}
if(frontceil)
{
@ -246,6 +304,10 @@ void P_SpawnSlope_Line(int linenum)
cslope = line->frontsector->c_slope =
P_MakeSlope(&point, &direction, dz, true);
// Set up some shit
cslope->extent = extent;
cslope->refpos = 2;
// Sync the linedata of the line that started this slope
// SRB2CBTODO: Anything special for remote(control sector)-based slopes later?
cslope->sourceline = line;
@ -270,8 +332,10 @@ void P_SpawnSlope_Line(int linenum)
cslope->highz = highest;
cslope->lowz = lowest;
cslope->zangle = R_PointToAngle2(0, origin.z, R_PointToDist2(origin.x, origin.y, point.x, point.y), point.z);
cslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z);
cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
P_CalculateSlopeNormal(cslope);
}
}
if(backfloor || backceil)
@ -301,7 +365,11 @@ void P_SpawnSlope_Line(int linenum)
dz = FixedDiv(line->frontsector->floorheight - point.z, extent);
fslope = line->backsector->f_slope =
P_MakeSlope(&point, &direction, dz, false);
P_MakeSlope(&point, &direction, dz, true);
// Set up some shit
fslope->extent = extent;
fslope->refpos = 3;
// Sync the linedata of the line that started this slope
// SRB2CBTODO: Anything special for remote(control sector)-based slopes later?
@ -327,8 +395,10 @@ void P_SpawnSlope_Line(int linenum)
fslope->highz = highest;
fslope->lowz = lowest;
cslope->zangle = R_PointToAngle2(0, origin.z, R_PointToDist2(origin.x, origin.y, point.x, point.y), point.z);
cslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z);
cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
P_CalculateSlopeNormal(fslope);
}
if(backceil)
{
@ -338,6 +408,10 @@ void P_SpawnSlope_Line(int linenum)
cslope = line->backsector->c_slope =
P_MakeSlope(&point, &direction, dz, true);
// Set up some shit
cslope->extent = extent;
cslope->refpos = 4;
// Sync the linedata of the line that started this slope
// SRB2CBTODO: Anything special for remote(control sector)-based slopes later?
cslope->sourceline = line;
@ -363,8 +437,10 @@ void P_SpawnSlope_Line(int linenum)
cslope->highz = highest;
cslope->lowz = lowest;
cslope->zangle = R_PointToAngle2(0, origin.z, R_PointToDist2(origin.x, origin.y, point.x, point.y), point.z);
cslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z);
cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
P_CalculateSlopeNormal(cslope);
}
}
@ -399,7 +475,7 @@ void P_CopySectorSlope(line_t *line)
line->special = 0; // Linedef was use to set slopes, it finished its job, so now make it a normal linedef
}
#ifdef SPRINGCLEAN
#include "byteptr.h"
#include "p_setup.h"
@ -652,7 +728,7 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
}
#endif

View file

@ -1,4 +1,4 @@
// Emacs style mode select -*- C++ -*-
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// Copyright(C) 2004 Stephen McGranahan
@ -7,12 +7,12 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -29,6 +29,9 @@
#define P_SLOPES_H__
#ifdef ESLOPE
void P_ResetDynamicSlopes(void);
void P_RunDynamicSlopes(void);
// P_MakeLineNormal
// Calculates a 2D normal for the given line and stores it in the line
void P_MakeLineNormal(line_t *line);
@ -74,7 +77,7 @@ float P_GetZAtf(pslope_t *slope, float x, float y);
// Returns the distance of the given point from the given origin and normal.
float P_DistFromPlanef(const v3float_t *point, const v3float_t *pori,
float P_DistFromPlanef(const v3float_t *point, const v3float_t *pori,
const v3float_t *pnormal);
#endif

View file

@ -4765,8 +4765,8 @@ void P_UpdateSpecials(void)
// POINT LIMIT
P_CheckPointLimit();
// Kalaron: ...We...have dynamic slopes *YESSSS*
P_SpawnDeferredSpecials();
// Dynamic slopeness
P_RunDynamicSlopes();
// ANIMATE TEXTURES
for (anim = anims; anim < lastanim; anim++)
@ -6447,6 +6447,25 @@ void P_SpawnSpecials(INT32 fromnetsave)
sectors[s].midmap = lines[i].frontsector->midmap;
break;
#ifdef ESLOPE // Slope specials. TODO move these to a different spot, maybe?
case 386:
case 387:
case 388:
case 389:
case 390:
case 391:
case 392:
case 393:
P_SpawnSlope_Line(i);
break;
// SoM: Copy slopes
case 394:
case 395:
case 396:
P_CopySectorSlope(&lines[i]);
break;
#endif
default:
break;
}

View file

@ -229,7 +229,7 @@ typedef struct secplane_t
#include "m_vector.h"
typedef struct
typedef struct pslope_s
{
// --- Information used in clipping/projection ---
// Origin vector for the plane
@ -240,12 +240,8 @@ typedef struct
v3fixed_t o;
v3float_t of;
// The normal of the 3d plane the slope creates.
v3fixed_t normal;
v3float_t normalf;
// 2-Dimentional vector (x, y) normalized. Used to determine distance from
// the origin in 2d mapspace.
// the origin in 2d mapspace. (Basically a thrust of FRACUNIT in xydirection angle)
v2fixed_t d;
v2float_t df;
@ -253,18 +249,22 @@ typedef struct
fixed_t zdelta;
float zdeltaf;
// The normal of the slope; will always point upward, and thus be inverted on ceilings. I think it's only needed for physics? -Red
v3fixed_t normal;
// For comparing when a slope should be rendered
fixed_t lowz;
fixed_t highz;
// SRB2CBTODO: This could be used for something?
// Determining the relative z values in a slope?
struct line_s *sourceline;
// This values only check and must be updated if the slope itself is modified
angle_t zangle; // Angle of the plane going up from the ground (not mesured in degrees)
angle_t xydirection; // The direction the slope is facing (north, west, south, etc.)
secplane_t secplane; // Extra data for collision and stuff
struct line_s *sourceline; // The line that generated the slope
fixed_t extent; // Distance value used for recalculating zdelta
UINT8 refpos; // 1=front floor 2=front ceiling 3=back floor 4=back ceiling (used for dynamic sloping) 0=disabled
struct pslope_s *next; // Make a linked list of dynamic slopes, for easy reference later
} pslope_t;
#endif