With cordite in the air, splintered steel, shell casings and powder burns, there’s only one explanation...
Discuss & improve the game engine.

Moderators: sparcdr, torhu, Tequila

Customize console.

Postby Conq » Fri Jul 10, 2009 4:37 pm

Hello World ! :-)

The patch that I submit today seems to be useless, however, I'm sure that some people whom are bored by ioquake3 basic console will enjoy these features:
- It allows people to change console style from "default" to "custom", which accepts to use special colors for console.
- Color values are stocked in cl_consoleColor<Color>.
- Transparency is also managed & stocked in cl_consoleColorAlpha.
- All those things are managed by /color command which works like this : "/console [color ([red] [green] [blue] [Alpha]) | type ([default|custom])]"

That's all. I think I'll add visual effects while console is opened or closed & a vim-alike mode.

Damn, I was going to forget it... Here is the patch :
Code: Select all
Index: code/client/client.h
===================================================================
--- code/client/client.h   (révision 260)
+++ code/client/client.h   (copie de travail)
@@ -526,6 +526,16 @@
 //
 // console
 //
+
+#ifdef SMOKINGUNS
+extern cvar_t *cl_consoleType;
+extern void Con_CustomizeConsole_f( void );
+char *Con_FindColorForNumber( int color );
+extern cvar_t *cl_consoleColor[3];
+extern int numColors;
+#endif /* SMOKINGUNS */
+
 void Con_DrawCharacter (int cx, int line, int num);
 
 void Con_CheckResize (void);
Index: code/client/cl_main.c
===================================================================
--- code/client/cl_main.c   (révision 260)
+++ code/client/cl_main.c   (copie de travail)
@@ -97,7 +97,12 @@
 
 cvar_t   *cl_guidServerUniq;
 
+//Console part
 cvar_t   *cl_consoleKeys;
+#ifdef SMOKINGUNS
+cvar_t  *cl_consoleType;
+cvar_t  *cl_consoleColor[3];
+#endif
 
 clientActive_t      cl;
 clientConnection_t   clc;
@@ -3074,6 +3079,9 @@
 ====================
 */
 void CL_Init( void ) {
+#ifdef SMOKINGUNS
+  int i;
+#endif
    Com_Printf( "----- Client Initialization -----\n" );
 
    Con_Init ();
@@ -3169,6 +3177,13 @@
 
    // ~ and `, as keys and characters
    cl_consoleKeys = Cvar_Get( "cl_consoleKeys", "~ ` 0x7e 0x60", CVAR_ARCHIVE);
+#ifdef SMOKINGUNS 
+  cl_consoleType = Cvar_Get( "cl_consoleType", "0", CVAR_ARCHIVE );
+  for( i = 0; i <= 3; i++ )
+  {
+    cl_consoleColor[i] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( i ) ), "0", CVAR_ARCHIVE );
+  }
+#endif
 
    // userinfo
    Cvar_Get ("name", "UnnamedPlayer", CVAR_USERINFO | CVAR_ARCHIVE );
@@ -3234,6 +3249,9 @@
    //
    // register our commands
    //
+#ifdef SMOKINGUNS
+  Cmd_AddCommand( "console", Con_CustomizeConsole_f );
+#endif
    Cmd_AddCommand ("cmd", CL_ForwardToServer_f);
    Cmd_AddCommand ("configstrings", CL_Configstrings_f);
    Cmd_AddCommand ("clientinfo", CL_Clientinfo_f);
