def run(self):
        t = self.globalClock.getFrameTime()
        timeDelta = t - self.globalClock.getRealTime()
        self.globalClock.setRealTime(t)
        messenger.send('resetClock', [timeDelta])
        if self.resumeFunc != None:
            self.resumeFunc()
        if self.stepping:
            self.step()
        else:
            self.running = True
            while self.running:
                try:
                    if len(self._frameProfileQueue):
                        numFrames, session, callback = self._frameProfileQueue.pop(
                        )

                        def _profileFunc(numFrames=numFrames):
                            self._doProfiledFrames(numFrames)

                        session.setFunc(_profileFunc)
                        session.run()
                        _profileFunc = None
                        if callback:
                            callback()
                        session.release()
                    else:
                        self.step()
                except KeyboardInterrupt:
                    self.stop()
                except SystemExit:
                    self.stop()
                    raise
                except IOError as ioError:
                    code, message = self._unpackIOError(ioError)
                    if code == 4:
                        self.stop()
                    else:
                        raise
                except Exception as e:
                    if self.extendedExceptions:
                        self.stop()
                        print_exc_plus()
                    else:
                        if ExceptionVarDump.wantStackDumpLog and ExceptionVarDump.dumpOnExceptionInit:
                            ExceptionVarDump._varDump__print(e)
                        raise
                except:
                    if self.extendedExceptions:
                        self.stop()
                        print_exc_plus()
                    else:
                        raise

        self.mgr.stopThreads()
        return
Esempio n. 2
0
    def run(self):
        t = self.globalClock.getFrameTime()
        timeDelta = t - self.globalClock.getRealTime()
        self.globalClock.setRealTime(t)
        messenger.send('resetClock', [timeDelta])
        if self.resumeFunc != None:
            self.resumeFunc()
        if self.stepping:
            self.step()
        else:
            self.running = True
            while self.running:
                try:
                    if len(self._frameProfileQueue):
                        numFrames, session, callback = self._frameProfileQueue.pop()

                        def _profileFunc(numFrames = numFrames):
                            self._doProfiledFrames(numFrames)

                        session.setFunc(_profileFunc)
                        session.run()
                        _profileFunc = None
                        if callback:
                            callback()
                        session.release()
                    else:
                        self.step()
                except KeyboardInterrupt:
                    self.stop()
                except IOError as ioError:
                    code, message = self._unpackIOError(ioError)
                    if code == 4:
                        self.stop()
                    else:
                        raise
                except Exception as e:
                    if self.extendedExceptions:
                        self.stop()
                        print_exc_plus()
                    else:
                        if ExceptionVarDump.wantStackDumpLog and ExceptionVarDump.dumpOnExceptionInit:
                            ExceptionVarDump._varDump__print(e)
                        raise
                except:
                    if self.extendedExceptions:
                        self.stop()
                        print_exc_plus()
                    else:
                        raise

        self.mgr.stopThreads()
        return
