From 37cd0a596e303b5bfe49bfda37559b82fbf6de7a Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 21 Dec 2019 16:00:39 +0000 Subject: [PATCH] Fixed crash bug Further improved player trails --- src/d_clisrv.c | 27 +++++++++++++++++---------- src/d_netcmd.c | 2 +- src/p_saveg.c | 46 ++++++++++++++++++++++------------------------ 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d10a4f6f2..64953b434 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5445,7 +5445,7 @@ boolean newLoadTic = false; #define MAXAUTOFUDGERTT 20 -boolean autotimefudge = true; +boolean autotimefudge; UINT8 autotimefudgetime = 0; UINT16 autotimefudgesamples = 0; UINT16 autotimefudgedata[MAXAUTOFUDGERTT]; @@ -5708,21 +5708,28 @@ static void RunSimulations() if (playeringame[j] && players[j].mo && j != consoleplayer) { // If there is a big discrepency between the player's current position and their last one, spawn a trail showing their movements - fixed_t distance = max(abs(steadyplayers[j].finalx - players[j].mo->x), - max(abs(steadyplayers[j].finaly - players[j].mo->y), - abs(steadyplayers[j].finalz - players[j].mo->z))); + fixed_t distance = max(abs(steadyplayers[j].finalx - steadyplayers[j].histx[histIndex]), + max(abs(steadyplayers[j].finaly - steadyplayers[j].histy[histIndex]), + abs(steadyplayers[j].finalz - steadyplayers[j].histz[histIndex]))); + fixed_t stepDistance = 60 << FRACBITS; // distance between trail steps // If player is changing direction quickly in a net simulation, create a ghost trail - if (distance > players[j].maxdash) + if (distance > stepDistance) { - for (int i = 0; i < histIndex; i++) + fixed_t numSteps = FixedDiv(distance, stepDistance) & ~FRACMASK; + fixed_t currentStep; // between 0 and 1 + fixed_t step = FixedDiv(1<x = steadyplayers[j].histx[i]; - ghost->y = steadyplayers[j].histy[i]; - ghost->z = steadyplayers[j].histz[i]; - ghost->fuse = i - (ghost->fuse - histIndex); + ghost->x = steadyplayers[j].finalx + FixedMul(steadyplayers[j].histx[histIndex] - steadyplayers[j].finalx, currentStep); + ghost->y = steadyplayers[j].finaly + FixedMul(steadyplayers[j].histy[histIndex] - steadyplayers[j].finaly, currentStep); + ghost->z = steadyplayers[j].finalz + FixedMul(steadyplayers[j].histz[histIndex] - steadyplayers[j].finalz, currentStep); + ghost->fuse = ghost->fuse + i - (numSteps>>FRACBITS); + i++; } } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index ed6580b82..9a03bd0d7 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -476,7 +476,7 @@ UINT8 splitscreen = 0; boolean circuitmap = true; // SRB2kart consvar_t cv_simulate = { "simulate", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL }; -static CV_PossibleValue_t simulateTics_cons_t[] = { {0, "MIN"}, {BACKUPTICS / 2, "MAX"}, {0, NULL} }; +static CV_PossibleValue_t simulateTics_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} }; consvar_t cv_simulatetics = { "simulatetics", "0", 0, simulateTics_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t netdelay_cons_t[] = { {0, "MIN"}, {250, "MAX"}, {0, NULL} }; diff --git a/src/p_saveg.c b/src/p_saveg.c index 34294d183..13f3c676c 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -457,6 +457,17 @@ static void P_LocalArchivePlayers(void) continue; WRITEMEM(save_p, &players[i], sizeof(player_t)); + + player_t* player = &((player_t*)save_p)[-1]; + +#define RELINK(var) if (var != NULL) var = (mobj_t*)var->mobjnum + RELINK(player->capsule); + RELINK(player->axis1); + RELINK(player->axis2); + RELINK(player->awayviewmobj); + RELINK(player->followmobj); + RELINK(player->drone); +#undef RELINK } } @@ -473,13 +484,6 @@ static void P_LocalUnArchivePlayers(void) continue; READMEM(save_p, &players[i], sizeof(player_t)); - - players[i].capsule = NULL; - players[i].axis1 = NULL; - players[i].axis2 = NULL; - players[i].awayviewmobj = NULL; - players[i].followmobj = NULL; - players[i].drone = NULL; } } @@ -2229,16 +2233,6 @@ static void P_LocalArchiveThinkers(void) RELINK(savedMobj->target); RELINK(savedMobj->hnext); RELINK(savedMobj->hprev); - - if (savedMobj->player) - { - RELINK(savedMobj->player->capsule); - RELINK(savedMobj->player->axis1); - RELINK(savedMobj->player->axis2); - RELINK(savedMobj->player->awayviewmobj); - RELINK(savedMobj->player->followmobj); - RELINK(savedMobj->player->drone); - } } } #undef RELINK @@ -3508,15 +3502,19 @@ static void P_LocalUnArchiveThinkers() RELINK(mobj->target); RELINK(mobj->hnext); RELINK(mobj->hprev); + } - if (mobj->player) + // restore player pointers (the above doesn't always seem to work perhaps because playeringame is false? + for (int i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) { - RELINK(mobj->player->capsule); - RELINK(mobj->player->axis1); - RELINK(mobj->player->axis2); - RELINK(mobj->player->awayviewmobj); - RELINK(mobj->player->followmobj); - RELINK(mobj->player->drone); + RELINK(players[i].capsule); + RELINK(players[i].axis1); + RELINK(players[i].axis2); + RELINK(players[i].awayviewmobj); + RELINK(players[i].followmobj); + RELINK(players[i].drone); } } #undef RELINK