Index: code/client/cl_console.c
===================================================================
--- code/client/cl_console.c   (révision 260)
+++ code/client/cl_console.c   (copie de travail)
@@ -585,6 +585,102 @@
 
 /*
 ================
+Con_CustomizeConsole_f
+
+Command that gives to user the power to
+customize his/her console.
+
+Available commands:
+  - /console color [red] [green] [blue] [Alpha]
+  - /console type [default|custom]
+================
+*/
+#ifdef SMOKINGUNS
+
+typedef struct colorArray_s
+{
+  int color;
+  char *name;
+} colorArray_t;
+
+colorArray_t colorArray[]=
+{
+  {
+    0,
+    "Red",
+  },
+  {
+    1,
+    "Green",
+  },
+  {
+    2,
+    "Blue",
+  },
+  {
+    3,
+    "Alpha",
+  },
+};
+
+int numColors = sizeof( colorArray ) / sizeof( colorArray[0] );
+
+//Save typing ( To use with conditions )
+#define ARG_DNTEXISTS( x ) (!argv[x] || !Q_stricmp( argv[x], "" ))
+void Con_CustomizeConsole_f( void )
+{
+  int argc = Cmd_Argc(  );
+  int i;
+  char *argv[argc];
+
+  for( i = 0; i <= argc; i++ )
+  {
+    argv[i] = Cmd_Argv( i );
+  }
+
+  if( ARG_DNTEXISTS( 1 ) )
+    Com_Printf( "^3usage:^7 /console ^3[^7color ^5(^3[^7red^3] [^7green^3] [^7blue^3] [^7Alpha^3]^5)^7 | type ^5(^3[^7default|custom^3]^5)" );
+  else
+  {
+    if( !Q_stricmp( argv[1], "color" ) )
+    {
+      if( argv[5] )
+      {
+        for( i = 0; i <= 3; i++ )
+        {
+          //cl_consoleColor[i]->value = atof( argv[i+2] );
+          Cvar_Set( va( "cl_consoleColor%s", Con_FindColorForNumber( i ) ), va( "%f", atof( argv[i+2] ) ) );
+        }
+      }
+    }
+    else if( !Q_stricmp( argv[1], "type" ) )
+    {
+      if( !Q_stricmp( argv[2], "default" ) )
+        //cl_consoleType->integer = 0;
+        Cvar_Set( "cl_consoleType", "0" );
+      else if( !Q_stricmp( argv[2], "custom" ) )
+        //cl_consoleType->integer = 1;
+        Cvar_Set( "cl_consoleType", "1" );
+    }
+  }
+}
+
+char *Con_FindColorForNumber( int color )
+{
+  int i;
+
+  for( i = 0; i < numColors; i++ )
+  {
+    if( i == color )
+    {
+      return colorArray[i].name;
+    }
+  }
+}
+#endif /* SMOKINGUNS */
+
+/*
+================
 Con_DrawSolidConsole
 
 Draws the console with the solid background
@@ -599,6 +695,9 @@
 //   qhandle_t      conShader;
    int            currentColor;
    vec4_t         color;
+#ifdef SMOKINGUNS
+  vec4_t    consoleColor;
+#endif
 
    lines = cls.glconfig.vidHeight * frac;
    if (lines <= 0)
@@ -613,20 +712,36 @@
 
    // draw the background
    y = frac * SCREEN_HEIGHT;
+
+#ifdef SMOKINGUNS
+  for( i = 0; i <= 3; i++ )
+  {
+    consoleColor[i] = cl_consoleColor[i]->value;
+  }
+#endif /* SMOKINGUNS */
+
    if ( y < 1 ) {
       y = 0;
    }
    else {
+#ifndef SMOKINGUNS
       SCR_DrawPic( 0, 0, SCREEN_WIDTH, y, cls.consoleShader );
+#else
+    if( cl_consoleType->integer == 1 )
+       SCR_FillRect( 0, 0, SCREEN_WIDTH, y, consoleColor );
+    else
+        SCR_DrawPic( 0, 0, SCREEN_WIDTH, y, cls.consoleShader );
+#endif
    }
 
    color[0] = 1;
    color[1] = 0;
    color[2] = 0;
-   color[3] = 1;
-   SCR_FillRect( 0, y, SCREEN_WIDTH, 2, color );
+   color[3] = 0.8;
 
+   SCR_FillRect( 0, y, SCREEN_WIDTH, 1, color );
 
+
    // draw the version number
 
    re.SetColor( g_color_table[ColorIndex(COLOR_RED)] );
Conq
Drifter
 
Posts: 13
Joined: Sun May 31, 2009 9:37 am



