Tutorial *123*
A short quick tutorial to add a frame rate limiter cvar to the Quake engine. Some of the uses for this are for netplay, the less frames being rendered the less updates needed to be sent to the server. It also allows you to play Quake at whatever framerate your GFX card can reach, not limited by Quake's default maximum of 72fps.
Now for the code.
At the top of host.c add the following line:

cvar_t	max_fps = {"max_fps", "72", true}; // MrG - max_fps

This is the cvar that will hold the maximum framerate value, and allow it to be editable at the console. The "72" is the default maximum fps of the engine, and the "true" means that this cvar will be saved to the config file and loaded each time Quake is started.
Now in the function Host_InitLocal, add the following line above the other calls to Cvar_RegisterVariable:

Cvar_RegisterVariable (&max_fps); // MrG - max_fps

This will register the cvar for use with Quake's console. A very important line for what we are doing!

Now locate the function Host_FilterTime, and replace:

if (!cls.timedemo && realtime - oldrealtime < 1.0/72.0)

with the following:

// MrG - max_fps

if (max_fps.value < 1) Cvar_SetValue("max_fps", 72);

if (!cls.timedemo && realtime - oldrealtime < 1.0/max_fps.value)

Now instead of being locked to 72fps when your GFX card can do more, it will be locked to the value of the max_fps cvar, unless that value is below 0, in which case Quake will revert to using the default value of 72.

Have fun playing Quake at several hundred FPS!

Not logged in
Sign up