feat: apply input once per tick and check death state for grace window
This commit is contained in:
parent
1e6d809382
commit
b14020c1a1
2 changed files with 11 additions and 14 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Reference in a new issue