Postby Lucky Bro » Fri Jul 10, 2009 7:16 pm

Cool job, Conq!
But how do we supposed to test the patch? I mean if I just put all this text in quotes in a file and ask my Tortoise to apply it - it won't let me to. It says: "Unknown line type was found in line 20 !". And I'm not in a mood today to do all that diff stuff manually.
The reason why is it happening is because of some formating that forum do on patch's text that you had copied there.
So, the better solution is to put a whole patch file somewhere. Yeah, that a really good question - where? I haven't found anything proper, even pastebins (systems which operate like online code buffers) do some formatting on code.
I stopped at rapidshare, but seems that the stuff will remove my patch right after few downloads :( I've even tried some photo sharing, but they did some checks on files.
So, that is a good question - how do we suppose to store and publish our patches?
Or may be someone has a good solution, then say it, please.
And one more thing is to explicitly declare the SG version of patch: 1.0 or 1.1 or both? SG still has both branches.
Nothing personal and no offence, Conq. I'm writing this to you because I almost sure that you'll understand the reasons why that is important. I was tended to say the same thing about Tequila's patch, but I decided that he had put there only quoted text because he wants us only to read the code. And he'll put a patch to SVN later and we may have the latest version with the latest update to the code to check.

Concerning the job - it is not useless, my brother has a girlfriend who is always watching him playing games, I think she'll like the possibility to have a pink console :)
And more seriously - any code published here is code to learn something. Not everyone is familiar with quake 3 engine, but I hope the more patches we'll have there published and discussed the more people will understand that quake 3 is not so hard thing to improve. And we will have more patches :)
Again, thanks for sharing :)
"You should know that the lies won't hide your flaws/No sense in hiding all of yours/You gave up on your dreams along the way" (c) "Fake it" by Seether
P.S. English isn't my native language.
User avatar
Lucky Bro
Gunslinger
 
Posts: 143
Joined: Mon Mar 09, 2009 4:12 pm



Postby Sucalakafufu » Sat Jul 11, 2009 12:17 am

@Lucky Bro
if Rapidshare doesnt fit your needs, try out Mediafire :)
SG Name: Sucalakafufu
Clan: [CWNN] - Clan With No Name
User avatar
Sucalakafufu
Gunslinger
 
Posts: 239
Joined: Thu Apr 16, 2009 8:59 am



Postby Lucky Bro » Sat Jul 11, 2009 8:35 am

Sucalakafufu,
Free&works like charm!
Will use it instead of anything else! Big thanks ;)
"You should know that the lies won't hide your flaws/No sense in hiding all of yours/You gave up on your dreams along the way" (c) "Fake it" by Seether
P.S. English isn't my native language.
User avatar
Lucky Bro
Gunslinger
 
Posts: 143
Joined: Mon Mar 09, 2009 4:12 pm



Postby Sucalakafufu » Sat Jul 11, 2009 11:09 am

Lucky Bro wrote:Sucalakafufu,
Free&works like charm!
Will use it instead of anything else! Big thanks ;)


no problemo :) its my favorite free file uploader/manager out there ;)
im glad i could help out :D
SG Name: Sucalakafufu
Clan: [CWNN] - Clan With No Name
User avatar
Sucalakafufu
Gunslinger
 
Posts: 239
Joined: Thu Apr 16, 2009 8:59 am



Postby Conq » Sat Jul 11, 2009 11:38 am

@LuckyBro: Hmmmm, on a *nix system you can use the command `patch -p0 < patch.diff` to apply it on your sources. I think it is possible to use it with cygwin ;-).
About the way to upload our patches, I think that we can use mediafire, as said by Sucalakafufu or any other file hoster.
Anyway, I think that we can use the syntax "$patchName-$patchVersion-$SGRelease.diff" where $patchName would be the name of your patch; $patchVersion the version of your patch & $SGRelease would be in a binary way: 01 for SG 1.0, 10 for SG 1.1 + release number of the svn reposistory, 11 for the both.
For example, my patch would be like : "customConsole-0.1-10+260.diff".

