Make sure lag_compensation_get_local_state() always returns a MarioState

This commit is contained in:
MysterD 2023-04-11 14:53:04 -07:00
parent 21c5079058
commit 6d13e010d8
1 changed files with 4 additions and 4 deletions

View File

@ -40,16 +40,16 @@ void lag_compensation_store(void) {
} }
struct MarioState* lag_compensation_get_local_state(struct NetworkPlayer* otherNp) { struct MarioState* lag_compensation_get_local_state(struct NetworkPlayer* otherNp) {
if (!otherNp) { return NULL; } if (!otherNp) { return &gMarioStates[0]; }
if (gNetworkType == NT_NONE) { return NULL; } if (gNetworkType == NT_NONE) { return &gMarioStates[0]; }
if (!sLocalStateHistoryReady) { return NULL; } if (!sLocalStateHistoryReady) { return &gMarioStates[0]; }
s32 pingToTicks = (otherNp->ping / 1000.0f) * 30; s32 pingToTicks = (otherNp->ping / 1000.0f) * 30;
if (pingToTicks > (MAX_LOCAL_STATE_HISTORY-1)) { if (pingToTicks > (MAX_LOCAL_STATE_HISTORY-1)) {
pingToTicks = (MAX_LOCAL_STATE_HISTORY-1); pingToTicks = (MAX_LOCAL_STATE_HISTORY-1);
} }
//LOG_INFO("Ping: %s :: %u :: %d", otherNp->name, otherNp->ping, pingToTicks); //LOG_INFO("Ping: %s :: %u :: %d", otherNp->name, otherNp->ping, pingToTicks);
if (pingToTicks == 0) { return NULL; } if (pingToTicks == 0) { return &gMarioStates[0]; }
s32 index = (s32)sLocalStateHistoryIndex - pingToTicks; s32 index = (s32)sLocalStateHistoryIndex - pingToTicks;
while (index < 0) { index += MAX_LOCAL_STATE_HISTORY; } while (index < 0) { index += MAX_LOCAL_STATE_HISTORY; }