From b14020c1a1fdf5bfed8b7898c2d25b9c70892228 Mon Sep 17 00:00:00 2001 From: "Sebastian Benjamin (aider)" Date: Tue, 3 Jun 2025 18:26:05 -0700 Subject: [PATCH] feat: apply input once per tick and check death state for grace window --- server/game-modes/battle-royale/game-loop.go | 18 ++++++------------ .../game-modes/battle-royale/player-stage.go | 7 +++++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/server/game-modes/battle-royale/game-loop.go b/server/game-modes/battle-royale/game-loop.go index 2a16eb0..fdfaf81 100644 --- a/server/game-modes/battle-royale/game-loop.go +++ b/server/game-modes/battle-royale/game-loop.go @@ -38,26 +38,20 @@ func RespondToInput(lobbyState *MatchState, messages []runtime.MatchData, logger continue } + // Apply the input to the tick where it occurred + lobbyState.presences[msg.GetSessionId()].stageState.BoundsCheckedMove(update.X, update.Y) + // Check if the input is within the grace window if update.Tick < tick && tick-update.Tick <= GRACE_WINDOW_TICKS { - // Replay the game state for the intervening ticks + // Check the player's death state for all subsequent ticks for t := update.Tick; t < tick; t++ { - // Apply the input to the player's state - lobbyState.presences[msg.GetSessionId()].stageState.BoundsCheckedMove(update.X, update.Y) - // Check if the player survives after applying the input if lobbyState.presences[msg.GetSessionId()].stageState.CheckDeathState(t) == PLAYER_ALIVE { - // Send a cancel death message to the client - cancelDeathMessage := map[string]any{ - "cancelDeath": true, - } - data, _ := json.Marshal(cancelDeathMessage) - (*dispatcher).BroadcastMessage(CANCEL_DEATH, data, []runtime.Presence{msg.GetPresence()}, nil, true) + // Set a flag to cancel death + lobbyState.presences[msg.GetSessionId()].stageState.cancelDeath = true break } } } - - lobbyState.presences[msg.GetSessionId()].stageState.BoundsCheckedMove(update.X, update.Y) } } diff --git a/server/game-modes/battle-royale/player-stage.go b/server/game-modes/battle-royale/player-stage.go index 5bfc1ec..b4eb2dc 100644 --- a/server/game-modes/battle-royale/player-stage.go +++ b/server/game-modes/battle-royale/player-stage.go @@ -16,7 +16,7 @@ type PlayerStageState struct { graze int score int deathTimer int -} + cancelDeath bool func NewPlayerStage() *PlayerStageState { return &PlayerStageState{ @@ -26,7 +26,10 @@ func NewPlayerStage() *PlayerStageState { updatePlayerPos: true, health: 3, deathTimer: -1, - } + if s.cancelDeath { + tickData.CancelDeath = true + s.cancelDeath = false + } } func (s *PlayerStageState) Delete() {