]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_edict.c
removed winsock_initialized counter as there are no longer two things initializing...
[xonotic/darkplaces.git] / pr_edict.c
index ac1f78353f203fe0d2cee719b6d89d52b9ed14b2..61f948c945e38ec8a9ea3328cc254b670fc36afd 100644 (file)
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 
 dprograms_t            *progs;
-dfunction_t            *pr_functions;
+mfunction_t            *pr_functions;
 char                   *pr_strings;
 ddef_t                 *pr_fielddefs;
 ddef_t                 *pr_globaldefs;
@@ -82,7 +82,7 @@ typedef struct {
 static gefv_cache      gefvCache[GEFV_CACHESIZE] = {{NULL, ""}, {NULL, ""}};
 
 ddef_t *ED_FindField (const char *name);
-dfunction_t *ED_FindFunction (const char *name);
+mfunction_t *ED_FindFunction (const char *name);
 
 // LordHavoc: in an effort to eliminate time wasted on GetEdictFieldValue...  these are defined as externs in progs.h
 int eval_gravity;
@@ -120,8 +120,8 @@ int eval_pmodel;
 int eval_punchvector;
 int eval_viewzoom;
 
-dfunction_t *SV_PlayerPhysicsQC;
-dfunction_t *EndFrameQC;
+mfunction_t *SV_PlayerPhysicsQC;
+mfunction_t *EndFrameQC;
 
 int FindFieldOffset(const char *field)
 {
@@ -215,10 +215,10 @@ edict_t *ED_Alloc (void)
                        return e;
                }
        }
-       
+
        if (i == MAX_EDICTS)
                Host_Error ("ED_Alloc: no free edicts");
-               
+
        sv.num_edicts++;
        e = EDICT_NUM(i);
        ED_ClearEdict (e);
@@ -249,7 +249,7 @@ void ED_Free (edict_t *ed)
        VectorClear(ed->v->angles);
        ed->v->nextthink = -1;
        ed->v->solid = 0;
-       
+
        ed->freetime = sv.time;
 }
 
@@ -264,7 +264,7 @@ ddef_t *ED_GlobalAtOfs (int ofs)
 {
        ddef_t          *def;
        int                     i;
-       
+
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
@@ -283,7 +283,7 @@ ddef_t *ED_FieldAtOfs (int ofs)
 {
        ddef_t          *def;
        int                     i;
-       
+
        for (i=0 ; i<progs->numfielddefs ; i++)
        {
                def = &pr_fielddefs[i];
@@ -337,9 +337,9 @@ ddef_t *ED_FindGlobal (const char *name)
 ED_FindFunction
 ============
 */
-dfunction_t *ED_FindFunction (const char *name)
+mfunction_t *ED_FindFunction (const char *name)
 {
-       dfunction_t             *func;
+       mfunction_t             *func;
        int                             i;
 
        for (i=0 ; i<progs->numfunctions ; i++)
@@ -364,7 +364,7 @@ char *PR_ValueString (etype_t type, eval_t *val)
 {
        static char line[1024]; // LordHavoc: enlarged a bit (was 256)
        ddef_t *def;
-       dfunction_t *f;
+       mfunction_t *f;
        int n;
 
        type &= ~DEF_SAVEGLOBAL;
@@ -425,7 +425,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val)
        int i;
        char *s;
        ddef_t *def;
-       dfunction_t *f;
+       mfunction_t *f;
 
        type &= ~DEF_SAVEGLOBAL;
 
@@ -622,7 +622,7 @@ ED_Write
 For savegames
 =============
 */
-void ED_Write (QFile *f, edict_t *ed)
+void ED_Write (qfile_t *f, edict_t *ed)
 {
        ddef_t  *d;
        int             *v;
@@ -630,11 +630,11 @@ void ED_Write (QFile *f, edict_t *ed)
        char    *name;
        int             type;
 
-       Qprintf (f, "{\n");
+       FS_Printf (f, "{\n");
 
        if (ed->free)
        {
-               Qprintf (f, "}\n");
+               FS_Printf (f, "}\n");
                return;
        }
 
@@ -655,11 +655,11 @@ void ED_Write (QFile *f, edict_t *ed)
                if (j == type_size[type])
                        continue;
 
-               Qprintf (f,"\"%s\" ",name);
-               Qprintf (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));
        }
 
-       Qprintf (f, "}\n");
+       FS_Printf (f, "}\n");
 }
 
 void ED_PrintNum (int ent)
@@ -753,14 +753,14 @@ FIXME: need to tag constants, doesn't really work
 ED_WriteGlobals
 =============
 */
-void ED_WriteGlobals (QFile *f)
+void ED_WriteGlobals (qfile_t *f)
 {
        ddef_t          *def;
        int                     i;
        char            *name;
        int                     type;
 
-       Qprintf (f,"{\n");
+       FS_Printf (f,"{\n");
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
@@ -773,10 +773,10 @@ void ED_WriteGlobals (QFile *f)
                        continue;
 
                name = PR_GetString(def->s_name);
-               Qprintf (f,"\"%s\" ", name);
-               Qprintf (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]));
        }
