Archive for the ‘dynamic timer’ Category

Dynamic Framerates

Wednesday, November 5th, 2008

One thing that I’ve started using in most of my projects where the processor could get hit heavily is a dynamic rendering system. This seems to be working really well, so I thought I’d share it.

I came across the idea from this post over at 8 bit rocket. The idea is pretty simple. A timer is set to run as fast as possible. Every time the timer executes, it runs a render cycle and a code cycle. It then checks how long the total cycle took and does 1 of 2 things. Either it sleeps for a certain amount of time, so that the swf doesn’t run too fast, or the next render cycle is dropped so the player can catch up. It’s a little more involved than that so if you want to know the finer details, head on over there.

I made some crucial adjustments to the code that’s presented there however. The biggest one was to make the code into a class, so that I could use it more easily. I’ve set up a system for registering renderers and updaters so they can be added and removed from the timer, and also added some events that get dispatched on render and update cycles. It works really well if you have an MVC setup, since the model and the view are already separate.

The source code is available here. Documentation after the jump.
(more…)