1
0
Fork 0

feat(fsm): make the special state "quit" exit the fsm.

This commit is contained in:
Henrik Hautakoski 2025-09-24 18:32:50 +02:00
parent 346cf350d8
commit 35e73f2b37
2 changed files with 9 additions and 3 deletions

View file

@ -32,17 +32,21 @@ func (m *Machine) Switch(name string) {
} }
// Update ticks the current state, then applies any queued transition. // 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 { if m.current == nil {
return return false
} }
m.current.Update(m, delta) m.current.Update(m, delta)
if m.pending != "" { if m.pending != "" {
if m.pending == "quit" {
return false
}
next := m.pending next := m.pending
m.pending = "" m.pending = ""
m.switchNow(next) m.switchNow(next)
} }
return true
} }
// Render proxies to current state. // Render proxies to current state.

View file

@ -43,7 +43,9 @@ func main() {
// Enter game loop // Enter game loop
for !rl.WindowShouldClose() { for !rl.WindowShouldClose() {
audio.Update() audio.Update()
fsm.Update(rl.GetFrameTime()) if !fsm.Update(rl.GetFrameTime()) {
break
}
fsm.Render() fsm.Render()
} }
} }