Actually fix slope generation (also whitespace stuff)

This commit is contained in:
RedEnchilada 2015-04-20 13:25:39 -05:00
parent f4ea285f02
commit 7703eae0e8
1 changed files with 182 additions and 181 deletions

View File

@ -1,4 +1,4 @@
// Emacs style mode select -*- C++ -*- // Emacs style mode select -*- C++ -*-
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// Copyright(C) 2004 Stephen McGranahan // Copyright(C) 2004 Stephen McGranahan
@ -7,12 +7,12 @@
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -45,7 +45,7 @@
// //
// Alocates and fill the contents of a slope structure. // Alocates and fill the contents of a slope structure.
// //
static pslope_t *P_MakeSlope(const v3float_t *o, const v2float_t *d, static pslope_t *P_MakeSlope(const v3float_t *o, const v2float_t *d,
const float zdelta, boolean isceiling) const float zdelta, boolean isceiling)
{ {
pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL); pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL);
@ -59,7 +59,7 @@ static pslope_t *P_MakeSlope(const v3float_t *o, const v2float_t *d,
ret->d.y = FLOAT_TO_FIXED(ret->df.y = d->y); ret->d.y = FLOAT_TO_FIXED(ret->df.y = d->y);
ret->zdelta = FLOAT_TO_FIXED(ret->zdeltaf = zdelta); ret->zdelta = FLOAT_TO_FIXED(ret->zdeltaf = zdelta);
// d = direction (v2float_t) // d = direction (v2float_t)
// //
// direction.x = line->nx; // direction.x = line->nx;
@ -101,9 +101,9 @@ static pslope_t *P_MakeSlope(const v3float_t *o, const v2float_t *d,
// Cross product length // Cross product length
len = (float)sqrt(ret->normalf.x * ret->normalf.x + len = (float)sqrt(ret->normalf.x * ret->normalf.x +
ret->normalf.y * ret->normalf.y + ret->normalf.y * ret->normalf.y +
ret->normalf.z * ret->normalf.z); ret->normalf.z * ret->normalf.z);
#ifdef SLOPETHINGS #ifdef SLOPETHINGS
if (len == 0) if (len == 0)
{ {
@ -117,18 +117,18 @@ static pslope_t *P_MakeSlope(const v3float_t *o, const v2float_t *d,
ret->normalf.x /= len; ret->normalf.x /= len;
ret->normalf.y /= len; ret->normalf.y /= len;
ret->normalf.z /= len; ret->normalf.z /= len;
// ZDoom // ZDoom
// cross = ret->normalf // cross = ret->normalf
// Fix backward normals // Fix backward normals
if ((ret->normalf.z < 0 && !isceiling) || (ret->normalf.z > 0 && isceiling)) if ((ret->normalf.z < 0 && !isceiling) || (ret->normalf.z > 0 && isceiling))
{ {
ret->normalf.x = -ret->normalf.x; ret->normalf.x = -ret->normalf.x;
ret->normalf.y = -ret->normalf.x; ret->normalf.y = -ret->normalf.x;
ret->normalf.z = -ret->normalf.x; ret->normalf.z = -ret->normalf.x;
} }
} }
return ret; return ret;
@ -200,10 +200,11 @@ static float P_GetExtent(sector_t *sector, line_t *line, v3float_t *o, v2float_t
if(dist > fardist) if(dist > fardist)
fardist = dist; fardist = dist;
// We shouldn't have to do this for v2... -Red // Okay, maybe do it for v2 as well?
/*dist = (float)fabs((FIXED_TO_FLOAT(li->v2->x) - o->x) * d->x + (FIXED_TO_FLOAT(li->v2->y) - o->y) * d->y); P_ClosestPointOnLine(li->v2->x, li->v2->y, line, &tempv);
dist = FIXED_TO_FLOAT(R_PointToDist2(tempv.x, tempv.y, li->v2->x, li->v2->y));
if(dist > fardist) if(dist > fardist)
fardist = dist;*/ fardist = dist;
} }
return fardist; return fardist;
@ -228,72 +229,72 @@ void P_SpawnSlope_Line(int linenum)
v3float_t origin, point; v3float_t origin, point;
v2float_t direction; v2float_t direction;
float dz, extent; float dz, extent;
boolean frontfloor = (special == 386 || special == 388 || special == 393); boolean frontfloor = (special == 386 || special == 388 || special == 393);
boolean backfloor = (special == 389 || special == 391 || special == 392); boolean backfloor = (special == 389 || special == 391 || special == 392);
boolean frontceil = (special == 387 || special == 388 || special == 392); boolean frontceil = (special == 387 || special == 388 || special == 392);
boolean backceil = (special == 390 || special == 391 || special == 393); boolean backceil = (special == 390 || special == 391 || special == 393);
if(!frontfloor && !backfloor && !frontceil && !backceil) if(!frontfloor && !backfloor && !frontceil && !backceil)
{ {
CONS_Printf("P_SpawnSlope_Line called with non-slope line special.\n"); CONS_Printf("P_SpawnSlope_Line called with non-slope line special.\n");
return; return;
} }
if(!line->frontsector || !line->backsector) if(!line->frontsector || !line->backsector)
{ {
CONS_Printf("P_SpawnSlope_Line used on a line without two sides.\n"); CONS_Printf("P_SpawnSlope_Line used on a line without two sides.\n");
return; return;
} }
// SRB2CBTODO: Transform origin relative to the bounds of an individual FOF // SRB2CBTODO: Transform origin relative to the bounds of an individual FOF
origin.x = (FIXED_TO_FLOAT(line->v2->x) + FIXED_TO_FLOAT(line->v1->x)) * 0.5f; origin.x = (FIXED_TO_FLOAT(line->v2->x) + FIXED_TO_FLOAT(line->v1->x)) * 0.5f;
origin.y = (FIXED_TO_FLOAT(line->v2->y) + FIXED_TO_FLOAT(line->v1->y)) * 0.5f; origin.y = (FIXED_TO_FLOAT(line->v2->y) + FIXED_TO_FLOAT(line->v1->y)) * 0.5f;
// For FOF slopes, make a special function to copy to the xy origin & direction relative to the position of the FOF on the map! // For FOF slopes, make a special function to copy to the xy origin & direction relative to the position of the FOF on the map!
if(frontfloor || frontceil) if(frontfloor || frontceil)
{ {
origin.z = FIXED_TO_FLOAT(line->backsector->floorheight); origin.z = FIXED_TO_FLOAT(line->backsector->floorheight);
direction.x = line->nx; direction.x = line->nx;
direction.y = line->ny; direction.y = line->ny;
extent = P_GetExtent(line->frontsector, line, &origin, &direction); extent = P_GetExtent(line->frontsector, line, &origin, &direction);
if(extent < 0.0f) if(extent < 0.0f)
{ {
CONS_Printf("P_SpawnSlope_Line failed to get frontsector extent on line number %i\n", linenum); CONS_Printf("P_SpawnSlope_Line failed to get frontsector extent on line number %i\n", linenum);
return; return;
} }
// reposition the origin according to the extent // reposition the origin according to the extent
point.x = origin.x + direction.x * extent; point.x = origin.x + direction.x * extent;
point.y = origin.y + direction.y * extent; point.y = origin.y + direction.y * extent;
direction.x = -direction.x; direction.x = -direction.x;
direction.y = -direction.y; direction.y = -direction.y;
// TODO: We take origin and point 's xy values and translate them to the center of an FOF! // TODO: We take origin and point 's xy values and translate them to the center of an FOF!
if(frontfloor) if(frontfloor)
{ {
point.z = FIXED_TO_FLOAT(line->frontsector->floorheight); // Startz point.z = FIXED_TO_FLOAT(line->frontsector->floorheight); // Startz
dz = (FIXED_TO_FLOAT(line->backsector->floorheight) - point.z) / extent; // Destinationz dz = (FIXED_TO_FLOAT(line->backsector->floorheight) - point.z) / extent; // Destinationz
// In P_SpawnSlopeLine the origin is the centerpoint of the sourcelinedef // In P_SpawnSlopeLine the origin is the centerpoint of the sourcelinedef
int slopeangle = 0; // All floors by default have no slope (an angle of 0, completely flat) int slopeangle = 0; // All floors by default have no slope (an angle of 0, completely flat)
v3float_t A = origin; // = line source v3float_t A = origin; // = line source
v3float_t B = point; // destination's value v3float_t B = point; // destination's value
v3float_t C = origin; // Point used to make a right triangle from A & B v3float_t C = origin; // Point used to make a right triangle from A & B
C.z = point.z; C.z = point.z;
// To find the "angle" of a slope, we make a right triangle out of the points we have, // To find the "angle" of a slope, we make a right triangle out of the points we have,
// point A - is point 1 of the hypotenuse, // point A - is point 1 of the hypotenuse,
// point B - is point 2 of the hypotenuse // point B - is point 2 of the hypotenuse
// point C - has the same Z value as point b, and the same XY value as A // point C - has the same Z value as point b, and the same XY value as A
// //
// We want to find the angle accross from the right angle // We want to find the angle accross from the right angle
// so we use some triginometry to find the angle(fun, right?) // so we use some triginometry to find the angle(fun, right?)
// We want to find the tanjent of this angle, this is: // We want to find the tanjent of this angle, this is:
@ -304,54 +305,54 @@ void P_SpawnSlope_Line(int linenum)
float triangopplength = abs(B.z - A.z); float triangopplength = abs(B.z - A.z);
float triangadjlength = sqrt((B.x-C.x)*(B.x-C.x) + (B.y - C.y)*(B.y - C.y)); float triangadjlength = sqrt((B.x-C.x)*(B.x-C.x) + (B.y - C.y)*(B.y - C.y));
//float trianghyplength = sqrt(triangopplength*triangopplength + triangadjlength*triangadjlength); // This is the hypotenuse //float trianghyplength = sqrt(triangopplength*triangopplength + triangadjlength*triangadjlength); // This is the hypotenuse
// So tanjent = opposite divided by adjecent // So tanjent = opposite divided by adjecent
float tanrelat = triangopplength/ triangadjlength; // tanjent = opposite / adjecent float tanrelat = triangopplength/ triangadjlength; // tanjent = opposite / adjecent
slopeangle = atan(tanrelat)* 180 / M_PI; // Now we use atan: *180 /M_PI is needed to convert the value into degrees slopeangle = atan(tanrelat)* 180 / M_PI; // Now we use atan: *180 /M_PI is needed to convert the value into degrees
fslope = line->frontsector->f_slope = fslope = line->frontsector->f_slope =
P_MakeSlope(&point, &direction, dz, false); P_MakeSlope(&point, &direction, dz, false);
// Now remember that f_slope IS a vector // Now remember that f_slope IS a vector
// fslope->o = origin 3D point 1 of the vector // fslope->o = origin 3D point 1 of the vector
// fslope->d = destination 3D point 2 of the vector // fslope->d = destination 3D point 2 of the vector
// fslope->normal is a 3D line perpendicular to the 3D vector // fslope->normal is a 3D line perpendicular to the 3D vector
// Sync the linedata of the line that started this slope // Sync the linedata of the line that started this slope
// SRB2CBTODO: Anything special for remote(control sector)-based slopes later? // SRB2CBTODO: Anything special for remote(control sector)-based slopes later?
line->frontsector->f_slope->sourceline = line; line->frontsector->f_slope->sourceline = line;
// To find the real highz/lowz of a slope, you need to check all the vertexes // To find the real highz/lowz of a slope, you need to check all the vertexes
// in the slope's sector with P_GetZAt to get the REAL lowz & highz // in the slope's sector with P_GetZAt to get the REAL lowz & highz
// Although these slopes are set by floorheights the ANGLE is what a slope is, // Although these slopes are set by floorheights the ANGLE is what a slope is,
// so technically any slope can extend on forever (they are just bound by sectors) // so technically any slope can extend on forever (they are just bound by sectors)
// *You can use sourceline as a reference to see if two slopes really are the same // *You can use sourceline as a reference to see if two slopes really are the same
// Default points for high and low // Default points for high and low
fixed_t highest = point.z > origin.z ? point.z : origin.z; fixed_t highest = point.z > origin.z ? point.z : origin.z;
fixed_t lowest = point.z < origin.z ? point.z : origin.z; fixed_t lowest = point.z < origin.z ? point.z : origin.z;
highest = FLOAT_TO_FIXED(highest); highest = FLOAT_TO_FIXED(highest);
lowest = FLOAT_TO_FIXED(lowest); lowest = FLOAT_TO_FIXED(lowest);
// Now check to see what the REAL high and low points of the slope inside the sector // Now check to see what the REAL high and low points of the slope inside the sector
size_t l; size_t l;
for (l = 0; l < line->frontsector->linecount; l++) for (l = 0; l < line->frontsector->linecount; l++)
{ {
if (P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y) > highest) if (P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y) > highest)
highest = P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y); highest = P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y);
if (P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y) < lowest) if (P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y) < lowest)
lowest = P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y); lowest = P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y);
} }
// Sets extra clipping data for the frontsector's slope // Sets extra clipping data for the frontsector's slope
fslope->highz = line->frontsector->f_slope->highz = highest; fslope->highz = line->frontsector->f_slope->highz = highest;
fslope->lowz = line->frontsector->f_slope->lowz = lowest; fslope->lowz = line->frontsector->f_slope->lowz = lowest;
fslope->zangle = slopeangle; fslope->zangle = slopeangle;
fslope->xydirection = R_PointToAngle2(FLOAT_TO_FIXED(A.x), FLOAT_TO_FIXED(A.y), FLOAT_TO_FIXED(B.x), FLOAT_TO_FIXED(B.y))/(ANGLE_45/45); fslope->xydirection = R_PointToAngle2(FLOAT_TO_FIXED(A.x), FLOAT_TO_FIXED(A.y), FLOAT_TO_FIXED(B.x), FLOAT_TO_FIXED(B.y))/(ANGLE_45/45);
secplane_t *srcplane = Z_Calloc(sizeof(*srcplane), PU_LEVEL, NULL); secplane_t *srcplane = Z_Calloc(sizeof(*srcplane), PU_LEVEL, NULL);
// ZDoom secplane port! YAY // ZDoom secplane port! YAY
// ret = f_slope or c_slope // ret = f_slope or c_slope
@ -359,48 +360,48 @@ void P_SpawnSlope_Line(int linenum)
srcplane->b = FLOAT_TO_FIXED (fslope->normalf.y); // cross[1] srcplane->b = FLOAT_TO_FIXED (fslope->normalf.y); // cross[1]
srcplane->c = FLOAT_TO_FIXED (fslope->normalf.z); // cross[2] srcplane->c = FLOAT_TO_FIXED (fslope->normalf.z); // cross[2]
srcplane->ic = DivScale32 (1, srcplane->c); // (1 << 32/srcplane->c) or FLOAT_TO_FIXED(1.0f/cross[2]); srcplane->ic = DivScale32 (1, srcplane->c); // (1 << 32/srcplane->c) or FLOAT_TO_FIXED(1.0f/cross[2]);
// destheight takes the destination height used in dz // destheight takes the destination height used in dz
srcplane->d = -TMulScale16 (srcplane->a, line->v1->x, // x srcplane->d = -TMulScale16 (srcplane->a, line->v1->x, // x
srcplane->b, line->v1->y, // y srcplane->b, line->v1->y, // y
srcplane->c, line->backsector->floorheight); // z srcplane->c, line->backsector->floorheight); // z
// Sync the secplane! // Sync the secplane!
fslope->secplane = line->frontsector->f_slope->secplane = *srcplane; fslope->secplane = line->frontsector->f_slope->secplane = *srcplane;
} }
if(frontceil) if(frontceil)
{ {
point.z = FIXED_TO_FLOAT(line->frontsector->ceilingheight); point.z = FIXED_TO_FLOAT(line->frontsector->ceilingheight);
dz = (FIXED_TO_FLOAT(line->backsector->ceilingheight) - point.z) / extent; dz = (FIXED_TO_FLOAT(line->backsector->ceilingheight) - point.z) / extent;
cslope = line->frontsector->c_slope = cslope = line->frontsector->c_slope =
P_MakeSlope(&point, &direction, dz, true); P_MakeSlope(&point, &direction, dz, true);
// Sync the linedata of the line that started this slope // Sync the linedata of the line that started this slope
// SRB2CBTODO: Anything special for remote(control sector)-based slopes later? // SRB2CBTODO: Anything special for remote(control sector)-based slopes later?
line->frontsector->c_slope->sourceline = line; line->frontsector->c_slope->sourceline = line;
// Remember the way the slope is formed // Remember the way the slope is formed
fixed_t highest = point.z > origin.z ? point.z : origin.z; fixed_t highest = point.z > origin.z ? point.z : origin.z;
fixed_t lowest = point.z < origin.z ? point.z : origin.z; fixed_t lowest = point.z < origin.z ? point.z : origin.z;
highest = FLOAT_TO_FIXED(highest); highest = FLOAT_TO_FIXED(highest);
lowest = FLOAT_TO_FIXED(lowest); lowest = FLOAT_TO_FIXED(lowest);
size_t l; size_t l;
for (l = 0; l < line->frontsector->linecount; l++) for (l = 0; l < line->frontsector->linecount; l++)
{ {
if (P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y) > highest) if (P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y) > highest)
highest = P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y); highest = P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y);
if (P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y) < lowest) if (P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y) < lowest)
lowest = P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y); lowest = P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y);
} }
// This line special sets extra clipping data for the frontsector's slope // This line special sets extra clipping data for the frontsector's slope
cslope->highz = line->frontsector->c_slope->highz = highest; cslope->highz = line->frontsector->c_slope->highz = highest;
cslope->lowz = line->frontsector->c_slope->lowz = lowest; cslope->lowz = line->frontsector->c_slope->lowz = lowest;
// SRB2CBTODO: Get XY angle of a slope and then awesome physics! // ESLOPE: // SRB2CBTODO: Get XY angle of a slope and then awesome physics! // ESLOPE:
//cslope->zangle = line->frontsector->c_slope->zangle = P_GetSlopezangle(line->frontsector, highvert, lowvert); //cslope->zangle = line->frontsector->c_slope->zangle = P_GetSlopezangle(line->frontsector, highvert, lowvert);
//100*(ANG45/45);//R_PointToAngle2(direction.x, direction.y, origin.x, origin.y); //100*(ANG45/45);//R_PointToAngle2(direction.x, direction.y, origin.x, origin.y);
@ -422,11 +423,11 @@ void P_SpawnSlope_Line(int linenum)
//srcheight = isceiling ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling); //srcheight = isceiling ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling);
//destheight = isceiling ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling); //destheight = isceiling ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling);
//P_GetZAtf(ret, v2.x, v2.y) //P_GetZAtf(ret, v2.x, v2.y)
// destheight takes the destination height used in dz // destheight takes the destination height used in dz
srcplane->d = -TMulScale16 (srcplane->a, line->v1->x, srcplane->d = -TMulScale16 (srcplane->a, line->v1->x,
srcplane->b, line->v1->y, srcplane->b, line->v1->y,
srcplane->c, line->backsector->ceilingheight); srcplane->c, line->backsector->ceilingheight);
// Sync the secplane! // Sync the secplane!
cslope->secplane = line->frontsector->c_slope->secplane = *srcplane; cslope->secplane = line->frontsector->c_slope->secplane = *srcplane;
} }
@ -437,46 +438,46 @@ void P_SpawnSlope_Line(int linenum)
// Backsector // Backsector
direction.x = -line->nx; direction.x = -line->nx;
direction.y = -line->ny; direction.y = -line->ny;
extent = P_GetExtent(line->backsector, line, &origin, &direction); extent = P_GetExtent(line->backsector, line, &origin, &direction);
if(extent < 0.0f) if(extent < 0.0f)
{ {
CONS_Printf("P_SpawnSlope_Line failed to get backsector extent on line number %i\n", linenum); CONS_Printf("P_SpawnSlope_Line failed to get backsector extent on line number %i\n", linenum);
return; return;
} }
// reposition the origin according to the extent // reposition the origin according to the extent
point.x = origin.x + direction.x * extent; point.x = origin.x + direction.x * extent;
point.y = origin.y + direction.y * extent; point.y = origin.y + direction.y * extent;
direction.x = -direction.x; direction.x = -direction.x;
direction.y = -direction.y; direction.y = -direction.y;
if(backfloor) if(backfloor)
{ {
point.z = FIXED_TO_FLOAT(line->backsector->floorheight); point.z = FIXED_TO_FLOAT(line->backsector->floorheight);
dz = (FIXED_TO_FLOAT(line->frontsector->floorheight) - point.z) / extent; dz = (FIXED_TO_FLOAT(line->frontsector->floorheight) - point.z) / extent;
fslope = line->backsector->f_slope = fslope = line->backsector->f_slope =
P_MakeSlope(&point, &direction, dz, false); P_MakeSlope(&point, &direction, dz, false);
// Sync the linedata of the line that started this slope // Sync the linedata of the line that started this slope
// SRB2CBTODO: Anything special for remote(control sector)-based slopes later? // SRB2CBTODO: Anything special for remote(control sector)-based slopes later?
line->backsector->f_slope->sourceline = line; line->backsector->f_slope->sourceline = line;
int slopeangle = 0; // All floors by default have no slope (an angle of 0) int slopeangle = 0; // All floors by default have no slope (an angle of 0)
v3float_t A = origin; // = line source v3float_t A = origin; // = line source
v3float_t B = point; // destination's value v3float_t B = point; // destination's value
v3float_t C = origin; v3float_t C = origin;
C.z = point.z; C.z = point.z;
// To find the "angle" of a slope, we make a right triangle out of the points we have, // To find the "angle" of a slope, we make a right triangle out of the points we have,
// point A - is point 1 of the hypotenuse, // point A - is point 1 of the hypotenuse,
// point B - is point 2 of the hypotenuse // point B - is point 2 of the hypotenuse
// point C - has the same Z value as point b, and the same XY value as A // point C - has the same Z value as point b, and the same XY value as A
// //
// We want to find the angle accross from the right angle // We want to find the angle accross from the right angle
// so we use some triginometry to find the angle(fun, right?) // so we use some triginometry to find the angle(fun, right?)
// We want to find the tanjent of this angle, this is: // We want to find the tanjent of this angle, this is:
@ -487,31 +488,31 @@ void P_SpawnSlope_Line(int linenum)
float triangopplength = abs(B.z - A.z); float triangopplength = abs(B.z - A.z);
float triangadjlength = sqrt((B.x-C.x)*(B.x-C.x) + (B.y - C.y)*(B.y - C.y)); float triangadjlength = sqrt((B.x-C.x)*(B.x-C.x) + (B.y - C.y)*(B.y - C.y));
//float trianghyplength = sqrt(triangopplength*triangopplength + triangadjlength*triangadjlength); // This is the hypotenuse //float trianghyplength = sqrt(triangopplength*triangopplength + triangadjlength*triangadjlength); // This is the hypotenuse
// So tanjent = opposite divided by adjecent // So tanjent = opposite divided by adjecent
float tanrelat = triangopplength/ triangadjlength; // tanjent = opposite / adjecent float tanrelat = triangopplength/ triangadjlength; // tanjent = opposite / adjecent
slopeangle = atan(tanrelat)* 180 / M_PI; // Now we use atan - *180 /M_PI is needed to convert the value into degrees slopeangle = atan(tanrelat)* 180 / M_PI; // Now we use atan - *180 /M_PI is needed to convert the value into degrees
// Remember the way the slope is formed // Remember the way the slope is formed
fixed_t highest = point.z > origin.z ? point.z : origin.z; fixed_t highest = point.z > origin.z ? point.z : origin.z;
fixed_t lowest = point.z < origin.z ? point.z : origin.z; fixed_t lowest = point.z < origin.z ? point.z : origin.z;
highest = FLOAT_TO_FIXED(highest); highest = FLOAT_TO_FIXED(highest);
lowest = FLOAT_TO_FIXED(lowest); lowest = FLOAT_TO_FIXED(lowest);
size_t l; size_t l;
for (l = 0; l < line->backsector->linecount; l++) for (l = 0; l < line->backsector->linecount; l++)
{ {
if (P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y) > highest) if (P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y) > highest)
highest = P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y); highest = P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y);
if (P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y) < lowest) if (P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y) < lowest)
lowest = P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y); lowest = P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y);
} }
// This line special sets extra clipping data for the frontsector's slope // This line special sets extra clipping data for the frontsector's slope
fslope->highz = line->backsector->f_slope->highz = highest; fslope->highz = line->backsector->f_slope->highz = highest;
fslope->lowz = line->backsector->f_slope->lowz = lowest; fslope->lowz = line->backsector->f_slope->lowz = lowest;
fslope->zangle = slopeangle; fslope->zangle = slopeangle;
// Get slope XY angle with secplane_t // Get slope XY angle with secplane_t
secplane_t *srcplane = Z_Calloc(sizeof(*srcplane), PU_LEVEL, NULL); secplane_t *srcplane = Z_Calloc(sizeof(*srcplane), PU_LEVEL, NULL);
@ -531,11 +532,11 @@ void P_SpawnSlope_Line(int linenum)
//srcheight = isceiling ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling); //srcheight = isceiling ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling);
//destheight = isceiling ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling); //destheight = isceiling ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling);
//P_GetZAtf(ret, v2.x, v2.y) //P_GetZAtf(ret, v2.x, v2.y)
// destheight takes the destination height used in dz // destheight takes the destination height used in dz
srcplane->d = -TMulScale16 (srcplane->a, line->v1->x, srcplane->d = -TMulScale16 (srcplane->a, line->v1->x,
srcplane->b, line->v1->y, srcplane->b, line->v1->y,
srcplane->c, line->frontsector->floorheight); srcplane->c, line->frontsector->floorheight);
// Sync the secplane! // Sync the secplane!
fslope->secplane = line->backsector->f_slope->secplane = *srcplane; fslope->secplane = line->backsector->f_slope->secplane = *srcplane;
} }
@ -543,35 +544,35 @@ void P_SpawnSlope_Line(int linenum)
{ {
point.z = FIXED_TO_FLOAT(line->backsector->ceilingheight); point.z = FIXED_TO_FLOAT(line->backsector->ceilingheight);
dz = (FIXED_TO_FLOAT(line->frontsector->ceilingheight) - point.z) / extent; dz = (FIXED_TO_FLOAT(line->frontsector->ceilingheight) - point.z) / extent;
cslope = line->backsector->c_slope = cslope = line->backsector->c_slope =
P_MakeSlope(&point, &direction, dz, true); P_MakeSlope(&point, &direction, dz, true);
// Sync the linedata of the line that started this slope // Sync the linedata of the line that started this slope
// SRB2CBTODO: Anything special for remote(control sector)-based slopes later? // SRB2CBTODO: Anything special for remote(control sector)-based slopes later?
line->backsector->c_slope->sourceline = line; line->backsector->c_slope->sourceline = line;
// Remember the way the slope is formed // Remember the way the slope is formed
fixed_t highest = point.z > origin.z ? point.z : origin.z; fixed_t highest = point.z > origin.z ? point.z : origin.z;
fixed_t lowest = point.z < origin.z ? point.z : origin.z; fixed_t lowest = point.z < origin.z ? point.z : origin.z;
highest = FLOAT_TO_FIXED(highest); highest = FLOAT_TO_FIXED(highest);
lowest = FLOAT_TO_FIXED(lowest); lowest = FLOAT_TO_FIXED(lowest);
size_t l; size_t l;
for (l = 0; l < line->backsector->linecount; l++) for (l = 0; l < line->backsector->linecount; l++)
{ {
if (P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y) > highest) if (P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y) > highest)
highest = P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y); highest = P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y);
if (P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y) < lowest) if (P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y) < lowest)
lowest = P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y); lowest = P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y);
} }
// This line special sets extra clipping data for the backsector's slope // This line special sets extra clipping data for the backsector's slope
cslope->highz = line->backsector->c_slope->highz = highest; cslope->highz = line->backsector->c_slope->highz = highest;
cslope->lowz = line->backsector->c_slope->lowz = lowest; cslope->lowz = line->backsector->c_slope->lowz = lowest;
// SRB2CBTODO: Get XY angle of a slope and then awesome physics! // ESLOPE: // SRB2CBTODO: Get XY angle of a slope and then awesome physics! // ESLOPE:
//cslope->zangle = line->backsector->c_slope->zangle = P_GetSlopezangle(line->backsector, highvert, lowvert); //cslope->zangle = line->backsector->c_slope->zangle = P_GetSlopezangle(line->backsector, highvert, lowvert);
//100*(ANG45/45);//R_PointToAngle2(direction.x, direction.y, origin.x, origin.y); //100*(ANG45/45);//R_PointToAngle2(direction.x, direction.y, origin.x, origin.y);
@ -593,16 +594,16 @@ void P_SpawnSlope_Line(int linenum)
//srcheight = isceiling ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling); //srcheight = isceiling ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling);
//destheight = isceiling ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling); //destheight = isceiling ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling);
//P_GetZAtf(ret, v2.x, v2.y) //P_GetZAtf(ret, v2.x, v2.y)
// destheight takes the destination height used in dz // destheight takes the destination height used in dz
srcplane->d = -TMulScale16 (srcplane->a, line->v1->x, srcplane->d = -TMulScale16 (srcplane->a, line->v1->x,
srcplane->b, line->v1->y, srcplane->b, line->v1->y,
srcplane->c, line->frontsector->ceilingheight); srcplane->c, line->frontsector->ceilingheight);
// Sync the secplane! // Sync the secplane!
cslope->secplane = line->backsector->c_slope->secplane = *srcplane; cslope->secplane = line->backsector->c_slope->secplane = *srcplane;
} }
} }
if(!line->tag) if(!line->tag)
return; return;
} }
@ -657,12 +658,12 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
mapthing_t *mt; mapthing_t *mt;
boolean vt_found = false; boolean vt_found = false;
size_t i, j, k, l, q; size_t i, j, k, l, q;
//size_t i; //size_t i;
//mapthing_t *mt; //mapthing_t *mt;
char *data; char *data;
char *datastart; char *datastart;
// SRB2CBTODO: WHAT IS (5 * sizeof (short))?! It = 10 // SRB2CBTODO: WHAT IS (5 * sizeof (short))?! It = 10
// anything else seems to make a map not load properly, // anything else seems to make a map not load properly,
// but this hard-coded value MUST have some reason for being what it is // but this hard-coded value MUST have some reason for being what it is
@ -683,34 +684,34 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
mt->options = READINT16(data); mt->options = READINT16(data);
// mt->z hasn't been set yet! // mt->z hasn't been set yet!
//mt->extrainfo = (byte)(mt->type >> 12); // slope things are special, they have a bigger range of types //mt->extrainfo = (byte)(mt->type >> 12); // slope things are special, they have a bigger range of types
//mt->type &= 4095; // SRB2CBTODO: WHAT IS THIS???? Mobj type limits?!!!! //mt->type &= 4095; // SRB2CBTODO: WHAT IS THIS???? Mobj type limits?!!!!
x = mt->x*FRACUNIT; x = mt->x*FRACUNIT;
y = mt->y*FRACUNIT; y = mt->y*FRACUNIT;
sector = R_PointInSubsector(x, y)->sector; sector = R_PointInSubsector(x, y)->sector;
// Z for objects // Z for objects
#ifdef ESLOPE #ifdef ESLOPE
if (sector->f_slope) if (sector->f_slope)
mt->z = (short)(P_GetZAt(sector->f_slope, x, y)>>FRACBITS); mt->z = (short)(P_GetZAt(sector->f_slope, x, y)>>FRACBITS);
else else
#endif #endif
mt->z = (short)(sector->floorheight>>FRACBITS); mt->z = (short)(sector->floorheight>>FRACBITS);
mt->z = mt->z + (mt->options >> ZSHIFT); mt->z = mt->z + (mt->options >> ZSHIFT);
if (mt->type == THING_VertexFloorZ || mt->type == THING_VertexCeilingZ) // THING_VertexFloorZ if (mt->type == THING_VertexFloorZ || mt->type == THING_VertexCeilingZ) // THING_VertexFloorZ
{ {
for(l = 0; l < numvertexes; l++) for(l = 0; l < numvertexes; l++)
{ {
if (vertexes[l].x == mt->x*FRACUNIT && vertexes[l].y == mt->y*FRACUNIT) if (vertexes[l].x == mt->x*FRACUNIT && vertexes[l].y == mt->y*FRACUNIT)
{ {
if (mt->type == THING_VertexFloorZ) if (mt->type == THING_VertexFloorZ)
{ {
vertexes[l].z = mt->z*FRACUNIT; vertexes[l].z = mt->z*FRACUNIT;
//I_Error("Z value: %i", vertexes[l].z/FRACUNIT); //I_Error("Z value: %i", vertexes[l].z/FRACUNIT);
} }
else else
{ {
vertexes[l].z = mt->z*FRACUNIT; // celing floor vertexes[l].z = mt->z*FRACUNIT; // celing floor
} }
@ -718,41 +719,41 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
} }
} }
//mt->type = 0; // VPHYSICS: Dynamic slopes //mt->type = 0; // VPHYSICS: Dynamic slopes
if (vt_found) if (vt_found)
{ {
for (k = 0; k < numsectors; k++) for (k = 0; k < numsectors; k++)
{ {
sector_t *sec = &sectors[k]; sector_t *sec = &sectors[k];
if (sec->linecount != 3) continue; // only works with triangular sectors if (sec->linecount != 3) continue; // only works with triangular sectors
v3float_t vt1, vt2, vt3; // cross = ret->normalf v3float_t vt1, vt2, vt3; // cross = ret->normalf
v3float_t vec1, vec2; v3float_t vec1, vec2;
int vi1, vi2, vi3; int vi1, vi2, vi3;
vi1 = (int)(sec->lines[0]->v1 - vertexes); vi1 = (int)(sec->lines[0]->v1 - vertexes);
vi2 = (int)(sec->lines[0]->v2 - vertexes); vi2 = (int)(sec->lines[0]->v2 - vertexes);
vi3 = (sec->lines[1]->v1 == sec->lines[0]->v1 || sec->lines[1]->v1 == sec->lines[0]->v2)? vi3 = (sec->lines[1]->v1 == sec->lines[0]->v1 || sec->lines[1]->v1 == sec->lines[0]->v2)?
(int)(sec->lines[1]->v2 - vertexes) : (int)(sec->lines[1]->v1 - vertexes); (int)(sec->lines[1]->v2 - vertexes) : (int)(sec->lines[1]->v1 - vertexes);
//if (vertexes[vi1].z) //if (vertexes[vi1].z)
// I_Error("OSNAP %i", vertexes[vi1].z/FRACUNIT); // I_Error("OSNAP %i", vertexes[vi1].z/FRACUNIT);
//if (vertexes[vi2].z) //if (vertexes[vi2].z)
// I_Error("OSNAP %i", vertexes[vi2].z/FRACUNIT); // I_Error("OSNAP %i", vertexes[vi2].z/FRACUNIT);
//if (vertexes[vi3].z) //if (vertexes[vi3].z)
// I_Error("OSNAP %i", vertexes[vi3].z/FRACUNIT); // I_Error("OSNAP %i", vertexes[vi3].z/FRACUNIT);
//I_Error("%i, %i", mt->z*FRACUNIT, vertexes[vi1].z); //I_Error("%i, %i", mt->z*FRACUNIT, vertexes[vi1].z);
//I_Error("%i, %i, %i", mt->x, mt->y, mt->z); //I_Error("%i, %i, %i", mt->x, mt->y, mt->z);
//P_SpawnMobj(mt->x*FRACUNIT, mt->y*FRACUNIT, mt->z*FRACUNIT, MT_RING); //P_SpawnMobj(mt->x*FRACUNIT, mt->y*FRACUNIT, mt->z*FRACUNIT, MT_RING);
// TODO: Make sure not to spawn in the same place 2x! (we need an object in every vertex of the // TODO: Make sure not to spawn in the same place 2x! (we need an object in every vertex of the
// triangle sector to setup the real vertex slopes // triangle sector to setup the real vertex slopes
// Check for the vertexes of all sectors // Check for the vertexes of all sectors
@ -780,31 +781,31 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
continue; continue;
} }
} }
vt1.x = FIXED_TO_FLOAT(vertexes[vi1].x); vt1.x = FIXED_TO_FLOAT(vertexes[vi1].x);
vt1.y = FIXED_TO_FLOAT(vertexes[vi1].y); vt1.y = FIXED_TO_FLOAT(vertexes[vi1].y);
vt2.x = FIXED_TO_FLOAT(vertexes[vi2].x); vt2.x = FIXED_TO_FLOAT(vertexes[vi2].x);
vt2.y = FIXED_TO_FLOAT(vertexes[vi2].y); vt2.y = FIXED_TO_FLOAT(vertexes[vi2].y);
vt3.x = FIXED_TO_FLOAT(vertexes[vi3].x); vt3.x = FIXED_TO_FLOAT(vertexes[vi3].x);
vt3.y = FIXED_TO_FLOAT(vertexes[vi3].y); vt3.y = FIXED_TO_FLOAT(vertexes[vi3].y);
for(j = 0; j < 2; j++) for(j = 0; j < 2; j++)
{ {
fixed_t z3; fixed_t z3;
//I_Error("Lo hicimos"); //I_Error("Lo hicimos");
vt1.z = mt->z;//FIXED_TO_FLOAT(j==0 ? sec->floorheight : sec->ceilingheight); vt1.z = mt->z;//FIXED_TO_FLOAT(j==0 ? sec->floorheight : sec->ceilingheight);
vt2.z = mt->z;//FIXED_TO_FLOAT(j==0? sec->floorheight : sec->ceilingheight); vt2.z = mt->z;//FIXED_TO_FLOAT(j==0? sec->floorheight : sec->ceilingheight);
z3 = mt->z;//j==0? sec->floorheight : sec->ceilingheight; // Destination height z3 = mt->z;//j==0? sec->floorheight : sec->ceilingheight; // Destination height
vt3.z = FIXED_TO_FLOAT(z3); vt3.z = FIXED_TO_FLOAT(z3);
if (P_PointOnLineSide(vertexes[vi3].x, vertexes[vi3].y, sec->lines[0]) == 0) if (P_PointOnLineSide(vertexes[vi3].x, vertexes[vi3].y, sec->lines[0]) == 0)
{ {
vec1.x = vt2.x - vt3.x; vec1.x = vt2.x - vt3.x;
vec1.y = vt2.y - vt3.y; vec1.y = vt2.y - vt3.y;
vec1.z = vt2.z - vt3.z; vec1.z = vt2.z - vt3.z;
vec2.x = vt1.x - vt3.x; vec2.x = vt1.x - vt3.x;
vec2.y = vt1.y - vt3.y; vec2.y = vt1.y - vt3.y;
vec2.z = vt1.z - vt3.z; vec2.z = vt1.z - vt3.z;
@ -814,24 +815,24 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
vec1.x = vt1.x - vt3.x; vec1.x = vt1.x - vt3.x;
vec1.y = vt1.y - vt3.y; vec1.y = vt1.y - vt3.y;
vec1.z = vt1.z - vt3.z; vec1.z = vt1.z - vt3.z;
vec2.x = vt2.x - vt3.x; vec2.x = vt2.x - vt3.x;
vec2.y = vt2.y - vt3.y; vec2.y = vt2.y - vt3.y;
vec2.z = vt2.z - vt3.z; vec2.z = vt2.z - vt3.z;
} }
pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL); pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL);
memset(ret, 0, sizeof(*ret)); memset(ret, 0, sizeof(*ret));
{ {
M_CrossProduct3f(&ret->normalf, &vec1, &vec2); M_CrossProduct3f(&ret->normalf, &vec1, &vec2);
// Cross product length // Cross product length
float len = (float)sqrt(ret->normalf.x * ret->normalf.x + float len = (float)sqrt(ret->normalf.x * ret->normalf.x +
ret->normalf.y * ret->normalf.y + ret->normalf.y * ret->normalf.y +
ret->normalf.z * ret->normalf.z); ret->normalf.z * ret->normalf.z);
if (len == 0) if (len == 0)
{ {
// Only happens when all vertices in this sector are on the same line. // Only happens when all vertices in this sector are on the same line.
@ -843,7 +844,7 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
ret->normalf.x /= len; ret->normalf.x /= len;
ret->normalf.y /= len; ret->normalf.y /= len;
ret->normalf.z /= len; ret->normalf.z /= len;
// ZDoom cross = ret->normalf // ZDoom cross = ret->normalf
// Fix backward normals // Fix backward normals
if ((ret->normalf.z < 0 && j == 0) || (ret->normalf.z > 0 && j == 1)) if ((ret->normalf.z < 0 && j == 0) || (ret->normalf.z > 0 && j == 1))
@ -852,11 +853,11 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
ret->normalf.x = -ret->normalf.x; ret->normalf.x = -ret->normalf.x;
ret->normalf.y = -ret->normalf.x; ret->normalf.y = -ret->normalf.x;
ret->normalf.z = -ret->normalf.x; ret->normalf.z = -ret->normalf.x;
} }
} }
secplane_t *srcplane = Z_Calloc(sizeof(*srcplane), PU_LEVEL, NULL); secplane_t *srcplane = Z_Calloc(sizeof(*srcplane), PU_LEVEL, NULL);
srcplane->a = FLOAT_TO_FIXED (ret->normalf.x); srcplane->a = FLOAT_TO_FIXED (ret->normalf.x);
srcplane->b = FLOAT_TO_FIXED (ret->normalf.y); srcplane->b = FLOAT_TO_FIXED (ret->normalf.y);
srcplane->c = FLOAT_TO_FIXED (ret->normalf.z); srcplane->c = FLOAT_TO_FIXED (ret->normalf.z);
@ -864,7 +865,7 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
srcplane->d = -TMulScale16 (srcplane->a, vertexes[vi3].x, srcplane->d = -TMulScale16 (srcplane->a, vertexes[vi3].x,
srcplane->b, vertexes[vi3].y, srcplane->b, vertexes[vi3].y,
srcplane->c, z3); srcplane->c, z3);
if (j == 0) if (j == 0)
{ {
sec->f_slope = ret; sec->f_slope = ret;
@ -876,20 +877,20 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
sec->c_slope->secplane = *srcplane; sec->c_slope->secplane = *srcplane;
} }
} }
} }
} }
} }
} }
Z_Free(datastart); Z_Free(datastart);
#if 0 // UDMF support #if 0 // UDMF support
for(i = 0; i < numvertexdatas; i++) for(i = 0; i < numvertexdatas; i++)
{ {
@ -898,23 +899,23 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
vt_heights[1][i] = vertexdatas[i].zCeiling; vt_heights[1][i] = vertexdatas[i].zCeiling;
vt_found = true; vt_found = true;
} }
if (vertexdatas[i].flags & VERTEXFLAG_ZFloorEnabled) if (vertexdatas[i].flags & VERTEXFLAG_ZFloorEnabled)
{ {
vt_heights[0][i] = vertexdatas[i].zFloor; vt_heights[0][i] = vertexdatas[i].zFloor;
vt_found = true; vt_found = true;
} }
} }
// If vertexdata_t is ever extended for non-slope usage, this will obviously have to be deferred or removed. // If vertexdata_t is ever extended for non-slope usage, this will obviously have to be deferred or removed.
delete[] vertexdatas; delete[] vertexdatas;
vertexdatas = NULL; vertexdatas = NULL;
numvertexdatas = 0; numvertexdatas = 0;
#endif #endif
} }
#include "p_maputl.h" #include "p_maputl.h"
@ -923,13 +924,13 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum)
static void P_SlopeLineToPointo (int lineid, fixed_t x, fixed_t y, fixed_t z, boolean slopeCeil) static void P_SlopeLineToPointo (int lineid, fixed_t x, fixed_t y, fixed_t z, boolean slopeCeil)
{ {
int linenum = -1; int linenum = -1;
while ((linenum = P_FindLineFromID (lineid, linenum)) != -1) while ((linenum = P_FindLineFromID (lineid, linenum)) != -1)
{ {
const line_t *line = &lines[linenum]; const line_t *line = &lines[linenum];
sector_t *sec; sector_t *sec;
secplane_t *plane; secplane_t *plane;
if (P_PointOnLineSide (x, y, line) == 0) if (P_PointOnLineSide (x, y, line) == 0)
{ {
sec = line->frontsector; sec = line->frontsector;
@ -950,9 +951,9 @@ static void P_SlopeLineToPointo (int lineid, fixed_t x, fixed_t y, fixed_t z, bo
{ {
plane = &sec->floorplane; plane = &sec->floorplane;
} }
FVector3 p, v1, v2, cross; FVector3 p, v1, v2, cross;
p[0] = FIXED2FLOAT (line->v1->x); p[0] = FIXED2FLOAT (line->v1->x);
p[1] = FIXED2FLOAT (line->v1->y); p[1] = FIXED2FLOAT (line->v1->y);
p[2] = FIXED2FLOAT (plane->ZatPoint (line->v1->x, line->v1->y)); p[2] = FIXED2FLOAT (plane->ZatPoint (line->v1->x, line->v1->y));
@ -962,7 +963,7 @@ static void P_SlopeLineToPointo (int lineid, fixed_t x, fixed_t y, fixed_t z, bo
v2[0] = FIXED2FLOAT (x - line->v1->x); v2[0] = FIXED2FLOAT (x - line->v1->x);
v2[1] = FIXED2FLOAT (y - line->v1->y); v2[1] = FIXED2FLOAT (y - line->v1->y);
v2[2] = FIXED2FLOAT (z) - p[2]; v2[2] = FIXED2FLOAT (z) - p[2];
cross = v1 ^ v2; cross = v1 ^ v2;
double len = cross.Length(); double len = cross.Length();
if (len == 0) if (len == 0)
@ -976,7 +977,7 @@ static void P_SlopeLineToPointo (int lineid, fixed_t x, fixed_t y, fixed_t z, bo
{ {
cross = -cross; cross = -cross;
} }
plane->a = FLOAT2FIXED (cross[0]); plane->a = FLOAT2FIXED (cross[0]);
plane->b = FLOAT2FIXED (cross[1]); plane->b = FLOAT2FIXED (cross[1]);
plane->c = FLOAT2FIXED (cross[2]); plane->c = FLOAT2FIXED (cross[2]);
@ -989,7 +990,7 @@ static void P_SlopeLineToPointo (int lineid, fixed_t x, fixed_t y, fixed_t z, bo
} }
#else #else
#if 0 #if 0
// P_SlopeLineToPoint, start from a specific linedef number(not tag) and slope to a mapthing with the angle of the linedef // P_SlopeLineToPoint, start from a specific linedef number(not tag) and slope to a mapthing with the angle of the linedef
static void P_SlopeLineToPoint(int linenum) static void P_SlopeLineToPoint(int linenum)
{ {
line_t *line = lines + linenum; line_t *line = lines + linenum;
@ -998,73 +999,73 @@ static void P_SlopeLineToPoint(int linenum)
v3float_t origin, point; v3float_t origin, point;
v2float_t direction; v2float_t direction;
float dz, extent; float dz, extent;
boolean frontfloor = (special == 386 || special == 388 || special == 393); boolean frontfloor = (special == 386 || special == 388 || special == 393);
boolean backfloor = (special == 389 || special == 391 || special == 392); boolean backfloor = (special == 389 || special == 391 || special == 392);
boolean frontceil = (special == 387 || special == 388 || special == 392); boolean frontceil = (special == 387 || special == 388 || special == 392);
boolean backceil = (special == 390 || special == 391 || special == 393); boolean backceil = (special == 390 || special == 391 || special == 393);
// SoM: We don't need the line to retain its special type // SoM: We don't need the line to retain its special type
line->special = 0; //SRB2CBTODO: ESLOPE: Maybe we do need it for another to check for a plane slope? line->special = 0; //SRB2CBTODO: ESLOPE: Maybe we do need it for another to check for a plane slope?
if(!frontfloor && !backfloor && !frontceil && !backceil) if(!frontfloor && !backfloor && !frontceil && !backceil)
{ {
CONS_Printf("P_SpawnSlope_Line called with non-slope line special.\n"); CONS_Printf("P_SpawnSlope_Line called with non-slope line special.\n");
return; return;
} }
if(!line->frontsector || !line->backsector) if(!line->frontsector || !line->backsector)
{ {
CONS_Printf("P_SpawnSlope_Line used on a line without two sides.\n"); CONS_Printf("P_SpawnSlope_Line used on a line without two sides.\n");
return; return;
} }
origin.x = (FIXED_TO_FLOAT(line->v2->x) + FIXED_TO_FLOAT(line->v1->x)) * 0.5f; origin.x = (FIXED_TO_FLOAT(line->v2->x) + FIXED_TO_FLOAT(line->v1->x)) * 0.5f;
origin.y = (FIXED_TO_FLOAT(line->v2->y) + FIXED_TO_FLOAT(line->v1->y)) * 0.5f; origin.y = (FIXED_TO_FLOAT(line->v2->y) + FIXED_TO_FLOAT(line->v1->y)) * 0.5f;
if(frontfloor || frontceil) if(frontfloor || frontceil)
{ {
// Do the front sector // Do the front sector
direction.x = line->nx; direction.x = line->nx;
direction.y = line->ny; direction.y = line->ny;
extent = P_GetExtent(line->frontsector, line, &origin, &direction); extent = P_GetExtent(line->frontsector, line, &origin, &direction);
if(extent < 0.0f) if(extent < 0.0f)
{ {
CONS_Printf("P_SpawnSlope_Line failed to get frontsector extent on line number %i\n", linenum); CONS_Printf("P_SpawnSlope_Line failed to get frontsector extent on line number %i\n", linenum);
return; return;
} }
// reposition the origin according to the extent // reposition the origin according to the extent
point.x = origin.x + direction.x * extent; point.x = origin.x + direction.x * extent;
point.y = origin.y + direction.y * extent; point.y = origin.y + direction.y * extent;
direction.x = -direction.x; direction.x = -direction.x;
direction.y = -direction.y; direction.y = -direction.y;
// CONS_Printf("Test: X: %f, Y: %f\n", origin.x, origin.y); // CONS_Printf("Test: X: %f, Y: %f\n", origin.x, origin.y);
if(frontfloor) if(frontfloor)
{ {
point.z = FIXED_TO_FLOAT(line->frontsector->floorheight); // Startz point.z = FIXED_TO_FLOAT(line->frontsector->floorheight); // Startz
dz = (FIXED_TO_FLOAT(line->backsector->floorheight) - point.z) / extent; // Destinationz dz = (FIXED_TO_FLOAT(line->backsector->floorheight) - point.z) / extent; // Destinationz
fslope = line->frontsector->f_slope = fslope = line->frontsector->f_slope =
P_MakeSlope(&point, &direction, dz, false); P_MakeSlope(&point, &direction, dz, false);
// Sync the linedata of the line that started this slope // Sync the linedata of the line that started this slope
// SRB2CBTODO: Anything special for remote(control sector)-based slopes later? // SRB2CBTODO: Anything special for remote(control sector)-based slopes later?
line->frontsector->f_slope->sourceline = line; line->frontsector->f_slope->sourceline = line;
// Remember the way the slope is formed // Remember the way the slope is formed
fixed_t highest = line->frontsector->floorheight > line->backsector->floorheight ? fixed_t highest = line->frontsector->floorheight > line->backsector->floorheight ?
line->frontsector->floorheight : line->backsector->floorheight; line->frontsector->floorheight : line->backsector->floorheight;
fixed_t lowest = line->frontsector->floorheight < line->backsector->floorheight ? fixed_t lowest = line->frontsector->floorheight < line->backsector->floorheight ?
line->frontsector->floorheight : line->backsector->floorheight; line->frontsector->floorheight : line->backsector->floorheight;
// This line special sets extra clipping data for the frontsector's slope // This line special sets extra clipping data for the frontsector's slope
fslope->highz = line->frontsector->f_slope->highz = highest; fslope->highz = line->frontsector->f_slope->highz = highest;
fslope->lowz = line->frontsector->f_slope->lowz = lowest; fslope->lowz = line->frontsector->f_slope->lowz = lowest;
// SRB2CBTODO: Get XY angle of a slope and then awesome physics! // ESLOPE: // SRB2CBTODO: Get XY angle of a slope and then awesome physics! // ESLOPE:
//fslope->zangle = line->frontsector->f_slope->zangle = P_GetSlopezangle(line->frontsector, highvert, lowvert); //fslope->zangle = line->frontsector->f_slope->zangle = P_GetSlopezangle(line->frontsector, highvert, lowvert);
//100*(ANG45/45);//R_PointToAngle2(direction.x, direction.y, origin.x, origin.y); //100*(ANG45/45);//R_PointToAngle2(direction.x, direction.y, origin.x, origin.y);
@ -1086,14 +1087,14 @@ static void P_SlopeLineToPoint(int linenum)
//srcheight = isceiling ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling); //srcheight = isceiling ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling);
//destheight = isceiling ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling); //destheight = isceiling ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling);
//P_GetZAtf(ret, v2.x, v2.y) //P_GetZAtf(ret, v2.x, v2.y)
// destheight takes the destination height used in dz // destheight takes the destination height used in dz
srcplane->d = -TMulScale16 (srcplane->a, line->v1->x, srcplane->d = -TMulScale16 (srcplane->a, line->v1->x,
srcplane->b, line->v1->y, srcplane->b, line->v1->y,
srcplane->c, line->backsector->floorheight); srcplane->c, line->backsector->floorheight);
// Sync the secplane! // Sync the secplane!
fslope->secplane = line->frontsector->f_slope->secplane = *srcplane; fslope->secplane = line->frontsector->f_slope->secplane = *srcplane;
} }
} }
} }
@ -1111,7 +1112,7 @@ static void P_SlopeLineToPoint(int linenum)
void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt) void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt)
{ {
FMapThing *mt; FMapThing *mt;
for (mt = firstmt; mt < lastmt; ++mt) for (mt = firstmt; mt < lastmt; ++mt)
{ {
if ((mt->type >= THING_SlopeFloorPointLine && if ((mt->type >= THING_SlopeFloorPointLine &&
@ -1121,7 +1122,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt)
fixed_t x, y, z; fixed_t x, y, z;
secplane_t *refplane; secplane_t *refplane;
sector_t *sec; sector_t *sec;
x = mt->x; x = mt->x;
y = mt->y; y = mt->y;
sec = P_PointInSector (x, y); sec = P_PointInSector (x, y);
@ -1136,7 +1137,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt)
z = refplane->ZatPoint (x, y) + (mt->z); 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); P_VavoomSlope(sec, mt->thingid, x, y, mt->z, mt->type & 1);
} }
else if (mt->type <= THING_SlopeCeilingPointLine) else if (mt->type <= THING_SlopeCeilingPointLine)
{ {
@ -1149,7 +1150,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt)
mt->type = 0; mt->type = 0;
} }
} }
for (mt = firstmt; mt < lastmt; ++mt) for (mt = firstmt; mt < lastmt; ++mt)
{ {
if (mt->type == THING_CopyFloorPlane || if (mt->type == THING_CopyFloorPlane ||
@ -1159,7 +1160,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt)
mt->type = 0; mt->type = 0;
} }
} }
P_SetSlopesFromVertexHeights(firstmt, lastmt); P_SetSlopesFromVertexHeights(firstmt, lastmt);
} }
#endif #endif
@ -1194,7 +1195,7 @@ float P_GetZAtf(pslope_t *slope, float x, float y)
{ {
//if (!slope) // SRB2CBTODO: keep this when done with debugging //if (!slope) // SRB2CBTODO: keep this when done with debugging
// I_Error("P_GetZAtf: slope parameter is NULL"); // I_Error("P_GetZAtf: slope parameter is NULL");
float dist = (x - slope->of.x) * slope->df.x + (y - slope->of.y) * slope->df.y; float dist = (x - slope->of.x) * slope->df.x + (y - slope->of.y) * slope->df.y;
return slope->of.z + (dist * slope->zdeltaf); return slope->of.z + (dist * slope->zdeltaf);
} }
@ -1202,10 +1203,10 @@ float P_GetZAtf(pslope_t *slope, float x, float y)
// //
// P_DistFromPlanef // P_DistFromPlanef
// //
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) const v3float_t *pnormal)
{ {
return (point->x - pori->x) * pnormal->x + return (point->x - pori->x) * pnormal->x +
(point->y - pori->y) * pnormal->y + (point->y - pori->y) * pnormal->y +
(point->z - pori->z) * pnormal->z; (point->z - pori->z) * pnormal->z;
} }