Tutorial: Adding centerprint logging a la FitzQuake

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Tutorial: Adding centerprint logging a la FitzQuake

Post by Baker »

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
Go to top of console.c and add this below cvar_t con_notifytime ...

Code: Select all

cvar_t		con_logcenterprint = {"con_logcenterprint", "1"}; //johnfitz
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_RegisterVariable (&con_logcenterprint);
Now we need to add the supporting code, so continue down and add these guys:

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 ();
	}
}
right above this ...

Code: Select all

/*
==============================================================================

DRAWING

==============================================================================
*/
1. cl_parse.c
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:

Code: Select all

void Con_LogCenterPrint (char *str);
And immediately below add this:

Code: Select all

	char		*str;
	extern	cvar_t con_nocenterprint;
Now further down ... find "case svc_centerprint:" and replace this:

Code: Select all

SCR_CenterPrint (MSG_ReadString ());
With:

Code: Select all

			str = MSG_ReadString ();
			SCR_CenterPrint (str);
			Con_LogCenterPrint (str);//johnfitz -- log centerprints to console
Likewise we need to do this with the svc_finale and svc_cutscene

So find 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;
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
			//johnfitz -- log centerprints to console
			str = MSG_ReadString ();
			SCR_CenterPrint (str);
			Con_LogCenterPrint (str);
			//johnfitz
			break;
And find 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;
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
			//johnfitz -- log centerprints to console
			str = MSG_ReadString ();
			SCR_CenterPrint (str);
			Con_LogCenterPrint (str);
			//johnfitz
			break;
The End. As no GL or software specific files are touched, the above changes it for both the GL and software renderers.
Last edited by Baker on Tue Nov 25, 2008 8:16 am, edited 2 times in total.
leileilol
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: Tutorial: Adding centerprint logging a la FitzQuake

Post by leileilol »

Baker wrote:This innovative feature made it's first appearance in FitzQuake, of course.
TomazQuake had it first in 1.48
Urre
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon
Contact:

Post by Urre »

Baker: you're a machine!

Moderators: shouldn't I3D start an Engine tutorials section?
I was once a Quake modder
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Tutorial: Adding centerprint logging a la FitzQuake

Post by Baker »

leileilol wrote:
Baker wrote:This innovative feature made it's first appearance in FitzQuake, of course.
TomazQuake had it first in 1.48
Corrected.

I was given some bad information a few years ago then, or at least I misintepreted it.
Tomaz
Posts: 67
Joined: Fri Nov 05, 2004 8:21 pm

Post by Tomaz »

Interesting tutorial.

I see I'm mentioned this time.
Thats nice.

Altho what I did was alot simpler, and way more sane than this code.

I wouldnt really call this code a centerprint logger tho, this more a "send centerprints to the console" which is actually what i did in TomazQuake as well except i just put:

if( print_center_to_console.value )
Con_Printf("%s\n", str);

in SCR_CenterPrint which coveres every center print made, and needs not adding extra function calls in seeral places.

Why add an extra function call at every place that SCR_CenterPrint is made instead of just adding it inside SCR_CenterPrint?

Also your tutorial contains some calls to Con_Quakebar. I might have missed something but I cant find that function anywhere.

I have checked TomazQuake, CleanQuake and original GLquake sources and its not mentioned anywhere.

Perhaps its good to include all needed parts in a tutorial? Or leave out the parts thats specific to the engine you copy and paste the code from?

Dont get me wrong, I think its excellent that you make tutorials.
But it would be even better if you at least understood what the tutorial is about. And make sure it actually works. ( And with the "understanding" part I dont specifically mean this tutorials but your tutorials in general )
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

I'm going to aggregate these comments here.
Tomaz wrote:Also your tutorial contains some calls to Con_Quakebar. I might have missed something but I cant find that function anywhere.

I have checked TomazQuake, CleanQuake and original GLquake sources and its not mentioned anywhere.

Perhaps its good to include all needed parts in a tutorial? Or leave out the parts thats specific to the engine you copy and paste the code from?
Guilty as charged. This is a bad tutorial because any tutorial that isn't complete, doesn't work for someone trying it.

And without the Con_QuakeBar, it doesn't work.
Tomaz wrote:(this is from the .ms2 mesh removing thread)

WTF?!?!?!?!

First you write a tutorial without a single comment on what is done or why. And then when someone asks what the old code did, you dont even know?
Answer: no I do not fully understand what is going on with .ms2 mesh removing.

Someone wanted to know how to remove .ms2 meshing.

I do not yet have a full understanding how the model system works in Quake.

