]> git.xonotic.org Git - voretournament/voretournament.git/blobdiff - misc/source/fteqcc-src/pr_edict.c
Update fteqcc source
[voretournament/voretournament.git] / misc / source / fteqcc-src / pr_edict.c
index a67b36851e358328db2960f22406f15069a86cb2..468aea459c22721514ec4237e5a2c10a1ade410c 100644 (file)
@@ -5,11 +5,6 @@ struct edict_s;
 #include "progsint.h"
 //#include "crc.h"
 
-/*int maxedicts;
-
-evalc_t spawnflagscache;
-*/
-
 #ifdef _WIN32
 //this is windows  all files are written with this endian standard. we do this to try to get a little more speed.
 #define NOENDIAN
@@ -18,30 +13,8 @@ evalc_t spawnflagscache;
 
 vec3_t vec3_origin;
 
-//edictrun_t *sv_edicts;
-//int sv_num_edicts;
-
-//int                          pr_edict_size;  // in bytes
-//int                          pr_max_edict_size;
-
-//unsigned short               pr_crc;
-
 fdef_t *ED_FieldAtOfs (progfuncs_t *progfuncs, unsigned int ofs);
-pbool  ED_ParseEpair (progfuncs_t *progfuncs, void *base, ddefXX_t *key, char *s, int bits);
-
-
-
-/*
-#define        MAX_FIELD_LEN   64
-#define GEFV_CACHESIZE 5
-
-typedef struct {
-       ddef_t  *pcache;
-       char    field[MAX_FIELD_LEN];
-} gefv_cache;
-
-static gefv_cache      gefvCache[GEFV_CACHESIZE] = {{NULL, ""}, {NULL, ""}};
-*/
+pbool  ED_ParseEpair (progfuncs_t *progfuncs, int qcptr, unsigned int fldofs, int fldtype, char *s);
 
 /*
 =================
@@ -487,7 +460,7 @@ char *PR_ValueString (progfuncs_t *progfuncs, etype_t type, eval_t *val)
        type &= ~DEF_SAVEGLOBAL;
 #endif
 
-       if (pr_types)
+       if (current_progstate && pr_types)
                type = pr_types[type].type;
 
        switch (type)
@@ -600,8 +573,8 @@ char *PR_UglyValueString (progfuncs_t *progfuncs, etype_t type, eval_t *val)
        type &= ~DEF_SAVEGLOBAL;
 #endif
 
-       if (pr_types)
-               type = pr_types[type].type;
+//     if (pr_types)
+//             type = pr_types[type].type;
 
        switch (type)
        {
@@ -1052,54 +1025,30 @@ Can parse either fields or globals
 returns false if error
 =============
 */
