]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_edict.c
cleaned up nearly all of the externs in .c files (moved to appropriate .h files)
[xonotic/darkplaces.git] / pr_edict.c
index d327821d53e3ff2fac629424604ad21082a69936..cec47e822e310a5094451d2271e9a195294f762f 100644 (file)
@@ -39,6 +39,7 @@ int           type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(void *
 ddef_t *ED_FieldAtOfs (int ofs);
 qboolean       ED_ParseEpair (void *base, ddef_t *key, char *s);
 
+cvar_t pr_checkextension = {"pr_checkextension", "1"};
 cvar_t nomonsters = {"nomonsters", "0"};
 cvar_t gamecfg = {"gamecfg", "0"};
 cvar_t scratch1 = {"scratch1", "0"};
@@ -106,11 +107,13 @@ int eval_idealpitch;
 int eval_pitch_speed;
 int eval_viewmodelforclient;
 int eval_nodrawtoclient;
+int eval_exteriormodeltoclient;
 int eval_drawonlytoclient;
 int eval_colormod;
 int eval_ping;
 int eval_movement;
 int eval_pmodel;
+int eval_punchvector;
 
 dfunction_t *SV_PlayerPhysicsQC;
 dfunction_t *EndFrameQC;
@@ -124,7 +127,7 @@ int FindFieldOffset(char *field)
        return d->ofs*4;
 }
 
-void FindEdictFieldOffsets()
+void FindEdictFieldOffsets(void)
 {
        eval_gravity = FindFieldOffset("gravity");
        eval_button3 = FindFieldOffset("button3");
@@ -153,11 +156,13 @@ void FindEdictFieldOffsets()
        eval_pitch_speed = FindFieldOffset("pitch_speed");
        eval_viewmodelforclient = FindFieldOffset("viewmodelforclient");
        eval_nodrawtoclient = FindFieldOffset("nodrawtoclient");
+       eval_exteriormodeltoclient = FindFieldOffset("exteriormodeltoclient");
        eval_drawonlytoclient = FindFieldOffset("drawonlytoclient");
        eval_colormod = FindFieldOffset("colormod");
        eval_ping = FindFieldOffset("ping");
        eval_movement = FindFieldOffset("movement");
        eval_pmodel = FindFieldOffset("pmodel");
+       eval_punchvector = FindFieldOffset("punchvector");
 
        // LordHavoc: allowing QuakeC to override the player movement code
        SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics");
@@ -207,7 +212,7 @@ edict_t *ED_Alloc (void)
        }
        
        if (i == MAX_EDICTS)
-               Sys_Error ("ED_Alloc: no free edicts");
+               Host_Error ("ED_Alloc: no free edicts");
                
        sv.num_edicts++;
        e = EDICT_NUM(i);
@@ -235,8 +240,8 @@ void ED_Free (edict_t *ed)
        ed->v.colormap = 0;
        ed->v.skin = 0;
        ed->v.frame = 0;
-       VectorCopy (vec3_origin, ed->v.origin);
-       VectorCopy (vec3_origin, ed->v.angles);
+       VectorClear(ed->v.origin);
+       VectorClear(ed->v.angles);
        ed->v.nextthink = -1;
        ed->v.solid = 0;
        
@@ -302,7 +307,6 @@ ddef_t *ED_FindField (char *name)
        return NULL;
 }
 
