]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cgamevm.c
reduced client memory usage by 29MB by making cl_max_entities dynamic (starts out...
[xonotic/darkplaces.git] / cgamevm.c
index 57f53dc84b58facfd3389bdbb556ec28307a1036..e2b33f4df8c743456d165b7b886ed72c68fd2bf5 100644 (file)
--- a/cgamevm.c
+++ b/cgamevm.c
@@ -23,7 +23,12 @@ static model_t *cgvm_model[MAX_CGVM_MODELS];
 
 void CL_CGVM_Init(void)
 {
-       cgvm_mempool = Mem_AllocPool("CGVM");
+       cgvm_mempool = Mem_AllocPool("CGVM", 0, NULL);
+}
+
+void CL_CGVM_Shutdown(void)
+{
+       Mem_FreePool (&cgvm_mempool);
 }
 
 void CL_CGVM_Clear(void)
@@ -87,7 +92,7 @@ unsigned char CGVM_MSG_ReadByte(void)
 
 short CGVM_MSG_ReadShort(void)
 {
-       int num;
+       short num;
        num = CGVM_MSG_ReadByte() | (CGVM_MSG_ReadByte() << 8);
        return num;
 }
@@ -130,7 +135,7 @@ void CGVM_Draw_Entity(const cgdrawentity_t *e)
                return;
 
        if (cgvm_renderentity >= CGVM_RENDERENTITIES
-        || r_refdef.numentities >= MAX_VISEDICTS)
+        || r_refdef.numentities >= r_refdef.maxentities)
                return;
 
        r = cgvm_renderentities + cgvm_renderentity;
@@ -143,14 +148,7 @@ void CGVM_Draw_Entity(const cgdrawentity_t *e)
                Con_Printf("CGVM_Draw_Entity: invalid model index %i\n", e->model);
                return;
        }
-       r->model = cgvm_model[e->model]; //Mod_ForName(e->model, false, false, false);
-       /*
-       if (!r->model)
-       {
-               Con_Printf("CGVM_Draw_Entity: unable to find model \"%s\"");
-               return;
-       }
-       */
+       r->model = cgvm_model[e->model];
 
        r->frame = e->frame2;
        // FIXME: support colormapping?
@@ -174,7 +172,9 @@ void CGVM_Draw_Entity(const cgdrawentity_t *e)
 
 void CGVM_Draw_Light(const cgdrawlight_t *l)
 {
-       CL_AllocDlight(NULL, (float *) l->origin, 1, l->light[0], l->light[1], l->light[2], 0, 0);
+       matrix4x4_t matrix;
+       Matrix4x4_CreateTranslate(&matrix, l->origin[0], l->origin[1], l->origin[2]);
+       CL_AllocDlight(NULL, &matrix, l->radius, l->color[0], l->color[1], l->color[2], 0, 0, 0, -1, true, 1, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
 }
 
 void *CGVM_Malloc(const int size)
@@ -203,10 +203,8 @@ float CGVM_TracePhysics(const float *start, const float *end, const float *world
        middle[2] = (worldmins[2] + worldmaxs[2]) * 0.5f;
        VectorAdd(start, middle, start2);
        VectorAdd(end, middle, end2);
-       frac = CL_TraceLine((float *)start2, (float *)end2, impactpos, impactnormal, 0, true);
+       frac = CL_TraceLine((float *)start2, (float *)end2, impactpos, impactnormal, true, NULL, SUPERCONTENTS_SOLID);
        VectorSubtract(impactpos, middle, impactpos);
-       //VectorCopy(end, impactpos);
-       //VectorClear(impactnormal);
        *impactentnum = -1;
        return frac;
 }
@@ -271,5 +269,7 @@ int CGVM_Model(const char *name)
 
 void CGVM_Stain(const float *origin, float radius, int cr1, int cg1, int cb1, int ca1, int cr2, int cg2, int cb2, int ca2)
 {
-       R_Stain((float *)origin, radius, cr1, cg1, cb1, ca1, cr2, cg2, cb2, ca2);
+       if (cl_stainmaps.integer)
+               R_Stain((float *)origin, radius, cr1, cg1, cb1, ca1, cr2, cg2, cb2, ca2);
 }
+