On my background: I have worked for 4 years as a C/C++ programmer in the game industry, and am now working on an indie project. I’m using Panda3D to build a puzzle/tower defense game, as it is the only all-in-one solution for Python that shows production-hardened craftsmanship.
I’m currently working on the surprisingly challenging task to provide two related abilities to the game:
pausing the game, while keeping the menu running
slowing down projectiles and enemies for a “bullet time” effect
Ideally, I would like to associate intervals and tasks with a different clock (timebase), so that I can use this clock to pause or slow down the game. (Or, alternatively, associate all elements that should always run regularly (menu, UI elements) with a different clock)
Are there best-practice facilities in Panda 3D that provide a no-headache approach to adapt my existing code, or will I have to build my own solutions?
I have experimented with providing a factory for intervals which adds these to a list on creation, but the issue here is when to remove them from the list - this also kind of duplicates what IntervalManager is doing, but I haven’t figured out how to circumvent the monopoly of ivalMgr to add intervals to my own manager . I don’t want to hack around anything.
Regarding tasks, I have not started work yet, as they seem easier to handle, but I’d also be glad for an easy solution to pause/resume/slowdown/speedup a group of tasks.
Thanks for the suggestion. I checked out your pause/resume code, and it probably works well, but I’m sorry to say that it’s completely undocumented and not maintained in a repository.
I wouldn’t be able to understand quickly what’s wrong with it if it breaks, and how to fix it best. I wouldn’t know where to report bugs or feature requests, and how to update my code pain-free.
I’d rather prefer a solution native to Panda3D.
Besides, the bullet time issue is still open. I couldn’t find anything in your snippets that looked like it was addressing this issue.
I know I’m a tough “customer”. But thanks for trying
I had these issues, too.
A clean and easy solution unfortunately is not existent in Panda.
I tried multiplying the global clock’s delta time, which worked pretty well and slowed down intervals.
Here’s the code:
(Click on the box to the left to turn framerate control on!)
from direct.showbase.ShowBase import *
from direct.interval.IntervalGlobal import *
from pandac.PandaModules import Point3, FrameRateMeter, ClockObject
from direct.gui.DirectGui import *
ShowBase()
#globalClock.setMode(globalClock.MNonRealTime)
#globalClock.setDt(1.0/30)
smiley = loader.loadModel("smiley")
smiley.reparentTo(render)
smiley.setY(10)
i = LerpPosInterval(smiley, 10, Point3(0,10,3))
i.start()
i.loop()
def toggleClockMode():
if globalClock.getMode() is globalClock.MNonRealTime:
print "setting clock to realtime"
globalClock.setMode(globalClock.MNormal)
globalClock.setRealTime(globalClock.getFrameTime()) # option 1
else:
print "setting clock to non realtime"
globalClock.setMode(globalClock.MNonRealTime)
slider = DirectSlider(range=(1.0/1, 1.0/300000), value=1.0/30, pageSize=3)
slider.setZ(-0.8)
button = DirectButton(command=toggleClockMode)
button.setScale(0.3)
button.setPos(-1.1, 0, -0.8)
def setFrameSpeed(task):
globalClock.setDt(slider["value"])
#globalClock.setRealTime(globalClock.getFrameTime()) # option 2
return task.cont
def printIt(task):
print "check"
return task.again
taskMgr.doMethodLater(3, printIt, "periodical print")
taskMgr.add(setFrameSpeed, "set frame speed")
run()
I haven’t tried it with animations, sound- or video playback.
To stop/pause a group of tasks you could create a second task chain (which is a group of tasks) and then set the frame budget on certain task chains to 0, which means that they won’t be run.
Alternatively look up a global state variable in all your tasks - this won’t work out of the box for panda-internal tasks like intervals, audio- or video playback. In fact it will only work for your own tasks.