fix rewind, fix sound local sound playing in freecam

This commit is contained in:
Latapostrophe 2019-09-09 22:15:50 +02:00
parent 45b62aa8a4
commit 18c8f47f9a
7 changed files with 55 additions and 53 deletions

View file

@ -6002,9 +6002,6 @@ void G_PreviewRewind(tic_t previewtime)
players[i].kartstuff[j] = info->playerinfo[i].player.kartstuff[j]; players[i].kartstuff[j] = info->playerinfo[i].player.kartstuff[j];
} }
if (demo.freecam)
return; // nope
for (i = splitscreen; i >= 0; i--) for (i = splitscreen; i >= 0; i--)
P_ResetCamera(&players[displayplayers[i]], &camera[i]); P_ResetCamera(&players[displayplayers[i]], &camera[i]);
} }

View file

@ -60,9 +60,9 @@ struct demovars_s {
DSM_WILLSAVE, DSM_WILLSAVE,
DSM_SAVED DSM_SAVED
} savemode; } savemode;
boolean freecam; boolean freecam;
}; };
extern struct demovars_s demo; extern struct demovars_s demo;

View file

@ -1062,7 +1062,7 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd)
} }
// This makes the roulette produce the random noises. // This makes the roulette produce the random noises.
if ((player->kartstuff[k_itemroulette] % 3) == 1 && P_IsDisplayPlayer(player)) if ((player->kartstuff[k_itemroulette] % 3) == 1 && P_IsDisplayPlayer(player) && !demo.freecam)
{ {
#define PLAYROULETTESND S_StartSound(NULL, sfx_itrol1 + ((player->kartstuff[k_itemroulette] / 3) % 8)) #define PLAYROULETTESND S_StartSound(NULL, sfx_itrol1 + ((player->kartstuff[k_itemroulette] / 3) % 8))
for (i = 0; i <= splitscreen; i++) for (i = 0; i <= splitscreen; i++)
@ -1096,7 +1096,7 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd)
//player->kartstuff[k_itemblinkmode] = 1; //player->kartstuff[k_itemblinkmode] = 1;
player->kartstuff[k_itemroulette] = 0; player->kartstuff[k_itemroulette] = 0;
player->kartstuff[k_roulettetype] = 0; player->kartstuff[k_roulettetype] = 0;
if (P_IsDisplayPlayer(player)) if (P_IsDisplayPlayer(player) && !demo.freecam)
S_StartSound(NULL, sfx_itrole); S_StartSound(NULL, sfx_itrole);
return; return;
} }
@ -1109,7 +1109,7 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd)
player->kartstuff[k_itemblinkmode] = 2; player->kartstuff[k_itemblinkmode] = 2;
player->kartstuff[k_itemroulette] = 0; player->kartstuff[k_itemroulette] = 0;
player->kartstuff[k_roulettetype] = 0; player->kartstuff[k_roulettetype] = 0;
if (P_IsDisplayPlayer(player)) if (P_IsDisplayPlayer(player) && !demo.freecam)
S_StartSound(NULL, sfx_dbgsal); S_StartSound(NULL, sfx_dbgsal);
return; return;
} }
@ -1141,7 +1141,7 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd)
player->kartstuff[k_itemamount] = 1; player->kartstuff[k_itemamount] = 1;
} }
if (P_IsDisplayPlayer(player)) if (P_IsDisplayPlayer(player) && !demo.freecam)
S_StartSound(NULL, ((player->kartstuff[k_roulettetype] == 1) ? sfx_itrolk : (mashed ? sfx_itrolm : sfx_itrolf))); S_StartSound(NULL, ((player->kartstuff[k_roulettetype] == 1) ? sfx_itrolk : (mashed ? sfx_itrolm : sfx_itrolf)));
player->kartstuff[k_itemblink] = TICRATE; player->kartstuff[k_itemblink] = TICRATE;

View file

