1.7.0 performance issues

digging the new way to run a panda app, I tried the helloworld code from the manual but founding it not really smooth as using the usual directstart import - is it just me or somebody else is experiencing this issue?

You mean, to instantiate a ShowBase explicitly instead of importing DirectStart? If you look at the contents of DirectStart.py, it contains exactly these lines:

print 'DirectStart: Starting the game.'

from direct.showbase import ShowBase
base = ShowBase.ShowBase()

So, it’s hard to imagine that moving these lines into your own code instead of in DirectStart.py will make a difference in the visible behavior.


well first off I started doing a child class down showBase:

class myworld(ShowBase):
  def __init__(self):

and such, and seeing that choppiness I thought was something wrong with my code, therefore I took the code found here in the manual and running straight as is I had exactly the same results. BTW I’m testing it with ubuntu (look the whole rig in my signature).

just to have another check, I tried the old code of the samew helloworld sample cited above and, guess what, is choppy as well - so looks like it is not a matter of the new showBase stuff but something above it, that is revelaed by that demo code. More than this I noted another performance issue (can’t remember if was there with 1.6 as well though) that when I resize wider a windows i.e. sized by default 800x600 the fps performance drop by halved.

I’m the one who renovated the tutorial pages and replaced that horrible DirectStart hack with the more direct ShowBase instantiation, so I figure I should comment here, on a relevant note, that I’m about to make one more revision to that tutorial. I’m thinking that subclassing ShowBase is a much cleaner and more intuitive approach than all this p3dApp stuff, which I went with to make it less counter-intuitive than the builtin hack makes things.

I’ve something ready for you if you like:

from math import pi, sin, cos

from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import Sequence
from panda3d.core import Point3

class myworld(ShowBase):
  def __init__(self):

    environ = self.loader.loadModel("models/environment")
    # Apply scale and position transforms on the model.
    environ.setScale(0.25, 0.25, 0.25)
    environ.setPos(-8, 42, 0)

    # Add the procedure to the task manager.
    self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")

    # Load and transform the panda actor - Note that is mandatory to store the actor object in a non volatile member otherwise you won't see it animate.
    self.pandaActor = Actor(
      "models/panda", {"walk": "models/panda-walk"}
    self.pandaActor.setScale(0.2, 0.2, 0.2)
    # Loop its animation.

    # Create the four lerp intervals needed for the panda to walk back and forth.
    pandaPosInterval1 = self.pandaActor.posInterval(
      9, Point3(0, -10, 0), startPos=Point3(0, 10, 0)
    pandaPosInterval2 = self.pandaActor.posInterval(
      9, Point3(0, 10, 0), startPos=Point3(0, -10, 0)
    pandaHprInterval1 = self.pandaActor.hprInterval(
      1, Point3(180, 0, 0), startHpr=Point3(0, 0, 0)
    pandaHprInterval2 = self.pandaActor.hprInterval(
      1, Point3(0, 0, 0), startHpr=Point3(180, 0, 0)

    # Create and play the sequence that coordinates the intervals.
    pandaPace = Sequence(
      pandaPosInterval1, pandaHprInterval1, pandaPosInterval2,
      pandaHprInterval2, name="pandaPace"

  # Define a procedure to move the camera.
  def spinCameraTask(self, task):
    angleDegrees = task.time * 6.0
    angleRadians = angleDegrees * (pi / 180.0)
    self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
    return task.cont


Wow, talk about a time saver. Thanks!

By the way, does anyone have any objections toward the subclassing approach? The way I see it, the only side-effect is it takes a bit more object-oriented programming and Python (as I am not making changes to the C++ side) understanding, but that doesn’t seem negative in my mind since Panda3D-Python users should already know Python, and since instantiating ShowBase already requires knowledge of object-oriented programming. I also figured that many libraries already take this approach, and that it makes things, as I mentioned, much more intuitive to mainstream programmers.

I don’t have any objections. ShowBase is actually designed to be subclassed from.


There. I just made the revision. Now I’m wondering about yet another possible change. Most of the functionality currently sits in MyApp.init() with the one exception being MyApp.spinCameraTask(). I’m wondering if a better approach would be for each tutorial section to add a new procedure (e.g. MyApp.loadEnvironment(), MyApp.spinCamera(), MyApp.loadActor(), MyApp.applyPace()) and call them in MyApp.init(). Any comments?

Hmm, we’re kind of splitting hairs at this point, but I guess it does seem a little better-organized to separate each of them out into a different method.