]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_edict.c
added TEXF_FORCENEAREST and TEXF_FORCELINEAR flags
[xonotic/darkplaces.git] / pr_edict.c
index 3d4553a489c5818b3ba197480be80745fe3474a9..374a9648ec541cf80e0bce1652aa7c04669e9eef 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)
 {
@@ -306,7 +306,7 @@ ddef_t *ED_FindField (const char *name)
        for (i=0 ; i<progs->numfielddefs ; i++)
        {
                def = &pr_fielddefs[i];
-               if (!strcmp(pr_strings + def->s_name,name) )
+               if (!strcmp(PR_GetString(def->s_name), name))
                        return def;
        }
        return NULL;
@@ -325,7 +325,7 @@ ddef_t *ED_FindGlobal (const char *name)
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
-               if (!strcmp(pr_strings + def->s_name,name) )
+               if (!strcmp(PR_GetString(def->s_name), name))
                        return def;
        }
        return NULL;
@@ -337,15 +337,15 @@ 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++)
        {
                func = &pr_functions[i];
-               if (!strcmp(pr_strings + func->s_name,name) )
+               if (!strcmp(PR_GetString(func->s_name), name))
                        return func;
        }
        return NULL;
@@ -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;
@@ -372,7 +372,7 @@ char *PR_ValueString (etype_t type, eval_t *val)
        switch (type)
        {
        case ev_string:
-               sprintf (line, "%s", pr_strings + val->string);
+               sprintf (line, "%s", PR_GetString(val->string));
                break;
        case ev_entity:
                n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict));
@@ -383,11 +383,11 @@ char *PR_ValueString (etype_t type, eval_t *val)
                break;
        case ev_function:
                f = pr_functions + val->function;
-               sprintf (line, "%s()", pr_strings + f->s_name);
+               sprintf (line, "%s()", PR_GetString(f->s_name));
                break;
        case ev_field:
                def = ED_FieldAtOfs ( val->_int );
-               sprintf (line, ".%s", pr_strings + def->s_name);
+               sprintf (line, ".%s", PR_GetString(def->s_name));
                break;
        case ev_void:
                sprintf (line, "void");
@@ -425,29 +425,29 @@ 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;
 
        switch (type)
        {
        case ev_string:
-               sprintf (line, "%s", pr_strings + val->string);
+               sprintf (line, "%s", PR_GetString(val->string));
                break;
        case ev_entity:
                sprintf (line, "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
                break;
        case ev_function:
                f = pr_functions + val->function;
-               sprintf (line, "%s", pr_strings + f->s_name);
+               sprintf (line, "%s", PR_GetString(f->s_name));
                break;
        case ev_field:
                def = ED_FieldAtOfs ( val->_int );
                // LordHavoc: parse the string a bit to turn special characters
                // (like newline, specifically) into escape codes,
                // this fixes saving games from various mods
-               //sprintf (line, "%s", pr_strings + def->s_name);
-               s = pr_strings + def->s_name;
+               //sprintf (line, "%s", PR_GetString(def->s_name));
+               s = PR_GetString(def->s_name);
                for (i = 0;i < 4095 && *s;)
                {
                        if (*s == '\n')
@@ -506,7 +506,7 @@ char *PR_GlobalString (int ofs)
        else
        {
                s = PR_ValueString (def->type, val);
-               sprintf (line,"%i(%s)%s", ofs, pr_strings + def->s_name, s);
+               sprintf (line,"%i(%s)%s", ofs, PR_GetString(def->s_name), s);
        }
 
        i = strlen(line);
@@ -527,7 +527,7 @@ char *PR_GlobalStringNoContents (int ofs)
        if (!def)
                sprintf (line,"%i(?)", ofs);
        else
-               sprintf (line,"%i(%s)", ofs, pr_strings + def->s_name);
+               sprintf (line,"%i(%s)", ofs, PR_GetString(def->s_name));
 
        i = strlen(line);
        for ( ; i<20 ; i++)
@@ -568,7 +568,7 @@ void ED_Print (edict_t *ed)
        for (i=1 ; i<progs->numfielddefs ; i++)
        {
                d = &pr_fielddefs[i];
-               name = pr_strings + d->s_name;
+               name = PR_GetString(d->s_name);
                if (name[strlen(name)-2] == '_')
                        continue;       // skip _x, _y, _z vars
 
@@ -641,7 +641,7 @@ void ED_Write (QFile *f, edict_t *ed)
        for (i=1 ; i<progs->numfielddefs ; i++)
        {
                d = &pr_fielddefs[i];
-               name = pr_strings + d->s_name;
+               name = PR_GetString(d->s_name);
                if (name[strlen(name)-2] == '_')
                        continue;       // skip _x, _y, _z vars
 
@@ -772,7 +772,7 @@ void ED_WriteGlobals (QFile *f)
                if (type != ev_string && type != ev_float && type != ev_entity)
                        continue;
 
-               name = pr_strings + def->s_name;                
+               name = PR_GetString(def->s_name);
                Qprintf (f,"\"%s\" ", name);
                Qprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));              
        }
@@ -868,14 +868,14 @@ 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);
 
        switch (key->type & ~DEF_SAVEGLOBAL)
        {
        case ev_string:
-               *(string_t *)d = ED_NewString (s) - pr_strings;
+               *(string_t *)d = PR_SetString(ED_NewString(s));
                break;
                
        case ev_float:
@@ -911,7 +911,7 @@ qboolean    ED_ParseEpair (void *base, ddef_t *key, const char *s)
                }
                *(int *)d = G_INT(def->ofs);
                break;
-       
+
        case ev_function:
                func = ED_FindFunction (s);
                if (!func)
@@ -1042,7 +1042,7 @@ void ED_LoadFromFile (const char *data)
 {
        edict_t *ent;
        int inhibit;
-       dfunction_t *func;
+       mfunction_t *func;
 
        ent = NULL;
        inhibit = 0;
@@ -1094,7 +1094,7 @@ void ED_LoadFromFile (const char *data)
                }
 
        // look for the spawn function
-               func = ED_FindFunction ( pr_strings + ent->v->classname );
+               func = ED_FindFunction (PR_GetString(ent->v->classname));
 
                if (!func)
                {
@@ -1172,6 +1172,7 @@ void PR_LoadProgs (void)
        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++)
@@ -1194,7 +1195,7 @@ void PR_LoadProgs (void)
        pr_crc = CRC_Block((qbyte *)progs, com_filesize);
 
 // byte swap the header
-       for (i=0 ; i<sizeof(*progs)/4 ; i++)
+       for (i = 0;i < (int) sizeof(*progs) / 4;i++)
                ((int *)progs)[i] = LittleLong ( ((int *)progs)[i] );
 
        if (progs->version != PROG_VERSION)
@@ -1202,7 +1203,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 +1229,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++)
@@ -1255,11 +1259,11 @@ void PR_LoadProgs (void)
        }
 
        // append the darkplaces fields
