1 """Meat Engine Hierarchical Finite State Machine (hFSM) Manager
2
3 This could be refactored so that a fsmMgr is an instatiatable class,
4 but for now it uses the "lazy singleton" pattern - the state stack is
5 a module global, and methods are just module functions. This is
6 adequate for my needs so far.
7
8 Use: create State objects, push them on the stack. Periodically call
9 the update and draw functions, and pass the handleKey and
10 handleMouseButton events in as appropriate. The top state will get
11 delegated to, which may choose to delegate further. For example, a
12 dialog box may choose to call the next state's draw code first, before
13 drawing itself.
14 """
15
16
32
33
34
35 gStateStack=[]
36
38 try:
39 oldTop=gStateStack[-1]
40 except:
41 oldTop=None
42
43 gStateStack.append(newState)
44 newState.parent=oldTop
45 newState.init()
46
47
50
51
55
56
62
68
74
81
87
90