]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_edict.c
Added a mempool parameter to FS_LoadFile
[xonotic/darkplaces.git] / pr_edict.c
index 2a77bac1d4df77add0a2927f635045d3f2c6103d..2f512093eff786f34dd3361aa4383d9999e0747c 100644 (file)
@@ -122,6 +122,10 @@ int eval_viewzoom;
 int eval_clientcolors;
 int eval_tag_entity;
 int eval_tag_index;
+int eval_light_lev;
+int eval_color;
+int eval_style;
+int eval_pflags;
 
 mfunction_t *SV_PlayerPhysicsQC;
 mfunction_t *EndFrameQC;
@@ -176,6 +180,10 @@ void FindEdictFieldOffsets(void)
        eval_clientcolors = FindFieldOffset("clientcolors");
        eval_tag_entity = FindFieldOffset("tag_entity");
        eval_tag_index = FindFieldOffset("tag_index");
+       eval_light_lev = FindFieldOffset("light_lev");
+       eval_color = FindFieldOffset("color");
+       eval_style = FindFieldOffset("style");
+       eval_pflags = FindFieldOffset("pflags");
 
        // LordHavoc: allowing QuakeC to override the player movement code
        SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics");
@@ -393,7 +401,7 @@ char *PR_ValueString (etype_t type, eval_t *val)
        switch (type)
        {
        case ev_string:
-               snprintf (line, sizeof (line), "%s", PR_GetString(val->string));
+               strncpy(line, PR_GetString(val->string), sizeof(line));
                break;
        case ev_entity:
                //n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict));
@@ -481,7 +489,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val)
                break;
        case ev_function:
                f = pr_functions + val->function;
-               snprintf (line, sizeof (line), "%s", PR_GetString(f->s_name));
+               strncpy(line, PR_GetString(f->s_name), sizeof(line));
                break;
        case ev_field:
                def = ED_FieldAtOfs ( val->_int );
@@ -568,7 +576,7 @@ For debugging
 */
 // 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)
+void ED_Print(edict_t *ed)
 {
        int             l;
        ddef_t  *d;
@@ -580,7 +588,7 @@ void ED_Print (edict_t *ed)
 
        if (ed->e->free)
        {
-               Con_Print("FREE\n");
+               Con_Print("FREE\n");
                return;
        }
 
@@ -628,12 +636,12 @@ void ED_Print (edict_t *ed)
                strlcat (tempstring, "\n", sizeof (tempstring));
                if (strlen(tempstring) >= 4096)
                {
-                       Con_Printf("%s", tempstring);
+                       Con_Print(tempstring);
                        tempstring[0] = 0;
                }
        }
        if (tempstring[0])
