Merge branch 'smooth_ropes' into 'next'

Smoother ropes and zoom tubes

Makes rope hangs and zoom tubes suck less. Specifically, they handle corners (and vertical height changes, ala sloped rope hangs) a LOT nicer. Ported from internal.

See merge request !139
This commit is contained in:
Monster Iestyn 2016-12-12 14:18:36 -05:00
commit 1ec97c242a

View file

@ -7057,7 +7057,6 @@ static void P_DoZoomTube(player_t *player)
mobj_t *waypoint = NULL; mobj_t *waypoint = NULL;
fixed_t dist; fixed_t dist;
boolean reverse; boolean reverse;
fixed_t speedx,speedy,speedz;
player->mo->height = P_GetPlayerSpinHeight(player); player->mo->height = P_GetPlayerSpinHeight(player);
@ -7078,17 +7077,17 @@ static void P_DoZoomTube(player_t *player)
if (dist < 1) if (dist < 1)
dist = 1; dist = 1;
speedx = FixedMul(FixedDiv(player->mo->tracer->x - player->mo->x, dist), (speed)); player->mo->momx = FixedMul(FixedDiv(player->mo->tracer->x - player->mo->x, dist), (speed));
speedy = FixedMul(FixedDiv(player->mo->tracer->y - player->mo->y, dist), (speed)); player->mo->momy = FixedMul(FixedDiv(player->mo->tracer->y - player->mo->y, dist), (speed));
speedz = FixedMul(FixedDiv(player->mo->tracer->z - player->mo->z, dist), (speed)); player->mo->momz = FixedMul(FixedDiv(player->mo->tracer->z - player->mo->z, dist), (speed));
// Calculate the distance between the player and the waypoint // Calculate the distance between the player and the waypoint
// 'dist' already equals this. // 'dist' already equals this.
// Will the player be FURTHER away if the momx/momy/momz is added to // Will the player go past the waypoint?
// his current coordinates, or closer? (shift down to fracunits to avoid approximation errors) if (speed > dist)
if (dist>>FRACBITS <= P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x - speedx, player->mo->tracer->y - player->mo->y - speedy), player->mo->tracer->z - player->mo->z - speedz)>>FRACBITS)
{ {
speed -= dist;
// If further away, set XYZ of player to waypoint location // If further away, set XYZ of player to waypoint location
P_UnsetThingPosition(player->mo); P_UnsetThingPosition(player->mo);
player->mo->x = player->mo->tracer->x; player->mo->x = player->mo->tracer->x;
@ -7128,14 +7127,9 @@ static void P_DoZoomTube(player_t *player)
{ {
CONS_Debug(DBG_GAMELOGIC, "Found waypoint (sequence %d, number %d).\n", waypoint->threshold, waypoint->health); CONS_Debug(DBG_GAMELOGIC, "Found waypoint (sequence %d, number %d).\n", waypoint->threshold, waypoint->health);
// calculate MOMX/MOMY/MOMZ for next waypoint P_SetTarget(&player->mo->tracer, waypoint);
// change angle
player->mo->angle = R_PointToAngle2(player->mo->x, player->mo->y, player->mo->tracer->x, player->mo->tracer->y);
if (player == &players[consoleplayer]) // calculate MOMX/MOMY/MOMZ for next waypoint
localangle = player->mo->angle;
else if (player == &players[secondarydisplayplayer])
localangle2 = player->mo->angle;
// change slope // change slope
dist = P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - player->mo->z); dist = P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - player->mo->z);
@ -7146,22 +7140,14 @@ static void P_DoZoomTube(player_t *player)
player->mo->momx = FixedMul(FixedDiv(player->mo->tracer->x - player->mo->x, dist), (speed)); player->mo->momx = FixedMul(FixedDiv(player->mo->tracer->x - player->mo->x, dist), (speed));
player->mo->momy = FixedMul(FixedDiv(player->mo->tracer->y - player->mo->y, dist), (speed)); player->mo->momy = FixedMul(FixedDiv(player->mo->tracer->y - player->mo->y, dist), (speed));
player->mo->momz = FixedMul(FixedDiv(player->mo->tracer->z - player->mo->z, dist), (speed)); player->mo->momz = FixedMul(FixedDiv(player->mo->tracer->z - player->mo->z, dist), (speed));
P_SetTarget(&player->mo->tracer, waypoint);
} }
else else
{ {
P_SetTarget(&player->mo->tracer, NULL); // Else, we just let him fly. P_SetTarget(&player->mo->tracer, NULL); // Else, we just let them fly.
CONS_Debug(DBG_GAMELOGIC, "Next waypoint not found, releasing from track...\n"); CONS_Debug(DBG_GAMELOGIC, "Next waypoint not found, releasing from track...\n");
} }
} }
else
{
player->mo->momx = speedx;
player->mo->momy = speedy;
player->mo->momz = speedz;
}
// change angle // change angle
if (player->mo->tracer) if (player->mo->tracer)
@ -7189,24 +7175,10 @@ static void P_DoRopeHang(player_t *player)
mobj_t *mo2; mobj_t *mo2;
mobj_t *waypoint = NULL; mobj_t *waypoint = NULL;
fixed_t dist; fixed_t dist;
fixed_t speedx,speedy,speedz;
fixed_t playerz; fixed_t playerz;
player->mo->height = P_GetPlayerHeight(player); player->mo->height = P_GetPlayerHeight(player);
if (player->cmd.buttons & BT_USE && !(player->pflags & PF_STASIS)) // Drop off of the rope
{
P_SetTarget(&player->mo->tracer, NULL);
player->pflags |= PF_JUMPED;
player->pflags &= ~PF_ROPEHANG;
if (!(player->pflags & PF_SLIDING) && (player->pflags & PF_JUMPED)
&& !(player->panim == PA_ROLL) && player->charability2 == CA2_SPINDASH)
P_SetPlayerMobjState(player->mo, S_PLAY_ATK1);
return;
}
// Play the 'clink' sound only if the player is moving. // Play the 'clink' sound only if the player is moving.
if (!(leveltime & 7) && player->speed) if (!(leveltime & 7) && player->speed)
S_StartSound(player->mo, sfx_s3k55); S_StartSound(player->mo, sfx_s3k55);
@ -7223,9 +7195,22 @@ static void P_DoRopeHang(player_t *player)
if (dist < 1) if (dist < 1)
dist = 1; dist = 1;
speedx = FixedMul(FixedDiv(player->mo->tracer->x - player->mo->x, dist), (speed)); player->mo->momx = FixedMul(FixedDiv(player->mo->tracer->x - player->mo->x, dist), (speed));
speedy = FixedMul(FixedDiv(player->mo->tracer->y - player->mo->y, dist), (speed)); player->mo->momy = FixedMul(FixedDiv(player->mo->tracer->y - player->mo->y, dist), (speed));
speedz = FixedMul(FixedDiv(player->mo->tracer->z - playerz, dist), (speed)); player->mo->momz = FixedMul(FixedDiv(player->mo->tracer->z - playerz, dist), (speed));
if (player->cmd.buttons & BT_USE && !(player->pflags & PF_STASIS)) // Drop off of the rope
{
P_SetTarget(&player->mo->tracer, NULL);
player->pflags |= PF_JUMPED;
player->pflags &= ~PF_ROPEHANG;
if (!(player->pflags & PF_SLIDING) && (player->pflags & PF_JUMPED)
&& !(player->panim == PA_ROLL) && player->charability2 == CA2_SPINDASH)
P_SetPlayerMobjState(player->mo, S_PLAY_ATK1);
return;
}
// If not allowed to move, we're done here. // If not allowed to move, we're done here.
if (!speed) if (!speed)
@ -7234,15 +7219,16 @@ static void P_DoRopeHang(player_t *player)
// Calculate the distance between the player and the waypoint // Calculate the distance between the player and the waypoint
// 'dist' already equals this. // 'dist' already equals this.
// Will the player be FURTHER away if the momx/momy/momz is added to // Will the player go past the waypoint?
// his current coordinates, or closer? (shift down to fracunits to avoid approximation errors) if (speed > dist)
if (dist>>FRACBITS <= P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x - speedx, player->mo->tracer->y - player->mo->y - speedy), player->mo->tracer->z - playerz - speedz)>>FRACBITS)
{ {
speed -= dist;
// If further away, set XYZ of player to waypoint location // If further away, set XYZ of player to waypoint location
P_UnsetThingPosition(player->mo); P_UnsetThingPosition(player->mo);
player->mo->x = player->mo->tracer->x; player->mo->x = player->mo->tracer->x;
player->mo->y = player->mo->tracer->y; player->mo->y = player->mo->tracer->y;
player->mo->z = player->mo->tracer->z - player->mo->height; player->mo->z = player->mo->tracer->z - player->mo->height;
playerz = player->mo->tracer->z;
P_SetThingPosition(player->mo); P_SetThingPosition(player->mo);
CONS_Debug(DBG_GAMELOGIC, "Looking for next waypoint...\n"); CONS_Debug(DBG_GAMELOGIC, "Looking for next waypoint...\n");
@ -7298,6 +7284,8 @@ static void P_DoRopeHang(player_t *player)
{ {
CONS_Debug(DBG_GAMELOGIC, "Found waypoint (sequence %d, number %d).\n", waypoint->threshold, waypoint->health); CONS_Debug(DBG_GAMELOGIC, "Found waypoint (sequence %d, number %d).\n", waypoint->threshold, waypoint->health);
P_SetTarget(&player->mo->tracer, waypoint);
// calculate MOMX/MOMY/MOMZ for next waypoint // calculate MOMX/MOMY/MOMZ for next waypoint
// change slope // change slope
dist = P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - playerz); dist = P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - playerz);
@ -7308,8 +7296,6 @@ static void P_DoRopeHang(player_t *player)
player->mo->momx = FixedMul(FixedDiv(player->mo->tracer->x - player->mo->x, dist), (speed)); player->mo->momx = FixedMul(FixedDiv(player->mo->tracer->x - player->mo->x, dist), (speed));
player->mo->momy = FixedMul(FixedDiv(player->mo->tracer->y - player->mo->y, dist), (speed)); player->mo->momy = FixedMul(FixedDiv(player->mo->tracer->y - player->mo->y, dist), (speed));
player->mo->momz = FixedMul(FixedDiv(player->mo->tracer->z - playerz, dist), (speed)); player->mo->momz = FixedMul(FixedDiv(player->mo->tracer->z - playerz, dist), (speed));
P_SetTarget(&player->mo->tracer, waypoint);
} }
else else
{ {
@ -7328,12 +7314,6 @@ static void P_DoRopeHang(player_t *player)
CONS_Debug(DBG_GAMELOGIC, "Next waypoint not found!\n"); CONS_Debug(DBG_GAMELOGIC, "Next waypoint not found!\n");
} }
} }
else
{
player->mo->momx = speedx;
player->mo->momy = speedy;
player->mo->momz = speedz;
}
} }
#if 0 #if 0