Esempio n. 3
0
 def __init__(self):
     self.config = getConfigShowbase()
     __builtins__['__dev__'] = self.config.GetBool('want-dev', 0)
     logStackDump = (self.config.GetBool('log-stack-dump', (not __dev__))
                     or self.config.GetBool('ai-log-stack-dump',
                                            (not __dev__)))
     uploadStackDump = self.config.GetBool('upload-stack-dump', 0)
     if logStackDump or uploadStackDump:
         ExceptionVarDump.install(logStackDump, uploadStackDump)
     if self.config.GetBool('use-vfs', 1):
         vfs = VirtualFileSystem.getGlobalPtr()
     else:
         vfs = None
     self.wantTk = self.config.GetBool('want-tk', 0)
     self.AISleep = self.config.GetFloat('ai-sleep', 0.04)
     self.AIRunningNetYield = self.config.GetBool('ai-running-net-yield', 0)
     self.AIForceSleep = self.config.GetBool('ai-force-sleep', 0)
     self.eventMgr = eventMgr
     self.messenger = messenger
     self.bboard = bulletinBoard
     self.taskMgr = taskMgr
     Task.TaskManager.taskTimerVerbose = self.config.GetBool(
         'task-timer-verbose', 0)
     Task.TaskManager.extendedExceptions = self.config.GetBool(
         'extended-exceptions', 0)
     self.sfxManagerList = None
     self.musicManager = None
     self.jobMgr = jobMgr
     self.hidden = NodePath('hidden')
     self.graphicsEngine = GraphicsEngine()
     globalClock = ClockObject.getGlobalClock()
     self.trueClock = TrueClock.getGlobalPtr()
     globalClock.setRealTime(self.trueClock.getShortTime())
     globalClock.setAverageFrameRateInterval(30.0)
     globalClock.tick()
     taskMgr.globalClock = globalClock
     __builtins__['ostream'] = Notify.out()
     __builtins__['globalClock'] = globalClock
     __builtins__['vfs'] = vfs
     __builtins__['hidden'] = self.hidden
     AIBase.notify.info('__dev__ == %s' % __dev__)
     PythonUtil.recordFunctorCreationStacks()
     __builtins__['wantTestObject'] = self.config.GetBool(
         'want-test-object', 0)
     self.wantStats = self.config.GetBool('want-pstats', 0)
     Task.TaskManager.pStatsTasks = self.config.GetBool('pstats-tasks', 0)
     taskMgr.resumeFunc = PStatClient.resumeAfterPause
     defaultValue = 1
     if __dev__:
         defaultValue = 0
     wantFakeTextures = self.config.GetBool('want-fake-textures-ai',
                                            defaultValue)
     if wantFakeTextures:
         loadPrcFileData('aibase', 'textures-header-only 1')
     self.wantPets = self.config.GetBool('want-pets', 1)
     if self.wantPets:
         if game.name == 'toontown':
             from toontown.pets import PetConstants
             self.petMoodTimescale = self.config.GetFloat(
                 'pet-mood-timescale', 1.0)
             self.petMoodDriftPeriod = self.config.GetFloat(
                 'pet-mood-drift-period', PetConstants.MoodDriftPeriod)
             self.petThinkPeriod = self.config.GetFloat(
                 'pet-think-period', PetConstants.ThinkPeriod)
             self.petMovePeriod = self.config.GetFloat(
                 'pet-move-period', PetConstants.MovePeriod)
             self.petPosBroadcastPeriod = self.config.GetFloat(
                 'pet-pos-broadcast-period',
                 PetConstants.PosBroadcastPeriod)
     self.wantBingo = self.config.GetBool('want-fish-bingo', 1)
     self.wantKarts = self.config.GetBool('wantKarts', 1)
     self.newDBRequestGen = self.config.GetBool(
         'new-database-request-generate', 1)
     self.waitShardDelete = self.config.GetBool('wait-shard-delete', 1)
     self.blinkTrolley = self.config.GetBool('blink-trolley', 0)
     self.fakeDistrictPopulations = self.config.GetBool(
         'fake-district-populations', 0)
     self.wantSwitchboard = self.config.GetBool('want-switchboard', 0)
     self.wantSwitchboardHacks = self.config.GetBool(
         'want-switchboard-hacks', 0)
     self.GEMdemoWhisperRecipientDoid = self.config.GetBool(
         'gem-demo-whisper-recipient-doid', 0)
     self.sqlAvailable = self.config.GetBool('sql-available', 1)
     self.backups = BackupManager.BackupManager(filepath='backups',
                                                extension='.bu')
     self.createStats()
     self.restart()
     return
