Improvements to slope collision/landing/ejecting/fajitas

This commit is contained in:
RedEnchilada 2015-05-15 12:35:54 -05:00
parent b69678f1a6
commit 445e778309
2 changed files with 41 additions and 26 deletions

View File

@ -1384,7 +1384,7 @@ void P_XYMovement(mobj_t *mo)
#ifdef ESLOPE #ifdef ESLOPE
pslope_t *oldslope = NULL; pslope_t *oldslope = NULL;
v3fixed_t slopemom; v3fixed_t slopemom;
fixed_t predictedz; fixed_t predictedz = 0;
#endif #endif
I_Assert(mo != NULL); I_Assert(mo != NULL);
@ -1437,7 +1437,7 @@ void P_XYMovement(mobj_t *mo)
oldslope = mo->standingslope; oldslope = mo->standingslope;
} }
} else if (P_IsObjectOnGround(mo)) } else if (P_IsObjectOnGround(mo) && !mo->momz)
predictedz = mo->z; predictedz = mo->z;
#endif #endif
@ -1562,38 +1562,48 @@ void P_XYMovement(mobj_t *mo)
#ifdef ESLOPE #ifdef ESLOPE
if (moved && oldslope) { // Check to see if we ran off if (moved && oldslope) { // Check to see if we ran off
//angle_t moveangle = R_PointToAngle2(mo->momx, mo->momy);
if (oldslope != mo->standingslope) { // First, compare different slopes if (oldslope != mo->standingslope) { // First, compare different slopes
// Start by quantizing momentum on this slope angle_t oldangle, newangle;
v3fixed_t test; angle_t moveangle = R_PointToAngle2(0, 0, mo->momx, mo->momy);
test.x = mo->momx;
test.y = mo->momy; oldangle = FixedMul((signed)oldslope->zangle, FINECOSINE((moveangle - oldslope->xydirection) >> ANGLETOFINESHIFT));
test.z = 0;
if (mo->standingslope) // Don't fuss with the rotation if we don't HAVE a slope if (mo->standingslope)
P_QuantizeMomentumToSlope(&test, mo->standingslope); newangle = FixedMul((signed)mo->standingslope->zangle, FINECOSINE((moveangle - mo->standingslope->xydirection) >> ANGLETOFINESHIFT));
else
newangle = 0;
// Now compare the Zs of the different quantizations // Now compare the Zs of the different quantizations
if (slopemom.z - test.z > P_AproxDistance(slopemom.x, slopemom.y/3) { // Allow for a bit of sticking - this value can be adjusted later if (oldangle-newangle > ANG30 && oldangle-newangle < ANGLE_180) { // Allow for a bit of sticking - this value can be adjusted later
mo->standingslope = oldslope; mo->standingslope = oldslope;
P_SlopeLaunch(mo); P_SlopeLaunch(mo);
//CONS_Printf("launched off of slope - ");
} }
} else if (predictedz-mo->z > P_AproxDistance(slopemom.x, slopemom.y)/3) { // Now check if we were supposed to stick to this slope
mo->standingslope = oldslope; /*CONS_Printf("old angle %f - new angle %f = %f\n",
FIXED_TO_FLOAT(AngleFixed(oldangle)),
FIXED_TO_FLOAT(AngleFixed(newangle)),
FIXED_TO_FLOAT(AngleFixed(oldangle-newangle))
);*/
} else if (predictedz-mo->z > abs(slopemom.z/2)) { // Now check if we were supposed to stick to this slope
//CONS_Printf("%d-%d > %d\n", (predictedz), (mo->z), (slopemom.z/2));
P_SlopeLaunch(mo); P_SlopeLaunch(mo);
} }
} else if (moved && mo->standingslope && predictedz) { } else if (moved && mo->standingslope && predictedz) {
slopemom.x = mo->momx; angle_t moveangle = R_PointToAngle2(0, 0, mo->momx, mo->momy);
slopemom.y = mo->momy; angle_t newangle = FixedMul((signed)mo->standingslope->zangle, FINECOSINE((moveangle - mo->standingslope->xydirection) >> ANGLETOFINESHIFT));
slopemom.z = 0;
P_QuantizeMomentumToSlope(&slopemom, mo->standingslope); /*CONS_Printf("flat to angle %f - predicted z of %f\n",
FIXED_TO_FLOAT(AngleFixed(ANGLE_MAX-newangle)),
if (-slopemom.z > P_AproxDistance(mo->momx, mo->momy)/3) { FIXED_TO_FLOAT(predictedz)
);*/
if (ANGLE_MAX-newangle > ANG30 && newangle > ANGLE_180) {
mo->momz = P_MobjFlip(mo)*FRACUNIT/2; mo->momz = P_MobjFlip(mo)*FRACUNIT/2;
mo->z = predictedz + P_MobjFlip(mo); mo->z = predictedz + P_MobjFlip(mo);
mo->standingslope = NULL; mo->standingslope = NULL;
CONS_Printf("Launched off of flat surface running into downward slope\n"); //CONS_Printf("Launched off of flat surface running into downward slope\n");
} }
} }
#endif #endif
@ -2300,11 +2310,6 @@ static void P_PlayerZMovement(mobj_t *mo)
if (!mo->player) if (!mo->player)
return; return;
#ifdef ESLOPE
if (mo->standingslope && !P_IsObjectOnGround(mo))
P_SlopeLaunch(mo);
#endif
// Intercept the stupid 'fall through 3dfloors' bug // Intercept the stupid 'fall through 3dfloors' bug
if (mo->subsector->sector->ffloors) if (mo->subsector->sector->ffloors)
P_AdjustMobjFloorZ_FFloors(mo, mo->subsector->sector, 0); P_AdjustMobjFloorZ_FFloors(mo, mo->subsector->sector, 0);
@ -2338,6 +2343,11 @@ static void P_PlayerZMovement(mobj_t *mo)
|| mo->player->playerstate == PST_REBORN) || mo->player->playerstate == PST_REBORN)
return; return;
#ifdef ESLOPE
if (mo->standingslope && !P_IsObjectOnGround(mo))
P_SlopeLaunch(mo);
#endif
// clip movement // clip movement
if (P_IsObjectOnGround(mo) && !(mo->flags & MF_NOCLIPHEIGHT)) if (P_IsObjectOnGround(mo) && !(mo->flags & MF_NOCLIPHEIGHT))
{ {
@ -2360,9 +2370,10 @@ static void P_PlayerZMovement(mobj_t *mo)
P_SetPlayerMobjState(mo, S_PLAY_STND); P_SetPlayerMobjState(mo, S_PLAY_STND);
#ifdef ESLOPE #ifdef ESLOPE
if (mo->eflags & MFE_VERTICALFLIP ? tmceilingslope : tmfloorslope) if (!mo->standingslope && (mo->eflags & MFE_VERTICALFLIP ? tmceilingslope : tmfloorslope)) {
// Handle landing on slope during Z movement // Handle landing on slope during Z movement
P_HandleSlopeLanding(mo, (mo->eflags & MFE_VERTICALFLIP ? tmceilingslope : tmfloorslope)); P_HandleSlopeLanding(mo, (mo->eflags & MFE_VERTICALFLIP ? tmceilingslope : tmfloorslope));
}
#endif #endif
if (P_MobjFlip(mo)*mo->momz < 0) // falling if (P_MobjFlip(mo)*mo->momz < 0) // falling

View File

@ -813,6 +813,8 @@ void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope)
mom.y = thing->momy; mom.y = thing->momy;
mom.z = thing->momz*2; mom.z = thing->momz*2;
//CONS_Printf("langing on slope\n");
// Reverse quantizing might could use its own function later // Reverse quantizing might could use its own function later
slope->zangle = ANGLE_MAX-slope->zangle; slope->zangle = ANGLE_MAX-slope->zangle;
P_QuantizeMomentumToSlope(&mom, slope); P_QuantizeMomentumToSlope(&mom, slope);
@ -822,6 +824,8 @@ void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope)
thing->momx = mom.x; thing->momx = mom.x;
thing->momy = mom.y; thing->momy = mom.y;
thing->momz = -P_MobjFlip(thing); thing->momz = -P_MobjFlip(thing);
thing->standingslope = slope;
} }
} }