mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-17 20:23:47 -04:00
other->source, push initial state on subscription
This commit is contained in:
parent
9581322f66
commit
26075761d7
@ -25,6 +25,7 @@ class PushesStateChanges:
|
|||||||
|
|
||||||
def _addSubscription(self, subscriber):
|
def _addSubscription(self, subscriber):
|
||||||
self._subscribers.add(subscriber)
|
self._subscribers.add(subscriber)
|
||||||
|
subscriber._recvStatePush(self)
|
||||||
|
|
||||||
def _removeSubscription(self, subscriber):
|
def _removeSubscription(self, subscriber):
|
||||||
self._subscribers.remove(subscriber)
|
self._subscribers.remove(subscriber)
|
||||||
@ -48,26 +49,33 @@ if __debug__:
|
|||||||
|
|
||||||
class ReceivesStateChanges:
|
class ReceivesStateChanges:
|
||||||
# base class for objects that subscribe to state changes from PushesStateChanges objects
|
# base class for objects that subscribe to state changes from PushesStateChanges objects
|
||||||
def __init__(self, other):
|
def __init__(self, source):
|
||||||
self._other = None
|
self._source = None
|
||||||
self._subscribeTo(other)
|
self._initSource = source
|
||||||
|
|
||||||
|
def _finishInit(self):
|
||||||
|
# initialization is split across two functions to allow objects that derive from this
|
||||||
|
# class to set everything up so that they can respond appropriately to the initial
|
||||||
|
# state push from the state source
|
||||||
|
self._subscribeTo(self._initSource)
|
||||||
|
del self._initSource
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
self._unsubscribe()
|
self._unsubscribe()
|
||||||
del self._other
|
del self._source
|
||||||
|
|
||||||
def _subscribeTo(self, other):
|
def _subscribeTo(self, source):
|
||||||
self._unsubscribe()
|
self._unsubscribe()
|
||||||
self._other = other
|
self._source = source
|
||||||
if self._other:
|
if self._source:
|
||||||
self._other._addSubscription(self)
|
self._source._addSubscription(self)
|
||||||
|
|
||||||
def _unsubscribe(self):
|
def _unsubscribe(self):
|
||||||
if self._other:
|
if self._source:
|
||||||
self._other._removeSubscription(self)
|
self._source._removeSubscription(self)
|
||||||
self._other = None
|
self._source = None
|
||||||
|
|
||||||
def _recvStatePush(self, other):
|
def _recvStatePush(self, source):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
@ -94,17 +102,18 @@ if __debug__:
|
|||||||
|
|
||||||
class StateChangeNode(PushesStateChanges, ReceivesStateChanges):
|
class StateChangeNode(PushesStateChanges, ReceivesStateChanges):
|
||||||
# base class that can be used to create a state-change notification chain
|
# base class that can be used to create a state-change notification chain
|
||||||
def __init__(self, other):
|
def __init__(self, source):
|
||||||
ReceivesStateChanges.__init__(self, other)
|
ReceivesStateChanges.__init__(self, source)
|
||||||
PushesStateChanges.__init__(self, other.getState())
|
PushesStateChanges.__init__(self, source.getState())
|
||||||
|
ReceivesStateChanges._finishInit(self)
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
PushesStateChanges.destroy(self)
|
PushesStateChanges.destroy(self)
|
||||||
ReceivesStateChanges.destroy(self)
|
ReceivesStateChanges.destroy(self)
|
||||||
|
|
||||||
def _recvStatePush(self, other):
|
def _recvStatePush(self, source):
|
||||||
# got a state push, apply new state to self
|
# got a state push, apply new state to self
|
||||||
self._handlePotentialStateChange(other._value)
|
self._handlePotentialStateChange(source._value)
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
sv = StateVar(0)
|
sv = StateVar(0)
|
||||||
@ -134,9 +143,9 @@ if __debug__:
|
|||||||
|
|
||||||
class FunctionCall(StateChangeNode):
|
class FunctionCall(StateChangeNode):
|
||||||
# calls func with new state whenever state changes
|
# calls func with new state whenever state changes
|
||||||
def __init__(self, other, func):
|
def __init__(self, source, func):
|
||||||
self._func = func
|
self._func = func
|
||||||
StateChangeNode.__init__(self, other)
|
StateChangeNode.__init__(self, source)
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
StateChangeNode.destroy(self)
|
StateChangeNode.destroy(self)
|
||||||
@ -167,10 +176,10 @@ if __debug__:
|
|||||||
|
|
||||||
class EnterExit(StateChangeNode):
|
class EnterExit(StateChangeNode):
|
||||||
# call enterFunc when our state becomes true, exitFunc when it becomes false
|
# call enterFunc when our state becomes true, exitFunc when it becomes false
|
||||||
def __init__(self, other, enterFunc, exitFunc):
|
def __init__(self, source, enterFunc, exitFunc):
|
||||||
self._enterFunc = enterFunc
|
self._enterFunc = enterFunc
|
||||||
self._exitFunc = exitFunc
|
self._exitFunc = exitFunc
|
||||||
StateChangeNode.__init__(self, other)
|
StateChangeNode.__init__(self, source)
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
StateChangeNode.destroy(self)
|
StateChangeNode.destroy(self)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user