feat(fsm): make the special state "quit" exit the fsm.
This commit is contained in:
parent
346cf350d8
commit
35e73f2b37
2 changed files with 9 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
4
main.go
4
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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue