From a201aa8ae4beab46d0d56f3b21afc9ca92c9dbf4 Mon Sep 17 00:00:00 2001 From: divverent Date: Sat, 16 Oct 2010 19:30:17 +0000 Subject: [PATCH] extension (does this need a QC extension name?): allow legacy networked entities to be attached to CSQC entities added using R_AddEntities with a draw mask. Helps with adopting CSQC networked players in an otherwise legacy networked game. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10540 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_main.c | 40 +++++++++++++++++++++++++++++----------- clvm_cmds.c | 2 ++ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/cl_main.c b/cl_main.c index be5497fe..26bac779 100644 --- a/cl_main.c +++ b/cl_main.c @@ -922,6 +922,7 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat int frame; float origin[3], angles[3], lerp; entity_t *t; + entity_render_t *r; //entity_persistent_t *p = &e->persistent; //entity_render_t *r = &e->render; // skip inactive entities and world @@ -954,22 +955,33 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat return; t = cl.entities + e->state_current.tagentity; // if the tag entity is inactive, skip it - if (!t->state_current.active) - return; - // update the parent first - CL_UpdateNetworkEntity(t, recursionlimit - 1, interpolate); + if (t->state_current.active) + { + // update the parent first + CL_UpdateNetworkEntity(t, recursionlimit - 1, interpolate); + r = &t->render; + } + else + { + // it may still be a CSQC entity... trying to use its + // info from last render frame (better than nothing) + if(!cl.csqc_server2csqcentitynumber[e->state_current.tagentity]) + return; + r = cl.csqcrenderentities + cl.csqc_server2csqcentitynumber[e->state_current.tagentity]; + if(!r->entitynumber) + return; // neither CSQC nor legacy entity... can't attach + } // make relative to the entity - matrix = &t->render.matrix; + matrix = &r->matrix; // some properties of the tag entity carry over - e->render.flags |= t->render.flags & (RENDER_EXTERIORMODEL | RENDER_VIEWMODEL); + e->render.flags |= r->flags & (RENDER_EXTERIORMODEL | RENDER_VIEWMODEL); // if a valid tagindex is used, make it relative to that tag instead - // FIXME: use a model function to get tag info (need to handle skeletal) - if (e->state_current.tagentity && e->state_current.tagindex >= 1 && t->render.model) + if (e->state_current.tagentity && e->state_current.tagindex >= 1 && r->model) { - if(!Mod_Alias_GetTagMatrix(t->render.model, t->render.frameblend, t->render.skeleton, e->state_current.tagindex - 1, &blendmatrix)) // i.e. no error + if(!Mod_Alias_GetTagMatrix(r->model, r->frameblend, r->skeleton, e->state_current.tagindex - 1, &blendmatrix)) // i.e. no error { // concat the tag matrices onto the entity matrix - Matrix4x4_Concat(&tempmatrix, &t->render.matrix, &blendmatrix); + Matrix4x4_Concat(&tempmatrix, &r->matrix, &blendmatrix); // use the constructed tag matrix matrix = &tempmatrix; } @@ -1372,7 +1384,13 @@ void CL_LinkNetworkEntity(entity_t *e) return; // if the tag entity is inactive, skip it if (!cl.entities[e->state_current.tagentity].state_current.active) - return; + { + if(!cl.csqc_server2csqcentitynumber[e->state_current.tagentity]) + return; + if(!cl.csqcrenderentities[cl.csqc_server2csqcentitynumber[e->state_current.tagentity]].entitynumber) + return; + // if we get here, it's properly csqc networked and attached + } } // create entity dlights associated with this entity diff --git a/clvm_cmds.c b/clvm_cmds.c index ed40c0de..cfebdfe3 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -744,6 +744,8 @@ void VM_CL_R_AddEntities (void) prog->globals.client->time = cl.time; for(i=1;inum_edicts;i++) { + // so we can easily check if CSQC entity #edictnum is currently drawn + cl.csqcrenderentities[i].entitynumber = 0; ed = &prog->edicts[i]; if(ed->priv.required->free) continue; -- 2.39.2