.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

Forum Thread
  Posts  
Per frame code operation (Groups : qc : Forum : vault() : Per frame code operation) Locked
Thread Options
numbersix
numbersix quake-c coder++
Jun 11 2014 Anchor

What is a frame?

Technical answer: En.wikipedia.org

A frame in a video game is a rendering of the scene for one update of the display device.
Frames are measured in units we are all familiar with: FPS

Why is this important to coders?

The answer is here: En.wikipedia.org

"In modern action-oriented games where players must visually track
animated objects and react quickly, frame rates of between 30 and
60 FPS are considered acceptable by most
"

To be visually appealing (look realistic) framerate must be more than 30 FPS and consistent. Input responsiveness is also a factor in this equation.

In theory a short enough think time ( Moddb.com ) could operate on a per frame basis.
It is likely, however, that you would miss frames.

Quake-c has 2 functions tied permanently to the game engine C code:

void () PlayerPreThink; // Called every frame before physics are run
void () PlayerPostThink; // Called every frame after physics are run

What kind of code is found in the per frame functions?

In general things that must be handled every frame for visual appeal or continuity.

Some physics, liquid movement and damage, jumping, artifact (like the quad) operation, certain sounds (like the landing thud), weapon auto switch, intermission and death / respawn.

What can be added?

There is a great amount of potential.
You could have: Bots, new artifacts, visible weapons with separate models (origin, model frame sync), code driven chasecam, flyer controls, status updates, runes, weapon sounds, and even magic spells!

I try to follow these guidelines:

Nothing that can be done with think or touch. Avoid code that is waiting on some event to complete, unless it _must_ be checked every frame.
This code gets run _every_ frame. I think possibly even more than once per frame.
Try to minimize intense loops and stack operations. Most efficient code is desirable.

Sample wrapper to make sure precisely 1 call happens per frame:

// global var in defs.qc
float cc_frame;

// in pre or post think
if (cc_frame != framecount)
{
// your code
MyCode();
cc_frame = framecount;
}

You are now armed for per frame code goodness.
Go make something awesome!

Edited by: numbersix

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.