X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=cgamevm.c;h=45b81c4e3e60f8326c82873f52c278984aa57b20;hb=71cde06e4bea4cbd75b4bc016befd8de1d6254c4;hp=9dd567e27ce5b27ebfc5049d81ebd91522691e2a;hpb=acec14f26ce90cb20357a0b2f2e161b1adaa706e;p=xonotic%2Fdarkplaces.git diff --git a/cgamevm.c b/cgamevm.c index 9dd567e2..45b81c4e 100644 --- a/cgamevm.c +++ b/cgamevm.c @@ -1,6 +1,7 @@ #include "quakedef.h" #include "cgame_api.h" +#include "cl_collision.h" #define CGVM_RENDERENTITIES 1024 @@ -11,7 +12,7 @@ static mempool_t *cgvm_mempool; static void (*cgvm_networkcode[256])(unsigned char num); -static byte *cgvm_netbuffer; +static unsigned char *cgvm_netbuffer; static int cgvm_netbufferlength; static int cgvm_netbufferpos; @@ -22,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) @@ -46,7 +52,7 @@ void CL_CGVM_Start(void) CG_Init(); // API call } -void CL_CGVM_ParseNetwork(byte *netbuffer, int length) +void CL_CGVM_ParseNetwork(unsigned char *netbuffer, int length) { int num; cgvm_netbuffer = netbuffer; @@ -56,7 +62,7 @@ void CL_CGVM_ParseNetwork(byte *netbuffer, int length) { num = CGVM_MSG_ReadByte(); if (cgvm_networkcode[num]) - cgvm_networkcode[num]((byte)num); + cgvm_networkcode[num]((unsigned char)num); else Host_Error("CL_CGVM_ParseNetwork: unregistered network code %i", num); } @@ -86,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; } @@ -129,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; @@ -142,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? @@ -173,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) @@ -193,21 +194,13 @@ float CGVM_RandomRange(const float r1, const float r2) float CGVM_TracePhysics(const float *start, const float *end, const float *worldmins, const float *worldmaxs, const float *entitymins, const float *entitymaxs, const cgphysentity_t *physentities, const int numphysentities, float *impactpos, float *impactnormal, int *impactentnum) { - float frac; - vec3_t start2, end2, middle; + trace_t trace; // FIXME: do tracing agains network entities and physentities here - // placeholder world only code assuming 0 size - middle[0] = (worldmins[0] + worldmaxs[0]) * 0.5f; - middle[1] = (worldmins[1] + worldmaxs[1]) * 0.5f; - middle[2] = (worldmins[2] + worldmaxs[2]) * 0.5f; - VectorAdd(start, middle, start2); - VectorAdd(end, middle, end2); - frac = TraceLine((float *)start2, (float *)end2, impactpos, impactnormal, 0, true); - VectorSubtract(impactpos, middle, impactpos); - //VectorCopy(end, impactpos); - //VectorClear(impactnormal); + trace = CL_TraceBox(start, vec3_origin, vec3_origin, end, true, NULL, SUPERCONTENTS_SOLID, false); + VectorCopy(trace.endpos, impactpos); + VectorCopy(trace.plane.normal, impactnormal); *impactentnum = -1; - return frac; + return trace.fraction; } char *CGVM_GetCvarString(const char *name) @@ -260,7 +253,7 @@ int CGVM_Model(const char *name) } if (i >= MAX_CGVM_MODELS) return 0; - model = Mod_ForName((char *)name, false, false, false); + model = Mod_ForName(name, false, false, false); if (!model) return 0; strcpy(cgvm_modelname[i], name); @@ -270,5 +263,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); } +