Verse Library verse

11 Fragment

Spawns and runs an asynchronous dispatcher to cycle through NPC behavioral states.

verse-library/verse-concurrency-async-race-state-machines/11-fragment.verse

# OnBegin spins up the state machine in the background and returns immediately.
InternalStateMachineHandler(NPCAgent : agent) : void =
    spawn{ InternalStateMachine(NPCAgent) }

# The dispatcher: pick the current state and run its method.
InternalStateMachine(InAgent : agent)<suspends> : void =
    case (CurrentState):
        npc_states.Idle  => StateIdle(InAgent)
        npc_states.Sleep => StateSleep(InAgent)
        npc_states.Hint  => StateHint(InAgent)
        # ...one method per state

Comments

    Sign in to vote, comment, or suggest an edit. Sign in