From 7c6dd0b22a5967ef64c52eba55999d69d31b790b Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Thu, 8 Dec 2022 01:03:51 -0800 Subject: [PATCH] Fix reprediction bug, used unsigned math, bad! --- buildsettings.h | 13 +++++++------ main.c | 16 ++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/buildsettings.h b/buildsettings.h index 69b6c3f..0a979dc 100644 --- a/buildsettings.h +++ b/buildsettings.h @@ -8,14 +8,15 @@ #ifdef DEBUG #define SERVER_ADDRESS "127.0.0.1" +// #define SERVER_ADDRESS "207.246.80.160" -// #define PROFILING +//#define PROFILING #define DEBUG_RENDERING -#define DEBUG_WORLD -#define UNLOCK_ALL -#define INFINITE_RESOURCES -#define NO_GRAVITY -#define NO_SUNS +//#define DEBUG_WORLD +//#define UNLOCK_ALL +//#define INFINITE_RESOURCES +//#define NO_GRAVITY +//#define NO_SUNS #else diff --git a/main.c b/main.c index 384f1ff..028e1a1 100644 --- a/main.c +++ b/main.c @@ -1537,12 +1537,11 @@ static void frame(void) { uint64_t server_current_tick = tick(&gs); - uint64_t ticks_should_repredict = predicted_to_tick - server_current_tick; + int ticks_should_repredict = (int)predicted_to_tick - (int)server_current_tick; - uint64_t healthy_num_ticks_ahead = (uint64_t)ceil((((double)peer->roundTripTime) / 1000.0) / TIMESTEP) + 6; + int healthy_num_ticks_ahead = (int)ceil((((double)peer->roundTripTime) / 1000.0) / TIMESTEP) + 6; - // keeps it stable even though causes jumps occasionally - uint64_t ticks_to_repredict = ticks_should_repredict; + int ticks_to_repredict = ticks_should_repredict; if (ticks_should_repredict < healthy_num_ticks_ahead - 1) { @@ -1550,15 +1549,16 @@ static void frame(void) } else if (ticks_should_repredict > healthy_num_ticks_ahead + 1) { - dilating_time_factor = 0.1; + dilating_time_factor = 0.9; } else { dilating_time_factor = 1.0; } + // snap in dire cases - if (ticks_should_repredict < healthy_num_ticks_ahead - TICKS_BEHIND_DO_SNAP) + if (healthy_num_ticks_ahead >= TICKS_BEHIND_DO_SNAP && ticks_should_repredict < healthy_num_ticks_ahead - TICKS_BEHIND_DO_SNAP) { Log("Snapping\n"); ticks_to_repredict = healthy_num_ticks_ahead; @@ -1569,7 +1569,7 @@ static void frame(void) { if (stm_ms(stm_diff(stm_now(), start_prediction_time)) > MAX_MS_SPENT_REPREDICTING) { - Log("Reprediction took longer than %f milliseconds, needs to repredict %llu more ticks\n", MAX_MS_SPENT_REPREDICTING, ticks_to_repredict); + Log("Reprediction took longer than %f milliseconds, needs to repredict %d more ticks\n", MAX_MS_SPENT_REPREDICTING, ticks_to_repredict); break; } apply_this_tick_of_input_to_player(tick(&gs)); @@ -1581,7 +1581,7 @@ static void frame(void) double reprediction_error = cpvdist(where_i_am, where_i_thought_id_be); InputFrame *biggest_frame = (InputFrame *)queue_most_recent_element(&input_queue); - if (reprediction_error >= 0.1) + if (reprediction_error >= 0.1 && biggest_frame != NULL) { Log("Big reprediction error %llu\n", biggest_frame->tick); }