Tutorial: Adding centerprint logging a la FitzQuake
Posted: Tue Nov 25, 2008 2:04 am
TomazQuake, FitzQuake, aguirReQuake and Qrack have centerprint logging (possibly some others). It is invaluable in single player when you are a slow reader and didn't have time to read the message on the screen.
This innovative feature made it's first appearance in TomazQuake.
(Correction via leileilol).
Center print logging
Adding it in
1. console.c
This innovative feature made it's first appearance in TomazQuake.
(Correction via leileilol).
Center print logging
Adding it in
1. console.c
1. cl_parse.cGo to top of console.c and add this below cvar_t con_notifytime ...
Add the cvar, now we need to register it. Go down to Con_Init and after "Cvar_RegisterVariable (&con_notifytime);" add:Code: Select all
cvar_t con_logcenterprint = {"con_logcenterprint", "1"}; //johnfitz
Now we need to add the supporting code, so continue down and add these guys:Code: Select all
Cvar_RegisterVariable (&con_logcenterprint);
right above this ...Code: Select all
/* ================ Con_CenterPrintf -- johnfitz -- pad each line with spaces to make it appear centered ================ */ void Con_CenterPrintf (int linewidth, char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; //the original message char line[MAXPRINTMSG]; //one line from the message char spaces[21]; //buffer for spaces char *src, *dst; int len, s; va_start (argptr,fmt); vsnprintf (msg, sizeof(msg), fmt,argptr); va_end (argptr); linewidth = min (linewidth, con_linewidth); for (src = msg; *src; ) { dst = line; while (*src && *src != '\n') *dst++ = *src++; *dst = 0; if (*src == '\n') src++; len = strlen(line); if (len < linewidth) { s = (linewidth-len)/2; memset (spaces, ' ', s); spaces[s] = 0; Con_Printf ("%s%s\n", spaces, line); } else Con_Printf ("%s\n", line); } } /* ================== Con_LogCenterPrint -- johnfitz -- echo centerprint message to the console ================== */ void Con_LogCenterPrint (char *str) { if (!strcmp(str, con_lastcenterstring)) return; //ignore duplicates if (cl.gametype == GAME_DEATHMATCH && con_logcenterprint.value != 2) return; //don't log in deathmatch strcpy(con_lastcenterstring, str); if (con_logcenterprint.value) { Con_Printf (Con_Quakebar(40)); Con_CenterPrintf (40, "%s\n", str); Con_Printf (Con_Quakebar(40)); Con_ClearNotify (); } }
Code: Select all
/* ============================================================================== DRAWING ============================================================================== */
The End. As no GL or software specific files are touched, the above changes it for both the GL and software renderers.Now we need to go to cl_parse.c and intercept the center print and re-route it to the above procedures ...
In cl_parse.c
Find: "void CL_ParseServerMessage (void)"
Immediately above, add:
And immediately below add this:Code: Select all
void Con_LogCenterPrint (char *str);
Now further down ... find "case svc_centerprint:" and replace this:Code: Select all
char *str; extern cvar_t con_nocenterprint;
With:Code: Select all
SCR_CenterPrint (MSG_ReadString ());
Likewise we need to do this with the svc_finale and svc_cutsceneCode: Select all
str = MSG_ReadString (); SCR_CenterPrint (str); Con_LogCenterPrint (str);//johnfitz -- log centerprints to console
So find this:
Replace with this:Code: Select all
case svc_finale: cl.intermission = 2; cl.completed_time = cl.time; vid.recalc_refdef = true; // go to full screen SCR_CenterPrint (MSG_ReadString ()); break;
And find this ...Code: Select all
case svc_finale: cl.intermission = 2; cl.completed_time = cl.time; vid.recalc_refdef = true; // go to full screen //johnfitz -- log centerprints to console str = MSG_ReadString (); SCR_CenterPrint (str); Con_LogCenterPrint (str); //johnfitz break;
And replace with this ...Code: Select all
case svc_cutscene: cl.intermission = 3; cl.completed_time = cl.time; vid.recalc_refdef = true; // go to full screen SCR_CenterPrint (MSG_ReadString ()); break;
Code: Select all
case svc_cutscene: cl.intermission = 3; cl.completed_time = cl.time; vid.recalc_refdef = true; // go to full screen //johnfitz -- log centerprints to console str = MSG_ReadString (); SCR_CenterPrint (str); Con_LogCenterPrint (str); //johnfitz break;