mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
added state change broadcast support
This commit is contained in:
parent
7ba76c1d39
commit
bab3da450c
@ -123,8 +123,13 @@ class FSM(DirectObject.DirectObject):
|
|||||||
|
|
||||||
notify = DirectNotifyGlobal.directNotify.newCategory("FSM")
|
notify = DirectNotifyGlobal.directNotify.newCategory("FSM")
|
||||||
|
|
||||||
|
SerialNum = 0
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self._serialNum = FSM.SerialNum
|
||||||
|
FSM.SerialNum += 1
|
||||||
|
self._broadcastStateChanges = False
|
||||||
# Initially, we are in the Off state by convention.
|
# Initially, we are in the Off state by convention.
|
||||||
self.state = 'Off'
|
self.state = 'Off'
|
||||||
|
|
||||||
@ -155,6 +160,15 @@ class FSM(DirectObject.DirectObject):
|
|||||||
if self.state != 'Off':
|
if self.state != 'Off':
|
||||||
self.__setState('Off')
|
self.__setState('Off')
|
||||||
|
|
||||||
|
def setBroadcastStateChanges(self, doBroadcast):
|
||||||
|
self._broadcastStateChanges = doBroadcast
|
||||||
|
def getStateChangeEvent(self):
|
||||||
|
# if setBroadcastStateChanges(True), this event will be sent through
|
||||||
|
# the messenger on every state change. The new and old states are
|
||||||
|
# accessible as self.oldState and self.newState, and the transition
|
||||||
|
# functions will already have been called.
|
||||||
|
return 'FSM-%s-%s-stateChange' % (self._serialNum, self.name)
|
||||||
|
|
||||||
def getCurrentOrNextState(self):
|
def getCurrentOrNextState(self):
|
||||||
# Returns the current state if we are in a state now, or the
|
# Returns the current state if we are in a state now, or the
|
||||||
# state we are transitioning into if we are currently within
|
# state we are transitioning into if we are currently within
|
||||||
@ -356,6 +370,9 @@ class FSM(DirectObject.DirectObject):
|
|||||||
del self.newState
|
del self.newState
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
if self._broadcastStateChanges:
|
||||||
|
messenger.send(self.getStateChangeEvent())
|
||||||
|
|
||||||
self.state = newState
|
self.state = newState
|
||||||
del self.oldState
|
del self.oldState
|
||||||
del self.newState
|
del self.newState
|
||||||
|
Loading…
x
Reference in New Issue
Block a user