From 35e73f2b37e75c0af270c11f04b28de27e08f383 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 24 Sep 2025 18:32:50 +0200 Subject: [PATCH] feat(fsm): make the special state "quit" exit the fsm. --- game/state/machine/machine.go | 8 ++++++-- main.go | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/game/state/machine/machine.go b/game/state/machine/machine.go index 06e8639..79e2ff1 100644 --- a/game/state/machine/machine.go +++ b/game/state/machine/machine.go @@ -32,17 +32,21 @@ func (m *Machine) Switch(name string) { } // Update ticks the current state, then applies any queued transition. -func (m *Machine) Update(delta float32) { +func (m *Machine) Update(delta float32) bool { if m.current == nil { - return + return false } m.current.Update(m, delta) if m.pending != "" { + if m.pending == "quit" { + return false + } next := m.pending m.pending = "" m.switchNow(next) } + return true } // Render proxies to current state. diff --git a/main.go b/main.go index f48c78a..9aa54d2 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,9 @@ func main() { // Enter game loop for !rl.WindowShouldClose() { audio.Update() - fsm.Update(rl.GetFrameTime()) + if !fsm.Update(rl.GetFrameTime()) { + break + } fsm.Render() } }