From 8ceba95bfaa973b3026111ff95d59334ad6d0b7d Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 25 May 2016 21:10:46 +0100 Subject: [PATCH 01/54] Fix slope collision detection for the camera See http://mb.srb2.org/showthread.php?t=41494 --- src/p_user.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 0ee5a36b4..4117cfc4c 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8123,6 +8123,8 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall { fixed_t myfloorz, myceilingz; fixed_t midz = thiscam->z + (thiscam->z - mo->z)/2; + fixed_t midx = ((mo->x>>FRACBITS) + (thiscam->x>>FRACBITS))<<(FRACBITS-1); + fixed_t midy = ((mo->y>>FRACBITS) + (thiscam->y>>FRACBITS))<<(FRACBITS-1); // Cameras use the heightsec's heights rather then the actual sector heights. // If you can see through it, why not move the camera through it too? @@ -8138,8 +8140,8 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall } else { - myfloorz = newsubsec->sector->floorheight; - myceilingz = newsubsec->sector->ceilingheight; + myfloorz = P_CameraGetFloorZ(thiscam, newsubsec->sector, midx, midy, NULL); + myceilingz = P_CameraGetCeilingZ(thiscam, newsubsec->sector, midx, midy, NULL); } // Check list of fake floors and see if floorz/ceilingz need to be altered. @@ -8151,17 +8153,21 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) { + fixed_t topheight, bottomheight; if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || GETSECSPECIAL(rover->master->frontsector->special, 4) == 12) continue; - delta1 = midz - (*rover->bottomheight - + ((*rover->topheight - *rover->bottomheight)/2)); - delta2 = thingtop - (*rover->bottomheight - + ((*rover->topheight - *rover->bottomheight)/2)); - if (*rover->topheight > myfloorz && abs(delta1) < abs(delta2)) - myfloorz = *rover->topheight; - if (*rover->bottomheight < myceilingz && abs(delta1) >= abs(delta2)) - myceilingz = *rover->bottomheight; + topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); + bottomheight = P_CameraGetFOFBottomZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); + + delta1 = midz - (bottomheight + + ((topheight - bottomheight)/2)); + delta2 = thingtop - (bottomheight + + ((topheight - bottomheight)/2)); + if (topheight > myfloorz && abs(delta1) < abs(delta2)) + myfloorz = topheight; + if (bottomheight < myceilingz && abs(delta1) >= abs(delta2)) + myceilingz = bottomheight; } } @@ -8275,18 +8281,22 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) { + fixed_t topheight, bottomheight; if ((rover->flags & FF_BLOCKOTHERS) && (rover->flags & FF_RENDERALL) && (rover->flags & FF_EXISTS) && GETSECSPECIAL(rover->master->frontsector->special, 4) != 12) { - if (*rover->bottomheight - thiscam->height < z - && midz < *rover->bottomheight) - z = *rover->bottomheight - thiscam->height-FixedMul(11*FRACUNIT, mo->scale); + topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); + bottomheight = P_CameraGetFOFBottomZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); - else if (*rover->topheight + thiscam->height > z - && midz > *rover->topheight) - z = *rover->topheight; + if (bottomheight - thiscam->height < z + && midz < bottomheight) + z = bottomheight - thiscam->height-FixedMul(11*FRACUNIT, mo->scale); - if ((mo->z >= *rover->topheight && midz < *rover->bottomheight) - || ((mo->z < *rover->bottomheight && mo->z+mo->height < *rover->topheight) && midz >= *rover->topheight)) + else if (topheight + thiscam->height > z + && midz > topheight) + z = topheight; + + if ((mo->z >= topheight && midz < bottomheight) + || ((mo->z < bottomheight && mo->z+mo->height < topheight) && midz >= topheight)) { // Can't see if (!resetcalled) From 2c73e2a2cdd992cdc839491b39346effbbe286a6 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 29 May 2016 16:47:38 +0100 Subject: [PATCH 02/54] Fix flung emeralds not disappearing in death pits (assuming it wasn't an intentional behaviour thing of course) --- src/p_mobj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 4122619d1..68fb1696f 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -2245,6 +2245,7 @@ static boolean P_ZMovement(mobj_t *mo) case MT_BLUETEAMRING: case MT_FLINGRING: case MT_FLINGCOIN: + case MT_FLINGEMERALD: // Remove flinged stuff from death pits. if (P_CheckDeathPitCollide(mo)) { @@ -2276,7 +2277,6 @@ static boolean P_ZMovement(mobj_t *mo) if (!(mo->momx || mo->momy || mo->momz)) return true; break; - case MT_FLINGEMERALD: case MT_NIGHTSWING: if (!(mo->momx || mo->momy || mo->momz)) return true; From fa002e58ad0f11f362a5bdfdb0629c9494906a1b Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 31 May 2016 15:01:19 +0100 Subject: [PATCH 03/54] Did a bunch of things to/for slopes. *The No Physics flag now works (Red, you might want to doublecheck this to see whether I haven't missed any eosteric stuff out). Going downhill is a little bumpy, and I'm not sure whether that's good or not. Someone help me out here? *The SRB2CB typeshims are now behind #ifdef ESLOPE_TYPESHIM instead of #if 1 for easier disabling. *Slopes' downhill thrusts are now scaled with regards to object gravity. This is actually untested in gravities other than normal and reverse normal but it's one line which can be easily reverted in that circumstance. I also checked with MI to make sure this is how it's calculated elsewhere, so fingers crossed this doesn't cause any edge cases. *As a consequence of the above point, there's now a function in p_mobj.c/h that returns an object's internal gravity - seperated out from the logic of P_CheckGravity, which really didn't need to be so monolithic. Multiply by global gravity to get the thrust. This should probably be available to Lua somehow, but I have absolutely no idea where to start with that. Wolfs, maybe? Non-comprehensive test file available at /toaster/slptst3.wad on the ftp. --- src/doomdef.h | 6 ++++++ src/p_mobj.c | 31 ++++++++++++++++++++++--------- src/p_mobj.h | 3 +++ src/p_slopes.c | 50 ++++++++++++++++++++++++++++++++++---------------- src/p_user.c | 8 ++++---- 5 files changed, 69 insertions(+), 29 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 9a1e5af9e..e645c0848 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -431,6 +431,12 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Kalaron/Eternity Engine slope code (SRB2CB ported) #define ESLOPE +#if defined(ESLOPE) +/// Backwards compatibility with SRB2CB's slope linedef types. +/// \note A simple shim that prints a warning. +#define ESLOPE_TYPESHIM +#endif + /// Delete file while the game is running. /// \note EXTREMELY buggy, tends to crash game. //#define DELFILE diff --git a/src/p_mobj.c b/src/p_mobj.c index 68fb1696f..775cd9d6d 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1252,13 +1252,12 @@ static void P_PlayerFlip(mobj_t *mo) } // -// P_CheckGravity +// P_GetMobjGravity // -// Checks the current gravity state -// of the object. If affect is true, -// a gravity force will be applied. +// Returns the current gravity +// value of the object. // -void P_CheckGravity(mobj_t *mo, boolean affect) +fixed_t P_GetMobjGravity(mobj_t *mo) { fixed_t gravityadd = 0; boolean no3dfloorgrav = true; // Custom gravity @@ -1400,11 +1399,25 @@ void P_CheckGravity(mobj_t *mo, boolean affect) if (goopgravity) gravityadd = -gravityadd/5; - if (affect) - mo->momz += FixedMul(gravityadd, mo->scale); - if (mo->player && !!(mo->eflags & MFE_VERTICALFLIP) != wasflip) P_PlayerFlip(mo); + + return gravityadd; +} + +// +// P_CheckGravity +// +// Checks the current gravity state +// of the object. If affect is true, +// a gravity force will be applied. +// +void P_CheckGravity(mobj_t *mo, boolean affect) +{ + fixed_t gravityadd = P_GetMobjGravity(mo); + + if (affect) + mo->momz += FixedMul(gravityadd, mo->scale); if (mo->type == MT_SKIM && mo->z + mo->momz <= mo->watertop && mo->z >= mo->watertop) { @@ -1480,7 +1493,7 @@ static void P_XYFriction(mobj_t *mo, fixed_t oldx, fixed_t oldy) && abs(player->rmomy) < FixedMul(STOPSPEED, mo->scale) && (!(player->cmd.forwardmove && !(twodlevel || mo->flags2 & MF2_TWOD)) && !player->cmd.sidemove && !(player->pflags & PF_SPINNING)) #ifdef ESLOPE - && !(player->mo->standingslope && abs(player->mo->standingslope->zdelta) >= FRACUNIT/2) + && !(player->mo->standingslope && (!(player->mo->standingslope->flags & SL_NOPHYSICS)) && (abs(player->mo->standingslope->zdelta) >= FRACUNIT/2)) #endif ) { diff --git a/src/p_mobj.h b/src/p_mobj.h index 9542ce8ba..de7f0c8d5 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -425,6 +425,9 @@ void P_AddCachedAction(mobj_t *mobj, INT32 statenum); // check mobj against water content, before movement code void P_MobjCheckWater(mobj_t *mobj); +// get mobj gravity +fixed_t P_GetMobjGravity(mobj_t *mo); + // Player spawn points void P_SpawnPlayer(INT32 playernum); void P_MovePlayerToSpawn(INT32 playernum, mapthing_t *mthing); diff --git a/src/p_slopes.c b/src/p_slopes.c index 6393ca4b5..f4ef4dcc2 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -16,6 +16,7 @@ #include "m_bbox.h" #include "z_zone.h" #include "p_local.h" +#include "p_mobj.h" #include "p_spec.h" #include "p_slopes.h" #include "p_setup.h" @@ -881,7 +882,7 @@ void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum) // Reset the dynamic slopes pointer, and read all of the fancy schmancy slopes void P_ResetDynamicSlopes(void) { size_t i; -#if 1 // Rewrite old specials to new ones, and give a console warning +#ifdef ESLOPE_TYPESHIM // Rewrite old specials to new ones, and give a console warning boolean warned = false; #endif @@ -894,7 +895,7 @@ void P_ResetDynamicSlopes(void) { { switch (lines[i].special) { -#if 1 // Rewrite old specials to new ones, and give a console warning +#ifdef ESLOPE_TYPESHIM // Rewrite old specials to new ones, and give a console warning #define WARNME if (!warned) {warned = true; CONS_Alert(CONS_WARNING, "This level uses old slope specials.\nA conversion will be needed before 2.2's release.\n");} case 386: case 387: @@ -1018,6 +1019,9 @@ fixed_t P_GetZAt(pslope_t *slope, fixed_t x, fixed_t y) // When given a vector, rotates it and aligns it to a slope void P_QuantizeMomentumToSlope(vector3_t *momentum, pslope_t *slope) { + if (slope->flags & SL_NOPHYSICS) + return; // No physics, no quantizing. + vector3_t axis; axis.x = -slope->d.y; axis.y = slope->d.x; @@ -1032,26 +1036,37 @@ void P_QuantizeMomentumToSlope(vector3_t *momentum, pslope_t *slope) // Handles slope ejection for objects void P_SlopeLaunch(mobj_t *mo) { - // Double the pre-rotation Z, then halve the post-rotation Z. This reduces the - // vertical launch given from slopes while increasing the horizontal launch - // given. Good for SRB2's gravity and horizontal speeds. - vector3_t slopemom; - slopemom.x = mo->momx; - slopemom.y = mo->momy; - slopemom.z = mo->momz*2; - P_QuantizeMomentumToSlope(&slopemom, mo->standingslope); - - mo->momx = slopemom.x; - mo->momy = slopemom.y; - mo->momz = slopemom.z/2; + if (!(mo->standingslope->flags & SL_NOPHYSICS)) // If there's physics, time for launching. + { + // Double the pre-rotation Z, then halve the post-rotation Z. This reduces the + // vertical launch given from slopes while increasing the horizontal launch + // given. Good for SRB2's gravity and horizontal speeds. + vector3_t slopemom; + slopemom.x = mo->momx; + slopemom.y = mo->momy; + slopemom.z = mo->momz*2; + P_QuantizeMomentumToSlope(&slopemom, mo->standingslope); + mo->momx = slopemom.x; + mo->momy = slopemom.y; + mo->momz = slopemom.z/2; + } + //CONS_Printf("Launched off of slope.\n"); mo->standingslope = NULL; } // Function to help handle landing on slopes void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope) -{ +{ + if (slope->flags & SL_NOPHYSICS) { // No physics, no need to make anything complicated. + if (P_MobjFlip(thing)*(thing->momz) < 0) { // falling, land on slope + thing->momz = -P_MobjFlip(thing); + thing->standingslope = slope; + } + return; + } + vector3_t mom; mom.x = thing->momx; mom.y = thing->momy; @@ -1081,6 +1096,9 @@ void P_ButteredSlope(mobj_t *mo) if (!mo->standingslope) return; + + if (mo->standingslope->flags & SL_NOPHYSICS) + return; // No physics, no butter. if (mo->flags & (MF_NOCLIPHEIGHT|MF_NOGRAVITY)) return; // don't slide down slopes if you can't touch them or you're not affected by gravity @@ -1116,7 +1134,7 @@ void P_ButteredSlope(mobj_t *mo) // This makes it harder to zigzag up steep slopes, as well as allows greater top speed when rolling down // Multiply by gravity - thrust = FixedMul(thrust, gravity); // TODO account for per-sector gravity etc + thrust = FixedMul(thrust, FixedMul(gravity, abs(P_GetMobjGravity(mo)))); // Now uses the absolute of mobj gravity. You're welcome. // Multiply by scale (gravity strength depends on mobj scale) thrust = FixedMul(thrust, mo->scale); diff --git a/src/p_user.c b/src/p_user.c index 4117cfc4c..461497bcb 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3741,7 +3741,7 @@ static void P_DoSpinDash(player_t *player, ticcmd_t *cmd) { if ((cmd->buttons & BT_USE) && player->speed < FixedMul(5<mo->scale) && !player->mo->momz && onground && !(player->pflags & PF_USEDOWN) && !(player->pflags & PF_SPINNING) #ifdef ESLOPE - && (!player->mo->standingslope || abs(player->mo->standingslope->zdelta) < FRACUNIT/2) + && (!player->mo->standingslope || (player->mo->standingslope->flags & SL_NOPHYSICS) || abs(player->mo->standingslope->zdelta) < FRACUNIT/2) #endif ) { @@ -3774,7 +3774,7 @@ static void P_DoSpinDash(player_t *player, ticcmd_t *cmd) else if ((cmd->buttons & BT_USE || ((twodlevel || (player->mo->flags2 & MF2_TWOD)) && cmd->forwardmove < -20)) && !player->climbing && !player->mo->momz && onground && (player->speed > FixedMul(5<mo->scale) #ifdef ESLOPE - || (player->mo->standingslope && abs(player->mo->standingslope->zdelta) >= FRACUNIT/2) + || (player->mo->standingslope && (!(player->mo->standingslope->flags & SL_NOPHYSICS)) && abs(player->mo->standingslope->zdelta) >= FRACUNIT/2) #endif ) && !(player->pflags & PF_USEDOWN) && !(player->pflags & PF_SPINNING)) { @@ -3790,7 +3790,7 @@ static void P_DoSpinDash(player_t *player, ticcmd_t *cmd) if (onground && player->pflags & PF_SPINNING && !(player->pflags & PF_STARTDASH) && player->speed < FixedMul(5*FRACUNIT,player->mo->scale) #ifdef ESLOPE - && (!player->mo->standingslope || abs(player->mo->standingslope->zdelta) < FRACUNIT/2) + && (!player->mo->standingslope || (player->mo->standingslope->flags & SL_NOPHYSICS) || abs(player->mo->standingslope->zdelta) < FRACUNIT/2) #endif ) { @@ -4776,7 +4776,7 @@ static void P_3dMovement(player_t *player) #ifdef ESLOPE if ((totalthrust.x || totalthrust.y) - && player->mo->standingslope && abs(player->mo->standingslope->zdelta) > FRACUNIT/2) { + && player->mo->standingslope && (!(player->mo->standingslope->flags & SL_NOPHYSICS)) && abs(player->mo->standingslope->zdelta) > FRACUNIT/2) { // Factor thrust to slope, but only for the part pushing up it! // The rest is unaffected. angle_t thrustangle = R_PointToAngle2(0, 0, totalthrust.x, totalthrust.y)-player->mo->standingslope->xydirection; From ad61050bb07825453b83fdd8735c2e85460d6ac2 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 31 May 2016 16:01:05 +0100 Subject: [PATCH 04/54] Whitespace removal. --- src/p_mobj.c | 2 +- src/p_slopes.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 775cd9d6d..35d8f1ad2 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1401,7 +1401,7 @@ fixed_t P_GetMobjGravity(mobj_t *mo) if (mo->player && !!(mo->eflags & MFE_VERTICALFLIP) != wasflip) P_PlayerFlip(mo); - + return gravityadd; } diff --git a/src/p_slopes.c b/src/p_slopes.c index f4ef4dcc2..462f7c3cb 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -1021,7 +1021,7 @@ void P_QuantizeMomentumToSlope(vector3_t *momentum, pslope_t *slope) { if (slope->flags & SL_NOPHYSICS) return; // No physics, no quantizing. - + vector3_t axis; axis.x = -slope->d.y; axis.y = slope->d.x; @@ -1051,14 +1051,14 @@ void P_SlopeLaunch(mobj_t *mo) mo->momy = slopemom.y; mo->momz = slopemom.z/2; } - + //CONS_Printf("Launched off of slope.\n"); mo->standingslope = NULL; } // Function to help handle landing on slopes void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope) -{ +{ if (slope->flags & SL_NOPHYSICS) { // No physics, no need to make anything complicated. if (P_MobjFlip(thing)*(thing->momz) < 0) { // falling, land on slope thing->momz = -P_MobjFlip(thing); @@ -1096,7 +1096,7 @@ void P_ButteredSlope(mobj_t *mo) if (!mo->standingslope) return; - + if (mo->standingslope->flags & SL_NOPHYSICS) return; // No physics, no butter. From 6058eec1c9c4c0b5129c72f94dce0e4a7dca01d8 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 31 May 2016 16:14:21 +0100 Subject: [PATCH 05/54] Holy shit. I spent two hours staring at how garbage this code was and didn't even realise it was #ifdef'd out behind a define not even mentioned in doomdef.h. It's not actually used anywhere (superseded entirely by the much nicer, much more relevant P_NewVertexSlope()... out with you, ancient, foul demons who should've been SPRINGCLEANed long ago. --- src/p_slopes.c | 255 ------------------------------------------------- src/p_slopes.h | 20 ---- 2 files changed, 275 deletions(-) diff --git a/src/p_slopes.c b/src/p_slopes.c index 462f7c3cb..cb5f07b2b 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -624,261 +624,6 @@ pslope_t *P_SlopeById(UINT16 id) return ret; } -#ifdef SPRINGCLEAN -#include "byteptr.h" - -#include "p_setup.h" -#include "p_local.h" - -//========================================================================== -// -// P_SetSlopesFromVertexHeights -// -//========================================================================== -void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum) -{ - mapthing_t *mt; - boolean vt_found = false; - size_t i, j, k, l, q; - - //size_t i; - //mapthing_t *mt; - char *data; - char *datastart; - - // SRB2CBTODO: WHAT IS (5 * sizeof (short))?! It = 10 - // anything else seems to make a map not load properly, - // but this hard-coded value MUST have some reason for being what it is - size_t snummapthings = W_LumpLength(lumpnum) / (5 * sizeof (short)); - mapthing_t *smapthings = Z_Calloc(snummapthings * sizeof (*smapthings), PU_LEVEL, NULL); - fixed_t x, y; - sector_t *sector; - // Spawn axis points first so they are - // at the front of the list for fast searching. - data = datastart = W_CacheLumpNum(lumpnum, PU_LEVEL); - mt = smapthings; - for (i = 0; i < snummapthings; i++, mt++) - { - mt->x = READINT16(data); - mt->y = READINT16(data); - mt->angle = READINT16(data); - mt->type = READINT16(data); - mt->options = READINT16(data); - // 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->type &= 4095; // SRB2CBTODO: WHAT IS THIS???? Mobj type limits?!!!! - x = mt->x*FRACUNIT; - y = mt->y*FRACUNIT; - sector = R_PointInSubsector(x, y)->sector; - // Z for objects -#ifdef ESLOPE - if (sector->f_slope) - mt->z = (short)(P_GetZAt(sector->f_slope, x, y)>>FRACBITS); - else -#endif - mt->z = (short)(sector->floorheight>>FRACBITS); - - mt->z = mt->z + (mt->options >> ZSHIFT); - - if (mt->type == THING_VertexFloorZ || mt->type == THING_VertexCeilingZ) // THING_VertexFloorZ - { - for(l = 0; l < numvertexes; l++) - { - if (vertexes[l].x == mt->x*FRACUNIT && vertexes[l].y == mt->y*FRACUNIT) - { - if (mt->type == THING_VertexFloorZ) - { - vertexes[l].z = mt->z*FRACUNIT; - //I_Error("Z value: %i", vertexes[l].z/FRACUNIT); - - } - else - { - vertexes[l].z = mt->z*FRACUNIT; // celing floor - } - vt_found = true; - } - } - //mt->type = 0; // VPHYSICS: Dynamic slopes - - - - - - - if (vt_found) - { - for (k = 0; k < numsectors; k++) - { - sector_t *sec = §ors[k]; - if (sec->linecount != 3) continue; // only works with triangular sectors - - v3float_t vt1, vt2, vt3; // cross = ret->normalf - v3float_t vec1, vec2; - - int vi1, vi2, vi3; - - vi1 = (int)(sec->lines[0]->v1 - 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)? - (int)(sec->lines[1]->v2 - vertexes) : (int)(sec->lines[1]->v1 - vertexes); - - //if (vertexes[vi1].z) - // I_Error("OSNAP %i", vertexes[vi1].z/FRACUNIT); - //if (vertexes[vi2].z) - // I_Error("OSNAP %i", vertexes[vi2].z/FRACUNIT); - //if (vertexes[vi3].z) - // I_Error("OSNAP %i", vertexes[vi3].z/FRACUNIT); - - //I_Error("%i, %i", mt->z*FRACUNIT, vertexes[vi1].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); - - // 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 - // Check for the vertexes of all sectors - for(q = 0; q < numvertexes; q++) - { - if (vertexes[q].x == mt->x*FRACUNIT && vertexes[q].y == mt->y*FRACUNIT) - { - //I_Error("yeah %i", vertexes[q].z); - P_SpawnMobj(vertexes[q].x, vertexes[q].y, vertexes[q].z, MT_RING); -#if 0 - if ((mt->y*FRACUNIT == vertexes[vi1].y && mt->x*FRACUNIT == vertexes[vi1].x && mt->z*FRACUNIT == vertexes[vi1].z) - && !(mt->y*FRACUNIT == vertexes[vi2].y && mt->x*FRACUNIT == vertexes[vi2].x && mt->z*FRACUNIT == vertexes[vi2].z) - && !(mt->y*FRACUNIT == vertexes[vi3].y && mt->x*FRACUNIT == vertexes[vi3].x && mt->z*FRACUNIT == vertexes[vi3].z)) - P_SpawnMobj(vertexes[vi1].x, vertexes[vi1].y, vertexes[vi1].z, MT_RING); - else if ((mt->y*FRACUNIT == vertexes[vi2].y && mt->x*FRACUNIT == vertexes[vi2].x && mt->z*FRACUNIT == vertexes[vi2].z) - && !(mt->y*FRACUNIT == vertexes[vi1].y && mt->x*FRACUNIT == vertexes[vi1].x && mt->z*FRACUNIT == vertexes[vi1].z) - && !(mt->y*FRACUNIT == vertexes[vi3].y && mt->x*FRACUNIT == vertexes[vi3].x && mt->z*FRACUNIT == vertexes[vi3].z)) - P_SpawnMobj(vertexes[vi2].x, vertexes[vi2].y, vertexes[vi2].z, MT_BOUNCETV); - else if ((mt->y*FRACUNIT == vertexes[vi3].y && mt->x*FRACUNIT == vertexes[vi3].x && mt->z*FRACUNIT == vertexes[vi3].z) - && !(mt->y*FRACUNIT == vertexes[vi2].y && mt->x*FRACUNIT == vertexes[vi2].x && mt->z*FRACUNIT == vertexes[vi2].z) - && !(mt->y*FRACUNIT == vertexes[vi1].y && mt->x*FRACUNIT == vertexes[vi1].x && mt->z*FRACUNIT == vertexes[vi1].z)) - P_SpawnMobj(vertexes[vi3].x, vertexes[vi3].y, vertexes[vi3].z, MT_GFZFLOWER1); - else -#endif - continue; - } - } - - vt1.x = FIXED_TO_FLOAT(vertexes[vi1].x); - vt1.y = FIXED_TO_FLOAT(vertexes[vi1].y); - vt2.x = FIXED_TO_FLOAT(vertexes[vi2].x); - vt2.y = FIXED_TO_FLOAT(vertexes[vi2].y); - vt3.x = FIXED_TO_FLOAT(vertexes[vi3].x); - vt3.y = FIXED_TO_FLOAT(vertexes[vi3].y); - - for(j = 0; j < 2; j++) - { - - fixed_t z3; - //I_Error("Lo hicimos"); - - 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); - z3 = mt->z;//j==0? sec->floorheight : sec->ceilingheight; // Destination height - vt3.z = FIXED_TO_FLOAT(z3); - - if (P_PointOnLineSide(vertexes[vi3].x, vertexes[vi3].y, sec->lines[0]) == 0) - { - vec1.x = vt2.x - vt3.x; - vec1.y = vt2.y - vt3.y; - vec1.z = vt2.z - vt3.z; - - vec2.x = vt1.x - vt3.x; - vec2.y = vt1.y - vt3.y; - vec2.z = vt1.z - vt3.z; - } - else - { - vec1.x = vt1.x - vt3.x; - vec1.y = vt1.y - vt3.y; - vec1.z = vt1.z - vt3.z; - - vec2.x = vt2.x - vt3.x; - vec2.y = vt2.y - vt3.y; - vec2.z = vt2.z - vt3.z; - } - - - pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL); - memset(ret, 0, sizeof(*ret)); - - { - M_CrossProduct3f(&ret->normalf, &vec1, &vec2); - - // Cross product length - float len = (float)sqrt(ret->normalf.x * ret->normalf.x + - ret->normalf.y * ret->normalf.y + - ret->normalf.z * ret->normalf.z); - - if (len == 0) - { - // Only happens when all vertices in this sector are on the same line. - // Let's just ignore this case. - //CONS_Printf("Slope thing at (%d,%d) lies directly on its target line.\n", (int)(x>>16), (int)(y>>16)); - return; - } - // cross/len - ret->normalf.x /= len; - ret->normalf.y /= len; - ret->normalf.z /= len; - - // ZDoom cross = ret->normalf - // Fix backward normals - if ((ret->normalf.z < 0 && j == 0) || (ret->normalf.z > 0 && j == 1)) - { - // cross = -cross - ret->normalf.x = -ret->normalf.x; - ret->normalf.y = -ret->normalf.x; - ret->normalf.z = -ret->normalf.x; - } - } - - secplane_t *srcplane = Z_Calloc(sizeof(*srcplane), PU_LEVEL, NULL); - - srcplane->a = FLOAT_TO_FIXED (ret->normalf.x); - srcplane->b = FLOAT_TO_FIXED (ret->normalf.y); - srcplane->c = FLOAT_TO_FIXED (ret->normalf.z); - //srcplane->ic = FixedDiv(FRACUNIT, srcplane->c); - srcplane->d = -TMulScale16 (srcplane->a, vertexes[vi3].x, - srcplane->b, vertexes[vi3].y, - srcplane->c, z3); - - if (j == 0) - { - sec->f_slope = ret; - sec->f_slope->secplane = *srcplane; - } - else if (j == 1) - { - sec->c_slope = ret; - sec->c_slope->secplane = *srcplane; - } - } - } - } - - - - - - - - - } - } - Z_Free(datastart); - - - - -} -#endif - // Reset the dynamic slopes pointer, and read all of the fancy schmancy slopes void P_ResetDynamicSlopes(void) { size_t i; diff --git a/src/p_slopes.h b/src/p_slopes.h index 80921a84b..dd9b6f2d2 100644 --- a/src/p_slopes.h +++ b/src/p_slopes.h @@ -21,26 +21,6 @@ void P_RunDynamicSlopes(void); // sectors. void P_SpawnSlope_Line(int linenum); -#ifdef SPRINGCLEAN -// Loads just map objects that make slopes, -// terrain affecting objects have to be spawned first -void P_SetSlopesFromVertexHeights(lumpnum_t lumpnum); - -typedef enum -{ - THING_SlopeFloorPointLine = 9500, - THING_SlopeCeilingPointLine = 9501, - THING_SetFloorSlope = 9502, - THING_SetCeilingSlope = 9503, - THING_CopyFloorPlane = 9510, - THING_CopyCeilingPlane = 9511, - THING_VavoomFloor=1500, - THING_VavoomCeiling=1501, - THING_VertexFloorZ=1504, - THING_VertexCeilingZ=1505, -} slopething_e; -#endif - // // P_CopySectorSlope // From da2abbb39ff5302ee7a86e0dd717f1185af0a00a Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 31 May 2016 16:24:51 +0100 Subject: [PATCH 06/54] Failed a build because C is an obnoxious language. --- src/p_slopes.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/p_slopes.c b/src/p_slopes.c index cb5f07b2b..bd354c500 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -764,10 +764,11 @@ fixed_t P_GetZAt(pslope_t *slope, fixed_t x, fixed_t y) // When given a vector, rotates it and aligns it to a slope void P_QuantizeMomentumToSlope(vector3_t *momentum, pslope_t *slope) { + vector3_t axis; // Fuck you, C90. + if (slope->flags & SL_NOPHYSICS) return; // No physics, no quantizing. - vector3_t axis; axis.x = -slope->d.y; axis.y = slope->d.x; axis.z = 0; @@ -804,6 +805,8 @@ void P_SlopeLaunch(mobj_t *mo) // Function to help handle landing on slopes void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope) { + vector3_t mom; // Ditto. + if (slope->flags & SL_NOPHYSICS) { // No physics, no need to make anything complicated. if (P_MobjFlip(thing)*(thing->momz) < 0) { // falling, land on slope thing->momz = -P_MobjFlip(thing); @@ -812,7 +815,6 @@ void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope) return; } - vector3_t mom; mom.x = thing->momx; mom.y = thing->momy; mom.z = thing->momz*2; From d998ddfae46f0250d1336488fe3e99ca1d2c4c95 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 31 May 2016 17:07:28 +0100 Subject: [PATCH 07/54] When you haven't found all the vertices, it's just not safe to carry on. Hit them with a descriptive I_Error so they don't get confused as hell like Glaber did. http://mb.srb2.org/showthread.php?t=41455 for reference. Also took the opportunity to nuke or otherwise neuter a bunch of Kalaron's bizzare ramblings (most are questions which have long-been answered by Red's efforts) at the same time. --- src/p_slopes.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/p_slopes.c b/src/p_slopes.c index bd354c500..659f8b330 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -200,7 +200,6 @@ static fixed_t P_GetExtent(sector_t *sector, line_t *line) // Find furthest vertex from the reference line. It, along with the two ends // of the line, will define the plane. - // SRB2CBTODO: Use a formula to get the slope to slide objects depending on how steep for(i = 0; i < sector->linecount; i++) { line_t *li = sector->lines[i]; @@ -232,7 +231,6 @@ static fixed_t P_GetExtent(sector_t *sector, line_t *line) // // Creates one or more slopes based on the given line type and front/back // sectors. -// Kalaron: Check if dynamic slopes need recalculation // void P_SpawnSlope_Line(int linenum) { @@ -277,7 +275,7 @@ void P_SpawnSlope_Line(int linenum) ny = -FixedDiv(line->dx, len); } - // SRB2CBTODO: Transform origin relative to the bounds of an individual FOF + // TODO: Transform origin relative to the bounds of an individual FOF origin.x = line->v1->x + (line->v2->x - line->v1->x)/2; origin.y = line->v1->y + (line->v2->y - line->v1->y)/2; @@ -328,7 +326,7 @@ void P_SpawnSlope_Line(int linenum) // fslope->normal is a 3D line perpendicular to the 3D vector // Sync the linedata of the line that started this slope - // SRB2CBTODO: Anything special for remote(control sector)-based slopes later? + // TODO: Anything special for control sector based slopes later? fslope->sourceline = line; // To find the real highz/lowz of a slope, you need to check all the vertexes @@ -380,7 +378,7 @@ void P_SpawnSlope_Line(int linenum) cslope->refpos = 2; // Sync the linedata of the line that started this slope - // SRB2CBTODO: Anything special for remote(control sector)-based slopes later? + // TODO: Anything special for control sector based slopes later? cslope->sourceline = line; // Remember the way the slope is formed @@ -446,7 +444,7 @@ void P_SpawnSlope_Line(int linenum) fslope->refpos = 3; // Sync the linedata of the line that started this slope - // SRB2CBTODO: Anything special for remote(control sector)-based slopes later? + // TODO: Anything special for control sector based slopes later? fslope->sourceline = line; // Remember the way the slope is formed @@ -489,7 +487,7 @@ void P_SpawnSlope_Line(int linenum) cslope->refpos = 4; // Sync the linedata of the line that started this slope - // SRB2CBTODO: Anything special for remote(control sector)-based slopes later? + // TODO: Anything special for control sector based slopes later? cslope->sourceline = line; // Remember the way the slope is formed @@ -555,16 +553,11 @@ static pslope_t *P_NewVertexSlope(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flag ret->vertices[2] = mt; } - if (!ret->vertices[0]) - CONS_Printf("PANIC 0\n"); - if (!ret->vertices[1]) - CONS_Printf("PANIC 1\n"); - if (!ret->vertices[2]) - CONS_Printf("PANIC 2\n"); - // Now set heights for each vertex, because they haven't been set yet for (i = 0; i < 3; i++) { mt = ret->vertices[i]; + if (!mt) // If a vertex wasn't found, it's game over. There's nothing you can do to recover (except maybe try and kill the slope instead - TODO?) + I_Error("Slope vertex %d (for linedef tag %d) not found.", i, tag1); if (mt->extrainfo) mt->z = mt->options; else From d4d44777f43297f398247f8db81302d493f25763 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 31 May 2016 17:43:27 +0100 Subject: [PATCH 08/54] Okay, now vertex slopes aren't placement-order-dependent any more. Hopefully this is the best way to handle things. --- src/p_slopes.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/p_slopes.c b/src/p_slopes.c index 659f8b330..d9e2cef66 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -546,9 +546,17 @@ static pslope_t *P_NewVertexSlope(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flag continue; if (!ret->vertices[0] && mt->angle == tag1) + { ret->vertices[0] = mt; + mt = mapthings; + i = 0; + } else if (!ret->vertices[1] && mt->angle == tag2) + { ret->vertices[1] = mt; + mt = mapthings; + i = 0; + } else if (!ret->vertices[2] && mt->angle == tag3) ret->vertices[2] = mt; } From 7071fbe29e5c078631c6dae366ca81bcbc570e34 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 31 May 2016 18:13:17 +0100 Subject: [PATCH 09/54] I made a mistake. Fuck git reverts, they are a nightmare, let's just do this the old fashioned way. --- src/p_slopes.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/p_slopes.c b/src/p_slopes.c index d9e2cef66..659f8b330 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -546,17 +546,9 @@ static pslope_t *P_NewVertexSlope(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flag continue; if (!ret->vertices[0] && mt->angle == tag1) - { ret->vertices[0] = mt; - mt = mapthings; - i = 0; - } else if (!ret->vertices[1] && mt->angle == tag2) - { ret->vertices[1] = mt; - mt = mapthings; - i = 0; - } else if (!ret->vertices[2] && mt->angle == tag3) ret->vertices[2] = mt; } From d24cc494439fcc3b2a92048be256199b191cf8bb Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 31 May 2016 21:31:29 +0100 Subject: [PATCH 10/54] Fix FOF height checks all over p_spec.c to account for slopes This fixes certain sector specials and linedef executor specials etc not accounting for players/mobjs touching sloped FOFs --- src/p_spec.c | 81 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index fbcb8b4f0..9e4c3f079 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2434,10 +2434,10 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (rover->master->frontsector->tag != line->tag) continue; - if (mo->z > *rover->topheight) + if (mo->z > P_GetSpecialTopZ(mo, sectors + rover->secnum, mo->subsector->sector)) continue; - if (mo->z + mo->height < *rover->bottomheight) + if (mo->z + mo->height < P_GetSpecialBottomZ(mo, sectors + rover->secnum, mo->subsector->sector)) continue; foundit = true; @@ -3227,8 +3227,8 @@ boolean P_IsFlagAtBase(mobjtype_t flag) if (GETSECSPECIAL(rover->master->frontsector->special, 4) != specialnum) continue; - if (mo->z <= *rover->topheight - && mo->z >= *rover->bottomheight) + if (mo->z <= P_GetSpecialTopZ(mo, sectors + rover->secnum, mo->subsector->sector) + && mo->z >= P_GetSpecialBottomZ(mo, sectors + rover->secnum, mo->subsector->sector)) return true; } } @@ -3262,12 +3262,17 @@ sector_t *P_PlayerTouchingSectorSpecial(player_t *player, INT32 section, INT32 n // Hmm.. maybe there's a FOF that has it... for (rover = player->mo->subsector->sector->ffloors; rover; rover = rover->next) { + fixed_t topheight, bottomheight; + if (GETSECSPECIAL(rover->master->frontsector->special, section) != number) continue; if (!(rover->flags & FF_EXISTS)) continue; + topheight = P_GetSpecialTopZ(player->mo, sectors + rover->secnum, player->mo->subsector->sector); + bottomheight = P_GetSpecialBottomZ(player->mo, sectors + rover->secnum, player->mo->subsector->sector); + // Check the 3D floor's type... if (rover->flags & FF_BLOCKPLAYER) { @@ -3275,27 +3280,27 @@ sector_t *P_PlayerTouchingSectorSpecial(player_t *player, INT32 section, INT32 n if ((rover->master->frontsector->flags & SF_FLIPSPECIAL_FLOOR) && !(rover->master->frontsector->flags & SF_FLIPSPECIAL_CEILING)) { - if ((player->mo->eflags & MFE_VERTICALFLIP) || player->mo->z != *rover->topheight) + if ((player->mo->eflags & MFE_VERTICALFLIP) || player->mo->z != topheight) continue; } else if ((rover->master->frontsector->flags & SF_FLIPSPECIAL_CEILING) && !(rover->master->frontsector->flags & SF_FLIPSPECIAL_FLOOR)) { if (!(player->mo->eflags & MFE_VERTICALFLIP) - || player->mo->z + player->mo->height != *rover->bottomheight) + || player->mo->z + player->mo->height != bottomheight) continue; } else if (rover->master->frontsector->flags & SF_FLIPSPECIAL_BOTH) { - if (!((player->mo->eflags & MFE_VERTICALFLIP && player->mo->z + player->mo->height == *rover->bottomheight) - || (!(player->mo->eflags & MFE_VERTICALFLIP) && player->mo->z == *rover->topheight))) + if (!((player->mo->eflags & MFE_VERTICALFLIP && player->mo->z + player->mo->height == bottomheight) + || (!(player->mo->eflags & MFE_VERTICALFLIP) && player->mo->z == topheight))) continue; } } else { // Water and DEATH FOG!!! heh - if (player->mo->z > *rover->topheight || (player->mo->z + player->mo->height) < *rover->bottomheight) + if (player->mo->z > topheight || (player->mo->z + player->mo->height) < bottomheight) continue; } @@ -3317,12 +3322,17 @@ sector_t *P_PlayerTouchingSectorSpecial(player_t *player, INT32 section, INT32 n // Hmm.. maybe there's a FOF that has it... for (rover = node->m_sector->ffloors; rover; rover = rover->next) { + fixed_t topheight, bottomheight; + if (GETSECSPECIAL(rover->master->frontsector->special, section) != number) continue; if (!(rover->flags & FF_EXISTS)) continue; + topheight = P_GetSpecialTopZ(player->mo, sectors + rover->secnum, player->mo->subsector->sector); + bottomheight = P_GetSpecialBottomZ(player->mo, sectors + rover->secnum, player->mo->subsector->sector); + // Check the 3D floor's type... if (rover->flags & FF_BLOCKPLAYER) { @@ -3330,27 +3340,27 @@ sector_t *P_PlayerTouchingSectorSpecial(player_t *player, INT32 section, INT32 n if ((rover->master->frontsector->flags & SF_FLIPSPECIAL_FLOOR) && !(rover->master->frontsector->flags & SF_FLIPSPECIAL_CEILING)) { - if ((player->mo->eflags & MFE_VERTICALFLIP) || player->mo->z != *rover->topheight) + if ((player->mo->eflags & MFE_VERTICALFLIP) || player->mo->z != topheight) continue; } else if ((rover->master->frontsector->flags & SF_FLIPSPECIAL_CEILING) && !(rover->master->frontsector->flags & SF_FLIPSPECIAL_FLOOR)) { if (!(player->mo->eflags & MFE_VERTICALFLIP) - || player->mo->z + player->mo->height != *rover->bottomheight) + || player->mo->z + player->mo->height != bottomheight) continue; } else if (rover->master->frontsector->flags & SF_FLIPSPECIAL_BOTH) { - if (!((player->mo->eflags & MFE_VERTICALFLIP && player->mo->z + player->mo->height == *rover->bottomheight) - || (!(player->mo->eflags & MFE_VERTICALFLIP) && player->mo->z == *rover->topheight))) + if (!((player->mo->eflags & MFE_VERTICALFLIP && player->mo->z + player->mo->height == bottomheight) + || (!(player->mo->eflags & MFE_VERTICALFLIP) && player->mo->z == topheight))) continue; } } else { // Water and DEATH FOG!!! heh - if (player->mo->z > *rover->topheight || (player->mo->z + player->mo->height) < *rover->bottomheight) + if (player->mo->z > topheight || (player->mo->z + player->mo->height) < bottomheight) continue; } @@ -4335,12 +4345,17 @@ sector_t *P_ThingOnSpecial3DFloor(mobj_t *mo) for (rover = sector->ffloors; rover; rover = rover->next) { + fixed_t topheight, bottomheight; + if (!rover->master->frontsector->special) continue; if (!(rover->flags & FF_EXISTS)) continue; + topheight = P_GetSpecialTopZ(mo, sectors + rover->secnum, sector); + bottomheight = P_GetSpecialBottomZ(mo, sectors + rover->secnum, sector); + // Check the 3D floor's type... if (((rover->flags & FF_BLOCKPLAYER) && mo->player) || ((rover->flags & FF_BLOCKOTHERS) && !mo->player)) @@ -4349,27 +4364,27 @@ sector_t *P_ThingOnSpecial3DFloor(mobj_t *mo) if ((rover->master->frontsector->flags & SF_FLIPSPECIAL_FLOOR) && !(rover->master->frontsector->flags & SF_FLIPSPECIAL_CEILING)) { - if ((mo->eflags & MFE_VERTICALFLIP) || mo->z != *rover->topheight) + if ((mo->eflags & MFE_VERTICALFLIP) || mo->z != topheight) continue; } else if ((rover->master->frontsector->flags & SF_FLIPSPECIAL_CEILING) && !(rover->master->frontsector->flags & SF_FLIPSPECIAL_FLOOR)) { if (!(mo->eflags & MFE_VERTICALFLIP) - || mo->z + mo->height != *rover->bottomheight) + || mo->z + mo->height != bottomheight) continue; } else if (rover->master->frontsector->flags & SF_FLIPSPECIAL_BOTH) { - if (!((mo->eflags & MFE_VERTICALFLIP && mo->z + mo->height == *rover->bottomheight) - || (!(mo->eflags & MFE_VERTICALFLIP) && mo->z == *rover->topheight))) + if (!((mo->eflags & MFE_VERTICALFLIP && mo->z + mo->height == bottomheight) + || (!(mo->eflags & MFE_VERTICALFLIP) && mo->z == topheight))) continue; } } else { // Water and intangible FOFs - if (mo->z > *rover->topheight || (mo->z + mo->height) < *rover->bottomheight) + if (mo->z > topheight || (mo->z + mo->height) < bottomheight) continue; } @@ -4391,12 +4406,17 @@ static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector) for (rover = sector->ffloors; rover; rover = rover->next) { + fixed_t topheight, bottomheight; + if (!rover->master->frontsector->special) continue; if (!(rover->flags & FF_EXISTS)) continue; + topheight = P_GetSpecialTopZ(player->mo, sectors + rover->secnum, sector); + bottomheight = P_GetSpecialBottomZ(player->mo, sectors + rover->secnum, sector); + // Check the 3D floor's type... if (rover->flags & FF_BLOCKPLAYER) { @@ -4404,27 +4424,27 @@ static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector) if ((rover->master->frontsector->flags & SF_FLIPSPECIAL_FLOOR) && !(rover->master->frontsector->flags & SF_FLIPSPECIAL_CEILING)) { - if ((player->mo->eflags & MFE_VERTICALFLIP) || player->mo->z != P_GetSpecialTopZ(player->mo, sectors + rover->secnum, sector)) + if ((player->mo->eflags & MFE_VERTICALFLIP) || player->mo->z != topheight) continue; } else if ((rover->master->frontsector->flags & SF_FLIPSPECIAL_CEILING) && !(rover->master->frontsector->flags & SF_FLIPSPECIAL_FLOOR)) { if (!(player->mo->eflags & MFE_VERTICALFLIP) - || player->mo->z + player->mo->height != P_GetSpecialBottomZ(player->mo, sectors + rover->secnum, sector)) + || player->mo->z + player->mo->height != bottomheight) continue; } else if (rover->master->frontsector->flags & SF_FLIPSPECIAL_BOTH) { - if (!((player->mo->eflags & MFE_VERTICALFLIP && player->mo->z + player->mo->height == P_GetSpecialBottomZ(player->mo, sectors + rover->secnum, sector)) - || (!(player->mo->eflags & MFE_VERTICALFLIP) && player->mo->z == P_GetSpecialTopZ(player->mo, sectors + rover->secnum, sector)))) + if (!((player->mo->eflags & MFE_VERTICALFLIP && player->mo->z + player->mo->height == bottomheight) + || (!(player->mo->eflags & MFE_VERTICALFLIP) && player->mo->z == topheight))) continue; } } else { // Water and DEATH FOG!!! heh - if (player->mo->z > P_GetSpecialTopZ(player->mo, sectors + rover->secnum, sector) || (player->mo->z + player->mo->height) < P_GetSpecialBottomZ(player->mo, sectors + rover->secnum, sector)) + if (player->mo->z > topheight || (player->mo->z + player->mo->height) < bottomheight) continue; } @@ -5276,7 +5296,15 @@ void T_LaserFlash(laserthink_t *flash) sourcesec = ffloor->master->frontsector; // Less to type! +#ifdef ESLOPE + top = (*ffloor->t_slope) ? P_GetZAt(*ffloor->t_slope, sector->soundorg.x, sector->soundorg.y) + : *ffloor->topheight; + bottom = (*ffloor->b_slope) ? P_GetZAt(*ffloor->b_slope, sector->soundorg.x, sector->soundorg.y) + : *ffloor->bottomheight; + sector->soundorg.z = (top + bottom)/2; +#else sector->soundorg.z = (*ffloor->topheight + *ffloor->bottomheight)/2; +#endif S_StartSound(§or->soundorg, sfx_laser); // Seek out objects to DESTROY! MUAHAHHAHAHAA!!!*cough* @@ -6875,6 +6903,11 @@ void T_Disappear(disappear_t *d) if (!(lines[d->sourceline].flags & ML_NOCLIMB)) { +#ifdef ESLOPE + if (*rover->t_slope) + sectors[s].soundorg.z = P_GetZAt(*rover->t_slope, sectors[s].soundorg.x, sectors[s].soundorg.y); + else +#endif sectors[s].soundorg.z = *rover->topheight; S_StartSound(§ors[s].soundorg, sfx_appear); } From 62c4338d60740d8147fab5503f23130f7604444f Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Wed, 1 Jun 2016 13:19:44 +0100 Subject: [PATCH 11/54] Added P_GetMobjGravity to Lua. Check /toaster/gravitytest.lua for sample script. --- src/lua_baselib.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 7678c7c49..05ba00d68 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -13,6 +13,7 @@ #include "doomdef.h" #ifdef HAVE_BLUA #include "p_local.h" +#include "p_mobj.h" // So we can have P_GetMobjGravity #include "p_setup.h" // So we can have P_SetupLevelSky #include "z_zone.h" #include "r_main.h" @@ -437,6 +438,16 @@ static int lib_pMobjFlip(lua_State *L) return 1; } +static int lib_pGetMobjGravity(lua_State *L) +{ + mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + //HUDSAFE + if (!mobj) + return LUA_ErrInvalid(L, "mobj_t"); + lua_pushinteger(L, P_GetMobjGravity(mobj)); + return 1; +} + static int lib_pWeaponOrPanel(lua_State *L) { mobjtype_t type = luaL_checkinteger(L, 1); @@ -2008,6 +2019,7 @@ static luaL_Reg lib[] = { {"P_SPMAngle",lib_pSPMAngle}, {"P_SpawnPlayerMissile",lib_pSpawnPlayerMissile}, {"P_MobjFlip",lib_pMobjFlip}, + {"P_GetMobjGravity",lib_pGetMobjGravity}, {"P_WeaponOrPanel",lib_pWeaponOrPanel}, {"P_FlashPal",lib_pFlashPal}, {"P_GetClosestAxis",lib_pGetClosestAxis}, From 76d108d760a004a6e522c3364452c89074c68f0b Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Wed, 1 Jun 2016 14:49:14 +0100 Subject: [PATCH 12/54] Whoops, didn't realise pushing fixed and integer were different. My mistake. --- src/lua_baselib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 05ba00d68..c88ece50c 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -444,7 +444,7 @@ static int lib_pGetMobjGravity(lua_State *L) //HUDSAFE if (!mobj) return LUA_ErrInvalid(L, "mobj_t"); - lua_pushinteger(L, P_GetMobjGravity(mobj)); + lua_pushfixed(L, P_GetMobjGravity(mobj)); return 1; } From ae8b45965c4eb13856faffa1d4330634d200250d Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Wed, 1 Jun 2016 16:45:10 +0100 Subject: [PATCH 13/54] No Size_t --> int in an I_Error print! [/rhyme] --- src/p_slopes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_slopes.c b/src/p_slopes.c index 659f8b330..4a8eadc5f 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -557,7 +557,7 @@ static pslope_t *P_NewVertexSlope(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flag for (i = 0; i < 3; i++) { mt = ret->vertices[i]; if (!mt) // If a vertex wasn't found, it's game over. There's nothing you can do to recover (except maybe try and kill the slope instead - TODO?) - I_Error("Slope vertex %d (for linedef tag %d) not found.", i, tag1); + I_Error("Slope vertex %s (for linedef tag %d) not found.", sizeu1(i), tag1); if (mt->extrainfo) mt->z = mt->options; else From 44a6e8bb54db02e7085ddf7098fad38c56928210 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Wed, 1 Jun 2016 19:52:12 +0100 Subject: [PATCH 14/54] I_Error description syntax consistency (buzzword buzzword buzzword). --- src/p_slopes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_slopes.c b/src/p_slopes.c index 4a8eadc5f..72abf02bb 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -557,7 +557,7 @@ static pslope_t *P_NewVertexSlope(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flag for (i = 0; i < 3; i++) { mt = ret->vertices[i]; if (!mt) // If a vertex wasn't found, it's game over. There's nothing you can do to recover (except maybe try and kill the slope instead - TODO?) - I_Error("Slope vertex %s (for linedef tag %d) not found.", sizeu1(i), tag1); + I_Error("P_NewVertexSlope: Slope vertex %s (for linedef tag %d) not found!", sizeu1(i), tag1); if (mt->extrainfo) mt->z = mt->options; else From 919e3ed0e242208290f358c172338c5515004ffe Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Wed, 1 Jun 2016 21:06:24 -0500 Subject: [PATCH 15/54] Make token available to Lua as a global variable Reviewed by @RedEnchilada --- src/dehacked.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dehacked.c b/src/dehacked.c index 199ea43ca..f7845af44 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8276,6 +8276,9 @@ static inline int lib_getenum(lua_State *L) } else if (fastcmp(word,"VERSIONSTRING")) { lua_pushstring(L, VERSIONSTRING); return 1; + } else if (fastcmp(word, "token")) { + lua_pushinteger(L, token); + return 1; } return 0; From 1493537dfc7f0d2544d621fbf30157a34693d29d Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 2 Jun 2016 14:39:41 +0100 Subject: [PATCH 16/54] Moved the standingslope check in P_ZMovement to after the FOF and height adjustment as it is in P_PlayerZMovement, as reccomended. Doesn't actually stop Crawla jittering, but might as well make it happen for consistency's sake. --- src/p_mobj.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 35d8f1ad2..acf5b1b36 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -2165,16 +2165,6 @@ static boolean P_ZMovement(mobj_t *mo) I_Assert(mo != NULL); I_Assert(!P_MobjWasRemoved(mo)); -#ifdef ESLOPE - if (mo->standingslope) - { - if (mo->flags & MF_NOCLIPHEIGHT) - mo->standingslope = NULL; - else if (!P_IsObjectOnGround(mo)) - P_SlopeLaunch(mo); - } -#endif - // Intercept the stupid 'fall through 3dfloors' bug if (mo->subsector->sector->ffloors) P_AdjustMobjFloorZ_FFloors(mo, mo->subsector->sector, 0); @@ -2189,6 +2179,16 @@ static boolean P_ZMovement(mobj_t *mo) } mo->z += mo->momz; +#ifdef ESLOPE + if (mo->standingslope) + { + if (mo->flags & MF_NOCLIPHEIGHT) + mo->standingslope = NULL; + else if (!P_IsObjectOnGround(mo)) + P_SlopeLaunch(mo); + } +#endif + switch (mo->type) { case MT_THROWNBOUNCE: From 213a9632ca4b5cd68902bc805cc625d5b24d3e41 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 2 Jun 2016 16:09:33 +0100 Subject: [PATCH 17/54] Let's multiply the thrust by the mobj's friction. You should have less chance of purchase on a slippery slope (tee hee) and more on a rough one, but the slopes were basically identical during testing before I implemented this change. --- src/p_slopes.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/p_slopes.c b/src/p_slopes.c index 72abf02bb..ec07ab2fe 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -864,8 +864,6 @@ void P_ButteredSlope(mobj_t *mo) mult = FINECOSINE(angle >> ANGLETOFINESHIFT); } - //CONS_Printf("%d\n", mult); - thrust = FixedMul(thrust, FRACUNIT*2/3 + mult/8); } @@ -873,11 +871,18 @@ void P_ButteredSlope(mobj_t *mo) thrust = FixedMul(thrust, FRACUNIT+P_AproxDistance(mo->momx, mo->momy)/16); // This makes it harder to zigzag up steep slopes, as well as allows greater top speed when rolling down - // Multiply by gravity - thrust = FixedMul(thrust, FixedMul(gravity, abs(P_GetMobjGravity(mo)))); // Now uses the absolute of mobj gravity. You're welcome. - // Multiply by scale (gravity strength depends on mobj scale) + // The strength of gravity depends on the global gravity base setting... + thrust = FixedMul(thrust, gravity); + + // ...the sector-based gravity strength... + thrust = FixedMul(thrust, abs(P_GetMobjGravity(mo))); + + // ...and the scale of the object. thrust = FixedMul(thrust, mo->scale); + // Let's also multiply by friction for good measure. + thrust = FixedMul(thrust, mo->friction); + P_Thrust(mo, mo->standingslope->xydirection, thrust); } From 882622d2e70616376e81f82b8471645a1ac75721 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 2 Jun 2016 16:42:07 +0100 Subject: [PATCH 18/54] ...I made two major mistakes with P_GetMobjGravity. *Didn't take into account object scale *Doubled force when on the ground (ignore what the comment of the line I moved says, it was relevant for slopes...) This also led to a mistake with slopes, where I was double-multiplying by the gravity constant to get half (because of a quirk of numbers...) --- src/p_mobj.c | 10 ++++++---- src/p_slopes.c | 12 +++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index acf5b1b36..843123d57 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1316,9 +1316,6 @@ fixed_t P_GetMobjGravity(mobj_t *mo) if (mo->eflags & MFE_UNDERWATER && !goopgravity) gravityadd = gravityadd/3; - if (!mo->momz) // mobj at stop, no floor, so feel the push of gravity! - gravityadd <<= 1; - if (mo->player) { if (mo->player->charability == CA_FLY && (mo->player->powers[pw_tailsfly] @@ -1402,6 +1399,8 @@ fixed_t P_GetMobjGravity(mobj_t *mo) if (mo->player && !!(mo->eflags & MFE_VERTICALFLIP) != wasflip) P_PlayerFlip(mo); + gravityadd = FixedMul(gravityadd, mo->scale); + return gravityadd; } @@ -1416,8 +1415,11 @@ void P_CheckGravity(mobj_t *mo, boolean affect) { fixed_t gravityadd = P_GetMobjGravity(mo); + if (!mo->momz) // mobj at stop, no floor, so feel the push of gravity! + gravityadd <<= 1; + if (affect) - mo->momz += FixedMul(gravityadd, mo->scale); + mo->momz += gravityadd; if (mo->type == MT_SKIM && mo->z + mo->momz <= mo->watertop && mo->z >= mo->watertop) { diff --git a/src/p_slopes.c b/src/p_slopes.c index ec07ab2fe..ed25f00f3 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -812,7 +812,7 @@ void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope) mom.y = thing->momy; mom.z = thing->momz*2; - //CONS_Printf("langing on slope\n"); + //CONS_Printf("Landing on slope\n"); // Reverse quantizing might could use its own function later slope->zangle = ANGLE_MAX-slope->zangle; @@ -871,16 +871,10 @@ void P_ButteredSlope(mobj_t *mo) thrust = FixedMul(thrust, FRACUNIT+P_AproxDistance(mo->momx, mo->momy)/16); // This makes it harder to zigzag up steep slopes, as well as allows greater top speed when rolling down - // The strength of gravity depends on the global gravity base setting... - thrust = FixedMul(thrust, gravity); - - // ...the sector-based gravity strength... + // Let's get the gravity strength for the object... thrust = FixedMul(thrust, abs(P_GetMobjGravity(mo))); - // ...and the scale of the object. - thrust = FixedMul(thrust, mo->scale); - - // Let's also multiply by friction for good measure. + // ... and its friction against the ground for good measure. thrust = FixedMul(thrust, mo->friction); P_Thrust(mo, mo->standingslope->xydirection, thrust); From c1caf2132328985fc5abdbe65f08dc22bbd0aa8e Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 2 Jun 2016 16:51:12 +0100 Subject: [PATCH 19/54] Reccomended by MI: Dividing by the original friction value just so slopes with normal friction don't behave differently between next and this branch. --- src/p_slopes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_slopes.c b/src/p_slopes.c index ed25f00f3..797c6a558 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -874,8 +874,8 @@ void P_ButteredSlope(mobj_t *mo) // Let's get the gravity strength for the object... thrust = FixedMul(thrust, abs(P_GetMobjGravity(mo))); - // ... and its friction against the ground for good measure. - thrust = FixedMul(thrust, mo->friction); + // ... and its friction against the ground for good measure (divided by original friction to keep behaviour for normal slopes the same). + thrust = FixedMul(thrust, FixedDiv(mo->friction, ORIG_FRICTION)); P_Thrust(mo, mo->standingslope->xydirection, thrust); } From 83c4dba4cee64f1bc1432f08cc5ba75aac822c24 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 2 Jun 2016 20:16:25 +0100 Subject: [PATCH 20/54] Fix crash reported by FuriousFox at http://mb.srb2.org/showthread.php?t=41536 Basically this makes sure numwadfiles is updated before loading the SOC/Lua scripts, so if a Lua script calls COM_BufInsertText with the contents "addfile scr_mysticrealm.wad" it can't overwrite the last written wadfile slot! Not that COM_BufInsertText really should be used like that to begin with --- src/w_wad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 40fea5223..aeaad3ced 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -475,11 +475,11 @@ UINT16 W_LoadWadFile(const char *filename) // CONS_Printf(M_GetText("Added file %s (%u lumps)\n"), filename, numlumps); wadfiles[numwadfiles] = wadfile; - W_LoadDehackedLumps(numwadfiles); + numwadfiles++; // must come BEFORE W_LoadDehackedLumps, so any addfile called by COM_BufInsertText called by Lua doesn't overwrite what we just loaded + W_LoadDehackedLumps(numwadfiles-1); W_InvalidateLumpnumCache(); - numwadfiles++; return wadfile->numlumps; } From ba528a075ee578bd4b10d4f1bb56b424c6e1ae44 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Sat, 4 Jun 2016 19:47:40 +0100 Subject: [PATCH 21/54] Last few changes as reccomended by Red. (<3 u, no hetero) --- src/doomdef.h | 2 +- src/p_slopes.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index e645c0848..cec46a32c 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -431,7 +431,7 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Kalaron/Eternity Engine slope code (SRB2CB ported) #define ESLOPE -#if defined(ESLOPE) +#ifdef ESLOPE /// Backwards compatibility with SRB2CB's slope linedef types. /// \note A simple shim that prints a warning. #define ESLOPE_TYPESHIM diff --git a/src/p_slopes.c b/src/p_slopes.c index 797c6a558..b6338d95d 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -275,7 +275,6 @@ void P_SpawnSlope_Line(int linenum) ny = -FixedDiv(line->dx, len); } - // TODO: Transform origin relative to the bounds of an individual FOF origin.x = line->v1->x + (line->v2->x - line->v1->x)/2; origin.y = line->v1->y + (line->v2->y - line->v1->y)/2; From 69f556d40a281caa75697bf2241703418c763648 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 5 Jun 2016 21:29:40 +0100 Subject: [PATCH 22/54] Split AA trees code from m_misc.c/.h into m_aatree.c/.h Also updated any relevant project files that I can think of to include the new files, as well as the makefile of course. Some of the other project files haven't been touched in years so I'll leave those alone ...unless someone objects --- SRB2.cbp | 33 +++++ src/CMakeLists.txt | 2 + src/Makefile | 1 + src/m_aatree.c | 167 +++++++++++++++++++++++++ src/m_aatree.h | 31 +++++ src/m_misc.c | 155 ----------------------- src/m_misc.h | 13 -- src/sdl/Srb2SDL-vc10.vcxproj | 2 + src/sdl/Srb2SDL-vc10.vcxproj.filters | 6 + src/w_wad.h | 4 +- src/win32/Srb2win-vc10.vcxproj | 2 + src/win32/Srb2win-vc10.vcxproj.filters | 6 + 12 files changed, 251 insertions(+), 171 deletions(-) create mode 100644 src/m_aatree.c create mode 100644 src/m_aatree.h diff --git a/SRB2.cbp b/SRB2.cbp index 43696ee2e..99a712264 100644 --- a/SRB2.cbp +++ b/SRB2.cbp @@ -2815,6 +2815,39 @@ HW3SOUND for 3D hardware sound support