Esempio n. 4
0
 def __init__(self):
     self.config = getConfigShowbase()
     __builtins__['__dev__'] = self.config.GetBool('want-dev', 0)
     if not self.config.GetBool('log-stack-dump', not __dev__):
         pass
     logStackDump = self.config.GetBool('ai-log-stack-dump', not __dev__)
     uploadStackDump = self.config.GetBool('upload-stack-dump', 0)
     if logStackDump or uploadStackDump:
         ExceptionVarDump.install(logStackDump, uploadStackDump)
     
     if self.config.GetBool('use-vfs', 1):
         vfs = VirtualFileSystem.getGlobalPtr()
     else:
         vfs = None
     self.wantTk = self.config.GetBool('want-tk', 0)
     self.AISleep = self.config.GetFloat('ai-sleep', 0.040000000000000001)
     self.AIRunningNetYield = self.config.GetBool('ai-running-net-yield', 0)
     self.AIForceSleep = self.config.GetBool('ai-force-sleep', 0)
     self.eventMgr = eventMgr
     self.messenger = messenger
     self.bboard = bulletinBoard
     self.taskMgr = taskMgr
     Task.TaskManager.taskTimerVerbose = self.config.GetBool('task-timer-verbose', 0)
     Task.TaskManager.extendedExceptions = self.config.GetBool('extended-exceptions', 0)
     self.sfxManagerList = None
     self.musicManager = None
     self.jobMgr = jobMgr
     self.hidden = NodePath('hidden')
     self.graphicsEngine = GraphicsEngine()
     globalClock = ClockObject.getGlobalClock()
     self.trueClock = TrueClock.getGlobalPtr()
     globalClock.setRealTime(self.trueClock.getShortTime())
     globalClock.setAverageFrameRateInterval(30.0)
     globalClock.tick()
     taskMgr.globalClock = globalClock
     __builtins__['ostream'] = Notify.out()
     __builtins__['globalClock'] = globalClock
     __builtins__['vfs'] = vfs
     __builtins__['hidden'] = self.hidden
     AIBase.notify.info('__dev__ == %s' % __dev__)
     PythonUtil.recordFunctorCreationStacks()
     __builtins__['wantTestObject'] = self.config.GetBool('want-test-object', 0)
     self.wantStats = self.config.GetBool('want-pstats', 0)
     Task.TaskManager.pStatsTasks = self.config.GetBool('pstats-tasks', 0)
     taskMgr.resumeFunc = PStatClient.resumeAfterPause
     defaultValue = 1
     if __dev__:
         defaultValue = 0
     
     wantFakeTextures = self.config.GetBool('want-fake-textures-ai', defaultValue)
     if wantFakeTextures:
         loadPrcFileData('aibase', 'textures-header-only 1')
     
     self.wantPets = self.config.GetBool('want-pets', 1)
     if self.wantPets:
         if game.name == 'toontown':
             PetConstants = PetConstants
             import toontown.pets
             self.petMoodTimescale = self.config.GetFloat('pet-mood-timescale', 1.0)
             self.petMoodDriftPeriod = self.config.GetFloat('pet-mood-drift-period', PetConstants.MoodDriftPeriod)
             self.petThinkPeriod = self.config.GetFloat('pet-think-period', PetConstants.ThinkPeriod)
             self.petMovePeriod = self.config.GetFloat('pet-move-period', PetConstants.MovePeriod)
             self.petPosBroadcastPeriod = self.config.GetFloat('pet-pos-broadcast-period', PetConstants.PosBroadcastPeriod)
         
     
     self.wantBingo = self.config.GetBool('want-fish-bingo', 1)
     self.wantKarts = self.config.GetBool('wantKarts', 1)
     self.newDBRequestGen = self.config.GetBool('new-database-request-generate', 1)
     self.waitShardDelete = self.config.GetBool('wait-shard-delete', 1)
     self.blinkTrolley = self.config.GetBool('blink-trolley', 0)
     self.fakeDistrictPopulations = self.config.GetBool('fake-district-populations', 0)
     self.wantSwitchboard = self.config.GetBool('want-switchboard', 0)
     self.wantSwitchboardHacks = self.config.GetBool('want-switchboard-hacks', 0)
     self.GEMdemoWhisperRecipientDoid = self.config.GetBool('gem-demo-whisper-recipient-doid', 0)
     self.sqlAvailable = self.config.GetBool('sql-available', 1)
     self.createStats()
     self.restart()
Esempio n. 5
0
    def run(self):
        """Starts the task manager running.  Does not return until an
        exception is encountered (including KeyboardInterrupt). """

        if PandaSystem.getPlatform() == 'emscripten':
            return

        # Set the clock to have last frame's time in case we were
        # Paused at the prompt for a long time
        t = self.globalClock.getFrameTime()
        timeDelta = t - self.globalClock.getRealTime()
        self.globalClock.setRealTime(t)
        messenger.send("resetClock", [timeDelta])

        if self.resumeFunc is not None:
            self.resumeFunc()

        if self.stepping:
            self.step()
        else:
            self.running = True
            while self.running:
                try:
                    if len(self._frameProfileQueue) > 0:
                        numFrames, session, callback = self._frameProfileQueue.pop(0)
                        def _profileFunc(numFrames=numFrames):
                            self._doProfiledFrames(numFrames)
                        session.setFunc(_profileFunc)
                        session.run()
                        _profileFunc = None
                        if callback:
                            callback()
                        session.release()
                    else:
                        self.step()
                except KeyboardInterrupt:
                    self.stop()
                except SystemExit:
                    self.stop()
                    raise
                except IOError as ioError:
                    code, message = self._unpackIOError(ioError)
                    # Since upgrading to Python 2.4.1, pausing the execution
                    # often gives this IOError during the sleep function:
                    #     IOError: [Errno 4] Interrupted function call
                    # So, let's just handle that specific exception and stop.
                    # All other IOErrors should still get raised.
                    # Only problem: legit IOError 4s will be obfuscated.
                    if code == 4:
                        self.stop()
                    else:
                        raise
                except Exception as e:
                    if self.extendedExceptions:
                        self.stop()
                        print_exc_plus()
                    else:
                        from direct.showbase import ExceptionVarDump
                        if ExceptionVarDump.wantStackDumpLog and \
                           ExceptionVarDump.dumpOnExceptionInit:
                            ExceptionVarDump._varDump__print(e)
                        raise
                except:
                    if self.extendedExceptions:
                        self.stop()
                        print_exc_plus()
                    else:
                        raise

        self.mgr.stopThreads()