Anyway, here is my patch ;-)

edit: I improved the way help's displayed & added "/console [frac] [percentage]" which defines what percentage of screen console will take. This value is stocked in cl_consoleFrac cvar.
Here is the patch.
Conq
Drifter
 
Posts: 13
Joined: Sun May 31, 2009 9:37 am



Postby Lucky Bro » Sat Jul 11, 2009 3:04 pm

Conq, thank you! That will make testing process much easier.
Are you sure, that you may create the patch.diff file by copying your code from quote you've listed above? And after that such file will be readable by any diff the same way as it readable before placing it in quotes here.. Just copy your diff anywhere here and then copy it back to diff file. If it works on Unix-like systems - well, nice to know. I have two different files after such operation and the second one is without previous formatting.
I think you don't need a revision mark in filename. Any patch explicitly stores such value inside itself for each file that you have modified:
Original patch wrote:--- code/client/client.h (révision 260)
+++ code/client/client.h (copie de travail)

About SG version - you may explicitly write it in filename - "<MyPatchName>_<MyVersion>_SG<SG version>.patch". It is up to you to decide how you'll write it. I was talking only about writing such information in main (first) post.
And about your link to your patch file.. "Télécharger ce fichier" is something that means "Get file"? :)

Now about your patch itself.
cl_main.c in CL_Init() you get color components for console in cycle.. What for do you need a whole cycle with a new int i variable?
May be just:
Suggestion wrote:#ifdef SMOKINGUNS
cl_consoleType = Cvar_Get( "cl_consoleType", "0", CVAR_ARCHIVE );
cl_consoleColor[0] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( 0 ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[1] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( 1 ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[2] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( 2 ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[3] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( 3 ) ), "0", CVAR_ARCHIVE );
#endif

instead of:
Original patch wrote:#ifdef SMOKINGUNS
int i;
#endif
...
#ifdef SMOKINGUNS
cl_consoleType = Cvar_Get( "cl_consoleType", "0", CVAR_ARCHIVE );
for( i = 0; i <= 3; i++ )
{
cl_consoleColor[i] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( i ) ), "0", CVAR_ARCHIVE );
}
#endif

But seems you don't have the last one (cl_consoleColor[3]).. Because you declare *cl_consoleColor in the following way:
cvar_t *cl_consoleColor[3];
Only 3 members.. Not 4. Where to do you writing the last one?
In cl_console.c:
int numColors = sizeof( colorArray ) / sizeof( colorArray[0] );
I suppose it will be 4? Why don't when just define it:
#define numColors 4
And may be you don't need to define at all.. Just simplify the following function:
Original patch wrote:char *Con_FindColorForNumber( int color )
{
int i;

for( i = 0; i < numColors; i++ )
{
if( i == color )
{
return colorArray[i].name;
}
}
}
#endif /* SMOKINGUNS */

->
Suggestion wrote:char *Con_FindColorForNumber( int color )
{
return colorArray[color].name;
}
#endif /* SMOKINGUNS */

And if you want to check boundaries - better to check them instead of creating cycle.
Here you want to save typing:
Original patch wrote://Save typing ( To use with conditions )
#define ARG_DNTEXISTS( x ) (!argv[x] || !Q_stricmp( argv[x], "" ))

But you are using this definition only once.. May be just write it explicitly in the following if rule?
I think other cycles for 4 iterations are not required too. You got only four color components. It is even better to explicitly handle each one of them.
And here you decided to reduce the width and opacity of console border, am I got it right?:
line 740 wrote: color[3] = 0.8;
SCR_FillRect( 0, y, SCREEN_WIDTH, 1, color );

Then this is very nice :)

I've learned much from your code :) So, thank you for sharing again :)
Haven't read the second edition yet.. It says "An unknown line type was found in line 42!".. Will check it later.
P.S. Sorry if I'm paying too much attention to the "little things", but those are ones which make code read and understand better after years of oblivion :) So the more intuitive code the more people will be able to improve it later. Good luck with your task!
"You should know that the lies won't hide your flaws/No sense in hiding all of yours/You gave up on your dreams along the way" (c) "Fake it" by Seether
P.S. English isn't my native language.
User avatar
Lucky Bro
Gunslinger
 
