Skip to content

Commit

Permalink
Fix tick-incrementation regression
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonAlling committed Jan 8, 2025
1 parent c065476 commit c8e02da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/Game.elm
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ reactToTick config tick (( _, currentRound ) as midRoundState) =
)


tickResultToGameState : Tick -> TickResult ( LeftoverFrameTime, MidRoundState ) -> GameState
tickResultToGameState tick tickResult =
tickResultToGameState : TickResult ( Tick, LeftoverFrameTime, MidRoundState ) -> GameState
tickResultToGameState tickResult =
case tickResult of
RoundKeepsGoing s ->
Active NotPaused (Moving tick s)
RoundKeepsGoing ( tick, leftoverFrameTime, midRoundState ) ->
Active NotPaused (Moving tick ( leftoverFrameTime, midRoundState ))

RoundEnds finishedRound ->
RoundOver finishedRound Dialog.NotOpen
Expand Down
6 changes: 1 addition & 5 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,10 @@ update msg ({ config, pressedButtons } as model) =

AnimationFrame { delta, leftoverTimeFromPreviousFrame, lastTick } midRoundState ->
let
tick : Tick
tick =
Tick.succ lastTick

( tickResult, cmd ) =
MainLoop.consumeAnimationFrame config delta lastTick ( leftoverTimeFromPreviousFrame, midRoundState )
in
( { model | appState = InGame (tickResultToGameState tick tickResult) }
( { model | appState = InGame (tickResultToGameState tickResult) }
, cmd
)

Expand Down
6 changes: 3 additions & 3 deletions src/MainLoop.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Types.Tick as Tick exposing (Tick)
import Types.Tickrate as Tickrate


consumeAnimationFrame : Config -> FrameTime -> Tick -> ( LeftoverFrameTime, MidRoundState ) -> ( TickResult ( LeftoverFrameTime, MidRoundState ), Cmd msg )
consumeAnimationFrame : Config -> FrameTime -> Tick -> ( LeftoverFrameTime, MidRoundState ) -> ( TickResult ( Tick, LeftoverFrameTime, MidRoundState ), Cmd msg )
consumeAnimationFrame config delta lastTick ( leftoverTimeFromPreviousFrame, midRoundState ) =
let
timeToConsume : FrameTime
Expand All @@ -25,7 +25,7 @@ consumeAnimationFrame config delta lastTick ( leftoverTimeFromPreviousFrame, mid
timestep =
1000 / Tickrate.toFloat config.kurves.tickrate

recurse : Tick -> ( LeftoverFrameTime, MidRoundState ) -> Cmd msg -> ( TickResult ( LeftoverFrameTime, MidRoundState ), Cmd msg )
recurse : Tick -> ( LeftoverFrameTime, MidRoundState ) -> Cmd msg -> ( TickResult ( Tick, LeftoverFrameTime, MidRoundState ), Cmd msg )
recurse lastTickReactedTo ( timeLeftToConsume, midRoundStateSoFar ) cmdSoFar =
if timeLeftToConsume >= timestep then
let
Expand All @@ -50,7 +50,7 @@ consumeAnimationFrame config delta lastTick ( leftoverTimeFromPreviousFrame, mid
)

else
( RoundKeepsGoing ( timeLeftToConsume, midRoundStateSoFar )
( RoundKeepsGoing ( lastTickReactedTo, timeLeftToConsume, midRoundStateSoFar )
, cmdSoFar
)
in
Expand Down

0 comments on commit c8e02da

Please sign in to comment.