]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cvar.c
removed detection of GL_NV_texture_shader extension which was previously used for...
[xonotic/darkplaces.git] / cvar.c
diff --git a/cvar.c b/cvar.c
index 990ebdb8a082a6bf97c86042d309df83aacc9765..886ea96e8b2385b842e86d2d0491f4bb8cde476c 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 
 cvar_t *cvar_vars = NULL;
+cvar_t *cvar_hashtable[65536];
 char *cvar_null_string = "";
 
 /*
@@ -31,9 +32,12 @@ Cvar_FindVar
 */
 cvar_t *Cvar_FindVar (const char *var_name)
 {
+       int hashindex;
        cvar_t *var;
 
-       for (var = cvar_vars;var;var = var->next)
+       // use hash lookup to minimize search time
+       hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name));
+       for (var = cvar_hashtable[hashindex];var;var = var->nextonhashchain)
                if (!strcasecmp (var_name, var->name))
                        return var;
 
@@ -199,7 +203,7 @@ void Cvar_CompleteCvarPrint (const char *partial)
        // Loop through the command list and print all matches
        for (cvar = cvar_vars; cvar; cvar = cvar->next)
                if (!strncasecmp(partial, cvar->name, len))
-                       Con_Printf("%s : \"%s\" (\"%s\") : %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
+                       Con_Printf ("%c3%s%s : \"%s\" (\"%s\") : %s\n", STRING_COLOR_TAG, cvar->name, STRING_COLOR_DEFAULT_STR, cvar->string, cvar->defstring, cvar->description);
 }
 
 
@@ -229,6 +233,25 @@ void Cvar_SetQuick_Internal (cvar_t *var, const char *value)
        var->integer = (int) var->value;
        if ((var->flags & CVAR_NOTIFY) && changed && sv.active)
                SV_BroadcastPrintf("\"%s\" changed to \"%s\"\n", var->name, var->string);
+#if 0
+       // TODO: add infostring support to the server?
+       if ((var->flags & CVAR_SERVERINFO) && changed && sv.active)
+       {
+               InfoString_SetValue(svs.serverinfo, sizeof(svs.serverinfo), var->name, var->string);
+               if (sv.active)
+               {
+                       MSG_WriteByte (&sv.reliable_datagram, svc_serverinfostring);
+                       MSG_WriteString (&sv.reliable_datagram, var->name);
+                       MSG_WriteString (&sv.reliable_datagram, var->string);
+               }
+       }
+#endif
+       if ((var->flags & CVAR_USERINFO) && changed && cls.state != ca_dedicated)
+       {
+               InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), var->name, var->string);
+               if (cls.state == ca_connected)
+                       Cmd_ForwardStringToServer(va("setinfo \"%s\" \"%s\"\n", var->name, var->string));
+       }
 }
 
 void Cvar_SetQuick (cvar_t *var, const char *value)
@@ -293,6 +316,7 @@ Adds a freestanding variable to the variable list.
 */
 void Cvar_RegisterVariable (cvar_t *variable)
 {
+       int hashindex;
        cvar_t *current, *next, *cvar;
        char *oldstr;
 
@@ -368,6 +392,11 @@ void Cvar_RegisterVariable (cvar_t *variable)
                cvar_vars = variable;
        }
        variable->next = next;
+
+       // link to head of list in this hash table index
+       hashindex = CRC_Block((const unsigned char *)variable->name, strlen(variable->name));
+       variable->nextonhashchain = cvar_hashtable[hashindex];
+       cvar_hashtable[hashindex] = variable;
 }
 
 /*
@@ -379,7 +408,8 @@ Adds a newly allocated variable to the variable list or sets its value.
 */
 cvar_t *Cvar_Get (const char *name, const char *value, int flags)
 {
-       cvar_t *cvar;
+       int hashindex;
+       cvar_t *current, *next, *cvar;
 
        if (developer.integer)
                Con_Printf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
@@ -424,8 +454,20 @@ cvar_t *Cvar_Get (const char *name, const char *value, int flags)
        cvar->description = "custom cvar";
 
 // link the variable in
-       cvar->next = cvar_vars;
-       cvar_vars = cvar;
+// alphanumerical order
+       for( current = NULL, next = cvar_vars ; next && strcmp( next->name, cvar->name ) < 0 ; current = next, next = next->next )
+               ;
+       if( current )
+               current->next = cvar;
+       else
+               cvar_vars = cvar;
+       cvar->next = next;
+
+       // link to head of list in this hash table index
+       hashindex = CRC_Block((const unsigned char *)cvar->name, strlen(cvar->name));
+       cvar->nextonhashchain = cvar_hashtable[hashindex];
+       cvar_hashtable[hashindex] = cvar;
+
        return cvar;
 }