Posts: 143
Joined: Mon Mar 09, 2009 4:12 pm



Postby Conq » Sat Jul 11, 2009 3:35 pm

"Télécharger ce fichier" means "Get file". Unfortunately, dl.free.fr is in french but it is the only file hoster that I found without boring flash things ;-).

About the registering of the variables, it is only a way to save typing ;-).

"cvar_t *cl_consoleColor[3];" has the four members needed to set the portion of red, green, blue & alpha things if you count the zero ;-).

"int numColors = sizeof( colorArray ) / sizeof( colorArray[0] );" is just in case we extend the table colorArray to take in account other things such as end color for a gradation.

"char *Con_FindColorForNumber( int color )
{
return colorArray[color].name;
}"
That could work, but if you give a color number that exceed array limit, you'll get a beautiful "(null)" return value :/.
Anyway, my way did the same thing in the first release of my patch, but it has been fixed in the second ;-).

"#define ARG_DNTEXISTS( x ) (!argv[x] || !Q_stricmp( argv[x], "" ))" <== Well, in the second version of my patch, I use it twice ;-).

"SCR_FillRect( 0, y, SCREEN_WIDTH, 1, color );" <== Damn, forgot to revert it. :|.

Good luck with your task!

Thanks :-).
Conq
Drifter
 
Posts: 13
Joined: Sun May 31, 2009 9:37 am



Postby Lucky Bro » Thu Jul 16, 2009 3:46 pm

Good day, Conq :)

Sorry for delay. I still can't apply your second edition of the patch. I don't want to figure out why it is happening. And I don't want for sure use anything else to get it applied because I'm having no troubles with my current SVN client while working with other patches and projects. I'm pretty sure that trouble is not because of my misconfigured SVN client (it uses default configuration anyway).
But since I promised to check your second version - I did it just by reading the diff file (very awkward method I should say). Nothing happy to say there too.. You didn't apply any of my previous remarks, so I don't see any reason to add new ones. Instead I'll try explain with more precision why I was asking you to apply the ones I mentioned in my previous post.

The following declaration:
The code wrote:cvar_t *cl_consoleColor[3];

will declare only 3 elements in array. With 0, 1 and 2 index numbers.
And when you access to the fourth element you access to something else instead. And if it wasn't your idea (it wasn't) you may corrupt something which is following after your variable in memory.

About all your cycles as I said - this is non convenient and not explicit way to handle four (even more) elements.
What typing you are trying to save?
Even in example code I've given you above are less lines when in yours. But it is undestandable even by those who don't know C or any coding language at all.
You have four (or more) elements. Each one of them has its own number. 0, 1, 2, 3.
If you want to explicitly show with which one you are working (I highly recommend you to do so) you may do the following enum or explicit definitions:
Example wrote:#define CL_RED_COLOR 0
#define CL_GREEN_COLOR 1
#define CL_BLUE_COLOR 2
#define CL_ALFA_COLOR 3
...

Here as well you may declare the number of colors:
Example wrote:#define CL_NUM_COLORS 4

(You may name them as you wish)
And that will make you code even more readable:
Example wrote:cvar_t *cl_consoleColor[CL_NUM_COLORS];
...
#ifdef SMOKINGUNS
cl_consoleType = Cvar_Get( "cl_consoleType", "0", CVAR_ARCHIVE );
cl_consoleColor[0] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_RED_COLOR ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[1] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_GREEN_COLOR ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[2] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_BLUE_COLOR ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[3] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_ALFA_COLOR ) ), "0", CVAR_ARCHIVE );
#endif

And so on with other cycles.

About boundaries in the following function:
The code wrote:char *Con_FindColorForNumber( int color )
{
return colorArray[color].name;
}
#endif /* SMOKINGUNS */

