mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
Applied patch from Nemesis13 partially ;-)
This commit is contained in:
parent
fcd2a2ec0d
commit
617e9d5e8c
@ -1,11 +1,9 @@
|
||||
"""Undocumented Module"""
|
||||
"""The new Finite State Machine module. This replaces the module
|
||||
previously called FSM.py (now called ClassicFSM.py).
|
||||
"""
|
||||
|
||||
__all__ = ['FSMException', 'FSM']
|
||||
|
||||
"""
|
||||
The new Finite State Machine module. This replaces the modules
|
||||
previously called FSM.py (now called ClassicFSM.py).
|
||||
"""
|
||||
|
||||
from direct.showbase.DirectObject import DirectObject
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
@ -145,6 +143,7 @@ class FSM(DirectObject):
|
||||
def __init__(self, name):
|
||||
self.fsmLock = RLock()
|
||||
self.name = name
|
||||
self.stateArray = []
|
||||
self._serialNum = FSM.SerialNum
|
||||
FSM.SerialNum += 1
|
||||
self._broadcastStateChanges = False
|
||||
@ -393,33 +392,42 @@ class FSM(DirectObject):
|
||||
finally:
|
||||
self.fsmLock.release()
|
||||
|
||||
|
||||
def requestNext(self, *args):
|
||||
"""request the 'next' state in the predefined state array"""
|
||||
"""Request the 'next' state in the predefined state array."""
|
||||
self.fsmLock.acquire()
|
||||
try:
|
||||
assert self.state in self.stateArray
|
||||
if self.stateArray:
|
||||
if not self.state in self.stateArray:
|
||||
self.request(self.stateArray[0])
|
||||
else:
|
||||
cur_index = self.stateArray.index(self.state)
|
||||
new_index = (cur_index + 1) % len(self.stateArray)
|
||||
self.request(self.stateArray[new_index], args)
|
||||
else:
|
||||
assert self.notifier.debug(
|
||||
"stateArray empty. Can't switch to next.")
|
||||
|
||||
curIndex = self.stateArray.index(self.state)
|
||||
newIndex = (curIndex + 1) % len(self.stateArray)
|
||||
|
||||
self.request(self.stateArray[newIndex], args)
|
||||
finally:
|
||||
self.fsmLock.release()
|
||||
|
||||
def requestPrev(self, *args):
|
||||
"""request the 'previous' state in the predefined state array"""
|
||||
"""Request the 'previous' state in the predefined state array."""
|
||||
self.fsmLock.acquire()
|
||||
try:
|
||||
assert self.state in self.stateArray
|
||||
|
||||
curIndex = self.stateArray.index(self.state)
|
||||
newIndex = (curIndex - 1) % len(self.stateArray)
|
||||
|
||||
self.request(self.stateArray[newIndex], args)
|
||||
if self.stateArray:
|
||||
if not self.state in self.stateArray:
|
||||
self.request(self.stateArray[0])
|
||||
else:
|
||||
cur_index = self.stateArray.index(self.state)
|
||||
new_index = (cur_index - 1) % len(self.stateArray)
|
||||
self.request(self.stateArray[new_index], args)
|
||||
else:
|
||||
assert self.notifier.debug(
|
||||
"stateArray empty. Can't switch to next.")
|
||||
finally:
|
||||
self.fsmLock.release()
|
||||
|
||||
|
||||
def __setState(self, newState, *args):
|
||||
# Internal function to change unconditionally to the indicated
|
||||
# state.
|
||||
|
Loading…
x
Reference in New Issue
Block a user