Tutorial *145*
One of the functions always sorely missed by us QuakeC coders was a way to catch the end of a frame, after all the physics and thinks had been executed. While it's simple to stick in a call to EndFrame, it's harder maintaining compatability with old mods when you expect a new function to exist. Taking a cue from QW, here is the 'official' QSG implimentation of EndFrame:

Open up PROGS.H find the line that reads



extern int			minimum_memory;

Under it, add:



extern func_t	EndFrame;

This variable will obviously hold the pointer to the function EndFrame in the QC. Open up PR_EDICT.C and scroll down to the function PR_LoadProgs, before it we'll define it and in it we'll set the variable up for use. Add this temporary variable declaration to the top of PR_LoadProgs:



func_t	EndFrame;

void PR_LoadProgs (void)
{
dfunction_t *f;

Then at the bottom of the same function add this code:



	EndFrame = 0;
if ((f = ED_FindFunction ("EndFrame")) != NULL)
EndFrame = (func_t)(f - pr_functions);

Last but not least, we need to execute this bugger somewhere, the place, of course, is in sv_phys.c, in the function called SV_Physics. After all entities have been processes and before the retouch code, stick the following lines. It has to be before the retouch code otherwise you may experience weird results occasionally.



	if (EndFrame)
{
// let the progs know that the frame has ended
pr_global_struct->self = EDICT_TO_PROG(sv.edicts);
pr_global_struct->other = EDICT_TO_PROG(sv.edicts);
pr_global_struct->time = sv.time;
PR_ExecuteProgram (EndFrame);
}

Viola! We now have an optional EndFrame function in the QC. As a test, modify world.qc, add a function EndFrame and have it print some annoying message. It will flood the console. Yipee! :)



 
Sign up
Login:
Passwd:
[Remember Me]