as I said if you want to check them - better to check them.
You may do any check like this one (it will return red component in case of out of boundaries - you may return "" if you think it is correct):
Just as example wrote:char *Con_FindColorForNumber( int color )
{
if (color < 0 || color > CL_NUM_COLORS )
return colorArray[CL_RED_COLOR].name
else
return colorArray[color].name;
}

And you are using it only internally, so that is only a developer who can make a mistake. Better to report about this mistake than to handle it anyhow. And to me this function seems to be a redundant one.. May be it is better to share that colorArray instead or something like this.

About definition of arguments check (as well as if you'll decide to use the definitions above) - it will be better if you'll place it at the beginning of the file or to some common shared header (I don't know to which one exactly, haven't check it.. client.h for colorArray and color definitions & q_shared.h for arguments check?). Because this definition could be used not only in your code but general in all code.

About thin and non opaque console edge - I thought it was your feature.. Seems to be nice.
The code wrote:color[3] = 0.8;
SCR_FillRect( 0, y, SCREEN_WIDTH, 1, color );


All other stuff seems to be nice. Your code is a really useful for ones who'll decide to add a new console command or tweak the look of console.
All the stuff has written above are just my suggestions. I don't insist on anything and even more - I don't care much since it is not me who'll perform the merge, so it should worry more him than me.
Thanks for sharing, good luck!

P.S. I think I'll quit SG/Q3 engine research for a while. I just lost my passion to look at it and I really don't understand where this all is going to with the ioQ3 backporting and other stuff I read here :) So I'm taking a break and you may breath free as usual since I won't be checking you ;)
..for a while :)
"You should know that the lies won't hide your flaws/No sense in hiding all of yours/You gave up on your dreams along the way" (c) "Fake it" by Seether
P.S. English isn't my native language.
User avatar
Lucky Bro
Gunslinger
 
Posts: 143
Joined: Mon Mar 09, 2009 4:12 pm



Postby Conq » Thu Jul 16, 2009 11:15 pm

"You didn't apply any of my previous remarks, so I don't see any reason to add new ones."
Well, I edited my post on 11 july 2009 at 5:38 am to say that I had a second version of my patch and you posted on on july 11, 2009 at 9:04 am. That's why this version doesn't take in account your modifications. ;-)

"#define CL_RED_COLOR 0
#define CL_GREEN_COLOR 1
#define CL_BLUE_COLOR 2
#define CL_ALFA_COLOR 3 "
Why not. Nevertheless, I think "enum { CL_RED_COLOR, CL_GREEN_COLOR, CL_BLUE_COLOR, CL_ALPHA_COLOR };" would be even better. :-)

"#define CL_NUM_COLORS 4"
Why not. However, for table of big structures (like gentities), I don't think that you will count every member of a table.

"cl_consoleColor[0] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_RED_COLOR ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[1] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_GREEN_COLOR ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[2] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_BLUE_COLOR ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[3] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_ALFA_COLOR ) ), "0", CVAR_ARCHIVE ); "
Hmmm, That's not really reader & typer friendly. Try to enlarge cl_consoleColor to 100 & the color table too. I don't think that people will enjoy to read 100 times the same things & coders will not appreciate to type that too :D.
Anyway, why define macros such as CL_*_COLOR if you use directly the number, like in "cl_consoleColor[0]" ? I think that we have to do a choice between the number & CL_*_COLOR. Personnaly, I think that people will not think that blue is at the first place for example ;-).

"client.h for colorArray and color definitions & q_shared.h for arguments check?"
Why not ;-).

Thanks a lot for you suggestions Lucky Bro :-). I'll see what I can do to improve my patch with them and post the improved way in the next version of my patch (The one with useless color gradation way ;p) in a few hours/days (depending on some other things) :-).

P.S: I don't use [*quote*] things because that makes huge posts on graphical web browsers ;-)
Conq
Drifter
 
Posts: 13
Joined: Sun May 31, 2009 9:37 am



Postby Lucky Bro » Fri Jul 17, 2009 10:35 am

