View previous topic :: View next topic |
Author |
Message |
Baker

Joined: 14 Mar 2006 Posts: 1538
|
Posted: Tue Nov 25, 2008 2:04 am Post subject: Tutorial: Adding centerprint logging a la FitzQuake |
|
|
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
Quote: | Go to top of console.c and add this below cvar_t con_notifytime ...
Code: | 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: | Cvar_RegisterVariable (&con_logcenterprint); |
Now we need to add the supporting code, so continue down and add these guys:
Code: | /*
================
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: | /*
==============================================================================
DRAWING
==============================================================================
*/ |
|
1. cl_parse.c
Quote: | 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: | void Con_LogCenterPrint (char *str); |
And immediately below add this:
Code: | char *str;
extern cvar_t con_nocenterprint; |
Now further down ... find "case svc_centerprint:" and replace this:
Code: | SCR_CenterPrint (MSG_ReadString ()); |
With:
Code: |
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: | 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: | 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: | 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: | 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 |
|
Back to top |
|
 |
leileilol

Joined: 15 Oct 2004 Posts: 1321
|
Posted: Tue Nov 25, 2008 6:53 am Post subject: Re: Tutorial: Adding centerprint logging a la FitzQuake |
|
|
Baker wrote: | This innovative feature made it's first appearance in FitzQuake, of course. |
TomazQuake had it first in 1.48 |
|
Back to top |
|
 |
Urre

Joined: 05 Nov 2004 Posts: 1073 Location: Sweden
|
Posted: Tue Nov 25, 2008 7:02 am Post subject: |
|
|
Baker: you're a machine!
Moderators: shouldn't I3D start an Engine tutorials section? _________________ Look out for Twigboy |
|
Back to top |
|
 |
Baker

Joined: 14 Mar 2006 Posts: 1538
|
Posted: Tue Nov 25, 2008 8:14 am Post subject: Re: Tutorial: Adding centerprint logging a la FitzQuake |
|
|
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. |
|
Back to top |
|
 |
Tomaz
Joined: 05 Nov 2004 Posts: 49
|
Posted: Mon Dec 01, 2008 1:55 pm Post subject: |
|
|
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 ) |
|
Back to top |
|
 |
Baker

Joined: 14 Mar 2006 Posts: 1538
|
Posted: Mon Dec 01, 2008 4:48 pm Post subject: |
|
|
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.
Quote: | 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.
Quote: | /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 |
|
Back to top |
|
 |
Tomaz
Joined: 05 Nov 2004 Posts: 49
|
Posted: Mon Dec 01, 2008 8:05 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
Baker

Joined: 14 Mar 2006 Posts: 1538
|
Posted: Mon Dec 01, 2008 8:50 pm Post subject: |
|
|
Quote: | 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.
Quote: | 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. |
|
Back to top |
|
 |
Urre

Joined: 05 Nov 2004 Posts: 1073 Location: Sweden
|
Posted: Mon Dec 01, 2008 9:07 pm Post subject: |
|
|
I'd discuss QC if it was actual discussion, apart from "How do I make gun?" _________________ Look out for Twigboy |
|
Back to top |
|
 |
Baker

Joined: 14 Mar 2006 Posts: 1538
|
Posted: Mon Dec 01, 2008 11:30 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
Baker

Joined: 14 Mar 2006 Posts: 1538
|
Posted: Tue Dec 02, 2008 2:13 pm Post subject: |
|
|
[quote="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. |
|
Back to top |
|
 |
c0burn
Joined: 05 Nov 2004 Posts: 158 Location: Liverpool, England
|
Posted: Tue Dec 02, 2008 4:28 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
scar3crow Inside3D Staff

Joined: 18 Jan 2005 Posts: 837 Location: Las Vegas, NV
|
Posted: Tue Dec 02, 2008 5:06 pm Post subject: |
|
|
Done _________________ ...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. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2004 phpBB Group
|