-               Con_Printf("%s", tempstring);
+               Con_Print(tempstring);
 }
 
 /*
@@ -651,11 +659,11 @@ void ED_Write (qfile_t *f, edict_t *ed)
        char    *name;
        int             type;
 
-       FS_Print(f, "{\n");
+       FS_Print(f, "{\n");
 
        if (ed->e->free)
        {
-               FS_Print(f, "}\n");
+               FS_Print(f, "}\n");
                return;
        }
 
@@ -676,16 +684,16 @@ void ED_Write (qfile_t *f, edict_t *ed)
                if (j == type_size[type])
                        continue;
 
-               FS_Printf (f,"\"%s\" ",name);
-               FS_Printf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
+               FS_Printf(f,"\"%s\" ",name);
+               FS_Printf(f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
        }
 
-       FS_Print(f, "}\n");
+       FS_Print(f, "}\n");
 }
 
 void ED_PrintNum (int ent)
 {
-       ED_Print (EDICT_NUM(ent));
+       ED_Print(EDICT_NUM(ent));
 }
 
 /*
@@ -699,7 +707,7 @@ void ED_PrintEdicts (void)
 {
        int             i;
 
-       Con_Printf ("%i entities\n", sv.num_edicts);
+       Con_Printf("%i entities\n", sv.num_edicts);
        for (i=0 ; i<sv.num_edicts ; i++)
                ED_PrintNum (i);
 }
@@ -716,9 +724,9 @@ void ED_PrintEdict_f (void)
        int             i;
 
        i = atoi (Cmd_Argv(1));
-       if (i >= sv.num_edicts)
+       if (i < 0 || i >= sv.num_edicts)
        {
-               Con_Printf("Bad edict number\n");
+               Con_Print("Bad edict number\n");
                return;
        }
        ED_PrintNum (i);
@@ -752,11 +760,11 @@ void ED_Count (void)
                        step++;
        }
 
-       Con_Printf ("num_edicts:%3i\n", sv.num_edicts);
-       Con_Printf ("active    :%3i\n", active);
-       Con_Printf ("view      :%3i\n", models);
-       Con_Printf ("touch     :%3i\n", solid);
-       Con_Printf ("step      :%3i\n", step);
+       Con_Printf("num_edicts:%3i\n", sv.num_edicts);
+       Con_Printf("active    :%3i\n", active);
+       Con_Printf("view      :%3i\n", models);
+       Con_Printf("touch     :%3i\n", solid);
+       Con_Printf("step      :%3i\n", step);
 
 }
 
@@ -781,7 +789,7 @@ void ED_WriteGlobals (qfile_t *f)
        char            *name;
        int                     type;
 
-       FS_Print(f,"{\n");
+       FS_Print(f,"{\n");
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
@@ -794,10 +802,10 @@ void ED_WriteGlobals (qfile_t *f)
                        continue;
 
                name = PR_GetString(def->s_name);
-               FS_Printf (f,"\"%s\" ", name);
-               FS_Printf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
+               FS_Printf(f,"\"%s\" ", name);
+               FS_Printf(f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
        }
-       FS_Print(f,"}\n");
+       FS_Print(f,"}\n");
 }
 
 /*
@@ -814,7 +822,7 @@ void ED_EdictSet_f(void)
 
        if(Cmd_Argc() != 4)
        {
-               Con_Printf("edictset <edict number> <field> <value>\n");
+               Con_Print("edictset <edict number> <field> <value>\n");
                return;
        }
        ed = EDICT_NUM(atoi(Cmd_Argv(1)));
@@ -858,7 +866,7 @@ void ED_ParseGlobals (const char *data)
                key = ED_FindGlobal (keyname);
                if (!key)
                {
-                       Con_DPrintf ("'%s' is not a global\n", keyname);
+                       Con_DPrintf("'%s' is not a global\n", keyname);
                        continue;
                }
 
@@ -976,7 +984,7 @@ qboolean ED_ParseEpair(edict_t *ent, ddef_t *key, const char *s)
                func = ED_FindFunction(s);
                if (!func)
                {
-                       Con_Printf ("ED_ParseEpair: Can't find function %s\n", s);
+                       Con_Printf("ED_ParseEpair: Can't find function %s\n", s);
                        return false;
                }
                val->function = func - pr_functions;
@@ -1058,7 +1066,7 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
                key = ED_FindField (keyname);
                if (!key)
                {
-                       Con_DPrintf ("'%s' is not a field\n", keyname);
+                       Con_DPrintf("'%s' is not a field\n", keyname);
                        continue;
                }
 
@@ -1148,8 +1156,8 @@ void ED_LoadFromFile (const char *data)
 //
                if (!ent->v->classname)
                {
-                       Con_Print("No classname for:\n");
-                       ED_Print (ent);
+                       Con_Print("No classname for:\n");
+                       ED_Print(ent);
                        ED_Free (ent);
                        continue;
                }
@@ -1161,8 +1169,8 @@ void ED_LoadFromFile (const char *data)
                {
                        if (developer.integer) // don't confuse non-developers with errors
                        {
-                               Con_Print("No spawn function for:\n");
-                               ED_Print (ent);
+                               Con_Print("No spawn function for:\n");
+                               ED_Print(ent);
                        }
                        ED_Free (ent);
                        continue;
@@ -1175,7 +1183,7 @@ void ED_LoadFromFile (const char *data)
                        died++;
        }
 
-       Con_DPrintf ("%i entities parsed, %i inhibited, %i spawned (%i removed self, %i stayed)\n", parsed, inhibited, spawned, died, spawned - died);
+       Con_DPrintf("%i entities parsed, %i inhibited, %i spawned (%i removed self, %i stayed)\n", parsed, inhibited, spawned, died, spawned - died);
 }
 
 
@@ -1225,7 +1233,11 @@ dpfield_t dpfields[] =
        {ev_vector, "punchvector"},
        {ev_float, "clientcolors"},
        {ev_entity, "tag_entity"},
-       {ev_float, "tag_index"}
+       {ev_float, "tag_index"},
+       {ev_float, "light_lev"},
+       {ev_float, "color"},
+       {ev_float, "style"},
+       {ev_float, "pflags"}
 };
 
 /*
@@ -1239,7 +1251,6 @@ void PR_LoadProgs (void)
        int i;
        dstatement_t *st;
        ddef_t *infielddefs;
-       void *temp;
        dfunction_t *dfunctions;
 
 // flush the non-C variable lookup cache
@@ -1249,16 +1260,11 @@ void PR_LoadProgs (void)
        Mem_EmptyPool(progs_mempool);
        Mem_EmptyPool(edictstring_mempool);
 
-       temp = FS_LoadFile ("progs.dat", false);
-       if (!temp)
+       progs = (dprograms_t *)FS_LoadFile ("progs.dat", progs_mempool, false);
+       if (!progs)
                Host_Error ("PR_LoadProgs: couldn't load progs.dat");
 
-       progs = (dprograms_t *)Mem_Alloc(progs_mempool, fs_filesize);
-
-       memcpy(progs, temp, fs_filesize);
-       Mem_Free(temp);
-
-       Con_DPrintf ("Programs occupy %iK.\n", fs_filesize/1024);
+       Con_DPrintf("Programs occupy %iK.\n", fs_filesize/1024);
 
        pr_crc = CRC_Block((qbyte *)progs, fs_filesize);
 
@@ -1268,7 +1274,7 @@ void PR_LoadProgs (void)
 
        if (progs->version != PROG_VERSION)
                Host_Error ("progs.dat has wrong version number (%i should be %i)", progs->version, PROG_VERSION);
-       if (progs->crc != PROGHEADER_CRC)
+       if (progs->crc != PROGHEADER_CRC && progs->crc != 32401) // tenebrae crc also allowed
                Host_Error ("progs.dat system vars have been modified, progdefs.h is out of date");
 
        //pr_functions = (dfunction_t *)((qbyte *)progs + progs->ofs_functions);
@@ -1462,7 +1468,7 @@ void PR_Fields_f (void)
        int *v;
        if (!sv.active)
        {
-               Con_Printf("no progs loaded\n");
+               Con_Print("no progs loaded\n");
                return;
        }
        counts = Mem_Alloc(tempmempool, progs->numfielddefs * sizeof(int));
@@ -1544,7 +1550,7 @@ void PR_Fields_f (void)
                strlcat (tempstring, "\n", sizeof (tempstring));
                if (strlen(tempstring) >= 4096)
                {
-                       Con_Printf("%s", tempstring);
+                       Con_Print(tempstring);
                        tempstring[0] = 0;
                }
                if (counts[i])
@@ -1562,7 +1568,7 @@ void PR_Globals_f (void)
        int i;
        if (!sv.active)
        {
-               Con_Printf("no progs loaded\n");
+               Con_Print("no progs loaded\n");
                return;
        }
        for (i = 0;i < progs->numglobaldefs;i++)