mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
cleaned up client sleep code
This commit is contained in:
parent
bbc5a5f19b
commit
805b7b61ef
@ -73,13 +73,6 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
|
|
||||||
self.wantStats = self.config.GetBool('want-pstats', 0)
|
self.wantStats = self.config.GetBool('want-pstats', 0)
|
||||||
|
|
||||||
self.clientSleep = self.config.GetFloat('client-sleep', 0.)
|
|
||||||
# magic-word override
|
|
||||||
self.mwClientSleep = 0.
|
|
||||||
|
|
||||||
# using 'sleep' once per frame to limit CPU usage.
|
|
||||||
self.sleepCycle = 0.0
|
|
||||||
|
|
||||||
# Fill this in with a function to invoke when the user "exits"
|
# Fill this in with a function to invoke when the user "exits"
|
||||||
# the program by closing the main window.
|
# the program by closing the main window.
|
||||||
self.exitFunc = None
|
self.exitFunc = None
|
||||||
@ -258,6 +251,11 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
# Setup the window controls - handy for multiwindow applications
|
# Setup the window controls - handy for multiwindow applications
|
||||||
self.setupWindowControls()
|
self.setupWindowControls()
|
||||||
|
|
||||||
|
# Client sleep
|
||||||
|
sleepTime = self.config.GetFloat('client-sleep', 0.0)
|
||||||
|
self.clientSleep = 0.0
|
||||||
|
self.setSleep(sleepTime)
|
||||||
|
|
||||||
# Start Tk and DIRECT if specified by Config.prc
|
# Start Tk and DIRECT if specified by Config.prc
|
||||||
fTk = self.config.GetBool('want-tk', 0)
|
fTk = self.config.GetBool('want-tk', 0)
|
||||||
# Start DIRECT if specified in Config.prc or in cluster mode
|
# Start DIRECT if specified in Config.prc or in cluster mode
|
||||||
@ -569,15 +567,18 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
Sets up a task that calls python 'sleep' every frame. This is a simple
|
Sets up a task that calls python 'sleep' every frame. This is a simple
|
||||||
way to reduce the CPU usage (and frame rate) of a panda program.
|
way to reduce the CPU usage (and frame rate) of a panda program.
|
||||||
"""
|
"""
|
||||||
if (self.sleepCycle == amount): return()
|
if (self.clientSleep == amount):
|
||||||
if (time == 0.0):
|
return
|
||||||
self.taskMgr.remove('sleep-cycle')
|
self.clientSleep = amount
|
||||||
|
if (amount == 0.0):
|
||||||
|
self.taskMgr.remove('clientSleep')
|
||||||
else:
|
else:
|
||||||
self.sleepCycle = amount
|
# Spawn it after igloop (at the end of each frame)
|
||||||
self.taskMgr.add(self.sleepCycleTask, 'sleep-cycle')
|
self.taskMgr.remove('clientSleep')
|
||||||
|
self.taskMgr.add(self.sleepCycleTask, 'clientSleep', priority = 55)
|
||||||
|
|
||||||
def sleepCycleTask(self, state):
|
def sleepCycleTask(self, task):
|
||||||
time.sleep(self.sleepCycle)
|
time.sleep(self.clientSleep)
|
||||||
return Task.cont
|
return Task.cont
|
||||||
|
|
||||||
def setFrameRateMeter(self, flag):
|
def setFrameRateMeter(self, flag):
|
||||||
@ -1203,12 +1204,6 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
# minimized, not just the main window. But it will do for
|
# minimized, not just the main window. But it will do for
|
||||||
# now until someone complains.
|
# now until someone complains.
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
else:
|
|
||||||
# magic word overrides config
|
|
||||||
if self.mwClientSleep:
|
|
||||||
time.sleep(self.mwClientSleep)
|
|
||||||
elif self.clientSleep:
|
|
||||||
time.sleep(self.clientSleep)
|
|
||||||
|
|
||||||
# Lerp stuff needs this event, and it must be generated in
|
# Lerp stuff needs this event, and it must be generated in
|
||||||
# C++, not in Python.
|
# C++, not in Python.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user