Esempio n. 6
0
def install():
    # make sure DIRECT print func is installed
    ExceptionVarDump.install()
    # and hook up to it
    ExceptionVarDump.setOutputFunc(_doPrint)
Esempio n. 7
0
    def run(self):
        """Starts the task manager running.  Does not return until an
        exception is encountered (including KeyboardInterrupt). """

        if PandaSystem.getPlatform() == 'emscripten':
            return

        # Set the clock to have last frame's time in case we were
        # Paused at the prompt for a long time
        t = self.globalClock.getFrameTime()
        timeDelta = t - self.globalClock.getRealTime()
        self.globalClock.setRealTime(t)
        messenger.send("resetClock", [timeDelta])

        if self.resumeFunc != None:
            self.resumeFunc()

        if self.stepping:
            self.step()
        else:
            self.running = True
            while self.running:
                try:
                    if len(self._frameProfileQueue):
                        numFrames, session, callback = self._frameProfileQueue.pop()
                        def _profileFunc(numFrames=numFrames):
                            self._doProfiledFrames(numFrames)
                        session.setFunc(_profileFunc)
                        session.run()
                        _profileFunc = None
                        if callback:
                            callback()
                        session.release()
                    else:
                        self.step()
                except KeyboardInterrupt:
                    self.stop()
                except SystemExit:
                    self.stop()
                    raise
                except IOError as ioError:
                    code, message = self._unpackIOError(ioError)
                    # Since upgrading to Python 2.4.1, pausing the execution
                    # often gives this IOError during the sleep function:
                    #     IOError: [Errno 4] Interrupted function call
                    # So, let's just handle that specific exception and stop.
                    # All other IOErrors should still get raised.
                    # Only problem: legit IOError 4s will be obfuscated.
                    if code == 4:
                        self.stop()
                    else:
                        raise
                except Exception as e:
                    if self.extendedExceptions:
                        self.stop()
                        print_exc_plus()
                    else:
                        if (ExceptionVarDump.wantStackDumpLog and
                            ExceptionVarDump.dumpOnExceptionInit):
                            ExceptionVarDump._varDump__print(e)
                        raise
                except:
                    if self.extendedExceptions:
                        self.stop()
                        print_exc_plus()
                    else:
                        raise

        self.mgr.stopThreads()
