]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_edict.c
Added MSVC6 project files
[xonotic/darkplaces.git] / pr_edict.c
index d327821d53e3ff2fac629424604ad21082a69936..382394dd5ccc2f171d368e9724309d515299f04e 100644 (file)
@@ -39,31 +39,32 @@ 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 nomonsters = {"nomonsters", "0"};
-cvar_t gamecfg = {"gamecfg", "0"};
-cvar_t scratch1 = {"scratch1", "0"};
-cvar_t scratch2 = {"scratch2", "0"};
-cvar_t scratch3 = {"scratch3", "0"};
-cvar_t scratch4 = {"scratch4", "0"};
-cvar_t savedgamecfg = {"savedgamecfg", "0", true};
-cvar_t saved1 = {"saved1", "0", true};
-cvar_t saved2 = {"saved2", "0", true};
-cvar_t saved3 = {"saved3", "0", true};
-cvar_t saved4 = {"saved4", "0", true};
-cvar_t decors = {"decors", "0"};
-cvar_t nehx00 = {"nehx00", "0"};cvar_t nehx01 = {"nehx01", "0"};
-cvar_t nehx02 = {"nehx02", "0"};cvar_t nehx03 = {"nehx03", "0"};
-cvar_t nehx04 = {"nehx04", "0"};cvar_t nehx05 = {"nehx05", "0"};
-cvar_t nehx06 = {"nehx06", "0"};cvar_t nehx07 = {"nehx07", "0"};
-cvar_t nehx08 = {"nehx08", "0"};cvar_t nehx09 = {"nehx09", "0"};
-cvar_t nehx10 = {"nehx10", "0"};cvar_t nehx11 = {"nehx11", "0"};
-cvar_t nehx12 = {"nehx12", "0"};cvar_t nehx13 = {"nehx13", "0"};
-cvar_t nehx14 = {"nehx14", "0"};cvar_t nehx15 = {"nehx15", "0"};
-cvar_t nehx16 = {"nehx16", "0"};cvar_t nehx17 = {"nehx17", "0"};
-cvar_t nehx18 = {"nehx18", "0"};cvar_t nehx19 = {"nehx19", "0"};
-cvar_t cutscene = {"cutscene", "1"};
+cvar_t pr_checkextension = {0, "pr_checkextension", "1"};
+cvar_t nomonsters = {0, "nomonsters", "0"};
+cvar_t gamecfg = {0, "gamecfg", "0"};
+cvar_t scratch1 = {0, "scratch1", "0"};
+cvar_t scratch2 = {0,"scratch2", "0"};
+cvar_t scratch3 = {0, "scratch3", "0"};
+cvar_t scratch4 = {0, "scratch4", "0"};
+cvar_t savedgamecfg = {CVAR_SAVE, "savedgamecfg", "0"};
+cvar_t saved1 = {CVAR_SAVE, "saved1", "0"};
+cvar_t saved2 = {CVAR_SAVE, "saved2", "0"};
+cvar_t saved3 = {CVAR_SAVE, "saved3", "0"};
+cvar_t saved4 = {CVAR_SAVE, "saved4", "0"};
+cvar_t decors = {0, "decors", "0"};
+cvar_t nehx00 = {0, "nehx00", "0"};cvar_t      nehx01 = {0, "nehx01", "0"};
+cvar_t nehx02 = {0, "nehx02", "0"};cvar_t      nehx03 = {0, "nehx03", "0"};
+cvar_t nehx04 = {0, "nehx04", "0"};cvar_t      nehx05 = {0, "nehx05", "0"};
+cvar_t nehx06 = {0, "nehx06", "0"};cvar_t      nehx07 = {0, "nehx07", "0"};
+cvar_t nehx08 = {0, "nehx08", "0"};cvar_t      nehx09 = {0, "nehx09", "0"};
+cvar_t nehx10 = {0, "nehx10", "0"};cvar_t      nehx11 = {0, "nehx11", "0"};
+cvar_t nehx12 = {0, "nehx12", "0"};cvar_t      nehx13 = {0, "nehx13", "0"};
+cvar_t nehx14 = {0, "nehx14", "0"};cvar_t      nehx15 = {0, "nehx15", "0"};
+cvar_t nehx16 = {0, "nehx16", "0"};cvar_t      nehx17 = {0, "nehx17", "0"};
+cvar_t nehx18 = {0, "nehx18", "0"};cvar_t      nehx19 = {0, "nehx19", "0"};
+cvar_t cutscene = {0, "cutscene", "1"};
 // LordHavoc: optional runtime bounds checking (speed drain, but worth it for security, on by default - breaks most QCCX features (used by CRMod and others))
