]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Rewrite CSQC's setmodel a bit.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 1 Feb 2008 16:21:37 +0000 (16:21 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 1 Feb 2008 16:21:37 +0000 (16:21 +0000)
Add support for CSQC_Ent_Spawn to csqc. A function that is called when a entity packet from the server arrives that requires a new entity.
entity( float entnum ) CSQC_Ent_Spawn;
CSQC_Ent_Spawn needs to spawn a new entity and set its .entnum field accordingly or simply return another existing entity or world if it wants to ignore that server entity. Subsequent CSQC_Ent_Update calls are routed to that entity (or CSQC_Ent_Spawn is called again when .Version increases).

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

clvm_cmds.c
csprogs.c
progsvm.h
prvm_edict.c

index b566f0521451c4bb055898eaf4f07f8fe1df5e4f..4f9627393bc604b1df30f985b0c2e12c0ca54057 100644 (file)
@@ -83,39 +83,44 @@ void VM_CL_setmodel (void)
        VM_SAFEPARMCOUNT(2, VM_CL_setmodel);
 
        e = PRVM_G_EDICT(OFS_PARM0);
+       e->fields.client->modelindex = 0;
+       e->fields.client->model = 0;
+
        m = PRVM_G_STRING(OFS_PARM1);
+       mod = NULL;
        for (i = 0;i < MAX_MODELS && cl.csqc_model_precache[i];i++)
        {
                if (!strcmp(cl.csqc_model_precache[i]->name, m))
                {
-                       e->fields.client->model = PRVM_SetEngineString(cl.csqc_model_precache[i]->name);
+                       mod = cl.csqc_model_precache[i];
+                       e->fields.client->model = PRVM_SetEngineString(mod->name);
                        e->fields.client->modelindex = -(i+1);
-                       return;
+                       break;
                }
        }
 
-       for (i = 0;i < MAX_MODELS;i++)
-       {
-               mod = cl.model_precache[i];
-               if (mod && !strcmp(mod->name, m))
+       if( !mod ) {
+               for (i = 0;i < MAX_MODELS;i++)
                {
-                       e->fields.client->model = PRVM_SetEngineString(mod->name);
-                       e->fields.client->modelindex = i;
-                       return;
+                       mod = cl.model_precache[i];
+                       if (mod && !strcmp(mod->name, m))
+                       {
+                               e->fields.client->model = PRVM_SetEngineString(mod->name);
+                               e->fields.client->modelindex = i;
+                               break;
+                       }
                }
        }
 
-       e->fields.client->modelindex = 0;
-       e->fields.client->model = 0;
-       VM_Warning ("setmodel: model '%s' not precached\n", m);
-
-       // TODO: check if this breaks needed consistency and maybe add a cvar for it too?? [1/10/2008 Black]
-       if (mod)
-       {
+       if( mod ) {
+               // TODO: check if this breaks needed consistency and maybe add a cvar for it too?? [1/10/2008 Black]
                SetMinMaxSize (e, mod->normalmins, mod->normalmaxs);
-       }
+       } 
        else
+       {
                SetMinMaxSize (e, vec3_origin, vec3_origin);
+               VM_Warning ("setmodel: model '%s' not precached\n", m);
+       }
 }
 
 // #4 void(entity e, vector min, vector max) setsize
index 6175e450045e629dc61c633fe73dbb10379c1851..c6b38b152094497e001053ee59e549f2fdda894b 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -554,21 +554,36 @@ void CSQC_ReadEntities (void)
                                        cl.csqc_server2csqcentitynumber[realentnum] = 0;
                                }
                                else
-                                       Con_Printf("Smth bad happens in csqc...\n");    //[515]: never happens ?
+                                       Con_Printf("Bad csqc_server2csqcentitynumber map\n");   //[515]: never happens ?
                        }
                        else
                        {
                                if(!prog->globals.client->self)
                                {
-                                       prvm_edict_t    *ed;
-                                       ed = PRVM_ED_Alloc();
-                                       ed->fields.client->entnum = realentnum;
-                                       prog->globals.client->self = cl.csqc_server2csqcentitynumber[realentnum] = PRVM_EDICT_TO_PROG(ed);
-                                       PRVM_G_FLOAT(OFS_PARM0) = 1;
+                                       if(!prog->funcoffsets.CSQC_Ent_Spawn)
+                                       {
+                                               prvm_edict_t    *ed;
+                                               ed = PRVM_ED_Alloc();
+                                               ed->fields.client->entnum = realentnum;
+                                               prog->globals.client->self = cl.csqc_server2csqcentitynumber[realentnum] = PRVM_EDICT_TO_PROG(ed);
+                                               PRVM_G_FLOAT(OFS_PARM0) = 1;
+                                               PRVM_ExecuteProgram(prog->funcoffsets.CSQC_Ent_Update, "QC function CSQC_Ent_Update is missing");
+                                       }
+                                       else
+                                       {
+                                               // entity( float entnum ) CSQC_Ent_Spawn;
+                                               // the qc function should set entnum, too (this way it also can return world [2/1/2008 Andreas]
+                                               PRVM_G_FLOAT(OFS_PARM0) = (float) realentnum;
+                                               // make sure no one gets wrong ideas
+                                               prog->globals.client->self = 0;
+                                               PRVM_ExecuteProgram(prog->funcoffsets.CSQC_Ent_Spawn, "QC function CSQC_Ent_Spawn is missing");
+                                               cl.csqc_server2csqcentitynumber[realentnum] = PRVM_EDICT( PRVM_G_INT( OFS_RETURN ) );
+                                       }
                                }
-                               else
+                               else {
                                        PRVM_G_FLOAT(OFS_PARM0) = 0;
-                               PRVM_ExecuteProgram(prog->funcoffsets.CSQC_Ent_Update, "QC function CSQC_Ent_Update is missing");
+                                       PRVM_ExecuteProgram(prog->funcoffsets.CSQC_Ent_Update, "QC function CSQC_Ent_Update is missing");
+                               }
                        }
                }
                prog->globals.client->self = oldself;
