From 10319386c2469cb881b4fbd978a3b2868e4a1886 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 11 Feb 2021 20:25:22 -0500 Subject: [PATCH 1/3] Do starttime calculation on second tick instead Attempts to fix replays & adding bots. --- src/k_kart.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/k_kart.h | 1 + src/p_setup.c | 50 ++++++++++++-------------------------------------- src/p_tick.c | 7 +++++++ 4 files changed, 71 insertions(+), 38 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 2f01f2dc0..026ac665f 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -43,6 +43,57 @@ // indirectitemcooldown is timer before anyone's allowed another Shrink/SPB // mapreset is set when enough players fill an empty server +void K_TimerInit(void) +{ + UINT8 i; + UINT8 numPlayers = 0; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i]) + { + continue; + } + + if (players[i].spectator == true) + { + continue; + } + + numPlayers++; + } + + if (numPlayers >= 2) + { + rainbowstartavailable = true; + } + else + { + rainbowstartavailable = false; + } + + if (numPlayers <= 2) + { + introtime = 0; // No intro in Record Attack / 1v1 + } + else + { + introtime = (108) + 5; // 108 for rotation, + 5 for white fade + } + + numbulbs = 5; + + if (numPlayers > 2) + { + numbulbs += (numPlayers-2); + } + + starttime = (introtime + (3*TICRATE)) + ((2*TICRATE) + (numbulbs * bulbtime)); // Start countdown time, + buffer time + + // NOW you can try to spawn in the Battle capsules, if there's not enough players for a match + K_SpawnBattleCapsules(); +} + UINT16 K_GetPlayerDontDrawFlag(player_t *player) { UINT16 flag = 0; diff --git a/src/k_kart.h b/src/k_kart.h index 9b92fff7c..71073587e 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -17,6 +17,7 @@ angle_t K_ReflectAngle(angle_t angle, angle_t against, fixed_t maxspeed, fixed_t void K_RegisterKartStuff(void); +void K_TimerInit(void); UINT16 K_GetPlayerDontDrawFlag(player_t *player); boolean K_IsPlayerLosing(player_t *player); fixed_t K_GetKartGameSpeedScalar(SINT8 value); diff --git a/src/p_setup.c b/src/p_setup.c index 6cd4ffd72..a9e05f6f8 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3427,29 +3427,6 @@ static void P_InitLevelSettings(void) players[i].follower = NULL; } - rainbowstartavailable = false; - - if (p >= 2) - rainbowstartavailable = true; - - if (p <= 2) - { - introtime = 0; // No intro in Record Attack / 1v1 - } - else - { - introtime = (108) + 5; // 108 for rotation, + 5 for white fade - } - - numbulbs = 5; - - if (p > 2) - { - numbulbs += (p-2); - } - - starttime = (introtime + (3*TICRATE)) + ((2*TICRATE) + (numbulbs * bulbtime)); // Start countdown time, + buffer time - // SRB2Kart: map load variables if (grandprixinfo.gp == true) { @@ -4149,21 +4126,6 @@ boolean P_LoadLevel(boolean fromnetsave) lastmaploaded = gamemap; // HAS to be set after saving!! } - if (!fromnetsave) // uglier hack - { // to make a newly loaded level start on the second frame. - INT32 buf = gametic % TICQUEUE; - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - G_CopyTiccmd(&players[i].cmd, &netcmds[buf][i], 1); - } - P_PreTicker(2); - LUAh_MapLoad(); - } - - // NOW you can try to spawn in the Battle capsules, if there's not enough players for a match - K_SpawnBattleCapsules(); - if (grandprixinfo.gp == true) { if (grandprixinfo.initalize == true) @@ -4183,6 +4145,18 @@ boolean P_LoadLevel(boolean fromnetsave) K_UpdateMatchRaceBots(); } + if (!fromnetsave) // uglier hack + { // to make a newly loaded level start on the second frame. + INT32 buf = gametic % TICQUEUE; + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + G_CopyTiccmd(&players[i].cmd, &netcmds[buf][i], 1); + } + P_PreTicker(2); + LUAh_MapLoad(); + } + // No render mode, stop here. if (rendermode == render_none) return true; diff --git a/src/p_tick.c b/src/p_tick.c index 71ded772c..85ee844dd 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -705,6 +705,13 @@ void P_Ticker(boolean run) if (demo.playback) G_StoreRewindInfo(); + if (leveltime == 2) + { + // The values needed to set this properly are not correct at map load, + // so we have to do it at the second tick instead... + K_TimerInit(); + } + // Z_CheckMemCleanup(); } From e2dcc35bcd5585709e320b4d87a713e2c50bf140 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 12 Feb 2021 20:25:03 -0500 Subject: [PATCH 2/3] Reset properties on map load --- src/g_game.c | 6 +++--- src/k_kart.c | 6 ++++++ src/k_kart.h | 1 + src/p_setup.c | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 0a494918f..155633606 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -246,11 +246,11 @@ INT32 gameovertics = 15*TICRATE; UINT8 ammoremovaltics = 2*TICRATE; // SRB2kart -tic_t introtime = 0; -tic_t starttime = 0; +tic_t introtime = 3; +tic_t starttime = 3; const tic_t bulbtime = TICRATE/2; -UINT8 numbulbs = 0; +UINT8 numbulbs = 1; tic_t raceexittime = 5*TICRATE + (2*TICRATE/3); tic_t battleexittime = 8*TICRATE; diff --git a/src/k_kart.c b/src/k_kart.c index 026ac665f..5a808a7b4 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -43,6 +43,12 @@ // indirectitemcooldown is timer before anyone's allowed another Shrink/SPB // mapreset is set when enough players fill an empty server +void K_TimerReset(void) +{ + starttime = introtime = 3; + numbulbs = 1; +} + void K_TimerInit(void) { UINT8 i; diff --git a/src/k_kart.h b/src/k_kart.h index 71073587e..0e3aa0ff4 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -17,6 +17,7 @@ angle_t K_ReflectAngle(angle_t angle, angle_t against, fixed_t maxspeed, fixed_t void K_RegisterKartStuff(void); +void K_TimerReset(void); void K_TimerInit(void); UINT16 K_GetPlayerDontDrawFlag(player_t *player); boolean K_IsPlayerLosing(player_t *player); diff --git a/src/p_setup.c b/src/p_setup.c index a9e05f6f8..6ffb2e427 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -4157,6 +4157,8 @@ boolean P_LoadLevel(boolean fromnetsave) LUAh_MapLoad(); } + K_TimerReset(); + // No render mode, stop here. if (rendermode == render_none) return true; From b91ceddcbf10b3c2fef55d311ea47dc408029dba Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 12 Feb 2021 20:27:14 -0500 Subject: [PATCH 3/3] Sync numbulbs I don't think this has ever caused issues (numbulbs is just for HUD), but the drawn bulbs on start up might as well be synched if the starttime needs to be resynched too. --- src/p_saveg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_saveg.c b/src/p_saveg.c index 0eff1e1d3..7ea1decdf 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -4178,6 +4178,7 @@ static void P_NetArchiveMisc(void) WRITEUINT32(save_p, introtime); WRITEUINT32(save_p, starttime); + WRITEUINT8(save_p, numbulbs); // Is it paused? if (paused) @@ -4312,6 +4313,7 @@ static inline boolean P_NetUnArchiveMisc(void) introtime = READUINT32(save_p); starttime = READUINT32(save_p); + numbulbs = READUINT8(save_p); // Is it paused? if (READUINT8(save_p) == 0x2f)