-cvar_t pr_boundscheck = {"pr_boundscheck", "1"};
+cvar_t pr_boundscheck = {0, "pr_boundscheck", "1"};
 
 #define        MAX_FIELD_LEN   64
 #define GEFV_CACHESIZE 2
@@ -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,8 @@ ED_Print
 For debugging
 =============
 */
-// LordHavoc: optimized this to print out much more quickly
+// LordHavoc: optimized this to print out much more quickly (tempstring)
+// LordHavoc: changed to print out every 4096 characters (incase there are a lot of fields to print)
 void ED_Print (edict_t *ed)
 {
        int             l;
@@ -547,7 +554,7 @@ void ED_Print (edict_t *ed)
        int             i, j;
        char    *name;
        int             type;
-       char    tempstring[8192]; // temporary string buffer
+       char    tempstring[8192], tempstring2[260]; // temporary string buffers
 
        if (ed->free)
        {
@@ -575,15 +582,36 @@ void ED_Print (edict_t *ed)
                if (j == type_size[type])
                        continue;
 
+               if (strlen(name) > 256)
+               {
+                       strncpy(tempstring2, name, 256);
+                       tempstring2[256] = tempstring2[257] = tempstring2[258] = '.';
+                       tempstring2[259] = 0;
+                       name = tempstring2;
+               }
                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));
+               name = PR_ValueString(d->type, (eval_t *)v);
+               if (strlen(name) > 256)
+               {
+                       strncpy(tempstring2, name, 256);
+                       tempstring2[256] = tempstring2[257] = tempstring2[258] = '.';
+                       tempstring2[259] = 0;
+                       name = tempstring2;
+               }
+               strcat(tempstring, name);
                strcat(tempstring, "\n");
+               if (strlen(tempstring) >= 4096)
+               {
+                       Con_Printf("%s", tempstring);
+                       tempstring[0] = 0;
+               }
        }
-       Con_Printf(tempstring);
+       if (tempstring[0])
+               Con_Printf("%s", tempstring);
 }
 
 /*
@@ -593,7 +621,7 @@ ED_Write
 For savegames
 =============
 */
-void ED_Write (FILE *f, edict_t *ed)
+void ED_Write (QFile *f, edict_t *ed)
 {
        ddef_t  *d;
        int             *v;
@@ -601,11 +629,11 @@ void ED_Write (FILE *f, edict_t *ed)
        char    *name;
        int             type;
 
-       fprintf (f, "{\n");
+       Qprintf (f, "{\n");
 
        if (ed->free)
        {
-               fprintf (f, "}\n");
+               Qprintf (f, "}\n");
                return;
        }
        
@@ -626,11 +654,11 @@ void ED_Write (FILE *f, edict_t *ed)
                if (j == type_size[type])
                        continue;
        
-               fprintf (f,"\"%s\" ",name);
-               fprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));               
+               Qprintf (f,"\"%s\" ",name);
+               Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));               
        }
 
-       fprintf (f, "}\n");
+       Qprintf (f, "}\n");
 }
 
 void ED_PrintNum (int ent)
@@ -724,14 +752,14 @@ FIXME: need to tag constants, doesn't really work
 ED_WriteGlobals
 =============
 */
-void ED_WriteGlobals (FILE *f)
+void ED_WriteGlobals (QFile *f)
 {
        ddef_t          *def;
        int                     i;
        char            *name;
        int                     type;
 
-       fprintf (f,"{\n");
+       Qprintf (f,"{\n");
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
@@ -740,16 +768,14 @@ 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;                
-               fprintf (f,"\"%s\" ", name);
-               fprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));              
+               Qprintf (f,"\"%s\" ", name);
+               Qprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));              
        }
-       fprintf (f,"}\n");
+       Qprintf (f,"}\n");
 }
 
 /*
@@ -759,7 +785,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 +833,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 +906,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 +1059,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 +1112,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 +1303,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 +1340,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 +1378,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 +1398,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;
 }