However, that fact isn't going to stop me from helping someone else who ask when I know the code works (i.e. it was a direct feature port).
Tomaz wrote:This is like the 5:th tutorial from you that i read that shows a feature and list a few engines that supports it, and also the 5:th tutorial that doesnt list TomazQuake as one of the engines supporting it.
I'm just trying to give a general description of the engines that I know offhand do or don't support a feature, not trying to cover every engine.

I fully recognize what you've contributed to the DNA pool of Quake ideas, like how Telejano was based off your engine etc and the comments I see in DarkPlaces changelog with your name and works such as Tomaz Mini Racer.
Nice tutorial, but why do I get the feeling you're not really sure what you're doing?
Sometimes I have full and total knowledge of the the tutorial I am writing. Key releasing, for instance.

Sometimes, I'm learning a little during writing the tutorial because I understand the concept but not the details. Ex: alpha tutorial.

And in the case of the .ms2 meshing, it was code re-post.

But the tutorials do get "peer review" here and I've only been working on engine stuff for about 18 months.

The first couple of tutorials, I didn't invest a proper effort in them, they were more like rough blueprints.

By the way, I don't take offense at your observations.
/Note: I left the Tonik name in the .ms2 tutorial because if you are going to use someone else's code, use it all. And #2, Tonik still does engine coding.

And as you noted and Spike also observed, the alpha tutorial is wasteful but (like Rook noted) is derived from the Nehahra protocol, I wanted to keep compatibility. Although I actually didn't. I do need to rewrite that tutorial.
/Edit = Softened up a section of the post.
Last edited by Baker on Mon Dec 01, 2008 10:35 pm, edited 1 time in total.
Tomaz
Posts: 67
Joined: Fri Nov 05, 2004 8:21 pm

Post by Tomaz »

Baker wrote:Answer: no I do not fully understand what is going on with .ms2 mesh removing.

Someone wanted to know how to remove .ms2 meshing.

I do not yet have a full understanding how the model system works in Quake.

However, that fact isn't going to stop me from helping someone else who ask when I know the code works (i.e. it was a direct feature port).
I agree, helping others is a good thing and isnt done enough around these parts, BUT! I would not call it a tutorial if it doesnt explain whats happening.
Baker wrote: By the way, I don't take offense at your observations.
Noone should ever take too much notice of what I say, I way to often sound more angry and judging than I really am ( honestly! )

I just got slightly ticked off after reading through the tutorial section and saw it having a way lower standard than I had hoped for.

But I'll make you a deal. If you keep doing tutorials, I'll keep reading them and try to comment on them in a more friendly way ( I CAN DO THAT! ) and that way we both get happy, the community gets more tutorials and hopefully we'll both be able to teach eachother something the other didnt know.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

I just got slightly ticked off after reading through the tutorial section and saw it having a way lower standard than I had hoped for.
I agree, I hate low standards. I get the same irritation when I encounter somethiing like a tutorial that doesn't work or a major omission.

In fact, before I got into engine coding, I was very good at complaining about how <insert any engine here> "sucked" or did this or that poorly.
But I'll make you a deal. If you keep doing tutorials, I'll keep reading them and try to comment on them in a more friendly way ( I CAN DO THAT! ) and that way we both get happy, the community gets more tutorials and hopefully we'll both be able to teach eachother something the other didnt know.
We definitely need more seasoned veterans eyes looking at things here and contributing and critiquing the idea pool.

A few months ago I was largely worried about asking engine questions because for the most part Spike was the only regular here and I didn't want to constantly impose on him.

Fortunately, it seems like more engine discussion is now going on here.
Urre
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon
Contact:

Post by Urre »

I'd discuss QC if it was actual discussion, apart from "How do I make gun?"
I was once a Quake modder
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

Tomaz wrote:Noone should ever take too much notice of what I say, I way to often sound more angry and judging than I really am ( honestly! )
Btw, I want to apologize for being a little defensive.

I am happy to see the engine section activity growing.

Watching QuakeSrc.org go down felt like a stake in the heart because I had only barely got into engine coding and in the blink of an eye there was suddenly nowhere to ask questions.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

Baker wrote:
Tomaz wrote:Noone should ever take too much notice of what I say, I way to often sound more angry and judging than I really am ( honestly! )
Btw, I want to apologize for being a little defensive.
c0burn
Posts: 208
Joined: Fri Nov 05, 2004 12:48 pm
Location: Liverpool, England
Contact:

Post by c0burn »

Urre wrote:I'd discuss QC if it was actual discussion, apart from "How do I make gun?"
Now I want to make this thread.
scar3crow
InsideQC Staff
Posts: 1054
Joined: Tue Jan 18, 2005 8:54 pm
Location: Alabama

Post by scar3crow »

...and all around me was the chaos of battle and the reek of running blood.... and for the first time in my life I knew true happiness.
Post Reply