mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
changed to not use setInitialState
This commit is contained in:
parent
ca15a720c9
commit
7183fb3b50
@ -41,7 +41,7 @@ class FourState:
|
|||||||
"""
|
"""
|
||||||
if __debug__:
|
if __debug__:
|
||||||
notify = DirectNotifyGlobal.directNotify.newCategory(
|
notify = DirectNotifyGlobal.directNotify.newCategory(
|
||||||
'FourStateFSM')
|
'FourState')
|
||||||
|
|
||||||
def __init__(self, names, durations = [0, 1, None, 1, 1]):
|
def __init__(self, names, durations = [0, 1, None, 1, 1]):
|
||||||
"""
|
"""
|
||||||
@ -56,6 +56,10 @@ class FourState:
|
|||||||
e.g. 3:
|
e.g. 3:
|
||||||
['off', 'deactivating', 'deactive', 'activating', 'activated', ]
|
['off', 'deactivating', 'deactive', 'activating', 'activated', ]
|
||||||
|
|
||||||
|
durations is a list of time values (floats) or None values.
|
||||||
|
|
||||||
|
Each list must have five entries.
|
||||||
|
|
||||||
More Details
|
More Details
|
||||||
|
|
||||||
Here is a diagram showing the where the names from the list
|
Here is a diagram showing the where the names from the list
|
||||||
@ -86,7 +90,8 @@ class FourState:
|
|||||||
oposite of 'on').
|
oposite of 'on').
|
||||||
"""
|
"""
|
||||||
assert(self.debugPrint("FourState(names=%s)"%(names)))
|
assert(self.debugPrint("FourState(names=%s)"%(names)))
|
||||||
self.doLaterTask = None
|
self.track = None
|
||||||
|
self.stateTime = 0.0
|
||||||
self.names = names
|
self.names = names
|
||||||
self.durations = durations
|
self.durations = durations
|
||||||
self.states = {
|
self.states = {
|
||||||
@ -124,13 +129,30 @@ class FourState:
|
|||||||
)
|
)
|
||||||
self.fsm.enterInitialState()
|
self.fsm.enterInitialState()
|
||||||
|
|
||||||
|
def setTrack(self, track):
|
||||||
|
assert(self.debugPrint("setTrack(track=%s)"%(track,)))
|
||||||
|
if self.track is not None:
|
||||||
|
self.track.pause()
|
||||||
|
self.track = None
|
||||||
|
if track is not None:
|
||||||
|
print "\n\nstarting", self.stateIndex, "duration", self.duration, "at", self.stateTime #*#
|
||||||
|
track.start(self.stateTime)
|
||||||
|
self.track = track
|
||||||
|
|
||||||
|
def enterStateN(self, stateIndex):
|
||||||
|
self.stateIndex = stateIndex
|
||||||
|
self.duration = self.durations[stateIndex] or 0.0
|
||||||
|
|
||||||
|
# The AI is the authority on setting the On value.
|
||||||
|
# If the client wants the state changed it needs to
|
||||||
|
# send a request to the AI.
|
||||||
#def setIsOn(self, isOn):
|
#def setIsOn(self, isOn):
|
||||||
# assert(self.debugPrint("setIsOn(isOn=%s)"%(isOn,)))
|
# assert(self.debugPrint("setIsOn(isOn=%s)"%(isOn,)))
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
#def getIsOn(self):
|
def isOn(self):
|
||||||
# assert(self.debugPrint("getIsOn() returning %s"%(self.isOn,)))
|
assert(self.debugPrint("isOn() returning %s (stateIndex=%s)"%(self.stateIndex==4, self.stateIndex)))
|
||||||
# return self.stateIndex==4
|
return self.stateIndex==4
|
||||||
|
|
||||||
def changedOnState(self, isOn):
|
def changedOnState(self, isOn):
|
||||||
"""
|
"""
|
||||||
@ -142,7 +164,7 @@ class FourState:
|
|||||||
|
|
||||||
def enterState0(self):
|
def enterState0(self):
|
||||||
assert(self.debugPrint("enter0()"))
|
assert(self.debugPrint("enter0()"))
|
||||||
self.stateIndex = 0
|
self.enterStateN(0)
|
||||||
|
|
||||||
def exitState0(self):
|
def exitState0(self):
|
||||||
assert(self.debugPrint("exit0()"))
|
assert(self.debugPrint("exit0()"))
|
||||||
@ -156,7 +178,7 @@ class FourState:
|
|||||||
|
|
||||||
def enterState1(self):
|
def enterState1(self):
|
||||||
assert(self.debugPrint("enterState1()"))
|
assert(self.debugPrint("enterState1()"))
|
||||||
self.stateIndex = 1
|
self.enterStateN(1)
|
||||||
|
|
||||||
def exitState1(self):
|
def exitState1(self):
|
||||||
assert(self.debugPrint("exitState1()"))
|
assert(self.debugPrint("exitState1()"))
|
||||||
@ -165,7 +187,7 @@ class FourState:
|
|||||||
|
|
||||||
def enterState2(self):
|
def enterState2(self):
|
||||||
assert(self.debugPrint("enterState2()"))
|
assert(self.debugPrint("enterState2()"))
|
||||||
self.stateIndex = 2
|
self.enterStateN(2)
|
||||||
|
|
||||||
def exitState2(self):
|
def exitState2(self):
|
||||||
assert(self.debugPrint("exitState2()"))
|
assert(self.debugPrint("exitState2()"))
|
||||||
@ -174,7 +196,7 @@ class FourState:
|
|||||||
|
|
||||||
def enterState3(self):
|
def enterState3(self):
|
||||||
assert(self.debugPrint("enterState3()"))
|
assert(self.debugPrint("enterState3()"))
|
||||||
self.stateIndex = 2
|
self.enterStateN(3)
|
||||||
|
|
||||||
def exitState3(self):
|
def exitState3(self):
|
||||||
assert(self.debugPrint("exitState3()"))
|
assert(self.debugPrint("exitState3()"))
|
||||||
@ -183,7 +205,7 @@ class FourState:
|
|||||||
|
|
||||||
def enterState4(self):
|
def enterState4(self):
|
||||||
assert(self.debugPrint("enterState4()"))
|
assert(self.debugPrint("enterState4()"))
|
||||||
self.stateIndex = 4
|
self.enterStateN(4)
|
||||||
self.changedOnState(1)
|
self.changedOnState(1)
|
||||||
|
|
||||||
def exitState4(self):
|
def exitState4(self):
|
||||||
|
@ -41,7 +41,7 @@ class FourStateAI:
|
|||||||
"""
|
"""
|
||||||
if __debug__:
|
if __debug__:
|
||||||
notify = DirectNotifyGlobal.directNotify.newCategory(
|
notify = DirectNotifyGlobal.directNotify.newCategory(
|
||||||
'FourStateFSM')
|
'FourStateAI')
|
||||||
|
|
||||||
def __init__(self, names, durations = [0, 1, None, 1, 1]):
|
def __init__(self, names, durations = [0, 1, None, 1, 1]):
|
||||||
"""
|
"""
|
||||||
@ -142,34 +142,34 @@ class FourStateAI:
|
|||||||
del self.states
|
del self.states
|
||||||
del self.fsm
|
del self.fsm
|
||||||
|
|
||||||
def getInitialState(self):
|
def getState(self):
|
||||||
assert(self.debugPrint("getInitialState() returning %s"%(self.stateIndex,)))
|
assert(self.debugPrint("getState() returning %s"%(self.stateIndex,)))
|
||||||
return self.stateIndex
|
return [self.stateIndex]
|
||||||
|
|
||||||
def setInitialState(self):
|
def sendState(self):
|
||||||
assert(self.debugPrint("setInitialState()"))
|
assert(self.debugPrint("sendState()"))
|
||||||
self.sendUpdate('setInitialState', [self.getInitialState()])
|
self.sendUpdate('setState', self.getState())
|
||||||
|
|
||||||
def setIsOn(self, isOn):
|
def setIsOn(self, isOn):
|
||||||
assert(self.debugPrint("setIsOn(isOn=%s)"%(isOn,)))
|
assert(self.debugPrint("setIsOn(isOn=%s)"%(isOn,)))
|
||||||
if isOn:
|
if isOn:
|
||||||
if self.stateIndex == 3:
|
if self.stateIndex != 4:
|
||||||
self.stateIndex = 4
|
# ...if it's not On; request turning on:
|
||||||
self.fsm.request(self.states[self.stateIndex])
|
self.fsm.request(self.states[3])
|
||||||
elif self.stateIndex != 4:
|
|
||||||
self.stateIndex = 3
|
|
||||||
self.fsm.request(self.states[self.stateIndex])
|
|
||||||
else:
|
else:
|
||||||
if self.stateIndex == 3:
|
if self.stateIndex != 2:
|
||||||
self.stateIndex = 4
|
# ...if it's not Off; request turning off:
|
||||||
self.fsm.request(self.states[self.stateIndex])
|
self.fsm.request(self.states[1])
|
||||||
elif self.stateIndex == 4:
|
#if isOn:
|
||||||
self.stateIndex = 1
|
# nextState = (4, 3, 3, 4, None)[self.stateIndex]
|
||||||
self.fsm.request(self.states[self.stateIndex])
|
#else:
|
||||||
|
# nextState = (2, 2, None, 1, 1)[self.stateIndex]
|
||||||
|
#if nextState is not None:
|
||||||
|
# self.fsm.request(self.states[nextState])
|
||||||
|
|
||||||
#def getIsOn(self):
|
def isOn(self):
|
||||||
# assert(self.debugPrint("getIsOn() returning %s"%(self.stateIndex==4,)))
|
assert(self.debugPrint("isOn() returning %s (stateIndex=%s)"%(self.stateIndex==4, self.stateIndex)))
|
||||||
# return self.stateIndex==4
|
return self.stateIndex==4
|
||||||
|
|
||||||
def changedOnState(self, isOn):
|
def changedOnState(self, isOn):
|
||||||
"""
|
"""
|
||||||
@ -192,8 +192,7 @@ class FourStateAI:
|
|||||||
may easily alter the network message.
|
may easily alter the network message.
|
||||||
"""
|
"""
|
||||||
assert(self.debugPrint("distributeStateChange()"))
|
assert(self.debugPrint("distributeStateChange()"))
|
||||||
self.setInitialState()
|
self.sendState()
|
||||||
self.sendUpdate('setState', [self.stateIndex, globalClockDelta.getRealNetworkTime()])
|
|
||||||
|
|
||||||
def enterStateN(self, stateIndex, nextStateIndex):
|
def enterStateN(self, stateIndex, nextStateIndex):
|
||||||
assert(self.debugPrint("enterStateN(stateIndex=%s, nextStateIndex=%s)"%(
|
assert(self.debugPrint("enterStateN(stateIndex=%s, nextStateIndex=%s)"%(
|
||||||
@ -218,7 +217,7 @@ class FourStateAI:
|
|||||||
|
|
||||||
def enterState0(self):
|
def enterState0(self):
|
||||||
assert(self.debugPrint("enter0()"))
|
assert(self.debugPrint("enter0()"))
|
||||||
self.stateIndex = 0
|
self.enterStateN(0, 0)
|
||||||
|
|
||||||
def exitState0(self):
|
def exitState0(self):
|
||||||
assert(self.debugPrint("exit0()"))
|
assert(self.debugPrint("exit0()"))
|
||||||
|
@ -13,7 +13,7 @@ from ClockDelta import *
|
|||||||
import ToontownGlobals
|
import ToontownGlobals
|
||||||
import DirectNotifyGlobal
|
import DirectNotifyGlobal
|
||||||
import FSM
|
import FSM
|
||||||
import DistributedInteractiveEntity
|
#import DistributedInteractiveEntity
|
||||||
import DelayDelete
|
import DelayDelete
|
||||||
import Localizer
|
import Localizer
|
||||||
|
|
||||||
|
@ -80,18 +80,13 @@ class DistributedInteractiveEntity(DistributedEntity.DistributedEntity):
|
|||||||
assert(not self.__dict__.has_key("ownerDoId"))
|
assert(not self.__dict__.has_key("ownerDoId"))
|
||||||
self.ownerDoId=ownerDoId
|
self.ownerDoId=ownerDoId
|
||||||
|
|
||||||
def setInitialState(self, state, timestamp):
|
|
||||||
"""
|
|
||||||
required dc field.
|
|
||||||
"""
|
|
||||||
assert(self.debugPrint("setInitialState(%s, %d)" % (state, timestamp)))
|
|
||||||
assert(not self.__dict__.has_key("initialState"))
|
|
||||||
self.initialState = state
|
|
||||||
self.initialStateTimestamp = timestamp
|
|
||||||
|
|
||||||
def setState(self, state, timestamp):
|
def setState(self, state, timestamp):
|
||||||
assert(self.debugPrint("setState(%s, %d)" % (state, timestamp)))
|
assert(self.debugPrint("setState(%s, %d)" % (state, timestamp)))
|
||||||
|
if self.isGenerated():
|
||||||
self.fsm.request(state, [globalClockDelta.localElapsedTime(timestamp)])
|
self.fsm.request(state, [globalClockDelta.localElapsedTime(timestamp)])
|
||||||
|
else:
|
||||||
|
self.initialState = state
|
||||||
|
self.initialStateTimestamp = timestamp
|
||||||
|
|
||||||
#def __getPropNodePath(self):
|
#def __getPropNodePath(self):
|
||||||
# assert(self.debugPrint("__getPropNodePath()"))
|
# assert(self.debugPrint("__getPropNodePath()"))
|
||||||
@ -113,7 +108,9 @@ class DistributedInteractiveEntity(DistributedEntity.DistributedEntity):
|
|||||||
# the AI server will reply with avatarExit.
|
# the AI server will reply with avatarExit.
|
||||||
|
|
||||||
def rejectInteract(self):
|
def rejectInteract(self):
|
||||||
"""Server doesn't let the avatar interact with prop"""
|
"""
|
||||||
|
Server doesn't let the avatar interact with prop.
|
||||||
|
"""
|
||||||
assert(self.debugPrint("rejectInteract()"))
|
assert(self.debugPrint("rejectInteract()"))
|
||||||
self.cr.playGame.getPlace().setState('walk')
|
self.cr.playGame.getPlace().setState('walk')
|
||||||
|
|
||||||
|
@ -66,11 +66,6 @@ class DistributedInteractiveEntityAI(DistributedEntityAI.DistributedEntityAI):
|
|||||||
assert(self.debugPrint("getAvatarInteract() returning: %s"%(self.avatarId,)))
|
assert(self.debugPrint("getAvatarInteract() returning: %s"%(self.avatarId,)))
|
||||||
return self.avatarId
|
return self.avatarId
|
||||||
|
|
||||||
def getInitialState(self):
|
|
||||||
assert(self.debugPrint("getInitialState()"))
|
|
||||||
return [self.fsm.getCurrentState().getName(),
|
|
||||||
globalClockDelta.getRealNetworkTime()]
|
|
||||||
|
|
||||||
#def getOwnerDoId(self):
|
#def getOwnerDoId(self):
|
||||||
# assert(self.debugPrint("getOwnerDoId() returning: %s"%(self.ownerDoId,)))
|
# assert(self.debugPrint("getOwnerDoId() returning: %s"%(self.ownerDoId,)))
|
||||||
# return self.ownerDoId
|
# return self.ownerDoId
|
||||||
@ -100,19 +95,21 @@ class DistributedInteractiveEntityAI(DistributedEntityAI.DistributedEntityAI):
|
|||||||
assert(self.notify.debug(" requestExit: invalid avatarId"))
|
assert(self.notify.debug(" requestExit: invalid avatarId"))
|
||||||
|
|
||||||
def getState(self):
|
def getState(self):
|
||||||
assert(self.debugPrint("getState()"))
|
r = [
|
||||||
return [self.fsm.getCurrentState().getName(),
|
self.fsm.getCurrentState().getName(),
|
||||||
globalClockDelta.getRealNetworkTime()]
|
globalClockDelta.getRealNetworkTime()]
|
||||||
|
assert(self.debugPrint("getState() returning %s"%(r,)))
|
||||||
|
return r
|
||||||
|
|
||||||
def d_setState(self, state):
|
def sendState(self):
|
||||||
assert(self.debugPrint("d_setState(state=%s)"%(state,)))
|
assert(self.debugPrint("sendState()"))
|
||||||
self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()])
|
self.sendUpdate('setState', self.getState())
|
||||||
|
|
||||||
##### off state #####
|
##### off state #####
|
||||||
|
|
||||||
def enterOff(self):
|
def enterOff(self):
|
||||||
assert(self.debugPrint("enterOff()"))
|
assert(self.debugPrint("enterOff()"))
|
||||||
#self.d_setState('off')
|
#self.setState('off')
|
||||||
|
|
||||||
def exitOff(self):
|
def exitOff(self):
|
||||||
assert(self.debugPrint("exitOff()"))
|
assert(self.debugPrint("exitOff()"))
|
||||||
@ -121,7 +118,7 @@ class DistributedInteractiveEntityAI(DistributedEntityAI.DistributedEntityAI):
|
|||||||
|
|
||||||
def enterAttract(self):
|
def enterAttract(self):
|
||||||
assert(self.debugPrint("enterAttract()"))
|
assert(self.debugPrint("enterAttract()"))
|
||||||
self.d_setState('attract')
|
self.sendState()
|
||||||
|
|
||||||
def exitAttract(self):
|
def exitAttract(self):
|
||||||
assert(self.debugPrint("exitAttract()"))
|
assert(self.debugPrint("exitAttract()"))
|
||||||
@ -130,7 +127,7 @@ class DistributedInteractiveEntityAI(DistributedEntityAI.DistributedEntityAI):
|
|||||||
|
|
||||||
def enterPlaying(self):
|
def enterPlaying(self):
|
||||||
assert(self.debugPrint("enterPlaying()"))
|
assert(self.debugPrint("enterPlaying()"))
|
||||||
self.d_setState('playing')
|
self.sendState()
|
||||||
|
|
||||||
def exitPlaying(self):
|
def exitPlaying(self):
|
||||||
assert(self.debugPrint("exitPlaying()"))
|
assert(self.debugPrint("exitPlaying()"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user