cl.num_brushmodel_entities = 0;
// tweak these if the game runs out
+ cl.max_csqcrenderentities = 0;
cl.max_entities = 256;
cl.max_static_entities = 256;
cl.max_effects = 256;
cl.num_effects = 0;
cl.num_beams = 0;
+ cl.csqcrenderentities = NULL;
cl.entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_entities * sizeof(entity_t));
cl.entities_active = (unsigned char *)Mem_Alloc(cls.levelmempool, cl.max_brushmodel_entities * sizeof(unsigned char));
cl.static_entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_static_entities * sizeof(entity_t));
}
}
+void CL_ExpandCSQCRenderEntities(int num)
+{
+ int oldmaxcsqcrenderentities;
+ entity_render_t *oldcsqcrenderentities;
+ if (num >= cl.max_csqcrenderentities)
+ {
+ if (num >= MAX_EDICTS)
+ Host_Error("CL_ExpandEntities: num %i >= %i", num, MAX_EDICTS);
+ oldmaxcsqcrenderentities = cl.max_csqcrenderentities;
+ oldcsqcrenderentities = cl.csqcrenderentities;
+ cl.max_csqcrenderentities = (num & ~255) + 256;
+ cl.csqcrenderentities = (entity_render_t *)Mem_Alloc(cls.levelmempool, cl.max_csqcrenderentities * sizeof(entity_render_t));
+ if (oldcsqcrenderentities)
+ {
+ memcpy(cl.csqcrenderentities, oldcsqcrenderentities, oldmaxcsqcrenderentities * sizeof(entity_render_t));
+ Mem_Free(oldcsqcrenderentities);
+ }
+ }
+}
+
/*
=====================
CL_Disconnect
vec3_t playercrouchmaxs;
int max_entities;
+ int max_csqcrenderentities;
int max_static_entities;
int max_effects;
int max_beams;
int max_showlmps;
entity_t *entities;
+ entity_render_t *csqcrenderentities;
unsigned char *entities_active;
entity_t *static_entities;
cl_effect_t *effects;
void CL_ClearState (void);
void CL_ExpandEntities(int num);
+void CL_ExpandCSQCRenderEntities(int num);
void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allowstarkey, qboolean allowmodel, qboolean quiet);
//============================================================================
//[515]: SCENE MANAGER builtins
-extern qboolean CSQC_AddRenderEdict (prvm_edict_t *ed);//csprogs.c
+extern qboolean CSQC_AddRenderEdict (prvm_edict_t *ed, int edictnum);//csprogs.c
static void CSQC_R_RecalcView (void)
{
continue;
if(!((int)ed->fields.client->drawmask & drawmask))
continue;
- CSQC_AddRenderEdict(ed);
+ CSQC_AddRenderEdict(ed, i);
}
// callprofile fixing hack: do not include this time in what is counted for CSQC_UpdateView
{
double t = Sys_DoubleTime();
VM_SAFEPARMCOUNT(1, VM_CL_R_AddEntity);
- CSQC_AddRenderEdict(PRVM_G_EDICT(OFS_PARM0));
+ CSQC_AddRenderEdict(PRVM_G_EDICT(OFS_PARM0), 0);
prog->functions[prog->funcoffsets.CSQC_UpdateView].totaltime -= Sys_DoubleTime() - t;
}
extern cvar_t cl_noplayershadow;
extern cvar_t r_equalize_entities_fullbright;
-qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
+qboolean CSQC_AddRenderEdict(prvm_edict_t *ed, int edictnum)
{
int renderflags;
int c;
if (!model)
return false;
- entrender = CL_NewTempEntity(0);
- if (!entrender)
- return false;
+ if (edictnum)
+ {
+ if (r_refdef.scene.numentities >= r_refdef.scene.maxentities)
+ return false;
+ entrender = cl.csqcrenderentities + edictnum;
+ r_refdef.scene.entities[r_refdef.scene.numentities++] = entrender;
+ entrender->entitynumber = edictnum;
+ //entrender->shadertime = 0; // shadertime was set by spawn()
+ entrender->alpha = 1;
+ entrender->scale = 1;
+ VectorSet(entrender->colormod, 1, 1, 1);
+ VectorSet(entrender->glowmod, 1, 1, 1);
+ entrender->allowdecals = true;
+ }
+ else
+ {
+ entrender = CL_NewTempEntity(0);
+ if (!entrender)
+ return false;
+ }
entrender->model = model;
entrender->skinnum = (int)ed->fields.client->skin;
void CL_VM_CB_InitEdict(prvm_edict_t *e)
{
+ int edictnum = PRVM_NUM_FOR_EDICT(e);
+ entity_render_t *entrender;
+ CL_ExpandCSQCRenderEntities(edictnum);
+ entrender = cl.csqcrenderentities + edictnum;
e->priv.server->move = false; // don't move on first frame
+ memset(entrender, 0, sizeof(*entrender));
+ entrender->shadertime = cl.time;
}
+extern void R_DecalSystem_Reset(decalsystem_t *decalsystem);
+
void CL_VM_CB_FreeEdict(prvm_edict_t *ed)
{
+ entity_render_t *entrender = cl.csqcrenderentities + PRVM_NUM_FOR_EDICT(ed);
+ R_DecalSystem_Reset(&entrender->decalsystem);
+ memset(entrender, 0, sizeof(*entrender));
World_UnlinkEdict(ed);
memset(ed->fields.client, 0, sizeof(*ed->fields.client));
World_Physics_RemoveFromEntity(&cl.world, ed);