-       for (i = 0;i < DPFIELDS;i++)
+       for (i = 0;i < (int) DPFIELDS;i++)
        {
                pr_fielddefs[progs->numfielddefs].type = dpfields[i].type;
                pr_fielddefs[progs->numfielddefs].ofs = progs->entityfields;
-               pr_fielddefs[progs->numfielddefs].s_name = dpfields[i].string - pr_strings;
+               pr_fielddefs[progs->numfielddefs].s_name = PR_SetString(dpfields[i].string);
                if (pr_fielddefs[progs->numfielddefs].type == ev_vector)
                        progs->entityfields += 3;
                else
@@ -1401,7 +1405,7 @@ void PR_Fields_f (void)
                for (i = 1;i < progs->numfielddefs;i++)
                {
                        d = &pr_fielddefs[i];
-                       name = pr_strings + d->s_name;
+                       name = PR_GetString(d->s_name);
                        if (name[strlen(name)-2] == '_')
                                continue;       // skip _x, _y, _z vars
                        v = (int *)((char *)ed->v + d->ofs*4);
@@ -1422,7 +1426,7 @@ void PR_Fields_f (void)
        for (i = 0;i < progs->numfielddefs;i++)
        {
                d = &pr_fielddefs[i];
-               name = pr_strings + d->s_name;
+               name = PR_GetString(d->s_name);
                if (name[strlen(name)-2] == '_')
                        continue;       // skip _x, _y, _z vars
                switch(d->type & ~DEF_SAVEGLOBAL)
@@ -1493,7 +1497,7 @@ void PR_Globals_f (void)
                return;
        }
        for (i = 0;i < progs->numglobaldefs;i++)
-               Con_Printf("%s\n", (pr_strings + pr_globaldefs[i].s_name));
+               Con_Printf("%s\n", PR_GetString(pr_globaldefs[i].s_name));
        Con_Printf("%i global variables, totalling %i bytes\n", progs->numglobals, progs->numglobals * 4);
 }
 
@@ -1574,14 +1578,14 @@ int EDICT_TO_PROG(edict_t *e)
 {
        int n;
        n = e - sv.edicts;
-       if ((unsigned int)n >= sv.max_edicts)
+       if ((unsigned int)n >= (unsigned int)sv.max_edicts)
                Host_Error("EDICT_TO_PROG: invalid edict %8p (number %i compared to world at %8p)\n", e, n, sv.edicts);
        return n;// EXPERIMENTAL
        //return (qbyte *)e->v - (qbyte *)sv.edictsfields;
 }
 edict_t *PROG_TO_EDICT(int n)
 {
-       if ((unsigned int)n >= sv.max_edicts)
+       if ((unsigned int)n >= (unsigned int)sv.max_edicts)
                Host_Error("PROG_TO_EDICT: invalid edict number %i\n", n);
        return sv.edictstable[n]; // EXPERIMENTAL
        //return sv.edictstable[(n) / (progs->entityfields * 4)];