-Its now possible to add support for other edict_private structs easily.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 12 Oct 2004 19:08:30 +0000 (19:08 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 12 Oct 2004 19:08:30 +0000 (19:08 +0000)
(Note: You have to derive them by composition from the original one -
e.g. struct server_edict_private_s { prvm_edict_private_t base; ... };
or just copy the elements from prvm_edict_private_t into the new struct -
and add them to the anonymous union p in prvm_edict_t.)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4623 d7cf8633-e32d-0410-b094-e92efae38249

progsvm.h
prvm_cmds.c
prvm_edict.c

index 3e64d43..12c85cd 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -170,7 +170,12 @@ typedef struct prvm_edict_s
 {
        // engine-private fields (stored in dynamically resized array)
        //edict_engineprivate_t *e;
-       prvm_edict_private_t *e;
+       union 
+       {
+               prvm_edict_private_t *e;
+               void                             *vp;
+               //add other types as you desire
+       } p;
        // QuakeC fields (stored in dynamically resized array)
        //entvars_t *v;
        void *v;
index 0a6acf8..0ab773f 100644 (file)
@@ -906,7 +906,7 @@ void VM_find (void)
        {
                prog->xfunction->builtinsprofile++;
                ed = PRVM_EDICT_NUM(e);
-               if (ed->e->free)
+               if (ed->p.e->free)
                        continue;
                t = PRVM_E_STRING(ed,f);
                if (!t)
@@ -947,7 +947,7 @@ void VM_findfloat (void)
        {
                prog->xfunction->builtinsprofile++;
                ed = PRVM_EDICT_NUM(e);
-               if (ed->e->free)
+               if (ed->p.e->free)
                        continue;
                if (PRVM_E_FLOAT(ed,f) == s)
                {
@@ -999,7 +999,7 @@ void VM_findchain (void)
        for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
        {
                prog->xfunction->builtinsprofile++;
-               if (ent->e->free)
+               if (ent->p.e->free)
                        continue;
                t = PRVM_E_STRING(ent,f);
                if (!t)
@@ -1048,7 +1048,7 @@ void VM_findchainfloat (void)
        for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
        {
                prog->xfunction->builtinsprofile++;
-               if (ent->e->free)
+               if (ent->p.e->free)
                        continue;
                if (E_FLOAT(ent,f) != s)
                        continue;
@@ -1274,7 +1274,7 @@ void VM_nextent (void)
                        return;
                }
                ent = PRVM_EDICT_NUM(i);
-               if (!ent->e->free)
+               if (!ent->p.e->free)
                {
                        VM_RETURN_EDICT(ent);
                        return;
@@ -3028,7 +3028,7 @@ void VM_M_writetofile(void)
        }
 
        ent = PRVM_G_EDICT(OFS_PARM1);  
-       if(ent->e->free)
+       if(ent->p.e->free)
        {
                Con_Printf("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1));
                return;
index 1f219f4..5df2714 100644 (file)
@@ -70,7 +70,7 @@ void PRVM_MEM_Alloc()
        // set edict pointers
        for(i = 0; i < prog->max_edicts; i++)
        {
-               prog->edicts[i].e = (prvm_edict_private_t *)((qbyte  *)prog->edictprivate + i * prog->edictprivate_size);
+               prog->edicts[i].p.e = (prvm_edict_private_t *)((qbyte  *)prog->edictprivate + i * prog->edictprivate_size);
                prog->edicts[i].v = (void*)((qbyte *)prog->edictsfields + i * prog->edict_size);
        }
 }
@@ -104,7 +104,7 @@ void PRVM_MEM_IncreaseEdicts()
        //set e and v pointers
        for(i = 0; i < prog->max_edicts; i++)
        {
-               prog->edicts[i].e = (prvm_edict_private_t *)((qbyte  *)prog->edictprivate + i * prog->edictprivate_size);
+               prog->edicts[i].p.e = (prvm_edict_private_t *)((qbyte  *)prog->edictprivate + i * prog->edictprivate_size);
                prog->edicts[i].v = (void*)((qbyte *)prog->edictsfields + i * prog->edict_size);
        }
 
@@ -191,7 +191,7 @@ void PRVM_ED_ClearEdict (prvm_edict_t *e)
 {
        int num;
        memset (e->v, 0, prog->progs->entityfields * 4);
-       e->e->free = false;
+       e->p.e->free = false;
        // LordHavoc: for consistency set these here
        num = PRVM_NUM_FOR_EDICT(e) - 1;
 
@@ -225,7 +225,7 @@ prvm_edict_t *PRVM_ED_Alloc (void)
                e = PRVM_EDICT_NUM(i);
                // the first couple seconds of server time can involve a lot of
                // freeing and allocating, so relax the replacement policy
-               if (e->e->free && ( e->e->freetime < 2 || (*prog->time - e->e->freetime) > 0.5 ) )
+               if (e->p.e->free && ( e->p.e->freetime < 2 || (*prog->time - e->p.e->freetime) > 0.5 ) )
                {
                        PRVM_ED_ClearEdict (e);
                        return e;
@@ -261,8 +261,8 @@ void PRVM_ED_Free (prvm_edict_t *ed)
 
        PRVM_GCALL(free_edict)(ed);
 
-       ed->e->free = true;
-       ed->e->freetime = *prog->time;
+       ed->p.e->free = true;
+       ed->p.e->freetime = *prog->time;
 }
 
 //===========================================================================
@@ -567,7 +567,7 @@ void PRVM_ED_Print(prvm_edict_t *ed)
        int             type;
        char    tempstring[8192], tempstring2[260]; // temporary string buffers
 
-       if (ed->e->free)
+       if (ed->p.e->free)
        {
                Con_Printf("%s: FREE\n",PRVM_NAME);
                return;
@@ -642,7 +642,7 @@ void PRVM_ED_Write (qfile_t *f, prvm_edict_t *ed)
 
        FS_Print(f, "{\n");
 
-       if (ed->e->free)
+       if (ed->p.e->free)
        {
                FS_Print(f, "}\n");
                return;
@@ -771,7 +771,7 @@ void PRVM_ED_Count_f (void)
                for (i=0 ; i<prog->num_edicts ; i++)
                {
                        ent = PRVM_EDICT_NUM(i);
-                       if (ent->e->free)
+                       if (ent->p.e->free)
                                continue;
                        active++;
                }
@@ -1111,7 +1111,7 @@ const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent)
        }
 
        if (!init)
-               ent->e->free = true;
+               ent->p.e->free = true;
 
        return data;
 }
@@ -1204,7 +1204,7 @@ void PRVM_ED_LoadFromFile (const char *data)
                }
        
                spawned++;
-               if (ent->e->free)
+               if (ent->p.e->free)
                        died++;
        }
 
@@ -1535,7 +1535,7 @@ void PRVM_Fields_f (void)
        for (ednum = 0;ednum < prog->max_edicts;ednum++)
        {
                ed = PRVM_EDICT_NUM(ednum);
-               if (ed->e->free)
+               if (ed->p.e->free)
                        continue;
                for (i = 1;i < prog->progs->numfielddefs;i++)
                {