]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cvar.c
eliminated model->meshlist, replaced with an embedded model->surfmesh to cut down...
[xonotic/darkplaces.git] / cvar.c
diff --git a/cvar.c b/cvar.c
index f3b9e70ec411668ef39ca0e8c98f6601ffa9fa1f..f836721f0641ce98383cfb8c482662de1abc9c1d 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);
 }
 
 
@@ -258,7 +262,7 @@ void Cvar_SetQuick (cvar_t *var, const char *value)
                return;
        }
 
-       if (developer.integer)
+       if (developer.integer >= 100)
                Con_Printf("Cvar_SetQuick({\"%s\", \"%s\", %i, \"%s\"}, \"%s\");\n", var->name, var->string, var->flags, var->defstring, value);
 
        Cvar_SetQuick_Internal(var, value);
@@ -312,10 +316,11 @@ Adds a freestanding variable to the variable list.
 */
 void Cvar_RegisterVariable (cvar_t *variable)
 {
+       int hashindex;
        cvar_t *current, *next, *cvar;
        char *oldstr;
 
-       if (developer.integer)
+       if (developer.integer >= 100)
                Con_Printf("Cvar_RegisterVariable({\"%s\", \"%s\", %i});\n", variable->name, variable->string, variable->flags);
 
 // first check to see if it has already been defined
@@ -324,7 +329,7 @@ void Cvar_RegisterVariable (cvar_t *variable)
        {
                if (cvar->flags & CVAR_ALLOCATED)
                {
-                       if (developer.integer)
+                       if (developer.integer >= 100)
                                Con_Printf("...  replacing existing allocated cvar {\"%s\", \"%s\", %i}\n", cvar->name, cvar->string, cvar->flags);
                        // fixed variables replace allocated ones
                        // (because the engine directly accesses fixed variables)
@@ -387,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;
 }
 
 /*
@@ -398,9 +408,10 @@ 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)
+       if (developer.integer >= 100)
                Con_Printf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
 
 // first check to see if it has already been defined
@@ -443,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;
 }