Optimizing Papervision Rendering Performance Part I

1 Comment

One of the big problems with Papervision as a 3D engine is that because it’s cross platform, not hardware accelerated, it really uses up a lot of the hardware CPU.
Many Papervision projects can really bog down the CPU and can be a major turnoff for a user or a site visitor.

One of the easiest most common sense things to do is to render only when necessary. This only works for certain types of Papervision projects. If you have a 3D 1st person shooter, this probably won’t apply as much since you are always in motion. However if you have a project with clearly defined animation states that end up into mostly static states, this trick is a good one.

What I do is have a global variable, singleton or what have you called NEEDS_RENDER, which is set to true only when you need to render of course. By that I mean, only when there’s animation. If the scene does not change, there’s no need for us to call the Papervision render loop to update the scene.

// our render loop should look something like this now:
private function enterFrameHandler(event:Event):void {

If we are doing tween based animation (I am a big fan of TweenMax), then right before we do the animation, we set ourvariable to true so that the render loop knows to update the scene.
We use the onComplete event to set the NEEDS_RENDER variable back to false so that when the animation is done, we are no longer updating the scene.

TweenMax.to(cube, 1, {
onComplete:function():void {NEEDS_RENDER = false;}

This works for really simple cases where we only have at most ONE animation going on at any one time. In a more complicated scene where there maybe animations starting in the middle of other animations ending, using this method will produce rendering artifacts where animations suddenly stop or freeze or disappear. This is because the previous animation has not had a chance to finish its animation when a new animation starts. When the first animation finishes, the global variable is set and the render loop gets the message to not have to update the scene. This results in the new animation not being able to finish.

The simple workaround for this is to use the onUpdate event of TweenMax. We just keep setting the variable to true on this event which will keep firing until the animation is complete.

TweenMax.to(cube, 1, {
onComplete:function():void {NEEDS_RENDER = false;},
onUpdate:function():void {NEEDS_RENDER = true;}

Using these simple techniques, I was able to get a Papervision project that was constantly eating up 70-80% CPU to something that hovered around 20%, only spiking up during the animation.

Popularity: 9% [?]

Ruby On Rails 2.0 Tutorial For Dummies


I just started learning Ruby On Rails. Since I like to be on the bleeding edge, I decided to go 2.0. What I found was that although there were a lot of tutorials on Rails 1.2, there was hardly anything on 2.0. To make matters worse, just enough had changed to make the tutorials on the web not very helpful to me. Fortunately my good friend Josh Kahn helped walk me through the basics and so I decided to take notes. (Note: this is for a Windows installation.) Yeah, I know, I said I was a Mac guy, but this is for work.

Curt Hibbs has already wrote a good intro to Ruby on Rails and some of the prerequisites to installing Rails, so I won’t rewrite that. Following his lead, I installed:


  1. Install Ruby using the One-Click Ruby Installer for Windows. (Version 1.8.6-26 as of April 28, 2008).
  2. Install Rails. The Windows installer comes with RubyGems package manager which lets you install the latest version of Rails. Go into the command prompt and run the command
    gem install rails –remote

    Answer ‘y’ to each question.

  3. Install MySQL using the Windows Essentials version. (Version 4.1.22 as of April 28, 2008). Go through the configuration wizard and accept all the settings till you get to Security Settings. Uncheck “Modify Security Settings.”
  4. Install a MySQL front end. I used HeidiSQL, a free open-source one, but there’s no reason you can’t use something else.

The Fun Stuff

This being the web and all, I’m not gonna regurgitate what someone else wrote. I found this pretty easy to follow tutorial by the guy who wrote the ONLamp Ruby on Rails tutorial, but for 2.02. Here’s the Cliff’s notes version for those lazy people like me along with some extra steps that were essential but not covered in the tutorial.

  1. Create a new Rails application called bookstore. In the command prompt, type:
    rails bookstore
  2. Create a scaffold for the bookstore. For this simple example, the bookstore has books with properties title and description. In the command prompt, type:
    ruby script/generate scaffold Book title:string description:text
  3. Configure your database. In your bookstore/config folder, open database.yaml. Your development configuration should look like this:
      adapter: mysql
      database: bookstore
      host: localhost
      username: root
      timeout: 5000
  4. Run the database migration script. Now that you’ve configured the database properly, go to the command prompt and type:
    rake db:migrate

    This will create the necessary tables.

  5. Start the server. In your command prompt, navigate to the bookstore directory and type:
    ruby script/server

That’s it. In your browser, navigate to and you should see your first Ruby On Rails 2.0 app. If you found this post useful, leave a comment. Feedback is appreciated as well.

Popularity: 8% [?]