index 3a6028b1bd4fc5828a1fd66b478c9741be6334ee..e5dd2d00d5b0979c55030f84c03526bb09000b11 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -258,6 +258,7 @@ typedef struct prvm_prog_funcoffsets_s
 {
        func_t CSQC_ConsoleCommand; // csqc
        func_t CSQC_Ent_Remove; // csqc
+       func_t CSQC_Ent_Spawn; // csqc DP_CSQC_ENT_SPAWN extension (BlackHC - TODO: needs to be added to dpextensions.qc)
        func_t CSQC_Ent_Update; // csqc
        func_t CSQC_Event; // csqc [515]: engine call this for its own needs so csqc can do some things according to what engine it's running on.  example: to say about edicts increase, whatever...
        func_t CSQC_Event_Sound; // csqc : called by engine when an incoming sound packet arrives so CSQC can act on it
@@ -515,8 +516,9 @@ void PRVM_ED_ParseGlobals (const char *data);
 
 void PRVM_ED_LoadFromFile (const char *data);
 
-prvm_edict_t *PRVM_EDICT_NUM_ERROR(int n, char *filename, int fileline);
-#define        PRVM_EDICT_NUM(n) (((unsigned)(n) < (unsigned int)prog->max_edicts) ? prog->edicts + (n) : PRVM_EDICT_NUM_ERROR(n, __FILE__, __LINE__))
+unsigned PRVM_EDICT_NUM_ERROR(int n, char *filename, int fileline);
+#define        PRVM_EDICT(n) (((unsigned)(n) < (unsigned int)prog->max_edicts) ? n : PRVM_EDICT_NUM_ERROR(n, __FILE__, __LINE__))
+#define        PRVM_EDICT_NUM(n) (prog->edicts + PRVM_EDICT(n))
 
 //int NUM_FOR_EDICT_ERROR(prvm_edict_t *e);
 #define PRVM_NUM_FOR_EDICT(e) ((int)((prvm_edict_t *)(e) - prog->edicts))
index 9e85cfc7dac516f735d56f1bc77a29ae73790782..600e84953905c44da3b45f285ebd973751e90fb0 100644 (file)
@@ -1425,6 +1425,7 @@ void PRVM_FindOffsets(void)
        prog->funcoffsets.CSQC_ConsoleCommand             = PRVM_ED_FindFunctionOffset("CSQC_ConsoleCommand");
        prog->funcoffsets.CSQC_Ent_Remove                 = PRVM_ED_FindFunctionOffset("CSQC_Ent_Remove");
        prog->funcoffsets.CSQC_Ent_Update                 = PRVM_ED_FindFunctionOffset("CSQC_Ent_Update");
+       prog->funcoffsets.CSQC_Ent_Spawn                  = PRVM_ED_FindFunctionOffset("CSQC_Ent_Spawn");
        prog->funcoffsets.CSQC_Event                      = PRVM_ED_FindFunctionOffset("CSQC_Event");
        prog->funcoffsets.CSQC_Event_Sound                = PRVM_ED_FindFunctionOffset("CSQC_Event_Sound");
        prog->funcoffsets.CSQC_Init                       = PRVM_ED_FindFunctionOffset("CSQC_Init");
@@ -2106,10 +2107,10 @@ void _PRVM_FreeAll(const char *filename, int fileline)
 }
 
 // LordHavoc: turned PRVM_EDICT_NUM into a #define for speed reasons
-prvm_edict_t *PRVM_EDICT_NUM_ERROR(int n, char *filename, int fileline)
+unsigned PRVM_EDICT_NUM_ERROR(int n, char *filename, int fileline)
 {
        PRVM_ERROR ("PRVM_EDICT_NUM: %s: bad number %i (called at %s:%i)", PRVM_NAME, n, filename, fileline);
-       return NULL;
+       return 0;
 }
 
 /*