@ -113,11 +113,8 @@ typedef struct camera_s
struct demofreecam_s { struct demofreecam_s {
camera_t *cam; // this is useful when the game is paused, notably camera_t *cam; // this is useful when the game is paused, notably
mobj_t *soundmobj; // mobj to play sound from, used in s_sound
fixed_t rewindx;
fixed_t rewindy;
fixed_t rewindz; // when rewinding, this is used to make sure the cam doesn't reset
angle_t localangle; // keeps track of the cam angle for cmds angle_t localangle; // keeps track of the cam angle for cmds
angle_t localaiming; // ditto with aiming angle_t localaiming; // ditto with aiming
boolean turnheld; // holding turn button for gradual turn speed boolean turnheld; // holding turn button for gradual turn speed

View file

@ -3201,8 +3201,9 @@ boolean P_SetupLevel(boolean skipprecip)
if (!dedicated) if (!dedicated)
{ {
for (i = 0; i <= splitscreen; i++) if (!demo.freecam)
P_SetupCamera(displayplayers[i], &camera[i]); for (i = 0; i <= splitscreen; i++)
P_SetupCamera(displayplayers[i], &camera[i]);
// Salt: CV_ClearChangedFlags() messes with your settings :( // Salt: CV_ClearChangedFlags() messes with your settings :(
/*if (!cv_cam_height.changed) /*if (!cv_cam_height.changed)

View file

@ -7217,11 +7217,11 @@ static ticcmd_t cameracmd;
struct demofreecam_s democam; struct demofreecam_s democam;
// called by m_menu to reinit cam input every time it's toggled // called by m_menu to reinit cam input every time it's toggled
void P_InitCameraCmd(void) void P_InitCameraCmd(void)
{ {
memset(&cameracmd, 0, sizeof(ticcmd_t)); // initialize cmd memset(&cameracmd, 0, sizeof(ticcmd_t)); // initialize cmd
} }
static ticcmd_t *P_CameraCmd(camera_t *cam) static ticcmd_t *P_CameraCmd(camera_t *cam)
{ {
@ -7231,17 +7231,17 @@ static ticcmd_t *P_CameraCmd(camera_t *cam)
boolean turnleft, turnright, mouseaiming; boolean turnleft, turnright, mouseaiming;
boolean invertmouse, lookaxis, usejoystick, kbl; boolean invertmouse, lookaxis, usejoystick, kbl;
angle_t lang; angle_t lang;
ticcmd_t *cmd = &cameracmd; ticcmd_t *cmd = &cameracmd;
if (!demo.playback) if (!demo.playback)
return cmd; // empty cmd, no. return cmd; // empty cmd, no.
lang = democam.localangle; lang = democam.localangle;
laim = democam.localaiming; laim = democam.localaiming;
th = democam.turnheld; th = democam.turnheld;
kbl = democam.keyboardlook; kbl = democam.keyboardlook;
G_CopyTiccmd(cmd, I_BaseTiccmd(), 1); // empty, or external driver G_CopyTiccmd(cmd, I_BaseTiccmd(), 1); // empty, or external driver
cmd->angleturn = (INT16)(lang >> 16); cmd->angleturn = (INT16)(lang >> 16);
@ -7295,7 +7295,7 @@ static ticcmd_t *P_CameraCmd(camera_t *cam)
cmd->angleturn = (INT16)(cmd->angleturn + (angleturn[tspeed])); cmd->angleturn = (INT16)(cmd->angleturn + (angleturn[tspeed]));
side -= sidemove[1]; side -= sidemove[1];
} }
cmd->angleturn = (INT16)(cmd->angleturn - ((mousex*(encoremode ? -1 : 1)*8))); cmd->angleturn = (INT16)(cmd->angleturn - ((mousex*(encoremode ? -1 : 1)*8)));
axis = JoyAxis(AXISMOVE, 1); axis = JoyAxis(AXISMOVE, 1);
@ -7342,7 +7342,7 @@ static ticcmd_t *P_CameraCmd(camera_t *cam)
laim = 0; laim = 0;
cmd->aiming = G_ClipAimingPitch(&laim); cmd->aiming = G_ClipAimingPitch(&laim);
mousex = mousey = mlooky = 0; mousex = mousey = mlooky = 0;
if (forward > MAXPLMOVE) if (forward > MAXPLMOVE)
@ -7362,35 +7362,32 @@ static ticcmd_t *P_CameraCmd(camera_t *cam)
} }
lang += (cmd->angleturn<<16); lang += (cmd->angleturn<<16);
democam.localangle = lang; democam.localangle = lang;
democam.localaiming = laim; democam.localaiming = laim;
democam.turnheld = th; democam.turnheld = th;
democam.keyboardlook = kbl; democam.keyboardlook = kbl;
return cmd; return cmd;
} }
void P_DemoCameraMovement(camera_t *cam) void P_DemoCameraMovement(camera_t *cam)
{ {
ticcmd_t *cmd; ticcmd_t *cmd;
angle_t thrustangle; angle_t thrustangle;
mobj_t *awayviewmobj_hack;
// update democam stuff with what we got here: // update democam stuff with what we got here:
democam.cam = cam; democam.cam = cam;
democam.localangle = cam->angle; democam.localangle = cam->angle;
democam.localaiming = cam->aiming; democam.localaiming = cam->aiming;
democam.rewindx = cam->x;
democam.rewindy = cam->y;
democam.rewindz = cam->z;
// first off we need to get button input // first off we need to get button input
cmd = P_CameraCmd(cam); cmd = P_CameraCmd(cam);
cam->aiming = cmd->aiming<<FRACBITS; cam->aiming = cmd->aiming<<FRACBITS;
cam->angle = cmd->angleturn<<16; cam->angle = cmd->angleturn<<16;
// camera movement: // camera movement:
if (cmd->buttons & BT_ACCELERATE) if (cmd->buttons & BT_ACCELERATE)
@ -7398,29 +7395,37 @@ void P_DemoCameraMovement(camera_t *cam)
else if (cmd->buttons & BT_BRAKE) else if (cmd->buttons & BT_BRAKE)
cam->z -= 32*mapobjectscale; cam->z -= 32*mapobjectscale;
cam->momx = cam->momy = cam->momz = 0; cam->momx = cam->momy = cam->momz = 0;
if (cmd->forwardmove != 0) if (cmd->forwardmove != 0)
{ {
thrustangle = cam->angle >> ANGLETOFINESHIFT; thrustangle = cam->angle >> ANGLETOFINESHIFT;
cam->momx += FixedMul(cmd->forwardmove*mapobjectscale, FINECOSINE(thrustangle)); cam->x += FixedMul(cmd->forwardmove*mapobjectscale, FINECOSINE(thrustangle));
cam->momy += FixedMul(cmd->forwardmove*mapobjectscale, FINESINE(thrustangle)); cam->y += FixedMul(cmd->forwardmove*mapobjectscale, FINESINE(thrustangle));
cam->momz += FixedMul(cmd->forwardmove*mapobjectscale, AIMINGTOSLOPE(cam->aiming)); cam->z += FixedMul(cmd->forwardmove*mapobjectscale, AIMINGTOSLOPE(cam->aiming));
// momentums are useless here, directly add to the coordinates
//funny thing cameras aren't mobjs so we gotta handle this ourselves;
cam->x += cam->momx;
cam->y += cam->momy;
cam->z += cam->momz;
// this.......... doesn't actually check for floors and walls and whatnot but the function to do that is a pure mess so fuck that. // this.......... doesn't actually check for floors and walls and whatnot but the function to do that is a pure mess so fuck that.
// besides freecam going inside walls sounds pretty cool on paper. // besides freecam going inside walls sounds pretty cool on paper.
} }
}
// awayviewmobj hack; this is to prevent us from hearing sounds from the player's perspective
awayviewmobj_hack = P_SpawnMobj(cam->x, cam->y, cam->z, MT_THOK);
awayviewmobj_hack->tics = 2;
awayviewmobj_hack->flags2 |= MF2_DONTDRAW;
democam.soundmobj = awayviewmobj_hack;
}
void P_ResetCamera(player_t *player, camera_t *thiscam) void P_ResetCamera(player_t *player, camera_t *thiscam)
{ {
if (demo.freecam)
return; // do not reset the camera there.
tic_t tries = 0; tic_t tries = 0;
fixed_t x, y, z; fixed_t x, y, z;
@ -7477,13 +7482,15 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
boolean cameranoclip; boolean cameranoclip;
subsector_t *newsubsec; subsector_t *newsubsec;
#endif #endif
democam.soundmobj = NULL; // reset this each frame, we don't want the game crashing for stupid reasons now do we
if (demo.freecam) if (demo.freecam)
{ {
P_DemoCameraMovement(thiscam); P_DemoCameraMovement(thiscam);
return true; return true;
} }
// We probably shouldn't move the camera if there is no player or player mobj somehow // We probably shouldn't move the camera if there is no player or player mobj somehow
if (!player || !player->mo) if (!player || !player->mo)
return true; return true;

View file

@ -442,7 +442,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)
listener_t listener3 = {0,0,0,0}; listener_t listener3 = {0,0,0,0};
listener_t listener4 = {0,0,0,0}; listener_t listener4 = {0,0,0,0};
mobj_t *listenmobj = players[displayplayers[0]].mo; mobj_t *listenmobj = democam.soundmobj ? : players[displayplayers[0]].mo;
mobj_t *listenmobj2 = NULL; mobj_t *listenmobj2 = NULL;
mobj_t *listenmobj3 = NULL; mobj_t *listenmobj3 = NULL;
mobj_t *listenmobj4 = NULL; mobj_t *listenmobj4 = NULL;
@ -903,7 +903,7 @@ void S_UpdateSounds(void)
listener_t listener3; listener_t listener3;
listener_t listener4; listener_t listener4;
mobj_t *listenmobj = players[displayplayers[0]].mo; mobj_t *listenmobj = democam.soundmobj ? : players[displayplayers[0]].mo;
mobj_t *listenmobj2 = NULL; mobj_t *listenmobj2 = NULL;
mobj_t *listenmobj3 = NULL; mobj_t *listenmobj3 = NULL;
mobj_t *listenmobj4 = NULL; mobj_t *listenmobj4 = NULL;