-pbool  ED_ParseEpair (progfuncs_t *progfuncs, void *base, ddefXX_t *key, char *s, int structtype)
+pbool  ED_ParseEpair (progfuncs_t *progfuncs, int qcptr, unsigned int fldofs, int fldtype, char *s)
 {
        int             i;
        char    string[128];
        fdef_t  *def;
        char    *v, *w;
-       void    *d;
        string_t st;
        dfunction_t     *func;
-
-       int type = 0; // warning about beign used without initializing it
-
-       switch(structtype)
-       {
-       case PST_DEFAULT:
-               d = (void *)((int *)base + ((ddef16_t*)key)->ofs);
-
-               if (pr_types)
-                       type = pr_types[((ddef16_t*)key)->type & ~DEF_SAVEGLOBAL].type;
-               else
-                       type = ((ddef16_t*)key)->type & ~DEF_SAVEGLOBAL;
-               break;
-       case PST_FTE32:
-               d = (void *)((int *)base + ((ddef32_t*)key)->ofs);
-
-               if (pr_types)
-                       type = pr_types[((ddef32_t*)key)->type & ~DEF_SAVEGLOBAL].type;
-               else
-                       type = ((ddef32_t*)key)->type & ~DEF_SAVEGLOBAL;
-               break;
-       default:
-               Sys_Error("Bad struct type in ED_ParseEpair");
-               d = 0;
-       }
+       int type = fldtype & ~DEF_SAVEGLOBAL;
+       qcptr += fldofs*sizeof(int);
 
        switch (type)
        {
        case ev_string:
                st = PR_StringToProgs(progfuncs, ED_NewString (progfuncs, s, 0));
-               *(string_t *)d = st;
+               *(string_t *)(progfuncs->stringtable + qcptr) = st;
                break;
 
        case ev_float:
-               *(float *)d = (float)atof (s);
+               *(float *)(progfuncs->stringtable + qcptr) = (float)atof (s);
                break;
 
        case ev_integer:
-               *(int *)d = atoi (s);
+               *(int *)(progfuncs->stringtable + qcptr) = atoi (s);
                break;
 
        case ev_vector:
@@ -1112,20 +1061,20 @@ pbool   ED_ParseEpair (progfuncs_t *progfuncs, void *base, ddefXX_t *key, char *s,
                                v++;
                        if (!*v)
                        {
-                               ((float *)d)[i] = (float)atof (w);
+                               ((float *)(progfuncs->stringtable + qcptr))[i] = (float)atof (w);
                                w = v;
                        }
                        else
                        {
                                *v = 0;
-                               ((float *)d)[i] = (float)atof (w);
+                               ((float *)(progfuncs->stringtable + qcptr))[i] = (float)atof (w);
                                w = v = v+1;
                        }
                }
                break;
 
        case ev_entity:
-               *(int *)d = atoi (s);
+               *(int *)(progfuncs->stringtable + qcptr) = atoi (s);
                break;
 
        case ev_field:
@@ -1135,13 +1084,13 @@ pbool   ED_ParseEpair (progfuncs_t *progfuncs, void *base, ddefXX_t *key, char *s,
                        printf ("Can't find field %s\n", s);
                        return false;
                }
-               *(int *)d = def->ofs;
+               *(int *)(progfuncs->stringtable + qcptr) = def->ofs;
                break;
 
        case ev_function:
                if (s[1]==':'&&s[2]=='\0')
                {
-                       *(func_t *)d = 0;
+                       *(func_t *)(progfuncs->stringtable + qcptr) = 0;
                        return true;
                }
                func = ED_FindFunction (progfuncs, s, &i, -1);
@@ -1150,7 +1099,7 @@ pbool     ED_ParseEpair (progfuncs_t *progfuncs, void *base, ddefXX_t *key, char *s,
                        printf ("Can't find function %s\n", s);
                        return false;
                }
-               *(func_t *)d = (func - pr_progstate[i].functions) | (i<<24);
+               *(func_t *)(progfuncs->stringtable + qcptr) = (func - pr_progstate[i].functions) | (i<<24);
                break;
 
        default:
@@ -1259,7 +1208,7 @@ char *ED_ParseEdict (progfuncs_t *progfuncs, char *data, edictrun_t *ent)
                }
 
 cont:
-               if (!ED_ParseEpair (progfuncs, ent->fields, (ddefXX_t*)key, qcc_token, PST_FTE32))
+               if (!ED_ParseEpair (progfuncs, (char*)ent->fields - progfuncs->stringtable, key->ofs, key->type, qcc_token))
                {
                        continue;
 //                     Sys_Error ("ED_ParseEdict: parse error on entities");
@@ -1690,6 +1639,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
        eval_t *fulldata;       //this is part of FTE_FULLSPAWNDATA
        char *datastart;
 
+       eval_t *selfvar = NULL;
        eval_t *var;
 
        char filename[128];
@@ -1699,6 +1649,8 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
        ddef16_t *d16;
        ddef32_t *d32;
        func_t CheckSpawn=0;
+       void *oldglobals = NULL;
+       int oldglobalssize = 0;
 
        extern edictrun_t tempedict;
 
@@ -1719,14 +1671,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
        {
                isloadgame = false;
 
-               if (pr_typecurrent>=0)
-                       num = ED_FindGlobalOfs(progfuncs, "__fullspawndata");
-               else
-                       num = 0;
-               if (num)
-                       fulldata = (eval_t *)((int *)pr_globals + num);
-               else
-                       fulldata = NULL;
+               fulldata = PR_FindGlobal(progfuncs, "__fullspawndata", PR_ANY, NULL);
        }
 
        while(1)
@@ -1854,6 +1799,14 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
                                current_progstate->builtins = externs->builtinsfor(num, header_crc);
                                current_progstate->numbuiltins = numbuiltins;
                        }
+
+                       if (num == 0 && oldglobals)
+                       {
+                               if (pr_progstate[0].globals_size == oldglobalssize)
+                                       memcpy(pr_progstate[0].globals, oldglobals, pr_progstate[0].globals_size);
+                               free(oldglobals);
+                               oldglobals = NULL;
+                       }
                }
                else if (!strcmp(qcc_token, "globals"))
                {
@@ -1905,7 +1858,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
                                        else
                                        {
                                                file = QCC_COM_Parse(file);
-                                               ED_ParseEpair(progfuncs, pr_globals, (ddefXX_t*)d16, qcc_token, PST_DEFAULT);
+                                               ED_ParseEpair(progfuncs, (char*)pr_globals - progfuncs->stringtable, d16->ofs, d16->type, qcc_token);
                                        }
                                        break;
                                case PST_QTEST:
@@ -1918,7 +1871,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
                                        else
                                        {
                                                file = QCC_COM_Parse(file);
-                                               ED_ParseEpair(progfuncs, pr_globals, (ddefXX_t*)d32, qcc_token, PST_FTE32);
+                                               ED_ParseEpair(progfuncs, (char*)pr_globals - progfuncs->stringtable, d32->ofs, d32->type, qcc_token);
                                        }
                                        break;
                                default:
@@ -1963,6 +1916,21 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
                                        Sys_Error("Bad key \"%s\" in general block", qcc_token);
                        }
 
