From 7183fb3b5081df54fae7e149b8d346f6e0b1cd2d Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Mon, 22 Dec 2003 23:13:54 +0000 Subject: [PATCH] changed to not use setInitialState --- direct/src/fsm/FourState.py | 42 ++++++++++++---- direct/src/fsm/FourStateAI.py | 49 +++++++++---------- direct/src/level/CutScene.py | 2 +- .../src/level/DistributedInteractiveEntity.py | 19 +++---- .../level/DistributedInteractiveEntityAI.py | 25 +++++----- 5 files changed, 76 insertions(+), 61 deletions(-) diff --git a/direct/src/fsm/FourState.py b/direct/src/fsm/FourState.py index d8e6ceb58f..a92f80efc7 100755 --- a/direct/src/fsm/FourState.py +++ b/direct/src/fsm/FourState.py @@ -41,7 +41,7 @@ class FourState: """ if __debug__: notify = DirectNotifyGlobal.directNotify.newCategory( - 'FourStateFSM') + 'FourState') def __init__(self, names, durations = [0, 1, None, 1, 1]): """ @@ -56,6 +56,10 @@ class FourState: e.g. 3: ['off', 'deactivating', 'deactive', 'activating', 'activated', ] + durations is a list of time values (floats) or None values. + + Each list must have five entries. + More Details Here is a diagram showing the where the names from the list @@ -86,7 +90,8 @@ class FourState: oposite of 'on'). """ assert(self.debugPrint("FourState(names=%s)"%(names))) - self.doLaterTask = None + self.track = None + self.stateTime = 0.0 self.names = names self.durations = durations self.states = { @@ -124,13 +129,30 @@ class FourState: ) 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): # assert(self.debugPrint("setIsOn(isOn=%s)"%(isOn,))) # pass - #def getIsOn(self): - # assert(self.debugPrint("getIsOn() returning %s"%(self.isOn,))) - # return self.stateIndex==4 + def isOn(self): + assert(self.debugPrint("isOn() returning %s (stateIndex=%s)"%(self.stateIndex==4, self.stateIndex))) + return self.stateIndex==4 def changedOnState(self, isOn): """ @@ -142,7 +164,7 @@ class FourState: def enterState0(self): assert(self.debugPrint("enter0()")) - self.stateIndex = 0 + self.enterStateN(0) def exitState0(self): assert(self.debugPrint("exit0()")) @@ -156,7 +178,7 @@ class FourState: def enterState1(self): assert(self.debugPrint("enterState1()")) - self.stateIndex = 1 + self.enterStateN(1) def exitState1(self): assert(self.debugPrint("exitState1()")) @@ -165,7 +187,7 @@ class FourState: def enterState2(self): assert(self.debugPrint("enterState2()")) - self.stateIndex = 2 + self.enterStateN(2) def exitState2(self): assert(self.debugPrint("exitState2()")) @@ -174,7 +196,7 @@ class FourState: def enterState3(self): assert(self.debugPrint("enterState3()")) - self.stateIndex = 2 + self.enterStateN(3) def exitState3(self): assert(self.debugPrint("exitState3()")) @@ -183,7 +205,7 @@ class FourState: def enterState4(self): assert(self.debugPrint("enterState4()")) - self.stateIndex = 4 + self.enterStateN(4) self.changedOnState(1) def exitState4(self): diff --git a/direct/src/fsm/FourStateAI.py b/direct/src/fsm/FourStateAI.py index fd3c3ecf94..81a8c3965f 100755 --- a/direct/src/fsm/FourStateAI.py +++ b/direct/src/fsm/FourStateAI.py @@ -41,7 +41,7 @@ class FourStateAI: """ if __debug__: notify = DirectNotifyGlobal.directNotify.newCategory( - 'FourStateFSM') + 'FourStateAI') def __init__(self, names, durations = [0, 1, None, 1, 1]): """ @@ -142,34 +142,34 @@ class FourStateAI: del self.states del self.fsm - def getInitialState(self): - assert(self.debugPrint("getInitialState() returning %s"%(self.stateIndex,))) - return self.stateIndex + def getState(self): + assert(self.debugPrint("getState() returning %s"%(self.stateIndex,))) + return [self.stateIndex] - def setInitialState(self): - assert(self.debugPrint("setInitialState()")) - self.sendUpdate('setInitialState', [self.getInitialState()]) + def sendState(self): + assert(self.debugPrint("sendState()")) + self.sendUpdate('setState', self.getState()) def setIsOn(self, isOn): assert(self.debugPrint("setIsOn(isOn=%s)"%(isOn,))) if isOn: - if self.stateIndex == 3: - self.stateIndex = 4 - self.fsm.request(self.states[self.stateIndex]) - elif self.stateIndex != 4: - self.stateIndex = 3 - self.fsm.request(self.states[self.stateIndex]) + if self.stateIndex != 4: + # ...if it's not On; request turning on: + self.fsm.request(self.states[3]) else: - if self.stateIndex == 3: - self.stateIndex = 4 - self.fsm.request(self.states[self.stateIndex]) - elif self.stateIndex == 4: - self.stateIndex = 1 - self.fsm.request(self.states[self.stateIndex]) + if self.stateIndex != 2: + # ...if it's not Off; request turning off: + self.fsm.request(self.states[1]) + #if isOn: + # nextState = (4, 3, 3, 4, None)[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): - # assert(self.debugPrint("getIsOn() returning %s"%(self.stateIndex==4,))) - # return self.stateIndex==4 + def isOn(self): + assert(self.debugPrint("isOn() returning %s (stateIndex=%s)"%(self.stateIndex==4, self.stateIndex))) + return self.stateIndex==4 def changedOnState(self, isOn): """ @@ -192,8 +192,7 @@ class FourStateAI: may easily alter the network message. """ assert(self.debugPrint("distributeStateChange()")) - self.setInitialState() - self.sendUpdate('setState', [self.stateIndex, globalClockDelta.getRealNetworkTime()]) + self.sendState() def enterStateN(self, stateIndex, nextStateIndex): assert(self.debugPrint("enterStateN(stateIndex=%s, nextStateIndex=%s)"%( @@ -218,7 +217,7 @@ class FourStateAI: def enterState0(self): assert(self.debugPrint("enter0()")) - self.stateIndex = 0 + self.enterStateN(0, 0) def exitState0(self): assert(self.debugPrint("exit0()")) diff --git a/direct/src/level/CutScene.py b/direct/src/level/CutScene.py index 20bde14257..d022978ef5 100755 --- a/direct/src/level/CutScene.py +++ b/direct/src/level/CutScene.py @@ -13,7 +13,7 @@ from ClockDelta import * import ToontownGlobals import DirectNotifyGlobal import FSM -import DistributedInteractiveEntity +#import DistributedInteractiveEntity import DelayDelete import Localizer diff --git a/direct/src/level/DistributedInteractiveEntity.py b/direct/src/level/DistributedInteractiveEntity.py index b27f382458..c254313ebb 100644 --- a/direct/src/level/DistributedInteractiveEntity.py +++ b/direct/src/level/DistributedInteractiveEntity.py @@ -79,19 +79,14 @@ class DistributedInteractiveEntity(DistributedEntity.DistributedEntity): assert(self.debugPrint("setOwnerDoId(%s)"%(ownerDoId,))) assert(not self.__dict__.has_key("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): assert(self.debugPrint("setState(%s, %d)" % (state, timestamp))) - self.fsm.request(state, [globalClockDelta.localElapsedTime(timestamp)]) + if self.isGenerated(): + self.fsm.request(state, [globalClockDelta.localElapsedTime(timestamp)]) + else: + self.initialState = state + self.initialStateTimestamp = timestamp #def __getPropNodePath(self): # assert(self.debugPrint("__getPropNodePath()")) @@ -113,7 +108,9 @@ class DistributedInteractiveEntity(DistributedEntity.DistributedEntity): # the AI server will reply with avatarExit. 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()")) self.cr.playGame.getPlace().setState('walk') diff --git a/direct/src/level/DistributedInteractiveEntityAI.py b/direct/src/level/DistributedInteractiveEntityAI.py index 6a0f6dbcc3..66a7dc7dc6 100644 --- a/direct/src/level/DistributedInteractiveEntityAI.py +++ b/direct/src/level/DistributedInteractiveEntityAI.py @@ -66,11 +66,6 @@ class DistributedInteractiveEntityAI(DistributedEntityAI.DistributedEntityAI): assert(self.debugPrint("getAvatarInteract() returning: %s"%(self.avatarId,))) return self.avatarId - def getInitialState(self): - assert(self.debugPrint("getInitialState()")) - return [self.fsm.getCurrentState().getName(), - globalClockDelta.getRealNetworkTime()] - #def getOwnerDoId(self): # assert(self.debugPrint("getOwnerDoId() returning: %s"%(self.ownerDoId,))) # return self.ownerDoId @@ -100,19 +95,21 @@ class DistributedInteractiveEntityAI(DistributedEntityAI.DistributedEntityAI): assert(self.notify.debug(" requestExit: invalid avatarId")) def getState(self): - assert(self.debugPrint("getState()")) - return [self.fsm.getCurrentState().getName(), - globalClockDelta.getRealNetworkTime()] + r = [ + self.fsm.getCurrentState().getName(), + globalClockDelta.getRealNetworkTime()] + assert(self.debugPrint("getState() returning %s"%(r,))) + return r - def d_setState(self, state): - assert(self.debugPrint("d_setState(state=%s)"%(state,))) - self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()]) + def sendState(self): + assert(self.debugPrint("sendState()")) + self.sendUpdate('setState', self.getState()) ##### off state ##### def enterOff(self): assert(self.debugPrint("enterOff()")) - #self.d_setState('off') + #self.setState('off') def exitOff(self): assert(self.debugPrint("exitOff()")) @@ -121,7 +118,7 @@ class DistributedInteractiveEntityAI(DistributedEntityAI.DistributedEntityAI): def enterAttract(self): assert(self.debugPrint("enterAttract()")) - self.d_setState('attract') + self.sendState() def exitAttract(self): assert(self.debugPrint("exitAttract()")) @@ -130,7 +127,7 @@ class DistributedInteractiveEntityAI(DistributedEntityAI.DistributedEntityAI): def enterPlaying(self): assert(self.debugPrint("enterPlaying()")) - self.d_setState('playing') + self.sendState() def exitPlaying(self): assert(self.debugPrint("exitPlaying()"))