Advertisement

Time-based animation via scripting

Started by August 19, 2004 06:28 AM
2 comments, last by evolutional 20 years, 3 months ago
Hi! I´m not sure whether this is a real scripting language question... i´ve just thought i post it into this forum. The background is that i currently finished implementing my scripting language (with a C-style syntax). Now, i have injected the scripting into my current FPS game environment, to test it further. I have animated a point light via a script (random flickering). but there is an (obvious) problem: The animation frequency varies with frame rate, as the frame rate increases, it becomes faster, and slower if the frame rate drops. So i need to make the scripts time based - but how? To explain the technical background, i have implemented some very simple script multi-threading. The virtual machine executes only a single instruction of the current thread per frame. After a specified timeout, the current thread yields to give concurrent threads the chance to run. here is a part from my main engine loop: I_SCRIPTINGVM->run_threads(0); // no timeout I_SCENE->render(); So, how can in realize it? I need to change the way my script is called depending on the frame rate... but this is getting me mad, i jst can´t get a grip out of it!! :( i would appreciate any ideas/input! thanks in advance Gammastrahler
There are, AFAIK, basically two options to make a game run at a constant rate:

1. Run your logic at a fixed rate, independently of the (variable) frame rate.

This is usually achieved by running the logic at the fastest frame rate you care about, and if rendering a frame takes longer, run the logic more than once per frame.

2. Use a variable time step, calibrated according to the current frame rate.

In this approach, EVERYTHING in your logic must be aware of the current time step, and moderate its actions based on it. This includes timers, movement, acceleration, weapon ammo reloads etc.

--

Although I've used 2 To reasonable effect in the past, I'd probably now recommend 1, which is what a lot of commercial games do.

Mark
Advertisement
Quote: Original post by markr
...Although I've used 2 To reasonable effect in the past, I'd probably now recommend 1, which is what a lot of commercial games do.

Mark


Is that true? Can you name some examples? Where did you find this out? I'm curious because I'm looking at both possibilities right now too. Time-independent movement really isn't that much of a challenge--but if you're logic is at a fixed rate there are all kinds of assumptions you can make that makes programming things like demos and input queuing a whole lot easier.
I currently use variable timesteps, but I think I'll be moving onto fixed timesteps after thinking about how useful they'll be here. Thinking about it, I actually coded a particle system with a fixed timestep once and it generally seemed to run better. I think I'll make the switch fairly soon.

This topic is closed to new replies.

Advertisement