Esempio n. 8
0
    def __init__(self):
        # Get the dconfig object
        self.config = getConfigShowbase()
        __builtins__["__dev__"] = self.config.GetBool('want-dev', 0)
        if self.config.GetBool('want-variable-dump', 0):
            ExceptionVarDump.install()

        logStackDump = (self.config.GetBool('log-stack-dump', (not __dev__))
                        or self.config.GetBool('ai-log-stack-dump',
                                               (not __dev__)))
        uploadStackDump = self.config.GetBool('upload-stack-dump', 0)
        if logStackDump or uploadStackDump:
            ExceptionVarDump.install(logStackDump, uploadStackDump)

        if self.config.GetBool('use-vfs', 1):
            vfs = VirtualFileSystem.getGlobalPtr()
        else:
            vfs = None

        # Store dconfig variables
        self.wantTk = self.config.GetBool('want-tk', 0)

        # How long should the AI sleep between frames to keep CPU usage down
        self.AISleep = self.config.GetFloat('ai-sleep', 0.04)
        self.AIRunningNetYield = self.config.GetBool('ai-running-net-yield', 0)
        self.AIForceSleep = self.config.GetBool('ai-force-sleep', 0)
        self.eventMgr = eventMgr
        self.messenger = messenger
        self.bboard = bulletinBoard

        self.taskMgr = taskMgr
        Task.TaskManager.taskTimerVerbose = self.config.GetBool(
            'task-timer-verbose', 0)
        Task.TaskManager.extendedExceptions = self.config.GetBool(
            'extended-exceptions', 0)

        self.sfxManagerList = None
        self.musicManager = None
        self.jobMgr = jobMgr

        self.hidden = NodePath('hidden')
        # each zone has its own render
        #self.render = NodePath('render')

        # This graphics engine is not intended to ever draw anything, it
        # advanced clocks and clears pstats state, just like on the client.
        self.graphicsEngine = GraphicsEngine()

        # Get a pointer to Panda's global ClockObject, used for
        # synchronizing events between Python and C.
        # object is exactly in sync with the TrueClock.
        globalClock = ClockObject.getGlobalClock()

        # Since we have already started up a TaskManager, and probably
        # a number of tasks; and since the TaskManager had to use the
        # TrueClock to tell time until this moment, make sure the
        # globalClock
        self.trueClock = TrueClock.getGlobalPtr()
        globalClock.setRealTime(self.trueClock.getShortTime())
        # set the amount of time used to compute average frame rate
        globalClock.setAverageFrameRateInterval(30.)
        globalClock.tick()

        # Now we can make the TaskManager start using the new globalClock.
        taskMgr.globalClock = globalClock

        __builtins__["ostream"] = Notify.out()
        __builtins__["globalClock"] = globalClock
        __builtins__["vfs"] = vfs
        __builtins__["hidden"] = self.hidden
        #__builtins__["render"] = self.render

        AIBase.notify.info('__dev__ == %s' % __dev__)

        # set up recording of Functor creation stacks in __dev__
        PythonUtil.recordFunctorCreationStacks()

        # This is temporary:
        __builtins__["wantTestObject"] = self.config.GetBool(
            'want-test-object', 0)

        self.wantStats = self.config.GetBool('want-pstats', 0)
        Task.TaskManager.pStatsTasks = self.config.GetBool('pstats-tasks', 0)
        # Set up the TaskManager to reset the PStats clock back
        # whenever we resume from a pause.  This callback function is
        # a little hacky, but we can't call it directly from within
        # the TaskManager because he doesn't know about PStats (and
        # has to run before libpanda is even loaded).
        taskMgr.resumeFunc = PStatClient.resumeAfterPause

        # in production, we want to use fake textures.
        defaultValue = 1
        if __dev__:
            defaultValue = 0
        wantFakeTextures = self.config.GetBool('want-fake-textures-ai',
                                               defaultValue)

        if wantFakeTextures:
            # Setting textures-header-only is a little better than
            # using fake-texture-image.  The textures' headers are
            # read to check their number of channels, etc., and then a
            # 1x1 blue texture is created.  It loads quickly, consumes
            # very little memory, and doesn't require a bogus texture
            # to be loaded repeatedly.
            loadPrcFileData('aibase', 'textures-header-only 1')

        # If there's a Toontown-specific AIBase, that's where the following
        # config flags should be.
        # I tried putting this logic in ToontownAIRepository, but wantPets is
        # needed during the import of ToontownAIRepository.py
        self.wantPets = self.config.GetBool('want-pets', 1)
        if self.wantPets:
            if game.name == 'toontown':
                from toontown.pets import PetConstants
                self.petMoodTimescale = self.config.GetFloat(
                    'pet-mood-timescale', 1.)
                self.petMoodDriftPeriod = self.config.GetFloat(
                    'pet-mood-drift-period', PetConstants.MoodDriftPeriod)
                self.petThinkPeriod = self.config.GetFloat(
                    'pet-think-period', PetConstants.ThinkPeriod)
                self.petMovePeriod = self.config.GetFloat(
                    'pet-move-period', PetConstants.MovePeriod)
                self.petPosBroadcastPeriod = self.config.GetFloat(
                    'pet-pos-broadcast-period',
                    PetConstants.PosBroadcastPeriod)

        self.wantBingo = self.config.GetBool('want-fish-bingo', 1)
        self.wantKarts = self.config.GetBool('wantKarts', 1)

        self.newDBRequestGen = self.config.GetBool(
            'new-database-request-generate', 1)

        self.waitShardDelete = self.config.GetBool('wait-shard-delete', 1)
        self.blinkTrolley = self.config.GetBool('blink-trolley', 0)
        self.fakeDistrictPopulations = self.config.GetBool(
            'fake-district-populations', 0)

        self.wantSwitchboard = self.config.GetBool('want-switchboard', 0)
        self.wantSwitchboardHacks = self.config.GetBool(
            'want-switchboard-hacks', 0)
        self.GEMdemoWhisperRecipientDoid = self.config.GetBool(
            'gem-demo-whisper-recipient-doid', 0)
        self.sqlAvailable = self.config.GetBool('sql-available', 1)

        self.createStats()

        self.restart()