Skip to content

Commit

Permalink
Clarify meaning of tick in GameTick message (#148)
Browse files Browse the repository at this point in the history
Tick-related off-by-one errors are a recurring issue. This is an attempt at clarifying that the tick in a `GameTick` message is the tick that should be reacted to, not the last tick that was reacted to.

💡 `git show --color-words=.`
  • Loading branch information
SimonAlling authored Jan 4, 2025
1 parent 9748bb2 commit 9111063
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ newRoundGameStateAndCmd config plannedMidRoundState =

type Msg
= SpawnTick SpawnState MidRoundState
| GameTick Tick MidRoundState
| GameTick { tickToReactTo : Tick } MidRoundState
| ButtonUsed ButtonDirection Button
| DialogChoiceMade Dialog.Option
| FocusLost
Expand Down Expand Up @@ -112,10 +112,10 @@ update msg ({ config, pressedButtons } as model) =
stepSpawnState config spawnState
|> Tuple.mapFirst (\makeActiveGameState -> { model | appState = InGame <| Active NotPaused <| makeActiveGameState plannedMidRoundState })

GameTick tick midRoundState ->
GameTick { tickToReactTo } midRoundState ->
let
( tickResult, cmd ) =
Game.reactToTick config tick midRoundState
Game.reactToTick config tickToReactTo midRoundState
in
( { model | appState = InGame (tickResultToGameState tickResult) }
, cmd
Expand Down Expand Up @@ -315,7 +315,7 @@ subscriptions model =
Time.every (1000 / model.config.spawn.flickerTicksPerSecond) (always <| SpawnTick spawnState plannedMidRoundState)

InGame (Active NotPaused (Moving lastTick midRoundState)) ->
Time.every (1000 / Tickrate.toFloat model.config.kurves.tickrate) (always <| GameTick (Tick.succ lastTick) midRoundState)
Time.every (1000 / Tickrate.toFloat model.config.kurves.tickrate) (always <| GameTick { tickToReactTo = Tick.succ lastTick } midRoundState)

InGame (Active Paused _) ->
Sub.none
Expand Down

0 comments on commit 9111063

Please # to comment.