예제 #1
0
    def beginBarrier(self, name, avIds, timeout, callback):
        # Begins waiting for a set of avatars.  When all avatars in
        # the list have reported back in or the callback has expired,
        # calls the indicated callback with the list of toons that
        # made it through.  There may be multiple barriers waiting
        # simultaneously on different lists of avatars, although they
        # should have different names.

        from otp.ai import Barrier
        context = self.__nextBarrierContext
        # We assume the context number is passed as a uint16.
        self.__nextBarrierContext = (self.__nextBarrierContext + 1) & 0xffff

        assert self.notify.debug('beginBarrier(%s, %s, %s, %s)' %
                                 (context, name, avIds, timeout))

        if avIds:
            barrier = Barrier.Barrier(name,
                                      self.uniqueName(name),
                                      avIds,
                                      timeout,
                                      doneFunc=PythonUtil.Functor(
                                          self.__barrierCallback, context,
                                          callback))
            self.__barriers[context] = barrier

            # Send the context number to each involved client.
            self.sendUpdate("setBarrierData", [self.__getBarrierData()])
        else:
            # No avatars; just call the callback immediately.
            callback(avIds)

        return context
예제 #2
0
 def debugCall(self, debugString=''):
     """
     If this notify is in debug mode, print the time of the
     call followed by the notifier category and
     the function call (with parameters).
     """
     if self.__debug:
         message = str(debugString)
         string = ":%s:%s \"%s\" %s" % (self.getOnlyTime(),
                                        self.__name, message,
                                        PythonUtil.traceParentCall())
         self.__log(string)
         self.__print(string)
     return 1  # to allow assert self.notify.debugCall("blah")
예제 #3
0
파일: Notifier.py 프로젝트: kralf/panda3d
 def debugCall(self, debugString=''):
     """
     If this notify is in debug mode, print the time of the
     call followed by the notifier category and
     the function call (with parameters).
     """
     if self.__debug:
         message = str(debugString)
         string = ":%s:%s \"%s\" %s"%(
             self.getOnlyTime(),
             self.__name,
             message,
             PythonUtil.traceParentCall())
         self.__log(string)
         self.__print(string)
     return 1 # to allow assert self.notify.debugCall("blah")
예제 #4
0
파일: Notifier.py 프로젝트: kralf/panda3d
    def debugStateCall(self, obj=None, fsmMemberName='fsm',
            secondaryFsm='secondaryFSM'):
        """
        If this notify is in debug mode, print the time of the
        call followed by the [fsm state] notifier category and
        the function call (with parameters).
        """
        #f.f_locals['self'].__init__.im_class.__name__
        if self.__debug:
            state = ''
            doId = ''
            if obj is not None:

                fsm=obj.__dict__.get(fsmMemberName)
                if fsm is not None:
                    stateObj = fsm.getCurrentState()
                    if stateObj is not None:
                        #state = "%s=%s"%(fsmMemberName, stateObj.getName())
                        state = stateObj.getName()

                fsm=obj.__dict__.get(secondaryFsm)
                if fsm is not None:
                    stateObj = fsm.getCurrentState()
                    if stateObj is not None:
                        #state = "%s=%s"%(fsmMemberName, stateObj.getName())
                        state = "%s, %s"%(state, stateObj.getName())

                if hasattr(obj, 'doId'):
                    doId = " doId:%s"%(obj.doId,)
            #if type(obj) == types.ClassType:
            #    name = "%s."%(obj.__class__.__name__,)
            string = ":%s:%s [%-7s] id(%s)%s %s"%(
                self.getOnlyTime(),
                self.__name,
                state,
                id(obj),
                doId,
                PythonUtil.traceParentCall())
            self.__log(string)
            self.__print(string)
        return 1 # to allow assert self.notify.debugStateCall(self)
예제 #5
0
    def setServerDelta(self, delta, timezone):
        """
        Call this method on any Notify object to globally change the
        timestamp printed for each line of all Notify objects.

        This synchronizes the timestamp with the server's known time
        of day, and also switches into the server's timezone.
        """
        delta = int(round(delta))
        Notifier.serverDelta = delta + time.timezone - timezone

        # The following call is necessary to make the output from C++
        # notify messages show the same timestamp as those generated
        # from Python-level notify messages.
        from panda3d.pandac import NotifyCategory
        NotifyCategory.setServerDelta(self.serverDelta)

        self.info(
            "Notify clock adjusted by %s (and timezone adjusted by %s hours) to synchronize with server."
            % (PythonUtil.formatElapsedSeconds(delta),
               (time.timezone - timezone) / 3600))
예제 #6
0
    def debugStateCall(self,
                       obj=None,
                       fsmMemberName='fsm',
                       secondaryFsm='secondaryFSM'):
        """
        If this notify is in debug mode, print the time of the
        call followed by the [fsm state] notifier category and
        the function call (with parameters).
        """
        #f.f_locals['self'].__init__.im_class.__name__
        if self.__debug:
            state = ''
            doId = ''
            if obj is not None:

                fsm = obj.__dict__.get(fsmMemberName)
                if fsm is not None:
                    stateObj = fsm.getCurrentState()
                    if stateObj is not None:
                        #state = "%s=%s"%(fsmMemberName, stateObj.getName())
                        state = stateObj.getName()

                fsm = obj.__dict__.get(secondaryFsm)
                if fsm is not None:
                    stateObj = fsm.getCurrentState()
                    if stateObj is not None:
                        #state = "%s=%s"%(fsmMemberName, stateObj.getName())
                        state = "%s, %s" % (state, stateObj.getName())

                if hasattr(obj, 'doId'):
                    doId = " doId:%s" % (obj.doId, )
            #if type(obj) == types.ClassType:
            #    name = "%s."%(obj.__class__.__name__,)
            string = ":%s:%s [%-7s] id(%s)%s %s" % (
                self.getOnlyTime(), self.__name, state, id(obj), doId,
                PythonUtil.traceParentCall())
            self.__log(string)
            self.__print(string)
        return 1  # to allow assert self.notify.debugStateCall(self)
예제 #7
0
 def calcTimeOfImpactOnPlane(startHeight, endHeight, startVel, accel):
     return PythonUtil.solveQuadratic(accel * .5, startVel,
                                      startHeight-endHeight)
예제 #8
0
파일: Notifier.py 프로젝트: kralf/panda3d
    def setServerDelta(self, delta, timezone):
        """
        Call this method on any Notify object to globally change the
        timestamp printed for each line of all Notify objects.

        This synchronizes the timestamp with the server's known time
        of day, and also switches into the server's timezone.
        """
        delta = int(round(delta))
        Notifier.serverDelta = delta + time.timezone - timezone

        # The following call is necessary to make the output from C++
        # notify messages show the same timestamp as those generated
        # from Python-level notify messages.
        from panda3d.pandac import NotifyCategory
        NotifyCategory.setServerDelta(self.serverDelta)

        self.info("Notify clock adjusted by %s (and timezone adjusted by %s hours) to synchronize with server." % (PythonUtil.formatElapsedSeconds(delta), (time.timezone - timezone) / 3600))
예제 #9
0
 def calcTimeOfImpactOnPlane(startHeight, endHeight, startVel, accel):
     return PythonUtil.solveQuadratic(accel * 0.5, startVel, startHeight - endHeight)