enum is not so obvious as exact definition. Of course, you may do explicit declaration in enum like CL_RED_COMPONENT=0, but I would prefer definitions. Especially in case when we have only 4 components.
I just typed the following as example:
cl_consoleColor[0] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_RED_COLOR ) ), "0", CVAR_ARCHIVE );
Sure you have to replace that 0 with CL_RED_COMPONENT too. I was talking only about idea not concrete realization.
I'm not talking about entities or any other structure or array. Only about your current code and its needs. When we'll look to entities -> we'll talk about them.
Just compare the following thing with any realization you may imagine:
Convenient wrote:cl_consoleColor[CL_RED_COLOR] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_RED_COLOR ) ), "0", CVAR_ARCHIVE );
cl_consoleColor[CL_GREEN_COLOR] = Cvar_Get( va( "cl_consoleColor%s", Con_FindColorForNumber( CL_GREEN_COLOR ) ), "0", CVAR_ARCHIVE );

(Not only assignment job - take any cycle you have)
And now let's imagine that one day here are no coders who knows C and Q3 engine but one needs to multiply the green component by two in assignment (just as example). In that case he don't need to look anywhere else except that part of the code. He will just add "* 2" to appropriate string.
And moreover - you don't need any comment! Your code is obvious. No search is required. Upper case usually used for definition, so one already knows that it is definition (if he is aware of C).
There is no way you may do such a thing inside any of your cycle. You'll need to break a cycle. And you'll need to add a comment to explain what is happening inside that cycle if you don't want each one to look to find what this 0, 1, 2 and 3 are mean.
Anyone knows exactly what is happening in each line of suggested code. When there will be 100 elements - it will be other discussion. And first question will be - why do you need 100 components to describe a console look change? And depend on what those 100 components will present - the proper way of treating and handling them should be chosen.

Thank you to paying attention too :) The coding section is pretty lonely when you trying to do anything with SG code. So, it is better when we together and can discuss anything against case when we are all alone with manuals.

Have a good day!
"You should know that the lies won't hide your flaws/No sense in hiding all of yours/You gave up on your dreams along the way" (c) "Fake it" by Seether
P.S. English isn't my native language.
User avatar
Lucky Bro
Gunslinger
 
Posts: 143
Joined: Mon Mar 09, 2009 4:12 pm



Postby Conq » Sat Jul 18, 2009 1:39 pm

I'll take in account your suggestions, thanks ;-).

Have a good day too ;-).
Conq
Drifter
 
Posts: 13
Joined: Sun May 31, 2009 9:37 am



Postby torhu » Sat Jul 18, 2009 8:55 pm

Personally I'm quite happy with the default console, thank you. 8)

But I wonder why you use four different cvars for the color, why not just one? cl_consoleColor could be a string, used like this:

Code: Select all
cl_consoleColor 1 0 1 0.7

That would give you a purple color, and some transparency. Then you wouldn't need the /console command, just set the cvar. If you leave out the alpha, it defaults to 1. Or the alpha could be separate, if you want to use it when using the background image too.

You could use COM_Parse and atof for parsing the string, and check cl_consoleColor->modified to see if has changed and needs to be parsed again.

Also, cl_consoleType could be cl_solidConsole and have 1 and 0 as values. That's simpler and more in line with the other cvars. :)
In game: =SG=monSter
Monster Browser
User avatar
torhu
SG Team
 
Posts: 1125
Joined: Thu Jan 06, 2005 8:12 pm
Location: Norway



Postby Conq » Mon Jul 20, 2009 8:36 pm

Could be nice ! :-)

I'll see what I can do ;-)
Conq
Drifter
 
Posts: 13
Joined: Sun May 31, 2009 9:37 am



Postby Tequila » Sat Oct 31, 2009 1:39 pm

:D
Maybe it's time to add such useless but funny patch to our 1.1 branch.

Conq, the dl.freefr link are out of date. Can you update your first post ? or give another link with your last work on that ?
8)
User avatar
Tequila
SG Team
 
Posts: 1100
Joined: Thu Nov 15, 2007 11:33 pm
Location: Montpellier, France



Next

Return to Code

Show Sidebar
Show Sidebar

User Control Panel

cron