-
 /*
 ============
 ED_FindGlobal
@@ -385,7 +389,7 @@ Returns a string describing *data in a type specific manner
 */
 char *PR_ValueString (etype_t type, eval_t *val)
 {
-       static char     line[256];
+       static char     line[1024]; // LordHavoc: enlarged a bit (was 256)
        ddef_t          *def;
        dfunction_t     *f;
        
@@ -411,10 +415,12 @@ char *PR_ValueString (etype_t type, eval_t *val)
                sprintf (line, "void");
                break;
        case ev_float:
-               sprintf (line, "%5.1f", val->_float);
+               // LordHavoc: changed from %5.1f to %10.4f
+               sprintf (line, "%10.4f", val->_float);
                break;
        case ev_vector:
-               sprintf (line, "'%5.1f %5.1f %5.1f'", val->vector[0], val->vector[1], val->vector[2]);
+               // LordHavoc: changed from %5.1f to %10.4f
+               sprintf (line, "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]);
                break;
        case ev_pointer:
                sprintf (line, "pointer");
@@ -538,7 +544,7 @@ ED_Print
 For debugging
 =============
 */
-// LordHavoc: optimized this to print out much more quickly
+// LordHavoc: optimized this to print out much more quickly (tempstring)
 void ED_Print (edict_t *ed)
 {
        int             l;
@@ -576,9 +582,9 @@ void ED_Print (edict_t *ed)
                        continue;
 
                strcat(tempstring, name);
-               l = strlen (name);
-               while (l++ < 15)
+               for (l = strlen(name);l < 14;l++)
                        strcat(tempstring, " ");
+               strcat(tempstring, " ");
 
                strcat(tempstring, PR_ValueString(d->type, (eval_t *)v));
                strcat(tempstring, "\n");
@@ -740,9 +746,7 @@ void ED_WriteGlobals (FILE *f)
                        continue;
                type &= ~DEF_SAVEGLOBAL;
 
-               if (type != ev_string
-               && type != ev_float
-               && type != ev_entity)
+               if (type != ev_string && type != ev_float && type != ev_entity)
                        continue;
 
                name = pr_strings + def->s_name;                
@@ -759,7 +763,7 @@ ED_ParseGlobals
 */
 void ED_ParseGlobals (char *data)
 {
-       char    keyname[64];
+       char    keyname[1024]; // LordHavoc: good idea? bad idea?  was 64
        ddef_t  *key;
 
        while (1)
@@ -807,7 +811,7 @@ char *ED_NewString (char *string)
        int             i,l;
        
        l = strlen(string) + 1;
-       new = Hunk_Alloc (l);
+       new = Hunk_AllocName (l, "edict string");
        new_p = new;
 
        for (i=0 ; i< l ; i++)
@@ -880,7 +884,7 @@ qboolean    ED_ParseEpair (void *base, ddef_t *key, char *s)
                if (!def)
                {
                        // LordHavoc: don't warn about worldspawn sky/fog fields because they don't require mod support
-                       if (strcmp(s, "sky") && strncmp(s, "fog_", 4) && strcmp(s, "skyboxsize"))
+                       if (strcmp(s, "sky") && strcmp(s, "fog") && strncmp(s, "fog_", 4) && strcmp(s, "farclip"))
                                Con_DPrintf ("Can't find field %s\n", s);
                        return false;
                }
@@ -1033,7 +1037,7 @@ void ED_LoadFromFile (char *data)
                if (!data)
                        break;
                if (com_token[0] != '{')
-                       Sys_Error ("ED_LoadFromFile: found %s when expecting {",com_token);
+                       Host_Error ("ED_LoadFromFile: found %s when expecting {",com_token);
 
                if (!ent)
                        ent = EDICT_NUM(0);
@@ -1086,7 +1090,7 @@ void ED_LoadFromFile (char *data)
                }
 
                pr_global_struct->self = EDICT_TO_PROG(ent);
-               PR_ExecuteProgram (func - pr_functions);
+               PR_ExecuteProgram (func - pr_functions, "");
        }       
 
        Con_DPrintf ("%i entities inhibited\n", inhibit);
@@ -1277,6 +1281,32 @@ void PR_LoadProgs (void)
 }
 
 
+void PR_Fields_f (void)
+{
+       int i;
+       if (!sv.active)
+       {
+               Con_Printf("no progs loaded\n");
+               return;
+       }
+       for (i = 0;i < progs->numfielddefs;i++)
+               Con_Printf("%s\n", (pr_strings + pr_fielddefs[i].s_name));
+       Con_Printf("%i entity fields, totalling %i bytes per edict, %i edicts, %i bytes total spent on edict fields\n", progs->entityfields, progs->entityfields * 4, MAX_EDICTS, progs->entityfields * 4 * MAX_EDICTS);
+}
+
+void PR_Globals_f (void)
+{
+       int i;
+       if (!sv.active)
+       {
+               Con_Printf("no progs loaded\n");
+               return;
+       }
+       for (i = 0;i < progs->numglobaldefs;i++)
+               Con_Printf("%s\n", (pr_strings + pr_globaldefs[i].s_name));
+       Con_Printf("%i global variables, totalling %i bytes\n", progs->numglobals, progs->numglobals * 4);
+}
+
 /*
 ===============
 PR_Init
@@ -1288,6 +1318,9 @@ void PR_Init (void)
        Cmd_AddCommand ("edicts", ED_PrintEdicts);
        Cmd_AddCommand ("edictcount", ED_Count);
        Cmd_AddCommand ("profile", PR_Profile_f);
+       Cmd_AddCommand ("pr_fields", PR_Fields_f);
+       Cmd_AddCommand ("pr_globals", PR_Globals_f);
+       Cvar_RegisterVariable (&pr_checkextension);
        Cvar_RegisterVariable (&nomonsters);
        Cvar_RegisterVariable (&gamecfg);
        Cvar_RegisterVariable (&scratch1);
@@ -1323,7 +1356,7 @@ void PR_Init (void)
 // LordHavoc: turned EDICT_NUM into a #define for speed reasons
 edict_t *EDICT_NUM_ERROR(int n)
 {
-       Sys_Error ("EDICT_NUM: bad number %i", n);
+       Host_Error ("EDICT_NUM: bad number %i", n);
        return NULL;
 }
 /*
@@ -1343,6 +1376,6 @@ int NUM_FOR_EDICT(edict_t *e)
        b = b / pr_edict_size;
        
        if (b < 0 || b >= sv.num_edicts)
-               Sys_Error ("NUM_FOR_EDICT: bad pointer");
+               Host_Error ("NUM_FOR_EDICT: bad pointer");
        return b;
 }