+                       if (oldglobals)
+                               free(oldglobals);
+                       oldglobals = NULL;
+                       if (pr_progstate[0].globals_size)
+                       {
+                               oldglobals = malloc(pr_progstate[0].globals_size);
+                               if (oldglobals)
+                               {
+                                       oldglobalssize = pr_progstate[0].globals_size;
+                                       memcpy(oldglobals, pr_progstate[0].globals, oldglobalssize);
+                               }
+                               else
+                                       printf("Unable to alloc %i bytes\n", pr_progstate[0].globals_size);
+                       }
+
                        PRAddressableFlush(progfuncs, -1);
                        resethunk=true;
 
@@ -2004,7 +1972,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
                                                        else
                                                        {
                                                                file = QCC_COM_Parse(file);
-                                                               ED_ParseEpair(progfuncs, pr_globals, (ddefXX_t*)d16, qcc_token, PST_DEFAULT);
+                                                               ED_ParseEpair(progfuncs, (char*)pr_globals - progfuncs->stringtable, d16->ofs, d16->type, qcc_token);
                                                        }
                                                        break;
                                                case PST_QTEST:
@@ -2017,7 +1985,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
                                                        else
                                                        {
                                                                file = QCC_COM_Parse(file);
-                                                               ED_ParseEpair(progfuncs, pr_globals, (ddefXX_t*)d32, qcc_token, PST_FTE32);
+                                                               ED_ParseEpair(progfuncs, (char*)pr_globals - progfuncs->stringtable, d32->ofs, d32->type, qcc_token);
                                                        }
                                                        break;
                                                default:
@@ -2097,8 +2065,6 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
                                }
                                else
                                {
-                                       eval_t *selfvar;
-
                                        //added by request of Mercury.
                                        if (fulldata)   //this is a vital part of HL map support!!!
                                        {       //essentually, it passes the ent's spawn info to the ent.
@@ -2113,8 +2079,10 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
                                                fulldata->string = PR_StringToProgs(progfuncs, spawndata);
                                        }
 
-                                       selfvar = (eval_t *)((int *)pr_globals + ED_FindGlobalOfs(progfuncs, "self"));
-                                       selfvar->edict = EDICT_TO_PROG(progfuncs, ed);
+                                       if (!selfvar)
+                                               selfvar = PR_FindGlobal(progfuncs, "self", PR_ANY, NULL);
+                                       if (selfvar)
+                                               selfvar->edict = EDICT_TO_PROG(progfuncs, ed);
 
                                        //DP_SV_SPAWNFUNC_PREFIX support
                                        eclassname = PR_StringToNative(progfuncs, var->string);
@@ -2164,6 +2132,10 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
                sv_num_edicts = numents;
        }
 
+       if (oldglobals)
+               free(oldglobals);
+       oldglobals = NULL;
+
        if (resethunk)
        {
                return entsize;
@@ -2505,6 +2477,7 @@ retry:
        current_progstate->statements = (void *)((qbyte *)pr_progs + pr_progs->ofs_statements);
 
        glob = pr_globals = (void *)((qbyte *)pr_progs + pr_progs->ofs_globals);
+       current_progstate->globals_size = pr_progs->numglobals*sizeof(*pr_globals);
 
        pr_linenums=NULL;
        pr_types=NULL;
@@ -2929,6 +2902,9 @@ retry:
                        {
                                if (st16[i].op >= OP_CALL1 && st16[i].op <= OP_CALL8)
                                        st16[i].op += OP_CALL1H - OP_CALL1;
+                               if (st16[i].op >= OP_RAND0 && st16[i].op <= OP_RANDV2)
+                                       if (!st16[i].c)
+                                               st16[i].c = OFS_RETURN;
                        }
                }
                break;
@@ -2958,6 +2934,9 @@ retry:
                        {
                                if (pr_statements32[i].op >= OP_CALL1 && pr_statements32[i].op <= OP_CALL8)
                                        pr_statements32[i].op += OP_CALL1H - OP_CALL1;
+                               if (pr_statements32[i].op >= OP_RAND0 && pr_statements32[i].op <= OP_RANDV2)
+                                       if (!pr_statements32[i].c)
+                                               pr_statements32[i].c = OFS_RETURN;
                        }
                }
                break;
@@ -3117,7 +3096,7 @@ retry:
                                d16 = ED_FindGlobal16(progfuncs, s);
                                if (!d16)
                                {
-                                       printf("Progs requires \"%s\" the external function \"%s\", but the definition was stripped", filename, s);
+                                       printf("Progs requires \"%s\" the external function \"%s\", but the definition was stripped\n", filename, s);
                                        PRHunkFree(progfuncs, hmark);
                                        pr_progs=NULL;
                                        return false;
@@ -3125,7 +3104,7 @@ retry:
 
                                ((int *)glob)[d16->ofs] = PR_FindFunc(progfuncs, s, PR_ANY);
                                if (!((int *)glob)[d16->ofs])
-                                       printf("Warning: Runtime-linked function %s was not found in primary progs (loading %s)", s, filename);
+                                       printf("Warning: Runtime-linked function %s could not be found (loading %s)\n", s, filename);
                                /*
                                d2 = ED_FindGlobalOfsFromProgs(progfuncs, s, 0, ev_function);
                                if (!d2)