예제 #1
0
 def watchKey(active = True):
     if active == True:
         inputState.set(input, True)
         self.keyMap[keyMapName] = 1
     else:
         inputState.set(input, False)
         self.keyMap[keyMapName] = 0
예제 #2
0
 def watchKey(active=True):
     if active == True:
         inputState.set(input, True)
         keyMap[keyMapName] = 1
     else:
         inputState.set(input, False)
         keyMap[keyMapName] = 0
예제 #3
0
def walkOff():
    """
    Changes the forward speed back to normal.
    Something I originally intended to implement as default, but never worked.
    """
    invoker = spellbook.getInvoker()
    runback = invoker.setWalkSpeedNormal()
    inputState.set(runback, inputState.isSet(runback) == True)
    return 'Turned walking speed off.'
예제 #4
0
def walkOn():
    """
    Changes the forward speed to make use of walking.
    Something I originally intended to implement as default, but never worked.
    """
    invoker = spellbook.getInvoker()
    walkslow = invoker.setWalkSpeedWalking()
    inputState.set(walkslow, inputState.isSet(walkslow) == True)
    return 'Turned walking speed on.'
예제 #5
0
 def grabMovement(self):
     # Keyboard
     self.tokenGroup.release()
     # This is used to climbUp
     self.tokenGroup.addToken(inputState.watchWithModifiers('climb', 'q', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('left', 'a', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('right', 'd', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('fall', 's', inputSource=inputState.WASD))
     for item in ['forward', 'left', 'reverse', 'right']:
         inputState.set(item, False, inputSource=inputState.WASD)
     self.isGrabMovement = True
예제 #6
0
def run():
    """Toggle "running", which makes you move much faster."""
    inputState.set('debugRunning', inputState.isSet('debugRunning') != True)
예제 #7
0
    def doMagicWord(self, word, avId, zoneId):
        wordIs = self.getWordIs(word)
        print word
        if wordIs('~oobe'):
            base.oobe()
        elif wordIs('~oobeCull'):
            base.oobeCull()
        elif wordIs('~tex'):
            self.doTex(word)
        elif wordIs('~texmem'):
            base.toggleTexMem()
        elif wordIs('~verts'):
            base.toggleShowVertices()
        elif wordIs('~wire'):
            base.toggleWireframe()
        elif wordIs('~stereo'):
            base.toggleStereo()
        elif wordIs('~showfont'):
            self.showfont(word[9:])
        elif wordIs('~hidefont'):
            self.hidefont()
        elif wordIs('~guiPopup'):
            self.toggleGuiPopup()
        elif wordIs('~showCS') or wordIs('~showcs'):
            bitmask = self.getCSBitmask(word[7:])
            render.showCS(bitmask)
            self.csShown = 1
        elif wordIs('~hideCS') or wordIs('~hidecs'):
            bitmask = self.getCSBitmask(word[7:])
            render.hideCS(bitmask)
            self.csShown = 0
        elif wordIs('~cs'):
            bitmask = self.getCSBitmask(word[3:])
            if self.csShown:
                render.hideCS(bitmask)
                self.csShown = 0
            else:
                render.showCS(bitmask)
                self.csShown = 1
        elif wordIs('~showShadowCollisions'):
            self.showShadowCollisions()
        elif wordIs('~hideShadowCollisions'):
            self.hideShadowCollisions()
        elif wordIs('~showCollisions'):
            self.showCollisions()
        elif wordIs('~hideCollisions'):
            self.hideCollisions()
        elif wordIs('~showCameraCollisions'):
            self.showCameraCollisions()
        elif wordIs('~hideCameraCollisions'):
            self.hideCameraCollisions()
        elif wordIs('~collidespam'):
            n = Notify.ptr().getCategory(':collide')
            if hasattr(self, '_collideSpamSeverity'):
                n.setSeverity(self._collideSpamSeverity)
                del self._collideSpamSeverity
            else:
                self._collideSpamSeverity = n.getSeverity()
                n.setSeverity(NSSpam)
        elif wordIs('~notify'):
            args = word.split()
            n = Notify.ptr().getCategory(args[1])
            n.setSeverity({
                'error': NSError,
                'warning': NSWarning,
                'info': NSInfo,
                'debug': NSDebug,
                'spam': NSSpam }[args[2]])
        elif wordIs('~stress'):
            factor = word[7:]
            if factor:
                factor = float(factor)
                LOD.setStressFactor(factor)
                response = 'Set LOD stress factor to %s' % factor
            else:
                factor = LOD.getStressFactor()
                response = 'LOD stress factor is %s' % factor
            self.setMagicWordResponse(response)
        elif wordIs('~for'):
            self.forAnother(word, avId, zoneId)
        elif wordIs('~badname'):
            word = '~for %s ~badname' % word[9:]
            print 'word is %s' % word
            self.forAnother(word, avId, zoneId)
        elif wordIs('~avId'):
            self.setMagicWordResponse(str(localAvatar.doId))
        elif wordIs('~doId'):
            name = string.strip(word[6:])
            objs = self.identifyDistributedObjects(name)
            if len(objs) == 0:
                response = '%s is unknown.' % name
            else:
                response = ''
                for (name, obj) in objs:
                    response += '\n%s %d' % (name, obj.doId)
                
                response = response[1:]
            self.setMagicWordResponse(response)
        elif wordIs('~exec'):
            ChatManager = ChatManager
            import otp.chat
            ChatManager.ChatManager.execChat = 1
        elif wordIs('~run'):
            self.toggleRun()
        elif wordIs('~runFaster'):
            if config.GetBool('want-running', 1):
                args = word.split()
                if len(args) > 1:
                    base.debugRunningMultiplier = float(args[1])
                else:
                    base.debugRunningMultiplier = 10
                inputState.set('debugRunning', True)
            
        elif wordIs('~who'):
            avIds = []
            for av in Avatar.Avatar.ActiveAvatars:
                if hasattr(av, 'getFriendsList'):
                    avIds.append(av.doId)
                    continue
            
            self.d_setWho(avIds)
        elif wordIs('~sync'):
            tm = self.cr.timeManager
            if tm == None:
                response = 'No TimeManager.'
                self.setMagicWordResponse(response)
            else:
                tm.extraSkew = 0.0
                skew = string.strip(word[5:])
                if skew != '':
                    tm.extraSkew = float(skew)
                
                globalClockDelta.clear()
                tm.handleHotkey()
        elif wordIs('~period'):
            timeout = string.strip(word[7:])
            if timeout != '':
                seconds = int(timeout)
                self.cr.stopPeriodTimer()
                self.cr.resetPeriodTimer(seconds)
                self.cr.startPeriodTimer()
            
            if self.cr.periodTimerExpired:
                response = 'Period timer has expired.'
            elif self.cr.periodTimerStarted:
                elapsed = globalClock.getFrameTime() - self.cr.periodTimerStarted
                secondsRemaining = self.cr.periodTimerSecondsRemaining - elapsed
                response = 'Period timer expires in %s seconds.' % int(secondsRemaining)
            else:
                response = 'Period timer not set.'
            self.setMagicWordResponse(response)
        elif wordIs('~DIRECT'):
            args = word.split()
            fEnableLight = 0
            if len(args) > 1:
                if direct and args[1] == 'CAM':
                    direct.enable()
                    taskMgr.removeTasksMatching('updateSmartCamera*')
                    camera.wrtReparentTo(render)
                    direct.cameraControl.enableMouseFly()
                    self.setMagicWordResponse('Enabled DIRECT camera')
                    return None
                elif args[1] == 'LIGHT':
                    fEnableLight = 1
                
            
            base.startTk()
            DirectSession = DirectSession
            import direct.directtools
            if fEnableLight:
                direct.enableLight()
            else:
                direct.enable()
            self.setMagicWordResponse('Enabled DIRECT')
        elif wordIs('~TT'):
            if not direct:
                return None
            
            args = word.split()
            if len(args) > 1:
                if args[1] == 'CAM':
                    direct.cameraControl.disableMouseFly()
                    camera.wrtReparentTo(base.localAvatar)
                    base.localAvatar.startUpdateSmartCamera()
                    self.setMagicWordResponse('Disabled DIRECT camera')
                    return None
                
            
            direct.disable()
            camera.wrtReparentTo(base.localAvatar)
            base.localAvatar.startUpdateSmartCamera()
            self.setMagicWordResponse('Disabled DIRECT')
        elif wordIs('~net'):
            if self.cr.networkPlugPulled():
                self.cr.restoreNetworkPlug()
                self.cr.startHeartbeat()
                response = 'Network restored.'
            else:
                self.cr.pullNetworkPlug()
                self.cr.stopHeartbeat()
                response = 'Network disconnected.'
            self.setMagicWordResponse(response)
        elif wordIs('~disconnect'):
            base.cr.distributedDistrict.sendUpdate('broadcastMessage')
        elif wordIs('~model'):
            args = word.split()
            path = args[1]
            model = loader.loadModel(path)
            model.reparentTo(localAvatar)
            model.wrtReparentTo(render)
            self.setMagicWordResponse('loaded %s' % path)
        elif wordIs('~axis'):
            axis = loader.loadModel('models/misc/xyzAxis.bam')
            axis.reparentTo(render)
            axis.setPos(base.localAvatar, 0, 0, 0)
            axis.setHpr(render, 0, 0, 0)
            axis10 = loader.loadModel('models/misc/xyzAxis.bam')
            axis10.reparentTo(render)
            axis10.setPos(base.localAvatar, 0, 0, 0)
            axis10.setScale(10)
            axis10.setHpr(render, 0, 0, 0)
            axis10.setColorScale(1, 1, 1, 0.40000000000000002)
            axis10.setTransparency(1)
        elif wordIs('~clearAxes') or wordIs('~clearAxis'):
            render.findAllMatches('**/xyzAxis.egg').detach()
        elif wordIs('~myAxis'):
            if hasattr(self, 'myAxis'):
                self.myAxis.detachNode()
                del self.myAxis
            else:
                self.myAxis = loader.loadModel('models/misc/xyzAxis.bam')
                self.myAxis.reparentTo(localAvatar)
        elif wordIs('~osd'):
            onScreenDebug.enabled = not (onScreenDebug.enabled)
        elif wordIs('~osdScale'):
            args = word.split()
            defScale = 0.050000000000000003
            if len(args) > 1:
                scale = float(args[1])
            else:
                scale = 1.0
            onScreenDebug.onScreenText.setScale(defScale * scale)
        elif wordIs('~osdTaskMgr'):
            if taskMgr.osdEnabled():
                taskMgr.stopOsd()
            elif not onScreenDebug.enabled:
                onScreenDebug.enabled = True
            
            taskMgr.startOsd()
        elif wordIs('~fps'):
            self.doFps(word, avId, zoneId)
        elif wordIs('~sleep'):
            args = word.split()
            if len(args) > 1:
                s = float(args[1])
                base.setSleep(s)
                response = 'sleeping %s' % s
            else:
                base.setSleep(0.0)
                response = 'not sleeping'
            self.setMagicWordResponse(response)
        elif wordIs('~objects'):
            args = word.split()
            ObjectReport = ObjectReport
            import direct.showbase
            report = ObjectReport.ObjectReport('client ~objects')
            if 'all' in args:
                self.notify.info('printing full object set...')
                report.getObjectPool().printObjsByType(printReferrers = 'ref' in args)
            
            if hasattr(self, 'baselineObjReport'):
                self.notify.info('calculating diff from baseline ObjectReport...')
                self.lastDiff = self.baselineObjReport.diff(report)
                if not 'diff' in args:
                    pass
                self.lastDiff.printOut(full = 'dif' in args)
            
            if 'baseline' in args or not hasattr(self, 'baselineObjReport'):
                self.notify.info('recording baseline ObjectReport...')
                if hasattr(self, 'baselineObjReport'):
                    self.baselineObjReport.destroy()
                
                self.baselineObjReport = report
            
            self.setMagicWordResponse('objects logged')
        elif wordIs('~objectcount'):
            
            def handleObjectCountDone(objectCount):
                self.setMagicWordResponse('object count logged')

            oc = ObjectCount('~objectcount', doneCallback = handleObjectCountDone)
        elif wordIs('~objecthg'):
            import gc as gc
            objs = gc.get_objects()
            type2count = { }
            for obj in objs:
                tn = safeTypeName(obj)
                type2count.setdefault(tn, 0)
                type2count[tn] += 1
            
            count2type = invertDictLossless(type2count)
            counts = count2type.keys()
            counts.sort()
            counts.reverse()
            for count in counts:
                print '%s: %s' % (count, count2type[count])
            
            self.setMagicWordResponse('~aiobjecthg complete')
        elif wordIs('~containers'):
            args = word.split()
            limit = 30
            if 'full' in args:
                limit = None
            
            ContainerReport.ContainerReport('~containers', log = True, limit = limit, threaded = True)
        elif wordIs('~garbage'):
            args = word.split()
            full = 'full' in args
            safeMode = 'safe' in args
            delOnly = 'delonly' in args
            cycleLimit = None
            for arg in args:
                
                try:
                    cycleLimit = int(arg)
                continue
                continue

            
            GarbageReport.GarbageLogger('~garbage', fullReport = full, threaded = True, safeMode = safeMode, delOnly = delOnly, cycleLimit = cycleLimit, doneCallback = self.garbageReportDone)
        elif wordIs('~guicreates'):
            base.printGuiCreates = True
            self.setMagicWordResponse('printing gui creation stacks')
        elif wordIs('~creategarbage'):
            args = word.split()
            num = 1
            if len(args) > 1:
                num = int(args[1])
            
            GarbageReport._createGarbage(num)
        elif wordIs('~leakTask'):
            
            def leakTask(task):
                return task.cont

            taskMgr.add(leakTask, uniqueName('leakedTask'))
            leakTask = None
        elif wordIs('~leakmessage'):
            MessengerLeakDetector._leakMessengerObject()
            self.down_setMagicWordResponse(senderId, 'messenger leak object created')
        elif wordIs('~pstats'):
            args = word.split()
            hostname = None
            port = None
            if len(args) > 1:
                hostname = args[1]
            
            if len(args) > 2:
                port = int(args[2])
            
            base.wantStats = 1
            Task.TaskManager.pStatsTasks = 1
            result = base.createStats(hostname, port)
            connectionName = '%s' % hostname
            if port is not None:
                connectionName += ':%s' % port
            
            if result:
                response = 'connected client pstats to %s' % connectionName
            else:
                response = 'could not connect pstats to %s' % connectionName
            self.setMagicWordResponse(response)
        elif wordIs('~profile'):
            args = word.split()
            if len(args) > 1:
                num = int(args[1])
            else:
                num = 5
            session = taskMgr.getProfileSession('~profile')
            session.setLogAfterProfile(True)
            taskMgr.profileFrames(num, session)
            self.setMagicWordResponse('profiling %s client frames...' % num)
        elif wordIs('~frameprofile'):
            args = word.split()
            wasOn = bool(taskMgr.getProfileFrames())
            if len(args) > 1:
                setting = bool(int(args[1]))
            else:
                setting = not wasOn
            taskMgr.setProfileFrames(setting)
            self.setMagicWordResponse('frame profiling %s%s' % (choice(setting, 'ON', 'OFF'), choice(wasOn == setting, ' already', '')))
        elif wordIs('~taskprofile'):
            args = word.split()
            wasOn = bool(taskMgr.getProfileTasks())
            if len(args) > 1:
                setting = bool(int(args[1]))
            else:
                setting = not wasOn
            taskMgr.setProfileTasks(setting)
            self.setMagicWordResponse('task profiling %s%s' % (choice(setting, 'ON', 'OFF'), choice(wasOn == setting, ' already', '')))
        elif wordIs('~taskspikethreshold'):
            args = word.split()
            if len(args) > 1:
                threshold = float(args[1])
                response = 'task spike threshold set to %ss' % threshold
            else:
                threshold = TaskProfiler.GetDefaultSpikeThreshold()
                response = 'task spike threshold reset to %ss' % threshold
            TaskProfiler.SetSpikeThreshold(threshold)
            self.setMagicWordResponse(response)
        elif wordIs('~logtaskprofiles'):
            args = word.split()
            if len(args) > 1:
                name = args[1]
            else:
                name = None
            taskMgr.logTaskProfiles(name)
            response = 'logged task profiles%s' % choice(name, ' for %s' % name, '')
            self.setMagicWordResponse(response)
        elif wordIs('~taskprofileflush'):
            args = word.split()
            if len(args) > 1:
                name = args[1]
            else:
                name = None
            taskMgr.flushTaskProfiles(name)
            response = 'flushed AI task profiles%s' % choice(name, ' for %s' % name, '')
            self.setMagicWordResponse(response)
        elif wordIs('~dobjectcount'):
            base.cr.printObjectCount()
            self.setMagicWordResponse('logging client distributed object count...')
        elif wordIs('~taskmgr'):
            print taskMgr
            self.setMagicWordResponse('logging client taskMgr...')
        elif wordIs('~jobmgr'):
            print jobMgr
            self.setMagicWordResponse('logging client jobMgr...')
        elif wordIs('~jobtime'):
            args = word.split()
            if len(args) > 1:
                time = float(args[1])
            else:
                time = None
            response = ''
            if time is None:
                time = jobMgr.getDefaultTimeslice()
                response = 'reset client jobMgr timeslice to %s ms' % time
            else:
                response = 'set client jobMgr timeslice to %s ms' % time
                time = time / 1000.0
            jobMgr.setTimeslice(time)
            self.setMagicWordResponse(response)
        elif wordIs('~detectleaks'):
            started = self.cr.startLeakDetector()
            self.setMagicWordResponse(choice(started, 'leak detector started', 'leak detector already started'))
        elif wordIs('~taskthreshold'):
            args = word.split()
            if len(args) > 1.0:
                threshold = float(args[1])
            else:
                threshold = None
            response = ''
            if threshold is None:
                threshold = taskMgr.DefTaskDurationWarningThreshold
                response = 'reset task duration warning threshold to %s' % threshold
            else:
                response = 'set task duration warning threshold to %s' % threshold
            taskMgr.setTaskDurationWarningThreshold(threshold)
            self.setMagicWordResponse(response)
        elif wordIs('~messenger'):
            print messenger
            self.setMagicWordResponse('logging client messenger...')
        elif wordIs('~clientcrash'):
            DelayedCall(Functor(self.notify.error, '~clientcrash: simulating a client crash'))
        elif wordIs('~badDelete'):
            doId = 0
            while doId in base.cr.doId2do:
                doId += 1
            DelayedCall(Functor(base.cr.deleteObjectLocation, ScratchPad(doId = doId), 1, 1))
            self.setMagicWordResponse('doing bad delete')
        elif wordIs('~idTags'):
            messenger.send('nameTagShowAvId', [])
            base.idTags = 1
        elif wordIs('~nameTags'):
            messenger.send('nameTagShowName', [])
            base.idTags = 0
        elif wordIs('~hideNames'):
            if NametagGlobals.getMasterNametagsVisible():
                NametagGlobals.setMasterNametagsVisible(0)
            else:
                NametagGlobals.setMasterNametagsVisible(1)
        elif wordIs('~hideGui'):
            if aspect2d.isHidden():
                aspect2d.show()
            else:
                aspect2d.hide()
        elif wordIs('~flush'):
            base.cr.doDataCache.flush()
            base.cr.cache.flush()
            self.setMagicWordResponse('client object and data caches flushed')
        elif wordIs('~prof'):
            import time as time
            name = 'default'
            p = Point3()
            ts = time.time()
            for i in xrange(1000000):
                p.set(1, 2, 3)
            
            tf = time.time()
            dt = tf - ts
            response = 'prof(%s): %s secs' % (name, dt)
            print response
            self.setMagicWordResponse(response)
        elif wordIs('~gptc'):
            args = word.split()
            if len(args) > 1.0 and hasattr(self.cr, 'leakDetector'):
                gptcJob = self.cr.leakDetector.getPathsToContainers('~gptc', args[1], Functor(self._handleGPTCfinished, args[1]))
            else:
                self.setMagicWordResponse('error')
        elif wordIs('~gptcn'):
            args = word.split()
            if len(args) > 1.0 and hasattr(self.cr, 'leakDetector'):
                gptcnJob = self.cr.leakDetector.getPathsToContainersNamed('~gptcn', args[1], Functor(self._handleGPTCNfinished, args[1]))
            else:
                self.setMagicWordResponse('error')
        else:
            return 0
        return 1
예제 #8
0
 def toggleRun(self):
     if config.GetBool('want-running', 1):
         inputState.set('debugRunning', inputState.isSet('debugRunning') != True)
예제 #9
0
    def disableControls(self, chat=False):
        if not self.controlsEnabled:
            return

        if base.localAvatar.battleControls:
            self.fpsCam.disableMouseMovement(False, not chat)

        self.ignore('alt')
        self.ignore(base.inputStore.NextCameraPosition)
        self.ignore(base.inputStore.PreviousCameraPosition)

        if not chat and (base.localAvatar.isThirdPerson()
                         or not base.localAvatar.battleControls):
            base.localAvatar.stopSmartCamera()

        inputState.set('forward', False, inputSource=inputState.WASD)
        inputState.set('reverse', False, inputSource=inputState.WASD)
        inputState.set('slideLeft', False, inputSource=inputState.WASD)
        inputState.set('slideRight', False, inputSource=inputState.WASD)
        inputState.set('jump', False, inputSource=inputState.WASD)
        inputState.set('crouch', False, inputSource=inputState.WASD)
        inputState.set('walk', False, inputSource=inputState.WASD)
        inputState.set('sprint', False, inputSource=inputState.WASD)
        inputState.set('use', False, inputSource=inputState.WASD)
        base.taskMgr.remove("LocalControls.handlePlayerControls")
        base.taskMgr.remove("LocalControls.handleFootsteps")
        base.taskMgr.remove("LocalControls.handleUse")
        self.controller.setLinearMovement(Vec3(0))
        self.controller.setAngularMovement(0)
        self.controlsEnabled = False
예제 #10
0
    def doMagicWord(self, word, avId, zoneId):
        wordIs = self.getWordIs(word)

        print word
        if wordIs("~oobe"):
            base.oobe()
        elif wordIs("~oobeCull"):
            base.oobeCull()
        elif wordIs("~tex"):
            self.doTex(word)
        elif wordIs("~texmem"):
            base.toggleTexMem()
        elif wordIs("~verts"):
            base.toggleShowVertices()
        elif wordIs("~wire"):
            base.toggleWireframe()
        elif wordIs("~stereo"):
            base.toggleStereo()
        elif wordIs("~showfont"):
            self.showfont(word[9:])
        elif wordIs("~hidefont"):
            self.hidefont()
        elif wordIs("~guiPopup"):
            self.toggleGuiPopup()

        elif wordIs("~showCS") or wordIs("~showcs"):
            bitmask = self.getCSBitmask(word[7:])
            render.showCS(bitmask)
            self.csShown = 1

        elif wordIs("~hideCS") or wordIs("~hidecs"):
            bitmask = self.getCSBitmask(word[7:])
            render.hideCS(bitmask)
            self.csShown = 0

        elif wordIs("~cs"):
            # Toggle hide/show collision solids:
            # (Also a shorthand for ~hideCS and ~showCS).
            bitmask = self.getCSBitmask(word[3:])
            if self.csShown:
                render.hideCS(bitmask)
                self.csShown = 0
            else:
                render.showCS(bitmask)
                self.csShown = 1

        elif wordIs("~showShadowCollisions"):
            self.showShadowCollisions()

        elif wordIs("~hideShadowCollisions"):
            self.hideShadowCollisions()

        elif wordIs("~showCollisions"):
            self.showCollisions()

        elif wordIs("~hideCollisions"):
            self.hideCollisions()

        elif wordIs("~showCameraCollisions"):
            self.showCameraCollisions()

        elif wordIs("~hideCameraCollisions"):
            self.hideCameraCollisions()

        elif wordIs("~collidespam"):
            n = Notify.ptr().getCategory(':collide')
            if hasattr(self, '_collideSpamSeverity'):
                n.setSeverity(self._collideSpamSeverity)
                del self._collideSpamSeverity
            else:
                self._collideSpamSeverity = n.getSeverity()
                n.setSeverity(NSSpam)

        elif wordIs("~notify"):
            args = word.split()
            n = Notify.ptr().getCategory(args[1])
            n.setSeverity({
                'error': NSError,
                'warning': NSWarning,
                'info': NSInfo,
                'debug': NSDebug,
                'spam': NSSpam,
            }[args[2]])

        # MPG we probably need generic versions of these
        #elif wordIs("~listen"):
        #    base.localAvatar.garbleChat = 0

        #elif wordIs("~nochat") or wordIs("~chat") or wordIs("~superchat"):
        #    base.localAvatar.garbleChat = 1

        elif wordIs("~stress"):
            factor = word[7:]
            if factor:
                factor = float(factor)
                LOD.setStressFactor(factor)
                response = "Set LOD stress factor to %s" % (factor)
            else:
                factor = LOD.getStressFactor()
                response = "LOD stress factor is %s" % (factor)

            self.setMagicWordResponse(response)

        elif wordIs("~for"):
            self.forAnother(word, avId, zoneId)

        elif wordIs("~badname"):
            # ~badname with an argument becomes ~for ... ~badname
            word = "~for %s ~badname" % (word[9:])
            print "word is %s" % (word)
            self.forAnother(word, avId, zoneId)

        elif wordIs('~avId'):
            self.setMagicWordResponse(str(localAvatar.doId))

        elif wordIs("~doId"):
            name = string.strip(word[6:])

            objs = self.identifyDistributedObjects(name)
            if (len(objs) == 0):
                response = "%s is unknown." % (name)
            else:
                response = ""
                for name, obj in objs:
                    response += "\n%s %d" % (name, obj.doId)
                response = response[1:]

            self.setMagicWordResponse(response)

        # MPG - need generic versions of these
        #elif wordIs("~collisions_on"):
        #    base.localAvatar.collisionsOn()

        #elif wordIs("~collisions_off"):
        #    base.localAvatar.collisionsOff()

        #elif wordIs('~addCameraPosition'):
        #    base.localAvatar.addCameraPosition()

        #elif wordIs('~removeCameraPosition'):
        #    base.localAvatar.removeCameraPosition()

        #elif wordIs('~printCameraPosition'):
        #    base.localAvatar.printCameraPosition(
        #        base.localAvatar.cameraIndex)

        #elif wordIs('~printCameraPositions'):
        #    base.localAvatar.printCameraPositions()

        elif wordIs("~exec"):
            # Enable execChat.
            from otp.chat import ChatManager
            ChatManager.ChatManager.execChat = 1

        elif wordIs("~run"):
            self.toggleRun()

        elif wordIs("~runFaster"):
            if (config.GetBool("want-running", 1)):
                args = word.split()
                if (len(args) > 1):
                    base.debugRunningMultiplier = float(args[1])
                else:
                    base.debugRunningMultiplier = 10
                inputState.set("debugRunning", True)

        elif wordIs("~who"):
            # Get all the nearby avIds and send them to the AI.
            avIds = []
            for av in Avatar.Avatar.ActiveAvatars:
                # If the avatar has a friends list, it's probably a
                # real avatar and not an NPC.
                if hasattr(av, "getFriendsList"):
                    avIds.append(av.doId)
            self.d_setWho(avIds)

        elif wordIs("~sync"):
            # Sync with the AI, like F6, but rather than accumulating
            # sync informatoin, throw away whatever information was
            # there from before.  If a second parameter is supplied,
            # it is a number of seconds of temporary extra skew to
            # apply; the default is 0.

            tm = self.cr.timeManager
            if tm == None:
                response = "No TimeManager."
                self.setMagicWordResponse(response)
            else:
                tm.extraSkew = 0.0
                skew = string.strip(word[5:])
                if skew != "":
                    tm.extraSkew = float(skew)
                globalClockDelta.clear()
                tm.handleHotkey()

        elif wordIs("~period"):
            # Reset the period timer to expire in the indicated number
            # of seconds, or with no parameter, report the number of
            # seconds remaining.

            timeout = string.strip(word[7:])
            if timeout != "":
                seconds = int(timeout)
                self.cr.stopPeriodTimer()
                self.cr.resetPeriodTimer(seconds)
                self.cr.startPeriodTimer()

            # Now report the number of seconds remaining.
            if self.cr.periodTimerExpired:
                response = "Period timer has expired."

            elif self.cr.periodTimerStarted:
                elapsed = globalClock.getFrameTime(
                ) - self.cr.periodTimerStarted
                secondsRemaining = self.cr.periodTimerSecondsRemaining - elapsed
                response = "Period timer expires in %s seconds." % (
                    int(secondsRemaining))
            else:
                response = "Period timer not set."

            self.setMagicWordResponse(response)

        elif wordIs("~DIRECT"):
            args = word.split()
            fEnableLight = 0
            if len(args) > 1:
                if direct and (args[1] == 'CAM'):
                    direct.enable()
                    taskMgr.removeTasksMatching('updateSmartCamera*')
                    camera.wrtReparentTo(render)
                    direct.cameraControl.enableMouseFly()
                    self.setMagicWordResponse("Enabled DIRECT camera")
                    return
                elif args[1] == 'LIGHT':
                    fEnableLight = 1
            # Start up DIRECT
            base.startTk()
            from direct.directtools import DirectSession
            if fEnableLight:
                direct.enableLight()
            else:
                direct.enable()
            self.setMagicWordResponse("Enabled DIRECT")

        elif wordIs("~TT"):
            if not direct:
                return
            args = word.split()
            if len(args) > 1:
                if (args[1] == 'CAM'):
                    direct.cameraControl.disableMouseFly()
                    camera.wrtReparentTo(base.localAvatar)
                    base.localAvatar.startUpdateSmartCamera()
                    self.setMagicWordResponse("Disabled DIRECT camera")
                    return
            # Return to toontown mode
            direct.disable()
            camera.wrtReparentTo(base.localAvatar)
            base.localAvatar.startUpdateSmartCamera()
            self.setMagicWordResponse("Disabled DIRECT")

        elif wordIs("~net"):
            # Simulate pulling or restoring the network plug.
            if self.cr.networkPlugPulled():
                self.cr.restoreNetworkPlug()
                self.cr.startHeartbeat()
                response = "Network restored."
            else:
                self.cr.pullNetworkPlug()
                self.cr.stopHeartbeat()
                response = "Network disconnected."
            self.setMagicWordResponse(response)

        elif wordIs('~disconnect'):
            # force a simulated disconnect
            # you can also do this from the OTP webpage
            base.cr.distributedDistrict.sendUpdate('broadcastMessage')

        elif wordIs("~model"):
            # load a model into the scene graph at the location of localAvatar
            args = word.split()
            path = args[1]
            model = loader.loadModel(path)
            model.reparentTo(localAvatar)
            model.wrtReparentTo(render)
            self.setMagicWordResponse('loaded %s' % path)

        elif wordIs("~axis"):
            # Show a 10 foot and 100 foot axis at the spot of the avatar
            # axis aligned to render
            axis = loader.loadModel("models/misc/xyzAxis.bam")
            axis.reparentTo(render)
            axis.setPos(base.localAvatar, 0, 0, 0)
            axis.setHpr(render, 0, 0, 0)
            axis10 = loader.loadModel("models/misc/xyzAxis.bam")
            axis10.reparentTo(render)
            axis10.setPos(base.localAvatar, 0, 0, 0)
            axis10.setScale(10)
            axis10.setHpr(render, 0, 0, 0)
            axis10.setColorScale(1, 1, 1, 0.4)
            axis10.setTransparency(1)

        elif (wordIs("~clearAxes") or wordIs("~clearAxis")):
            # Remove the effects of ~axis calls
            render.findAllMatches("**/xyzAxis.egg").detach()

        elif wordIs("~myAxis"):
            if hasattr(self, 'myAxis'):
                self.myAxis.detachNode()
                del self.myAxis
            else:
                self.myAxis = loader.loadModel("models/misc/xyzAxis.bam")
                self.myAxis.reparentTo(localAvatar)

        elif (wordIs("~osd")):
            onScreenDebug.enabled = not onScreenDebug.enabled

        elif wordIs("~osdScale"):
            args = word.split()
            defScale = .05
            if len(args) > 1:
                scale = float(args[1])
            else:
                scale = 1.
            onScreenDebug.onScreenText.setScale(defScale * scale)

        elif wordIs('~osdTaskMgr'):
            if taskMgr.osdEnabled():
                taskMgr.stopOsd()
            else:
                if not onScreenDebug.enabled:
                    onScreenDebug.enabled = True
                taskMgr.startOsd()

        elif wordIs("~fps"):
            self.doFps(word, avId, zoneId)

        elif wordIs("~sleep"):
            args = word.split()
            if len(args) > 1:
                s = float(args[1])
                base.setSleep(s)
                response = 'sleeping %s' % s
            else:
                base.setSleep(0.0)
                response = 'not sleeping'
            self.setMagicWordResponse(response)

        elif wordIs('~objects'):
            args = word.split()
            from direct.showbase import ObjectReport
            report = ObjectReport.ObjectReport('client ~objects')

            if 'all' in args:
                self.notify.info('printing full object set...')
                report.getObjectPool().printObjsByType(
                    printReferrers='ref' in args)

            if hasattr(self, 'baselineObjReport'):
                self.notify.info(
                    'calculating diff from baseline ObjectReport...')
                self.lastDiff = self.baselineObjReport.diff(report)
                self.lastDiff.printOut(full=('diff' in args or 'dif' in args))

            if 'baseline' in args or not hasattr(self, 'baselineObjReport'):
                self.notify.info('recording baseline ObjectReport...')
                if hasattr(self, 'baselineObjReport'):
                    self.baselineObjReport.destroy()
                self.baselineObjReport = report

            self.setMagicWordResponse('objects logged')

        elif wordIs('~objecthg'):
            import gc
            objs = gc.get_objects()
            type2count = {}
            for obj in objs:
                tn = safeTypeName(obj)
                type2count.setdefault(tn, 0)
                type2count[tn] += 1
            count2type = invertDictLossless(type2count)
            counts = count2type.keys()
            counts.sort()
            counts.reverse()
            for count in counts:
                print '%s: %s' % (count, count2type[count])
            self.setMagicWordResponse('~aiobjecthg complete')

        elif wordIs('~containers'):
            args = word.split()
            limit = 30
            if 'full' in args:
                limit = None
            ContainerReport.ContainerReport('~containers',
                                            log=True,
                                            limit=limit,
                                            threaded=True)

        elif wordIs('~garbage'):
            args = word.split()
            # it can take a LOOONG time to print out the garbage referrers and referents
            # by reference (as opposed to by number)
            full = 'full' in args
            safeMode = 'safe' in args
            delOnly = 'delonly' in args
            # This does a garbage collection and dumps the list of leaked (uncollectable) objects to the log.
            GarbageReport.GarbageLogger('~garbage',
                                        fullReport=full,
                                        threaded=True,
                                        safeMode=safeMode,
                                        delOnly=delOnly,
                                        doneCallback=self.garbageReportDone)
            # this is coming back from the AI
            #self.setMagicWordResponse('garbage logged')

        elif wordIs('~guicreates'):
            base.printGuiCreates = True
            self.setMagicWordResponse('printing gui creation stacks')

        elif wordIs("~creategarbage"):
            GarbageReport._createGarbage()
            # this is coming back from the AI
            #self.setMagicWordResponse(senderId, 'leaked garbage created')

        elif wordIs('~leakTask'):

            def leakTask(task):
                return task.cont

            taskMgr.add(leakTask, uniqueName('leakedTask'))
            leakTask = None
            # this is coming back from the AI
            #self.setMagicWordResponse(senderId, 'leaked task created')

        elif wordIs('~leakmessage'):
            MessengerLeakDetector._leakMessengerObject()
            self.down_setMagicWordResponse(senderId,
                                           'messenger leak object created')

        elif wordIs('~pstats'):
            args = word.split()
            hostname = None
            port = None
            if len(args) > 1:
                hostname = args[1]
            if len(args) > 2:
                port = int(args[2])
            # make sure pstats is enabled
            base.wantStats = 1
            Task.TaskManager.pStatsTasks = 1
            result = base.createStats(hostname, port)
            connectionName = '%s' % hostname
            if port is not None:
                connectionName += ':%s' % port
            if result:
                response = 'connected client pstats to %s' % connectionName
            else:
                response = 'could not connect pstats to %s' % connectionName
            self.setMagicWordResponse(response)

        elif wordIs('~profile'):
            args = word.split()
            if len(args) > 1:
                num = int(args[1])
            else:
                num = 5
            session = taskMgr.getProfileSession('~profile')
            session.setLogAfterProfile(True)
            taskMgr.profileFrames(num, session)
            self.setMagicWordResponse('profiling %s client frames...' % num)

        elif wordIs('~frameprofile'):
            args = word.split()
            wasOn = bool(taskMgr.getProfileFrames())
            if len(args) > 1:
                setting = bool(int(args[1]))
            else:
                setting = not wasOn
            taskMgr.setProfileFrames(setting)
            self.setMagicWordResponse(
                'frame profiling %s%s' %
                (choice(setting, 'ON',
                        'OFF'), choice(wasOn == setting, ' already', '')))

        elif wordIs('~taskprofile'):
            args = word.split()
            wasOn = bool(taskMgr.getProfileTasks())
            if len(args) > 1:
                setting = bool(int(args[1]))
            else:
                setting = not wasOn
            taskMgr.setProfileTasks(setting)
            self.setMagicWordResponse(
                'task profiling %s%s' %
                (choice(setting, 'ON',
                        'OFF'), choice(wasOn == setting, ' already', '')))

        elif wordIs('~taskspikethreshold'):
            args = word.split()
            if len(args) > 1:
                threshold = float(args[1])
                response = 'task spike threshold set to %ss' % threshold
            else:
                threshold = TaskProfiler.GetDefaultSpikeThreshold()
                response = 'task spike threshold reset to %ss' % threshold
            TaskProfiler.SetSpikeThreshold(threshold)
            self.setMagicWordResponse(response)

        elif wordIs('~logtaskprofiles'):
            args = word.split()
            if len(args) > 1:
                name = args[1]
            else:
                name = None
            taskMgr.logTaskProfiles(name)
            response = 'logged task profiles%s' % choice(
                name, ' for %s' % name, '')
            self.setMagicWordResponse(response)

        elif wordIs('~taskprofileflush'):
            args = word.split()
            if len(args) > 1:
                name = args[1]
            else:
                name = None
            taskMgr.flushTaskProfiles(name)
            response = 'flushed AI task profiles%s' % choice(
                name, ' for %s' % name, '')
            self.setMagicWordResponse(response)

        elif wordIs('~objectcount'):
            base.cr.printObjectCount()
            self.setMagicWordResponse(
                'logging client distributed object count...')

        elif wordIs('~taskmgr'):
            print taskMgr
            self.setMagicWordResponse('logging client taskMgr...')

        elif wordIs('~jobmgr'):
            print jobMgr
            self.setMagicWordResponse('logging client jobMgr...')

        elif wordIs('~jobtime'):
            args = word.split()
            if len(args) > 1:
                time = float(args[1])
            else:
                time = None
            response = ''
            if time is None:
                time = jobMgr.getDefaultTimeslice()
                response = 'reset client jobMgr timeslice to %s ms' % time
            else:
                response = 'set client jobMgr timeslice to %s ms' % time
                time = time / 1000.
            jobMgr.setTimeslice(time)
            self.setMagicWordResponse(response)

        elif wordIs('~detectleaks'):
            started = self.cr.startLeakDetector()
            self.setMagicWordResponse(
                choice(
                    started,
                    'leak detector started',
                    'leak detector already started',
                ))

        elif wordIs('~taskthreshold'):
            args = word.split()
            if len(args) > 1.:
                threshold = float(args[1])
            else:
                threshold = None
            response = ''
            if threshold is None:
                threshold = taskMgr.DefTaskDurationWarningThreshold
                response = 'reset task duration warning threshold to %s' % threshold
            else:
                response = 'set task duration warning threshold to %s' % threshold
            taskMgr.setTaskDurationWarningThreshold(threshold)
            self.setMagicWordResponse(response)

        elif wordIs('~messenger'):
            print messenger
            self.setMagicWordResponse('logging client messenger...')

        elif wordIs('~clientcrash'):
            # if we call notify.error directly, the magic word mgr will catch it
            # self.notify.error doesn't seem to work either
            DelayedCall(
                Functor(self.notify.error,
                        '~clientcrash: simulating a client crash'))

        elif wordIs('~badDelete'):
            doId = 0
            while doId in base.cr.doId2do:
                doId += 1
            # location (0,0) is special, pass in (1,1)
            # deleteObjectLocation expects a DO, pass in a ScratchPad instead
            # we must delay the call because magicWordMgr is in a big try/except block
            DelayedCall(
                Functor(base.cr.deleteObjectLocation, ScratchPad(doId=doId), 1,
                        1))
            self.setMagicWordResponse('doing bad delete')

        elif wordIs("~idTags"):
            messenger.send('nameTagShowAvId', [])
            base.idTags = 1

        elif wordIs("~nameTags"):
            messenger.send('nameTagShowName', [])
            base.idTags = 0

        elif wordIs("~hideNames"):
            # note do ~hideNames before ~hideGui if you want both off
            if NametagGlobals.getMasterNametagsVisible():
                NametagGlobals.setMasterNametagsVisible(0)
            else:
                NametagGlobals.setMasterNametagsVisible(1)

        elif wordIs("~hideGui"):
            if aspect2d.isHidden():
                aspect2d.show()
            else:
                aspect2d.hide()

        elif wordIs('~flush'):
            base.cr.doDataCache.flush()
            base.cr.cache.flush()
            self.setMagicWordResponse('client object and data caches flushed')

        elif wordIs('~prof'):
            import time

            ### set up ###
            name = 'default'
            p = Point3()
            ##############

            ts = time.time()
            for i in xrange(1000000):

                ### code to be timed ###
                p.set(1, 2, 3)
                ########################

            tf = time.time()
            dt = tf - ts
            response = 'prof(%s): %s secs' % (name, dt)
            print response
            self.setMagicWordResponse(response)

        elif wordIs('~gptc'):
            args = word.split()
            if len(args) > 1. and hasattr(self.cr, 'leakDetector'):
                gptcJob = self.cr.leakDetector.getPathsToContainers(
                    '~gptc', args[1], Functor(self._handleGPTCfinished,
                                              args[1]))
            else:
                self.setMagicWordResponse('error')

        elif wordIs('~gptcn'):
            args = word.split()
            if len(args) > 1. and hasattr(self.cr, 'leakDetector'):
                gptcnJob = self.cr.leakDetector.getPathsToContainersNamed(
                    '~gptcn', args[1],
                    Functor(self._handleGPTCNfinished, args[1]))
            else:
                self.setMagicWordResponse('error')

        else:
            # Not a magic word I know!
            return 0

        return 1
 def toggleRun(self):
     if config.GetBool("want-running", 1):
         inputState.set("debugRunning", inputState.isSet("debugRunning") != True)
예제 #12
0
def run():
    """
    Toggles debugging run speed.
    """
    inputState.set("debugRunning", inputState.isSet("debugRunning") != True)
    return "Toggled debug run speed."
예제 #13
0
def run():
    """
    Toggles debugging run speed.
    """
    inputState.set('debugRunning', inputState.isSet('debugRunning') != True)
    return 'Toggled debug run speed.'
예제 #14
0
 def toggleRun(self):
     if(ConfigVariableBool("want-running",1).getValue()):
         inputState.set("debugRunning",
                        inputState.isSet("debugRunning") != True)
def run():
    """Toggle "running", which makes you move much faster."""
    inputState.set('debugRunning', inputState.isSet('debugRunning') != True)
    def setWASDTurn(self, turn):
        self.__WASDTurn = turn
        if not self.isEnabled:
            return
        keymap = settings.get('keymap', {})
        turnLeftWASDSet = inputState.isSet('turnLeft', inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet('turnRight', inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet('slideLeft', inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet('slideRight', inputSource=inputState.WASD)
        for token in self.WASDTurnTokens:
            token.release()

        if turn:
            self.WASDTurnTokens = (inputState.watchWithModifiers('turnLeft', keymap.get('MOVE_LEFT', base.MOVE_LEFT), inputSource=inputState.WASD), inputState.watchWithModifiers('turnRight', keymap.get('MOVE_RIGHT', base.MOVE_RIGHT), inputSource=inputState.WASD))
            inputState.set('turnLeft', slideLeftWASDSet, inputSource=inputState.WASD)
            inputState.set('turnRight', slideRightWASDSet, inputSource=inputState.WASD)
            inputState.set('slideLeft', False, inputSource=inputState.WASD)
            inputState.set('slideRight', False, inputSource=inputState.WASD)
        else:
            self.WASDTurnTokens = (inputState.watchWithModifiers('slideLeft', keymap.get('MOVE_LEFT', base.MOVE_LEFT), inputSource=inputState.WASD), inputState.watchWithModifiers('slideRight', keymap.get('MOVE_RIGHT', base.MOVE_RIGHT), inputSource=inputState.WASD))
            inputState.set('slideLeft', turnLeftWASDSet, inputSource=inputState.WASD)
            inputState.set('slideRight', turnRightWASDSet, inputSource=inputState.WASD)
            inputState.set('turnLeft', False, inputSource=inputState.WASD)
            inputState.set('turnRight', False, inputSource=inputState.WASD)
    def doMagicWord(self, word, avId, zoneId):
        wordIs = self.getWordIs(word)
        print word
        if wordIs("~oobe"):
            base.oobe()
        elif wordIs("~oobeCull"):
            base.oobeCull()
        elif wordIs("~tex"):
            self.doTex(word)
        elif wordIs("~texmem"):
            base.toggleTexMem()
        elif wordIs("~verts"):
            base.toggleShowVertices()
        elif wordIs("~wire"):
            base.toggleWireframe()
        elif wordIs("~stereo"):
            base.toggleStereo()
        elif wordIs("~showfont"):
            self.showfont(word[9:])
        elif wordIs("~hidefont"):
            self.hidefont()
        elif wordIs("~guiPopup"):
            self.toggleGuiPopup()
        elif wordIs("~showCS") or wordIs("~showcs"):
            bitmask = self.getCSBitmask(word[7:])
            render.showCS(bitmask)
            self.csShown = 1
        elif wordIs("~hideCS") or wordIs("~hidecs"):
            bitmask = self.getCSBitmask(word[7:])
            render.hideCS(bitmask)
            self.csShown = 0
        elif wordIs("~cs"):
            bitmask = self.getCSBitmask(word[3:])
            if self.csShown:
                render.hideCS(bitmask)
                self.csShown = 0
            else:
                render.showCS(bitmask)
                self.csShown = 1
        elif wordIs("~showShadowCollisions"):
            self.showShadowCollisions()
        elif wordIs("~hideShadowCollisions"):
            self.hideShadowCollisions()
        elif wordIs("~showCollisions"):
            self.showCollisions()
        elif wordIs("~hideCollisions"):
            self.hideCollisions()
        elif wordIs("~showCameraCollisions"):
            self.showCameraCollisions()
        elif wordIs("~hideCameraCollisions"):
            self.hideCameraCollisions()
        elif wordIs("~collidespam"):
            n = Notify.ptr().getCategory(":collide")
            if hasattr(self, "_collideSpamSeverity"):
                n.setSeverity(self._collideSpamSeverity)
                del self._collideSpamSeverity
            else:
                self._collideSpamSeverity = n.getSeverity()
                n.setSeverity(NSSpam)
        elif wordIs("~notify"):
            args = word.split()
            n = Notify.ptr().getCategory(args[1])
            n.setSeverity(
                {"error": NSError, "warning": NSWarning, "info": NSInfo, "debug": NSDebug, "spam": NSSpam}[args[2]]
            )
        elif wordIs("~stress"):
            factor = word[7:]
            if factor:
                factor = float(factor)
                LOD.setStressFactor(factor)
                response = "Set LOD stress factor to %s" % factor
            else:
                factor = LOD.getStressFactor()
                response = "LOD stress factor is %s" % factor
            self.setMagicWordResponse(response)
        elif wordIs("~for"):
            self.forAnother(word, avId, zoneId)
        elif wordIs("~badname"):
            word = "~for %s ~badname" % word[9:]
            print "word is %s" % word
            self.forAnother(word, avId, zoneId)
        elif wordIs("~avId"):
            self.setMagicWordResponse(str(localAvatar.doId))
        elif wordIs("~doId"):
            name = string.strip(word[6:])
            objs = self.identifyDistributedObjects(name)
            if len(objs) == 0:
                response = "%s is unknown." % name
            else:
                response = ""
                for name, obj in objs:
                    response += "\n%s %d" % (name, obj.doId)

                response = response[1:]
            self.setMagicWordResponse(response)
        elif wordIs("~exec"):
            from otp.chat import ChatManager

            ChatManager.ChatManager.execChat = 1
        elif wordIs("~run"):
            self.toggleRun()
        elif wordIs("~runFaster"):
            if config.GetBool("want-running", 1):
                args = word.split()
                if len(args) > 1:
                    base.debugRunningMultiplier = float(args[1])
                else:
                    base.debugRunningMultiplier = 10
                inputState.set("debugRunning", True)
        elif wordIs("~who"):
            avIds = []
            for av in Avatar.Avatar.ActiveAvatars:
                if hasattr(av, "getFriendsList"):
                    avIds.append(av.doId)

            self.d_setWho(avIds)
        elif wordIs("~sync"):
            tm = self.cr.timeManager
            if tm == None:
                response = "No TimeManager."
                self.setMagicWordResponse(response)
            else:
                tm.extraSkew = 0.0
                skew = string.strip(word[5:])
                if skew != "":
                    tm.extraSkew = float(skew)
                globalClockDelta.clear()
                tm.handleHotkey()
        elif wordIs("~period"):
            timeout = string.strip(word[7:])
            if timeout != "":
                seconds = int(timeout)
                self.cr.stopPeriodTimer()
                self.cr.resetPeriodTimer(seconds)
                self.cr.startPeriodTimer()
            if self.cr.periodTimerExpired:
                response = "Period timer has expired."
            elif self.cr.periodTimerStarted:
                elapsed = globalClock.getFrameTime() - self.cr.periodTimerStarted
                secondsRemaining = self.cr.periodTimerSecondsRemaining - elapsed
                response = "Period timer expires in %s seconds." % int(secondsRemaining)
            else:
                response = "Period timer not set."
            self.setMagicWordResponse(response)
        elif wordIs("~DIRECT"):
            args = word.split()
            fEnableLight = 0
            if len(args) > 1:
                if direct and args[1] == "CAM":
                    direct.enable()
                    taskMgr.removeTasksMatching("updateSmartCamera*")
                    camera.wrtReparentTo(render)
                    direct.cameraControl.enableMouseFly()
                    self.setMagicWordResponse("Enabled DIRECT camera")
                    return
                elif args[1] == "LIGHT":
                    fEnableLight = 1
            base.startTk()
            from direct.directtools import DirectSession

            if fEnableLight:
                direct.enableLight()
            else:
                direct.enable()
            self.setMagicWordResponse("Enabled DIRECT")
        elif wordIs("~TT"):
            if not direct:
                return
            args = word.split()
            if len(args) > 1:
                if args[1] == "CAM":
                    direct.cameraControl.disableMouseFly()
                    camera.wrtReparentTo(base.localAvatar)
                    base.localAvatar.startUpdateSmartCamera()
                    self.setMagicWordResponse("Disabled DIRECT camera")
                    return
            direct.disable()
            camera.wrtReparentTo(base.localAvatar)
            base.localAvatar.startUpdateSmartCamera()
            self.setMagicWordResponse("Disabled DIRECT")
        elif wordIs("~net"):
            if self.cr.networkPlugPulled():
                self.cr.restoreNetworkPlug()
                self.cr.startHeartbeat()
                response = "Network restored."
            else:
                self.cr.pullNetworkPlug()
                self.cr.stopHeartbeat()
                response = "Network disconnected."
            self.setMagicWordResponse(response)
        elif wordIs("~disconnect"):
            base.cr.distributedDistrict.sendUpdate("broadcastMessage")
        elif wordIs("~model"):
            args = word.split()
            path = args[1]
            model = loader.loadModel(path)
            model.reparentTo(localAvatar)
            model.wrtReparentTo(render)
            self.setMagicWordResponse("loaded %s" % path)
        elif wordIs("~axis"):
            axis = loader.loadModel("models/misc/xyzAxis.bam")
            axis.reparentTo(render)
            axis.setPos(base.localAvatar, 0, 0, 0)
            axis.setHpr(render, 0, 0, 0)
            axis10 = loader.loadModel("models/misc/xyzAxis.bam")
            axis10.reparentTo(render)
            axis10.setPos(base.localAvatar, 0, 0, 0)
            axis10.setScale(10)
            axis10.setHpr(render, 0, 0, 0)
            axis10.setColorScale(1, 1, 1, 0.4)
            axis10.setTransparency(1)
        elif wordIs("~clearAxes") or wordIs("~clearAxis"):
            render.findAllMatches("**/xyzAxis.egg").detach()
        elif wordIs("~myAxis"):
            if hasattr(self, "myAxis"):
                self.myAxis.detachNode()
                del self.myAxis
            else:
                self.myAxis = loader.loadModel("models/misc/xyzAxis.bam")
                self.myAxis.reparentTo(localAvatar)
        elif wordIs("~osd"):
            onScreenDebug.enabled = not onScreenDebug.enabled
        elif wordIs("~osdScale"):
            args = word.split()
            defScale = 0.05
            if len(args) > 1:
                scale = float(args[1])
            else:
                scale = 1.0
            onScreenDebug.onScreenText.setScale(defScale * scale)
        elif wordIs("~osdTaskMgr"):
            if taskMgr.osdEnabled():
                taskMgr.stopOsd()
            else:
                if not onScreenDebug.enabled:
                    onScreenDebug.enabled = True
                taskMgr.startOsd()
        elif wordIs("~fps"):
            self.doFps(word, avId, zoneId)
        elif wordIs("~sleep"):
            args = word.split()
            if len(args) > 1:
                s = float(args[1])
                base.setSleep(s)
                response = "sleeping %s" % s
            else:
                base.setSleep(0.0)
                response = "not sleeping"
            self.setMagicWordResponse(response)
        elif wordIs("~objects"):
            args = word.split()
            from direct.showbase import ObjectReport

            report = ObjectReport.ObjectReport("client ~objects")
            if "all" in args:
                self.notify.info("printing full object set...")
                report.getObjectPool().printObjsByType(printReferrers="ref" in args)
            if hasattr(self, "baselineObjReport"):
                self.notify.info("calculating diff from baseline ObjectReport...")
                self.lastDiff = self.baselineObjReport.diff(report)
                self.lastDiff.printOut(full="diff" in args or "dif" in args)
            if "baseline" in args or not hasattr(self, "baselineObjReport"):
                self.notify.info("recording baseline ObjectReport...")
                if hasattr(self, "baselineObjReport"):
                    self.baselineObjReport.destroy()
                self.baselineObjReport = report
            self.setMagicWordResponse("objects logged")
        elif wordIs("~objectcount"):

            def handleObjectCountDone(objectCount):
                self.setMagicWordResponse("object count logged")

            oc = ObjectCount("~objectcount", doneCallback=handleObjectCountDone)
        elif wordIs("~objecthg"):
            import gc

            objs = gc.get_objects()
            type2count = {}
            for obj in objs:
                tn = safeTypeName(obj)
                type2count.setdefault(tn, 0)
                type2count[tn] += 1

            count2type = invertDictLossless(type2count)
            counts = count2type.keys()
            counts.sort()
            counts.reverse()
            for count in counts:
                print "%s: %s" % (count, count2type[count])

            self.setMagicWordResponse("~aiobjecthg complete")
        elif wordIs("~containers"):
            args = word.split()
            limit = 30
            if "full" in args:
                limit = None
            ContainerReport.ContainerReport("~containers", log=True, limit=limit, threaded=True)
        elif wordIs("~garbage"):
            args = word.split()
            full = "full" in args
            safeMode = "safe" in args
            delOnly = "delonly" in args
            GarbageReport.GarbageLogger(
                "~garbage",
                fullReport=full,
                threaded=True,
                safeMode=safeMode,
                delOnly=delOnly,
                doneCallback=self.garbageReportDone,
            )
        elif wordIs("~guicreates"):
            base.printGuiCreates = True
            self.setMagicWordResponse("printing gui creation stacks")
        elif wordIs("~creategarbage"):
            GarbageReport._createGarbage()
        elif wordIs("~leakTask"):

            def leakTask(task):
                return task.cont

            taskMgr.add(leakTask, uniqueName("leakedTask"))
            leakTask = None
        elif wordIs("~leakmessage"):
            MessengerLeakDetector._leakMessengerObject()
            self.down_setMagicWordResponse(senderId, "messenger leak object created")
        elif wordIs("~pstats"):
            args = word.split()
            hostname = None
            port = None
            if len(args) > 1:
                hostname = args[1]
            if len(args) > 2:
                port = int(args[2])
            base.wantStats = 1
            Task.TaskManager.pStatsTasks = 1
            result = base.createStats(hostname, port)
            connectionName = "%s" % hostname
            if port is not None:
                connectionName += ":%s" % port
            if result:
                response = "connected client pstats to %s" % connectionName
            else:
                response = "could not connect pstats to %s" % connectionName
            self.setMagicWordResponse(response)
        elif wordIs("~profile"):
            args = word.split()
            if len(args) > 1:
                num = int(args[1])
            else:
                num = 5
            session = taskMgr.getProfileSession("~profile")
            session.setLogAfterProfile(True)
            taskMgr.profileFrames(num, session)
            self.setMagicWordResponse("profiling %s client frames..." % num)
        elif wordIs("~frameprofile"):
            args = word.split()
            wasOn = bool(taskMgr.getProfileFrames())
            if len(args) > 1:
                setting = bool(int(args[1]))
            else:
                setting = not wasOn
            taskMgr.setProfileFrames(setting)
            self.setMagicWordResponse(
                "frame profiling %s%s" % (choice(setting, "ON", "OFF"), choice(wasOn == setting, " already", ""))
            )
        elif wordIs("~taskprofile"):
            args = word.split()
            wasOn = bool(taskMgr.getProfileTasks())
            if len(args) > 1:
                setting = bool(int(args[1]))
            else:
                setting = not wasOn
            taskMgr.setProfileTasks(setting)
            self.setMagicWordResponse(
                "task profiling %s%s" % (choice(setting, "ON", "OFF"), choice(wasOn == setting, " already", ""))
            )
        elif wordIs("~taskspikethreshold"):
            args = word.split()
            if len(args) > 1:
                threshold = float(args[1])
                response = "task spike threshold set to %ss" % threshold
            else:
                threshold = TaskProfiler.GetDefaultSpikeThreshold()
                response = "task spike threshold reset to %ss" % threshold
            TaskProfiler.SetSpikeThreshold(threshold)
            self.setMagicWordResponse(response)
        elif wordIs("~logtaskprofiles"):
            args = word.split()
            if len(args) > 1:
                name = args[1]
            else:
                name = None
            taskMgr.logTaskProfiles(name)
            response = "logged task profiles%s" % choice(name, " for %s" % name, "")
            self.setMagicWordResponse(response)
        elif wordIs("~taskprofileflush"):
            args = word.split()
            if len(args) > 1:
                name = args[1]
            else:
                name = None
            taskMgr.flushTaskProfiles(name)
            response = "flushed AI task profiles%s" % choice(name, " for %s" % name, "")
            self.setMagicWordResponse(response)
        elif wordIs("~dobjectcount"):
            base.cr.printObjectCount()
            self.setMagicWordResponse("logging client distributed object count...")
        elif wordIs("~taskmgr"):
            print taskMgr
            self.setMagicWordResponse("logging client taskMgr...")
        elif wordIs("~jobmgr"):
            print jobMgr
            self.setMagicWordResponse("logging client jobMgr...")
        elif wordIs("~jobtime"):
            args = word.split()
            if len(args) > 1:
                time = float(args[1])
            else:
                time = None
            response = ""
            if time is None:
                time = jobMgr.getDefaultTimeslice()
                response = "reset client jobMgr timeslice to %s ms" % time
            else:
                response = "set client jobMgr timeslice to %s ms" % time
                time = time / 1000.0
            jobMgr.setTimeslice(time)
            self.setMagicWordResponse(response)
        elif wordIs("~detectleaks"):
            started = self.cr.startLeakDetector()
            self.setMagicWordResponse(choice(started, "leak detector started", "leak detector already started"))
        elif wordIs("~taskthreshold"):
            args = word.split()
            if len(args) > 1.0:
                threshold = float(args[1])
            else:
                threshold = None
            response = ""
            if threshold is None:
                threshold = taskMgr.DefTaskDurationWarningThreshold
                response = "reset task duration warning threshold to %s" % threshold
            else:
                response = "set task duration warning threshold to %s" % threshold
            taskMgr.setTaskDurationWarningThreshold(threshold)
            self.setMagicWordResponse(response)
        elif wordIs("~messenger"):
            print messenger
            self.setMagicWordResponse("logging client messenger...")
        elif wordIs("~clientcrash"):
            DelayedCall(Functor(self.notify.error, "~clientcrash: simulating a client crash"))
        elif wordIs("~badDelete"):
            doId = 0
            while doId in base.cr.doId2do:
                doId += 1

            DelayedCall(Functor(base.cr.deleteObjectLocation, ScratchPad(doId=doId), 1, 1))
            self.setMagicWordResponse("doing bad delete")
        elif wordIs("~idTags"):
            messenger.send("nameTagShowAvId", [])
            base.idTags = 1
        elif wordIs("~nameTags"):
            messenger.send("nameTagShowName", [])
            base.idTags = 0
        elif wordIs("~hideNames"):
            if NametagGlobals.getMasterNametagsVisible():
                NametagGlobals.setMasterNametagsVisible(0)
            else:
                NametagGlobals.setMasterNametagsVisible(1)
        elif wordIs("~hideGui"):
            if aspect2d.isHidden():
                aspect2d.show()
            else:
                aspect2d.hide()
        elif wordIs("~flush"):
            base.cr.doDataCache.flush()
            base.cr.cache.flush()
            self.setMagicWordResponse("client object and data caches flushed")
        elif wordIs("~prof"):
            import time

            name = "default"
            p = Point3()
            ts = time.time()
            for i in xrange(1000000):
                p.set(1, 2, 3)

            tf = time.time()
            dt = tf - ts
            response = "prof(%s): %s secs" % (name, dt)
            print response
            self.setMagicWordResponse(response)
        elif wordIs("~gptc"):
            args = word.split()
            if len(args) > 1.0 and hasattr(self.cr, "leakDetector"):
                gptcJob = self.cr.leakDetector.getPathsToContainers(
                    "~gptc", args[1], Functor(self._handleGPTCfinished, args[1])
                )
            else:
                self.setMagicWordResponse("error")
        elif wordIs("~gptcn"):
            args = word.split()
            if len(args) > 1.0 and hasattr(self.cr, "leakDetector"):
                gptcnJob = self.cr.leakDetector.getPathsToContainersNamed(
                    "~gptcn", args[1], Functor(self._handleGPTCNfinished, args[1])
                )
            else:
                self.setMagicWordResponse("error")
        else:
            return 0
        return 1
    def setWASDTurn(self, turn):
        self.__WASDTurn = turn

        if not self.isEnabled:
            return
        
        turnLeftWASDSet = inputState.isSet("turnLeft", inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet("turnRight", inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet("slideLeft", inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet("slideRight", inputSource=inputState.WASD)

        for token in self.WASDTurnTokens:
            token.release()

        if turn:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("turnLeft", "a", inputSource=inputState.WASD),
                inputState.watchWithModifiers("turnRight", "d", inputSource=inputState.WASD),
                )

            inputState.set("turnLeft", slideLeftWASDSet, inputSource=inputState.WASD)
            inputState.set("turnRight", slideRightWASDSet, inputSource=inputState.WASD)

            inputState.set("slideLeft", False, inputSource=inputState.WASD)
            inputState.set("slideRight", False, inputSource=inputState.WASD)

        else:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("slideLeft", "a", inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideRight", "d", inputSource=inputState.WASD),
                )

            inputState.set("slideLeft", turnLeftWASDSet, inputSource=inputState.WASD)
            inputState.set("slideRight", turnRightWASDSet, inputSource=inputState.WASD)
                
            inputState.set("turnLeft", False, inputSource=inputState.WASD)
            inputState.set("turnRight", False, inputSource=inputState.WASD)
 def toggleRun(self):
     if config.GetBool('want-running', 1):
         inputState.set('debugRunning', inputState.isSet('debugRunning') != True)
예제 #20
0
    def setWASDTurn(self, turn):
        self.__WASDTurn = turn

        if not self.isEnabled:
            return

        turnLeftWASDSet = inputState.isSet("turnLeft", inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet("turnRight", inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet("slideLeft", inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet("slideRight", inputSource=inputState.WASD)

        for token in self.WASDTurnTokens:
            token.release()

        if turn:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("turnLeft", "a", inputSource=inputState.WASD),
                inputState.watchWithModifiers("turnRight", "d", inputSource=inputState.WASD),
                )

            inputState.set("turnLeft", slideLeftWASDSet, inputSource=inputState.WASD)
            inputState.set("turnRight", slideRightWASDSet, inputSource=inputState.WASD)

            inputState.set("slideLeft", False, inputSource=inputState.WASD)
            inputState.set("slideRight", False, inputSource=inputState.WASD)

        else:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("slideLeft", "a", inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideRight", "d", inputSource=inputState.WASD),
                )

            inputState.set("slideLeft", turnLeftWASDSet, inputSource=inputState.WASD)
            inputState.set("slideRight", turnRightWASDSet, inputSource=inputState.WASD)

            inputState.set("turnLeft", False, inputSource=inputState.WASD)
            inputState.set("turnRight", False, inputSource=inputState.WASD)
    def doMagicWord(self, word, avId, zoneId):
        wordIs = self.getWordIs(word)
        print word
        if wordIs('~oobe'):
            base.oobe()
        elif wordIs('~oobeCull'):
            base.oobeCull()
        elif wordIs('~tex'):
            self.doTex(word)
        elif wordIs('~texmem'):
            base.toggleTexMem()
        elif wordIs('~verts'):
            base.toggleShowVertices()
        elif wordIs('~wire'):
            base.toggleWireframe()
        elif wordIs('~stereo'):
            base.toggleStereo()
        elif wordIs('~showfont'):
            self.showfont(word[9:])
        elif wordIs('~hidefont'):
            self.hidefont()
        elif wordIs('~guiPopup'):
            self.toggleGuiPopup()
        elif wordIs('~showCS') or wordIs('~showcs'):
            bitmask = self.getCSBitmask(word[7:])
            render.showCS(bitmask)
            self.csShown = 1
        elif wordIs('~hideCS') or wordIs('~hidecs'):
            bitmask = self.getCSBitmask(word[7:])
            render.hideCS(bitmask)
            self.csShown = 0
        elif wordIs('~cs'):
            bitmask = self.getCSBitmask(word[3:])
            if self.csShown:
                render.hideCS(bitmask)
                self.csShown = 0
            else:
                render.showCS(bitmask)
                self.csShown = 1
        elif wordIs('~showShadowCollisions'):
            self.showShadowCollisions()
        elif wordIs('~hideShadowCollisions'):
            self.hideShadowCollisions()
        elif wordIs('~showCollisions'):
            self.showCollisions()
        elif wordIs('~hideCollisions'):
            self.hideCollisions()
        elif wordIs('~showCameraCollisions'):
            self.showCameraCollisions()
        elif wordIs('~hideCameraCollisions'):
            self.hideCameraCollisions()
        elif wordIs('~collidespam'):
            n = Notify.ptr().getCategory(':collide')
            if hasattr(self, '_collideSpamSeverity'):
                n.setSeverity(self._collideSpamSeverity)
                del self._collideSpamSeverity
            else:
                self._collideSpamSeverity = n.getSeverity()
                n.setSeverity(NSSpam)
        elif wordIs('~notify'):
            args = word.split()
            n = Notify.ptr().getCategory(args[1])
            n.setSeverity({'error': NSError,
             'warning': NSWarning,
             'info': NSInfo,
             'debug': NSDebug,
             'spam': NSSpam}[args[2]])
        elif wordIs('~stress'):
            factor = word[7:]
            if factor:
                factor = float(factor)
                LOD.setStressFactor(factor)
                response = 'Set LOD stress factor to %s' % factor
            else:
                factor = LOD.getStressFactor()
                response = 'LOD stress factor is %s' % factor
            self.setMagicWordResponse(response)
        elif wordIs('~for'):
            self.forAnother(word, avId, zoneId)
        elif wordIs('~badname'):
            word = '~for %s ~badname' % word[9:]
            print 'word is %s' % word
            self.forAnother(word, avId, zoneId)
        elif wordIs('~avId'):
            self.setMagicWordResponse(str(localAvatar.doId))
        elif wordIs('~doId'):
            name = string.strip(word[6:])
            objs = self.identifyDistributedObjects(name)
            if len(objs) == 0:
                response = '%s is unknown.' % name
            else:
                response = ''
                for name, obj in objs:
                    response += '\n%s %d' % (name, obj.doId)

                response = response[1:]
            self.setMagicWordResponse(response)
        elif wordIs('~exec'):
            from otp.chat import ChatManager
            ChatManager.ChatManager.execChat = 1
        elif wordIs('~run'):
            self.toggleRun()
        elif wordIs('~runFaster'):
            if config.GetBool('want-running', 1):
                args = word.split()
                if len(args) > 1:
                    base.debugRunningMultiplier = float(args[1])
                else:
                    base.debugRunningMultiplier = 10
                inputState.set('debugRunning', True)
        elif wordIs('~who'):
            avIds = []
            for av in Avatar.Avatar.ActiveAvatars:
                if hasattr(av, 'getFriendsList'):
                    avIds.append(av.doId)

            self.d_setWho(avIds)
        elif wordIs('~sync'):
            tm = self.cr.timeManager
            if tm == None:
                response = 'No TimeManager.'
                self.setMagicWordResponse(response)
            else:
                tm.extraSkew = 0.0
                skew = string.strip(word[5:])
                if skew != '':
                    tm.extraSkew = float(skew)
                globalClockDelta.clear()
                tm.handleHotkey()
        elif wordIs('~period'):
            timeout = string.strip(word[7:])
            if timeout != '':
                seconds = int(timeout)
                self.cr.stopPeriodTimer()
                self.cr.resetPeriodTimer(seconds)
                self.cr.startPeriodTimer()
            if self.cr.periodTimerExpired:
                response = 'Period timer has expired.'
            elif self.cr.periodTimerStarted:
                elapsed = globalClock.getFrameTime() - self.cr.periodTimerStarted
                secondsRemaining = self.cr.periodTimerSecondsRemaining - elapsed
                response = 'Period timer expires in %s seconds.' % int(secondsRemaining)
            else:
                response = 'Period timer not set.'
            self.setMagicWordResponse(response)
        elif wordIs('~DIRECT'):
            args = word.split()
            fEnableLight = 0
            if len(args) > 1:
                if direct and args[1] == 'CAM':
                    direct.enable()
                    taskMgr.removeTasksMatching('updateSmartCamera*')
                    camera.wrtReparentTo(render)
                    direct.cameraControl.enableMouseFly()
                    self.setMagicWordResponse('Enabled DIRECT camera')
                    return
                elif args[1] == 'LIGHT':
                    fEnableLight = 1
            base.startTk()
            from direct.directtools import DirectSession
            if fEnableLight:
                direct.enableLight()
            else:
                direct.enable()
            self.setMagicWordResponse('Enabled DIRECT')
        elif wordIs('~TT'):
            if not direct:
                return
            args = word.split()
            if len(args) > 1:
                if args[1] == 'CAM':
                    direct.cameraControl.disableMouseFly()
                    camera.wrtReparentTo(base.localAvatar)
                    base.localAvatar.startUpdateSmartCamera()
                    self.setMagicWordResponse('Disabled DIRECT camera')
                    return
            direct.disable()
            camera.wrtReparentTo(base.localAvatar)
            base.localAvatar.startUpdateSmartCamera()
            self.setMagicWordResponse('Disabled DIRECT')
        elif wordIs('~net'):
            if self.cr.networkPlugPulled():
                self.cr.restoreNetworkPlug()
                self.cr.startHeartbeat()
                response = 'Network restored.'
            else:
                self.cr.pullNetworkPlug()
                self.cr.stopHeartbeat()
                response = 'Network disconnected.'
            self.setMagicWordResponse(response)
        elif wordIs('~disconnect'):
            base.cr.distributedDistrict.sendUpdate('broadcastMessage')
        elif wordIs('~model'):
            args = word.split()
            path = args[1]
            model = loader.loadModel(path)
            model.reparentTo(localAvatar)
            model.wrtReparentTo(render)
            self.setMagicWordResponse('loaded %s' % path)
        elif wordIs('~axis'):
            axis = loader.loadModel('models/misc/xyzAxis.bam')
            axis.reparentTo(render)
            axis.setPos(base.localAvatar, 0, 0, 0)
            axis.setHpr(render, 0, 0, 0)
            axis10 = loader.loadModel('models/misc/xyzAxis.bam')
            axis10.reparentTo(render)
            axis10.setPos(base.localAvatar, 0, 0, 0)
            axis10.setScale(10)
            axis10.setHpr(render, 0, 0, 0)
            axis10.setColorScale(1, 1, 1, 0.4)
            axis10.setTransparency(1)
        elif wordIs('~clearAxes') or wordIs('~clearAxis'):
            render.findAllMatches('**/xyzAxis.egg').detach()
        elif wordIs('~myAxis'):
            if hasattr(self, 'myAxis'):
                self.myAxis.detachNode()
                del self.myAxis
            else:
                self.myAxis = loader.loadModel('models/misc/xyzAxis.bam')
                self.myAxis.reparentTo(localAvatar)
        elif wordIs('~osd'):
            onScreenDebug.enabled = not onScreenDebug.enabled
        elif wordIs('~osdScale'):
            args = word.split()
            defScale = 0.05
            if len(args) > 1:
                scale = float(args[1])
            else:
                scale = 1.0
            onScreenDebug.onScreenText.setScale(defScale * scale)
        elif wordIs('~osdTaskMgr'):
            if taskMgr.osdEnabled():
                taskMgr.stopOsd()
            else:
                if not onScreenDebug.enabled:
                    onScreenDebug.enabled = True
                taskMgr.startOsd()
        elif wordIs('~fps'):
            self.doFps(word, avId, zoneId)
        elif wordIs('~sleep'):
            args = word.split()
            if len(args) > 1:
                s = float(args[1])
                base.setSleep(s)
                response = 'sleeping %s' % s
            else:
                base.setSleep(0.0)
                response = 'not sleeping'
            self.setMagicWordResponse(response)
        elif wordIs('~objects'):
            args = word.split()
            from direct.showbase import ObjectReport
            report = ObjectReport.ObjectReport('client ~objects')
            if 'all' in args:
                self.notify.info('printing full object set...')
                report.getObjectPool().printObjsByType(printReferrers='ref' in args)
            if hasattr(self, 'baselineObjReport'):
                self.notify.info('calculating diff from baseline ObjectReport...')
                self.lastDiff = self.baselineObjReport.diff(report)
                self.lastDiff.printOut(full='diff' in args or 'dif' in args)
            if 'baseline' in args or not hasattr(self, 'baselineObjReport'):
                self.notify.info('recording baseline ObjectReport...')
                if hasattr(self, 'baselineObjReport'):
                    self.baselineObjReport.destroy()
                self.baselineObjReport = report
            self.setMagicWordResponse('objects logged')
        elif wordIs('~objectcount'):

            def handleObjectCountDone(objectCount):
                self.setMagicWordResponse('object count logged')

            oc = ObjectCount('~objectcount', doneCallback=handleObjectCountDone)
        elif wordIs('~objecthg'):
            import gc
            objs = gc.get_objects()
            type2count = {}
            for obj in objs:
                tn = safeTypeName(obj)
                type2count.setdefault(tn, 0)
                type2count[tn] += 1

            count2type = invertDictLossless(type2count)
            counts = count2type.keys()
            counts.sort()
            counts.reverse()
            for count in counts:
                print '%s: %s' % (count, count2type[count])

            self.setMagicWordResponse('~aiobjecthg complete')
        elif wordIs('~containers'):
            args = word.split()
            limit = 30
            if 'full' in args:
                limit = None
            ContainerReport.ContainerReport('~containers', log=True, limit=limit, threaded=True)
        elif wordIs('~garbage'):
            args = word.split()
            full = 'full' in args
            safeMode = 'safe' in args
            delOnly = 'delonly' in args
            GarbageReport.GarbageLogger('~garbage', fullReport=full, threaded=True, safeMode=safeMode, delOnly=delOnly, doneCallback=self.garbageReportDone)
        elif wordIs('~guicreates'):
            base.printGuiCreates = True
            self.setMagicWordResponse('printing gui creation stacks')
        elif wordIs('~creategarbage'):
            GarbageReport._createGarbage()
        elif wordIs('~leakTask'):

            def leakTask(task):
                return task.cont

            taskMgr.add(leakTask, uniqueName('leakedTask'))
            leakTask = None
        elif wordIs('~leakmessage'):
            MessengerLeakDetector._leakMessengerObject()
            self.down_setMagicWordResponse(senderId, 'messenger leak object created')
        elif wordIs('~pstats'):
            args = word.split()
            hostname = None
            port = None
            if len(args) > 1:
                hostname = args[1]
            if len(args) > 2:
                port = int(args[2])
            base.wantStats = 1
            Task.TaskManager.pStatsTasks = 1
            result = base.createStats(hostname, port)
            connectionName = '%s' % hostname
            if port is not None:
                connectionName += ':%s' % port
            if result:
                response = 'connected client pstats to %s' % connectionName
            else:
                response = 'could not connect pstats to %s' % connectionName
            self.setMagicWordResponse(response)
        elif wordIs('~profile'):
            args = word.split()
            if len(args) > 1:
                num = int(args[1])
            else:
                num = 5
            session = taskMgr.getProfileSession('~profile')
            session.setLogAfterProfile(True)
            taskMgr.profileFrames(num, session)
            self.setMagicWordResponse('profiling %s client frames...' % num)
        elif wordIs('~frameprofile'):
            args = word.split()
            wasOn = bool(taskMgr.getProfileFrames())
            if len(args) > 1:
                setting = bool(int(args[1]))
            else:
                setting = not wasOn
            taskMgr.setProfileFrames(setting)
            self.setMagicWordResponse('frame profiling %s%s' % (choice(setting, 'ON', 'OFF'), choice(wasOn == setting, ' already', '')))
        elif wordIs('~taskprofile'):
            args = word.split()
            wasOn = bool(taskMgr.getProfileTasks())
            if len(args) > 1:
                setting = bool(int(args[1]))
            else:
                setting = not wasOn
            taskMgr.setProfileTasks(setting)
            self.setMagicWordResponse('task profiling %s%s' % (choice(setting, 'ON', 'OFF'), choice(wasOn == setting, ' already', '')))
        elif wordIs('~taskspikethreshold'):
            args = word.split()
            if len(args) > 1:
                threshold = float(args[1])
                response = 'task spike threshold set to %ss' % threshold
            else:
                threshold = TaskProfiler.GetDefaultSpikeThreshold()
                response = 'task spike threshold reset to %ss' % threshold
            TaskProfiler.SetSpikeThreshold(threshold)
            self.setMagicWordResponse(response)
        elif wordIs('~logtaskprofiles'):
            args = word.split()
            if len(args) > 1:
                name = args[1]
            else:
                name = None
            taskMgr.logTaskProfiles(name)
            response = 'logged task profiles%s' % choice(name, ' for %s' % name, '')
            self.setMagicWordResponse(response)
        elif wordIs('~taskprofileflush'):
            args = word.split()
            if len(args) > 1:
                name = args[1]
            else:
                name = None
            taskMgr.flushTaskProfiles(name)
            response = 'flushed AI task profiles%s' % choice(name, ' for %s' % name, '')
            self.setMagicWordResponse(response)
        elif wordIs('~dobjectcount'):
            base.cr.printObjectCount()
            self.setMagicWordResponse('logging client distributed object count...')
        elif wordIs('~taskmgr'):
            print taskMgr
            self.setMagicWordResponse('logging client taskMgr...')
        elif wordIs('~jobmgr'):
            print jobMgr
            self.setMagicWordResponse('logging client jobMgr...')
        elif wordIs('~jobtime'):
            args = word.split()
            if len(args) > 1:
                time = float(args[1])
            else:
                time = None
            response = ''
            if time is None:
                time = jobMgr.getDefaultTimeslice()
                response = 'reset client jobMgr timeslice to %s ms' % time
            else:
                response = 'set client jobMgr timeslice to %s ms' % time
                time = time / 1000.0
            jobMgr.setTimeslice(time)
            self.setMagicWordResponse(response)
        elif wordIs('~detectleaks'):
            started = self.cr.startLeakDetector()
            self.setMagicWordResponse(choice(started, 'leak detector started', 'leak detector already started'))
        elif wordIs('~taskthreshold'):
            args = word.split()
            if len(args) > 1.0:
                threshold = float(args[1])
            else:
                threshold = None
            response = ''
            if threshold is None:
                threshold = taskMgr.DefTaskDurationWarningThreshold
                response = 'reset task duration warning threshold to %s' % threshold
            else:
                response = 'set task duration warning threshold to %s' % threshold
            taskMgr.setTaskDurationWarningThreshold(threshold)
            self.setMagicWordResponse(response)
        elif wordIs('~messenger'):
            print messenger
            self.setMagicWordResponse('logging client messenger...')
        elif wordIs('~clientcrash'):
            DelayedCall(Functor(self.notify.error, '~clientcrash: simulating a client crash'))
        elif wordIs('~badDelete'):
            doId = 0
            while doId in base.cr.doId2do:
                doId += 1

            DelayedCall(Functor(base.cr.deleteObjectLocation, ScratchPad(doId=doId), 1, 1))
            self.setMagicWordResponse('doing bad delete')
        elif wordIs('~idTags'):
            messenger.send('nameTagShowAvId', [])
            base.idTags = 1
        elif wordIs('~nameTags'):
            messenger.send('nameTagShowName', [])
            base.idTags = 0
        elif wordIs('~hideNames'):
            if NametagGlobals.getMasterNametagsVisible():
                NametagGlobals.setMasterNametagsVisible(0)
            else:
                NametagGlobals.setMasterNametagsVisible(1)
        elif wordIs('~hideGui'):
            if aspect2d.isHidden():
                aspect2d.show()
            else:
                aspect2d.hide()
        elif wordIs('~flush'):
            base.cr.doDataCache.flush()
            base.cr.cache.flush()
            self.setMagicWordResponse('client object and data caches flushed')
        elif wordIs('~prof'):
            import time
            name = 'default'
            p = Point3()
            ts = time.time()
            for i in xrange(1000000):
                p.set(1, 2, 3)

            tf = time.time()
            dt = tf - ts
            response = 'prof(%s): %s secs' % (name, dt)
            print response
            self.setMagicWordResponse(response)
        elif wordIs('~gptc'):
            args = word.split()
            if len(args) > 1.0 and hasattr(self.cr, 'leakDetector'):
                gptcJob = self.cr.leakDetector.getPathsToContainers('~gptc', args[1], Functor(self._handleGPTCfinished, args[1]))
            else:
                self.setMagicWordResponse('error')
        elif wordIs('~gptcn'):
            args = word.split()
            if len(args) > 1.0 and hasattr(self.cr, 'leakDetector'):
                gptcnJob = self.cr.leakDetector.getPathsToContainersNamed('~gptcn', args[1], Functor(self._handleGPTCNfinished, args[1]))
            else:
                self.setMagicWordResponse('error')
        else:
            return 0
        return 1
예제 #22
0
    def setWASDTurn(self, turn):
        # This probably needs to be cleaned up, I don't think Toontown uses slide anywhere
        self.__WASDTurn = turn

        if not self.isEnabled:
            return

        keymap = settings.get('keymap', {})

        turnLeftWASDSet = inputState.isSet("turnLeft",
                                           inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet("turnRight",
                                            inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet("slideLeft",
                                            inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet("slideRight",
                                             inputSource=inputState.WASD)

        for token in self.WASDTurnTokens:
            token.release()

        if turn:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("turnLeft",
                                              keymap.get(
                                                  'MOVE_LEFT', base.MOVE_LEFT),
                                              inputSource=inputState.WASD),
                inputState.watchWithModifiers("turnRight",
                                              keymap.get(
                                                  'MOVE_RIGHT',
                                                  base.MOVE_RIGHT),
                                              inputSource=inputState.WASD),
            )

            inputState.set("turnLeft",
                           slideLeftWASDSet,
                           inputSource=inputState.WASD)
            inputState.set("turnRight",
                           slideRightWASDSet,
                           inputSource=inputState.WASD)

            inputState.set("slideLeft", False, inputSource=inputState.WASD)
            inputState.set("slideRight", False, inputSource=inputState.WASD)

        else:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("slideLeft",
                                              keymap.get(
                                                  'MOVE_LEFT', base.MOVE_LEFT),
                                              inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideRight",
                                              keymap.get(
                                                  'MOVE_RIGHT',
                                                  base.MOVE_RIGHT),
                                              inputSource=inputState.WASD),
            )

            inputState.set("slideLeft",
                           turnLeftWASDSet,
                           inputSource=inputState.WASD)
            inputState.set("slideRight",
                           turnRightWASDSet,
                           inputSource=inputState.WASD)

            inputState.set("turnLeft", False, inputSource=inputState.WASD)
            inputState.set("turnRight", False, inputSource=inputState.WASD)
예제 #23
0
 def toggleRun(self):
     if (config.GetBool("want-running", 1)):
         inputState.set("debugRunning",
                        inputState.isSet("debugRunning") != True)
예제 #24
0
def run():
    """
    Toggles debugging run speed.
    """
    inputState.set('debugRunning', inputState.isSet('debugRunning') != True)
    return 'Toggled debug run speed.'
    def setWASDTurn(self, turn):
        self._ControlManager__WASDTurn = turn
        if not self.isEnabled:
            return None

        turnLeftWASDSet = inputState.isSet('turnLeft',
                                           inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet('turnRight',
                                            inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet('slideLeft',
                                            inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet('slideRight',
                                             inputSource=inputState.WASD)
        for token in self.WASDTurnTokens:
            token.release()

        if turn:
            self.WASDTurnTokens = (inputState.watchWithModifiers(
                'turnLeft', 'a', inputSource=inputState.WASD),
                                   inputState.watchWithModifiers(
                                       'turnRight',
                                       'd',
                                       inputSource=inputState.WASD))
            inputState.set('turnLeft',
                           slideLeftWASDSet,
                           inputSource=inputState.WASD)
            inputState.set('turnRight',
                           slideRightWASDSet,
                           inputSource=inputState.WASD)
            inputState.set('slideLeft', False, inputSource=inputState.WASD)
            inputState.set('slideRight', False, inputSource=inputState.WASD)
        else:
            self.WASDTurnTokens = (inputState.watchWithModifiers(
                'slideLeft', 'a', inputSource=inputState.WASD),
                                   inputState.watchWithModifiers(
                                       'slideRight',
                                       'd',
                                       inputSource=inputState.WASD))
            inputState.set('slideLeft',
                           turnLeftWASDSet,
                           inputSource=inputState.WASD)
            inputState.set('slideRight',
                           turnRightWASDSet,
                           inputSource=inputState.WASD)
            inputState.set('turnLeft', False, inputSource=inputState.WASD)
            inputState.set('turnRight', False, inputSource=inputState.WASD)