-       Qprintf (f,"}\n");
+       FS_Printf (f,"}\n");
 }
 
 /*
@@ -868,7 +868,7 @@ qboolean    ED_ParseEpair (void *base, ddef_t *key, const char *s)
        ddef_t  *def;
        char    *v, *w;
        void    *d;
-       dfunction_t     *func;
+       mfunction_t     *func;
 
        d = (void *)((int *)base + key->ofs);
 
@@ -877,11 +877,11 @@ qboolean  ED_ParseEpair (void *base, ddef_t *key, const char *s)
        case ev_string:
                *(string_t *)d = PR_SetString(ED_NewString(s));
                break;
-               
+
        case ev_float:
                *(float *)d = atof (s);
                break;
-               
+
        case ev_vector:
                strcpy (string, s);
                v = string;
@@ -1042,12 +1042,12 @@ void ED_LoadFromFile (const char *data)
 {
        edict_t *ent;
        int inhibit;
-       dfunction_t *func;
+       mfunction_t *func;
 
        ent = NULL;
        inhibit = 0;
        pr_global_struct->time = sv.time;
-       
+
 // parse ents
        while (1)
        {
@@ -1068,7 +1068,7 @@ void ED_LoadFromFile (const char *data)
                {
                        if (((int)ent->v->spawnflags & SPAWNFLAG_NOT_DEATHMATCH))
                        {
-                               ED_Free (ent);  
+                               ED_Free (ent);
                                inhibit++;
                                continue;
                        }
@@ -1166,12 +1166,14 @@ dpfield_t dpfields[] =
 PR_LoadProgs
 ===============
 */
+extern void PR_Cmd_Reset (void);
 void PR_LoadProgs (void)
 {
        int i;
        dstatement_t *st;
        ddef_t *infielddefs;
        void *temp;
+       dfunction_t *dfunctions;
 
 // flush the non-C variable lookup cache
        for (i=0 ; i<GEFV_CACHESIZE ; i++)
@@ -1180,18 +1182,18 @@ void PR_LoadProgs (void)
        Mem_EmptyPool(progs_mempool);
        Mem_EmptyPool(edictstring_mempool);
 
-       temp = COM_LoadFile ("progs.dat", false);
+       temp = FS_LoadFile ("progs.dat", false);
        if (!temp)
                Host_Error ("PR_LoadProgs: couldn't load progs.dat");
 
-       progs = (dprograms_t *)Mem_Alloc(progs_mempool, com_filesize);
+       progs = (dprograms_t *)Mem_Alloc(progs_mempool, fs_filesize);
 
-       memcpy(progs, temp, com_filesize);
+       memcpy(progs, temp, fs_filesize);
        Mem_Free(temp);
 
-       Con_DPrintf ("Programs occupy %iK.\n", com_filesize/1024);
+       Con_DPrintf ("Programs occupy %iK.\n", fs_filesize/1024);
 
-       pr_crc = CRC_Block((qbyte *)progs, com_filesize);
+       pr_crc = CRC_Block((qbyte *)progs, fs_filesize);
 
 // byte swap the header
        for (i = 0;i < (int) sizeof(*progs) / 4;i++)
@@ -1202,7 +1204,8 @@ void PR_LoadProgs (void)
        if (progs->crc != PROGHEADER_CRC)
                Host_Error ("progs.dat system vars have been modified, progdefs.h is out of date");
 
-       pr_functions = (dfunction_t *)((qbyte *)progs + progs->ofs_functions);
+       //pr_functions = (dfunction_t *)((qbyte *)progs + progs->ofs_functions);
+       dfunctions = (dfunction_t *)((qbyte *)progs + progs->ofs_functions);
        pr_strings = (char *)progs + progs->ofs_strings;
        pr_globaldefs = (ddef_t *)((qbyte *)progs + progs->ofs_globaldefs);
 
@@ -1227,14 +1230,16 @@ void PR_LoadProgs (void)
                pr_statements[i].c = LittleShort(pr_statements[i].c);
        }
 
-       for (i=0 ; i<progs->numfunctions; i++)
+       pr_functions = Mem_Alloc(progs_mempool, sizeof(mfunction_t) * progs->numfunctions);
+       for (i = 0;i < progs->numfunctions;i++)
        {
-               pr_functions[i].first_statement = LittleLong (pr_functions[i].first_statement);
-               pr_functions[i].parm_start = LittleLong (pr_functions[i].parm_start);
-               pr_functions[i].s_name = LittleLong (pr_functions[i].s_name);
-               pr_functions[i].s_file = LittleLong (pr_functions[i].s_file);
-               pr_functions[i].numparms = LittleLong (pr_functions[i].numparms);
-               pr_functions[i].locals = LittleLong (pr_functions[i].locals);
+               pr_functions[i].first_statement = LittleLong (dfunctions[i].first_statement);
+               pr_functions[i].parm_start = LittleLong (dfunctions[i].parm_start);
+               pr_functions[i].s_name = LittleLong (dfunctions[i].s_name);
+               pr_functions[i].s_file = LittleLong (dfunctions[i].s_file);
+               pr_functions[i].numparms = LittleLong (dfunctions[i].numparms);
+               pr_functions[i].locals = LittleLong (dfunctions[i].locals);
+               memcpy(pr_functions[i].parm_size, dfunctions[i].parm_size, sizeof(dfunctions[i].parm_size));
        }
 
        for (i=0 ; i<progs->numglobaldefs ; i++)
@@ -1376,6 +1381,7 @@ void PR_LoadProgs (void)
 
        FindEdictFieldOffsets(); // LordHavoc: update field offset list
        PR_Execute_ProgsLoaded();
+       PR_Cmd_Reset();
 }
 
 
@@ -1502,6 +1508,7 @@ void PR_Globals_f (void)
 PR_Init
 ===============
 */
+extern void PR_Cmd_Init(void);
 void PR_Init (void)
 {
        Cmd_AddCommand ("edict", ED_PrintEdict_f);
@@ -1545,6 +1552,8 @@ void PR_Init (void)
 
        progs_mempool = Mem_AllocPool("progs.dat");
        edictstring_mempool = Mem_AllocPool("edict strings");
+
+       PR_Cmd_Init();
 }
 
 // LordHavoc: turned EDICT_NUM into a #define for speed reasons