Timebase for tasks and intervals for pausing & slow moti

Return to Scripting Issues

Timebase for tasks and intervals for pausing & slow moti

Postby paniq » Wed Apr 18, 2012 5:07 am

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 your time :)
paniq
 
Posts: 6
Joined: Sat Apr 19, 2008 9:31 pm

Postby ynjh_jo » Wed Apr 18, 2012 6:16 am

click my sig, it should help.
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby paniq » Wed Apr 18, 2012 1:03 pm

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 :)
paniq
 
Posts: 6
Joined: Sat Apr 19, 2008 9:31 pm

Postby Nemesis#13 » Mon Apr 23, 2012 7:02 am

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!)
Code: Select all
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.

If you come up with other ideas, let me know.
User avatar
Nemesis#13
 
Posts: 1040
Joined: Mon Aug 04, 2008 8:09 pm
Location: Germany


Return to Scripting Issues

Who is online

Users browsing this forum: Google [Bot] and 0 guests