Tutorial *17*

This tutorial will show you how to add a CONSOLE CLOCK to the Quake2 executable. It is a simple & basic tutorial, But a nice touch to add to the Engine.

There are no new files needed for this tutorial & only the need to add a few lines of code,

The first step is to actually start including some new code to the engine, so open up the file 'console.c' and scroll down to the 'Con_DrawConsole' function near to the bottom of this file and locate the following lines lines..



	void Con_DrawConsole (float frac)

	{
int i, j, x, y, n; int rows; char *text; int row; int lines; char version[64]; char dlbar[1024];

You now need to add below them these lines...



//[QBS] added for console clock

	char timebuf[20];

	char tmpbuf[24];

   	 _strtime( timebuf );

//[QBS]end

Ok, next find the following piece of code (still in the same function)..

Find the code section that reads...



	re.DrawStretchPic (0, -viddef.height+lines, viddef.width, viddef.height, "conback");

	SCR_AddDirtyPoint (0,0);

	SCR_AddDirtyPoint (viddef.width-1,lines-1);

and below it change this piece of code from..



	Com_sprintf (version, sizeof(version), "v%4.2f", VERSION);

	for (x=0 ; x<5 ; x++)

	re.DrawChar (viddef.width-44+x*8, lines-12, 128 + version[x] );

To read like the below:



//[QBS]  Time Tutorial

	Com_sprintf (version, sizeof(version), "Quake2 v%4.2f",VERSION);//[QBS] added Quake2

	for (x=0 ; x<12 ; x++)//[QBS] was x<5

	re.DrawChar (viddef.width-153+x*8, lines-35, 128 + version[x] );// lines- was 44



//[QBS] Modified for clock on console



	Com_sprintf (tmpbuf, sizeof(tmpbuf), "Time %s",timebuf);

	for (x=0 ; x<13 ; x++)// was x<5

	re.DrawChar (viddef.width-150+x*8, lines-25, 128 + tmpbuf[x] );

//[QBS]end



// draw the text

As you can see, all I've done is made a small change to the version number (it now prints 'Quake2 v2.xx' instead of just the number). In doing this, I also have had to move where the text was drawn, to make room for it. It's now '12' letters long instead of '5', and begins at line position '35' instead of '44'.

Drawing the actual clock is even easier, it's the same code as above - but this time we are writing the text from 'timebuf' (where we put the time at the beginning of the tutorial) to 'tmpbuf', and drawing that. It's 13 letters long, and begins at line position 25.

Well, there ends this small but useful tutorial. No more having to ALT-TAB your Quake2 to see what time it is or how long you have been playing,

Have Fun!
Richard Steele
Quadrant@PlanetQuake.com



 
Sign up
Login:
Passwd:
[Remember Me]