Move quake calculation code to r_main.c, keep timer in p_tick.c

This commit is contained in:
GoldenTails 2022-09-06 18:42:12 -05:00
parent a546b553c4
commit 90a93a516e
2 changed files with 25 additions and 22 deletions

View file

@ -739,29 +739,7 @@ void P_Ticker(boolean run)
countdown2--;
if (quake.time)
{
fixed_t ir = quake.intensity>>1;
if (quake.epicenter) {
// Calculate 3D distance from epicenter, using camera.
// Uses only player 1 camera because only one quake variable exists.
fixed_t xydist = R_PointToDist2(camera.x, camera.y, quake.epicenter->x, quake.epicenter->y);
fixed_t dist = R_PointToDist2(0, camera.z, xydist, quake.epicenter->z);
// More effect closer to epicenter, outside of radius = no effect
if (!quake.radius || dist > quake.radius)
ir = 0;
else
ir = FixedMul(ir, FRACUNIT - FixedDiv(dist, quake.radius));
}
quake.x = M_RandomRange(-ir,ir);
quake.y = M_RandomRange(-ir,ir);
quake.z = M_RandomRange(-ir,ir);
--quake.time;
}
else
quake.x = quake.y = quake.z = 0;
if (metalplayback)
G_ReadMetalTic(metalplayback);

View file

@ -1123,6 +1123,7 @@ void R_SetupFrame(player_t *player)
{
camera_t *thiscam;
boolean chasecam = false;
boolean ispaused = paused || P_AutoPause();
if (splitscreen && player == &players[secondarydisplayplayer]
&& player != &players[consoleplayer])
@ -1191,6 +1192,30 @@ void R_SetupFrame(player_t *player)
}
}
}
if (quake.time && !ispaused)
{
fixed_t ir = quake.intensity>>1;
if (quake.epicenter) {
// Calculate 3D distance from epicenter, using the camera.
fixed_t xydist = R_PointToDist2(thiscam->x, thiscam->y, quake.epicenter->x, quake.epicenter->y);
fixed_t dist = R_PointToDist2(0, thiscam->z, xydist, quake.epicenter->z);
// More effect closer to epicenter, outside of radius = no effect
if (!quake.radius || dist > quake.radius)
ir = 0;
else
ir = FixedMul(ir, FRACUNIT - FixedDiv(dist, quake.radius));
}
quake.x = M_RandomRange(-ir,ir);
quake.y = M_RandomRange(-ir,ir);
quake.z = M_RandomRange(-ir,ir);
}
else if (!ispaused)
quake.x = quake.y = quake.z = 0;
viewz += quake.z;
viewplayer = player;