]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_edict.c
KRIMZON_SV_PARSECLIENTCOMMAND extension (untested currently!)
[xonotic/darkplaces.git] / pr_edict.c
index 6c54a7edeca664f2485aa6d404b4abc1ab34aa16..b7d347304a8c2c3c22245668fe001cd97129b7bc 100644 (file)
@@ -122,6 +122,8 @@ int eval_viewzoom;
 
 mfunction_t *SV_PlayerPhysicsQC;
 mfunction_t *EndFrameQC;
+//KrimZon - SERVER COMMANDS IN QUAKEC
+mfunction_t *SV_ParseClientCommandQC;
 
 int FindFieldOffset(const char *field)
 {
@@ -173,6 +175,8 @@ void FindEdictFieldOffsets(void)
        SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics");
        // LordHavoc: support for endframe
        EndFrameQC = ED_FindFunction ("EndFrame");
+       //KrimZon - SERVER COMMANDS IN QUAKEC
+       SV_ParseClientCommandQC = ED_FindFunction ("SV_ParseClientCommand");
 }
 
 /*
@@ -185,7 +189,7 @@ Sets everything to NULL
 void ED_ClearEdict (edict_t *e)
 {
        memset (e->v, 0, progs->entityfields * 4);
-       e->free = false;
+       e->e->free = false;
 }
 
 /*
@@ -199,6 +203,7 @@ instead of being removed and recreated, which can cause interpolated
 angles and bad trails.
 =================
 */
+extern void SV_IncreaseEdicts(void);
 edict_t *ED_Alloc (void)
 {
        int                     i;
@@ -209,7 +214,7 @@ edict_t *ED_Alloc (void)
                e = 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->free && ( e->freetime < 2 || sv.time - e->freetime > 0.5 ) )
+               if (e->e->free && ( e->e->freetime < 2 || sv.time - e->e->freetime > 0.5 ) )
                {
                        ED_ClearEdict (e);
                        return e;
@@ -220,6 +225,8 @@ edict_t *ED_Alloc (void)
                Host_Error ("ED_Alloc: no free edicts");
 
        sv.num_edicts++;
+       if (sv.num_edicts >= sv.max_edicts)
+               SV_IncreaseEdicts();
        e = EDICT_NUM(i);
        ED_ClearEdict (e);
 
@@ -238,7 +245,7 @@ void ED_Free (edict_t *ed)
 {
        SV_UnlinkEdict (ed);            // unlink from world bsp
 
-       ed->free = true;
+       ed->e->free = true;
        ed->v->model = 0;
        ed->v->takedamage = 0;
        ed->v->modelindex = 0;
@@ -250,7 +257,7 @@ void ED_Free (edict_t *ed)
        ed->v->nextthink = -1;
        ed->v->solid = 0;
 
-       ed->freetime = sv.time;
+       ed->e->freetime = sv.time;
 }
 
 //===========================================================================
@@ -375,7 +382,8 @@ char *PR_ValueString (etype_t type, eval_t *val)
                sprintf (line, "%s", PR_GetString(val->string));
                break;
        case ev_entity:
-               n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict));
+               //n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict));
+               n = val->edict;
                if (n < 0 || n >= MAX_EDICTS)
                        sprintf (line, "entity %i (invalid!)", n);
                else
@@ -557,7 +565,7 @@ void ED_Print (edict_t *ed)
        int             type;
        char    tempstring[8192], tempstring2[260]; // temporary string buffers
 
-       if (ed->free)
+       if (ed->e->free)
        {
                Con_Printf ("FREE\n");
                return;
@@ -632,7 +640,7 @@ void ED_Write (qfile_t *f, edict_t *ed)
 
        FS_Printf (f, "{\n");
 
-       if (ed->free)
+       if (ed->e->free)
        {
                FS_Printf (f, "}\n");
                return;
@@ -720,7 +728,7 @@ void ED_Count (void)
        for (i=0 ; i<sv.num_edicts ; i++)
        {
                ent = EDICT_NUM(i);
-               if (ent->free)
+               if (ent->e->free)
                        continue;
                active++;
                if (ent->v->solid)
@@ -1017,7 +1025,7 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
        }
 
        if (!init)
-               ent->free = true;
+               ent->e->free = true;
 
        return data;
 }
@@ -1114,7 +1122,7 @@ void ED_LoadFromFile (const char *data)
                pr_global_struct->self = EDICT_TO_PROG(ent);
                PR_ExecuteProgram (func - pr_functions, "");
                spawned++;
-               if (ent->free)
+               if (ent->e->free)
                        died++;
        }
 
@@ -1409,7 +1417,7 @@ void PR_Fields_f (void)
        for (ednum = 0;ednum < MAX_EDICTS;ednum++)
        {
                ed = EDICT_NUM(ednum);
-               if (ed->free)
+               if (ed->e->free)
                        continue;
                for (i = 1;i < progs->numfielddefs;i++)
                {
@@ -1564,12 +1572,19 @@ void PR_Init (void)
 }
 
 // LordHavoc: turned EDICT_NUM into a #define for speed reasons
-edict_t *EDICT_NUM_ERROR(int n)
+edict_t *EDICT_NUM_ERROR(int n, char *filename, int fileline)
 {
-       Host_Error ("EDICT_NUM: bad number %i", n);
+       Host_Error ("EDICT_NUM: bad number %i (called at %f:%i)", n, filename, fileline);
        return NULL;
 }
 
+/*
+int NUM_FOR_EDICT_ERROR(edict_t *e)
+{
+       Host_Error ("NUM_FOR_EDICT: bad pointer %p (world is %p, entity number would be %i)", e, sv.edicts, e - sv.edicts);
+       return 0;
+}
+
 int NUM_FOR_EDICT(edict_t *e)
 {
        int n;
@@ -1579,13 +1594,13 @@ int NUM_FOR_EDICT(edict_t *e)
        return n;
 }
 
-int NoCrash_NUM_FOR_EDICT(edict_t *e)
-{
-       return e - sv.edicts;
-}
+//int NoCrash_NUM_FOR_EDICT(edict_t *e)
+//{
+//     return e - sv.edicts;
+//}
 
 //#define      EDICT_TO_PROG(e) ((qbyte *)(((edict_t *)e)->v) - (qbyte *)(sv.edictsfields))
-//#define PROG_TO_EDICT(e) (sv.edictstable[(e) / (progs->entityfields * 4)])
+//#define PROG_TO_EDICT(e) (sv.edicts + ((e) / (progs->entityfields * 4)))
 int EDICT_TO_PROG(edict_t *e)
 {
        int n;
@@ -1599,7 +1614,8 @@ edict_t *PROG_TO_EDICT(int n)
 {
        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)];
+       return sv.edicts + n; // EXPERIMENTAL
+       //return sv.edicts + ((n) / (progs->entityfields * 4));
 }
+*/