From: havoc Date: Wed, 15 Mar 2006 01:01:53 +0000 (+0000) Subject: removed cgame and ui code (both unused), this reduces memory use a bit X-Git-Tag: xonotic-v0.1.0preview~4203 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2b784d13eb570cf4d3cedf7f445d5947cc769646;p=xonotic%2Fdarkplaces.git removed cgame and ui code (both unused), this reduces memory use a bit git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6115 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cg_math.h b/cg_math.h deleted file mode 100644 index d8c539e1..00000000 --- a/cg_math.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -// mathlib.h - -#ifndef CG_MATH_H -#define CG_MATH_H - - -#ifndef true -#define true 1 -#define false 0 -#endif - -#ifndef M_PI -#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h -#endif - -#ifndef NULL -#define NULL ((void *)0) -#endif - -typedef float vec_t; -typedef vec_t vec2_t[2]; -typedef vec_t vec3_t[3]; -typedef vec_t vec4_t[4]; -typedef vec_t vec5_t[5]; -typedef vec_t vec6_t[6]; -typedef vec_t vec7_t[7]; -typedef vec_t vec8_t[8]; -struct mplane_s; -extern vec3_t vec3_origin; - -#define nanmask (255<<23) -#define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) - -#define bound(min,num,max) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min)) - -#ifndef min -#define min(A,B) ((A) < (B) ? (A) : (B)) -#define max(A,B) ((A) > (B) ? (A) : (B)) -#endif - -#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN)) - -#define DEG2RAD(a) ((a) * ((float) M_PI / 180.0f)) -#define RAD2DEG(a) ((a) * (180.0f / (float) M_PI)) -#define ANGLEMOD(a) (((int) ((a) * (65536.0f / 360.0f)) & 65535) * (360.0f / 65536.0f)) - -#define VectorNegate(a,b) ((b)[0]=-((a)[0]),(b)[1]=-((a)[1]),(b)[2]=-((a)[2])) -#define VectorSet(a,b,c,d) ((a)[0]=(b),(a)[1]=(c),(a)[2]=(d)) -#define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0) -#define DotProduct(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]) -#define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2]) -#define VectorAdd(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2]) -#define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2]) -#define CrossProduct(a,b,c) ((c)[0]=(a)[1]*(b)[2]-(a)[2]*(b)[1],(c)[1]=(a)[2]*(b)[0]-(a)[0]*(b)[2],(c)[2]=(a)[0]*(b)[1]-(a)[1]*(b)[0]) -#define VectorNormalize(v) {float ilength = 1.0f / (float) sqrt(DotProduct(v,v));v[0] *= ilength;v[1] *= ilength;v[2] *= ilength;} -#define VectorNormalize2(v,dest) {float ilength = 1.0f / (float) sqrt(DotProduct(v,v));dest[0] = v[0] * ilength;dest[1] = v[1] * ilength;dest[2] = v[2] * ilength;} -#define VectorNormalizeDouble(v) {double ilength = 1.0 / (float) sqrt(DotProduct(v,v));v[0] *= ilength;v[1] *= ilength;v[2] *= ilength;} -#define VectorDistance2(a, b) (((a)[0] - (b)[0]) * ((a)[0] - (b)[0]) + ((a)[1] - (b)[1]) * ((a)[1] - (b)[1]) + ((a)[2] - (b)[2]) * ((a)[2] - (b)[2])) -#define VectorDistance(a, b) (sqrt(VectorDistance2(a,b))) -#define VectorLength(a) sqrt(DotProduct(a, a)) -#define VectorScale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale)) -#define VectorCompare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])&&((a)[2]==(b)[2])) -#define VectorMA(a, scale, b, c) ((c)[0] = (a)[0] + (scale) * (b)[0],(c)[1] = (a)[1] + (scale) * (b)[1],(c)[2] = (a)[2] + (scale) * (b)[2]) -#define VectorRandom(v) {do{(v)[0] = CGVM_RandomRange(-1, 1);(v)[1] = CGVM_RandomRange(-1, 1);(v)[2] = CGVM_RandomRange(-1, 1);}while(DotProduct(v, v) > 1);} - -void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); -// LordHavoc: proper matrix version of AngleVectors -void AngleVectorsFLU (vec3_t angles, vec3_t forward, vec3_t left, vec3_t up); -// LordHavoc: builds a [3][4] matrix -void AngleMatrix (vec3_t angles, vec3_t translate, vec_t matrix[][4]); - -// LordHavoc: like AngleVectors, but taking a forward vector instead of angles, useful! -void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up); - -#endif - diff --git a/cgame.c b/cgame.c deleted file mode 100644 index 5b1f3a9f..00000000 --- a/cgame.c +++ /dev/null @@ -1,364 +0,0 @@ - -#include -#include "cgame_api.h" -#include "cg_math.h" - -static double gametime, frametime; - -struct localentity_s; -typedef struct localentity_s -{ - float dietime; - vec3_t velocity; - vec3_t avelocity; - vec3_t worldmins; - vec3_t worldmaxs; - vec3_t entitymins; - vec3_t entitymaxs; - vec3_t lastimpactorigin; // updated by physics code, used by gib blood stains - float bouncescale; - float airfrictionscale; - float gravityscale; - void (*framethink)(struct localentity_s *e); - void (*touchnetwork)(struct localentity_s *self); - cgdrawentity_t draw; -} -localentity_t; - -#define MAX_LOCALENTITIES 1024 -static int numlocalentities; -static localentity_t *localentity; -// true if the entity is alive (not freed) -static unsigned char *localentityactive; -// time the entity was freed -static float *localentityfreetime; - -static cgphysentity_t *phys_entity; -static int phys_entities; - -static float cg_gravity; - -static void readvector(vec3_t v) -{ - v[0] = CGVM_MSG_ReadFloat(); - v[1] = CGVM_MSG_ReadFloat(); - v[2] = CGVM_MSG_ReadFloat(); -} - -static localentity_t *entspawn(void) -{ - int i, best; - float bestfreetime; - bestfreetime = (float) (gametime + 100.0); - best = -1; - for (i = 0;i < MAX_LOCALENTITIES;i++) - { - if (!localentityactive[i] && bestfreetime > localentityfreetime[i]) - { - bestfreetime = localentityfreetime[i]; - best = i; - if (bestfreetime < gametime) - break; - } - } - if (best >= 0) - { - // update numlocalentities to include the newly allocated slot - numlocalentities = max(numlocalentities, best + 1); - memset(localentity + best, 0, sizeof(*localentity)); - localentityactive[best] = true; - return localentity + best; - } - return NULL; -} - -static void entremove(localentity_t *e) -{ - int i; - i = (int)((e - localentity) / sizeof(localentity_t)); - if (i < 0 || i >= numlocalentities) - return; // this should be an error - //memset(e, 0, sizeof(*e)); - localentityactive[i] = false; - localentityfreetime[i] = (float)gametime + 1.0f; - // since an entity was removed, we may be able to reduce the number of - // active entities - while (numlocalentities > 0 && !localentityactive[numlocalentities-1]) - numlocalentities--; -} - -static void phys_setupphysentities(void) -{ - phys_entities = 0; - /* - for (i = 0;i < MAX_LOCALENTITIES;i++) - { - if (localentityactive[i] && localentities[i].solid) - { - l = localentities + i; - } - } - */ -} - -static void phys_moveentities(void) -{ - int i; - localentity_t *l; - for (i = 0;i < numlocalentities;i++) - { - if (localentityactive[i]) - { - l = localentity + i; - if (l->framethink) - { - l->framethink(l); - if (!localentityactive[i]) - continue; - } - if (l->draw.model) - CGVM_Draw_Entity(&l->draw); - } - } -} - -static void phys_updateentities(void) -{ - phys_setupphysentities(); - phys_moveentities(); -} - -static void phys_update(localentity_t *e) -{ - vec3_t impactpos, impactnormal, end; - int impactentnum; - float t, f, frac, bounce; - t = (float)frametime; - if (t == 0) - return; - VectorMA(e->draw.angles, t, e->avelocity, e->draw.angles); - VectorMA(e->draw.origin, t, e->velocity, end); - frac = CGVM_TracePhysics(e->draw.origin, end, e->worldmins, e->worldmaxs, e->entitymins, e->entitymaxs, phys_entity, phys_entities, impactpos, impactnormal, &impactentnum); - VectorCopy(impactpos, e->draw.origin); - if (frac < 1) - { - bounce = DotProduct(e->velocity, impactnormal) * -e->bouncescale; - VectorMA(e->velocity, bounce, impactnormal, e->velocity); - if (impactnormal[2] >= 0.7 && DotProduct(e->velocity, e->velocity) < 100*100) - { - VectorClear(e->velocity); - VectorClear(e->avelocity); - } - - if (e->touchnetwork) - e->touchnetwork(e); - // FIXME: do some kind of touch code here if physentities get implemented - - VectorCopy(impactpos, e->lastimpactorigin); - } - - if (e->airfrictionscale) - { - if (DotProduct(e->velocity, e->velocity) < 10*10) - { - VectorClear(e->velocity); - VectorClear(e->avelocity); - } - else - { - f = 1 - (t * e->airfrictionscale); - if (f > 0) - { - VectorScale(e->velocity, f, e->velocity); - if (DotProduct(e->avelocity, e->avelocity) < 10*10) - { - VectorClear(e->avelocity); - } - else - { - VectorScale(e->avelocity, f, e->avelocity); - } - } - else - { - VectorClear(e->velocity); - VectorClear(e->avelocity); - } - } - } - if (e->gravityscale) - e->velocity[2] += cg_gravity * e->gravityscale * t; -} - -static void explosiondebris_framethink(localentity_t *self) -{ - if (gametime > self->dietime) - { - self->draw.scale -= (float)(frametime * 3.0); - if (self->draw.scale < 0.05f) - { - entremove(self); - return; - } - } - phys_update(self); -} - -static void gib_framethink(localentity_t *self) -{ - if (gametime > self->dietime) - { - self->draw.scale -= (float)frametime * 3.0f; - if (self->draw.scale < 0.05f) - { - entremove(self); - return; - } - } - /* - if (gametime > self->trailnexttime) - { - self->trailnexttime = gametime + 0.1f; - CGVM_BloodParticle(self->draw.origin, self->velocity); - } - */ - phys_update(self); -} - -static void gib_touchnetwork(localentity_t *self) -{ - if (VectorDistance2(self->draw.origin, self->lastimpactorigin) >= 5*5) - CGVM_Stain(self->draw.origin, 64, 64, 24, 24, 48, 192, 48, 48, 48); -} - -static void net_explosion(unsigned char num) -{ - int i; - float r; - vec3_t org; - double time; - localentity_t *e; - // need the time to know when the rubble should fade - time = CGVM_Time(); - // read the network data - readvector(org); - - for (i = 0;i < 40;i++) - { - e = entspawn(); - if (!e) - return; - - VectorCopy(org, e->draw.origin); - e->draw.angles[0] = CGVM_RandomRange(0, 360); - e->draw.angles[1] = CGVM_RandomRange(0, 360); - e->draw.angles[2] = CGVM_RandomRange(0, 360); - VectorRandom(e->velocity); - VectorScale(e->velocity, 300, e->velocity); - e->velocity[2] -= (float)cg_gravity * 0.1f; - e->avelocity[0] = CGVM_RandomRange(0, 1440); - e->avelocity[1] = CGVM_RandomRange(0, 1440); - e->avelocity[2] = CGVM_RandomRange(0, 1440); - r = CGVM_RandomRange(0, 3); - if (r < 1) - e->draw.model = CGVM_Model("progs/rubble1.mdl"); - else if (r < 2) - e->draw.model = CGVM_Model("progs/rubble2.mdl"); - else - e->draw.model = CGVM_Model("progs/rubble3.mdl"); - e->draw.alpha = 1; - e->draw.scale = 1; - e->draw.frame1 = 0; - e->draw.frame2 = 0; - e->draw.framelerp = 0; - e->draw.skinnum = 5; - VectorSet(e->worldmins, 0, 0, -8); - VectorSet(e->worldmaxs, 0, 0, -8); - VectorSet(e->entitymins, -8, -8, -8); - VectorSet(e->entitymaxs, 8, 8, 8); - e->bouncescale = 1.4f; - e->gravityscale = 1; - e->airfrictionscale = 1; - e->framethink = explosiondebris_framethink; - e->dietime = (float)time + 5.0f; - } -} - -static void net_gibshower(unsigned char num) -{ - int i, count; - float r, velocityscale; - vec3_t org; - double time; - localentity_t *e; - // need the time to know when the gibs should fade - time = CGVM_Time(); - // read the network data - count = CGVM_MSG_ReadByte(); - velocityscale = (float)(CGVM_MSG_ReadByte() * 100); - readvector(org); - - for (i = 0;i < count;i++) - { - e = entspawn(); - if (!e) - return; - - VectorCopy(org, e->draw.origin); - e->draw.angles[0] = CGVM_RandomRange(0, 360); - e->draw.angles[1] = CGVM_RandomRange(0, 360); - e->draw.angles[2] = CGVM_RandomRange(0, 360); - VectorRandom(e->velocity); - VectorScale(e->velocity, velocityscale, e->velocity); - e->velocity[2] -= (float)(cg_gravity * 0.1); - e->avelocity[0] = CGVM_RandomRange(0, 1440); - e->avelocity[1] = CGVM_RandomRange(0, 1440); - e->avelocity[2] = CGVM_RandomRange(0, 1440); - r = CGVM_RandomRange(0, 3); - if (r < 1) - e->draw.model = CGVM_Model("progs/gib1.mdl"); - else if (r < 2) - e->draw.model = CGVM_Model("progs/gib2.mdl"); - else - e->draw.model = CGVM_Model("progs/gib3.mdl"); - e->draw.alpha = 1; - e->draw.scale = 1; - e->draw.frame1 = 0; - e->draw.frame2 = 0; - e->draw.framelerp = 0; - e->draw.skinnum = 0; - VectorSet(e->worldmins, 0, 0, -8); - VectorSet(e->worldmaxs, 0, 0, -8); - VectorSet(e->entitymins, -8, -8, -8); - VectorSet(e->entitymaxs, 8, 8, 8); - e->bouncescale = 1.5; - e->gravityscale = 1; - e->airfrictionscale = 1; - e->framethink = gib_framethink; - e->touchnetwork = gib_touchnetwork; - e->dietime = (float)time + CGVM_RandomRange(3.0f, 5.0f); - } -} - -// called by engine -void CG_Init(void) -{ - numlocalentities = 0; - localentity = (localentity_t *)CGVM_Malloc(sizeof(*localentity) * MAX_LOCALENTITIES); - localentityactive = (unsigned char *)CGVM_Malloc(sizeof(*localentityactive) * MAX_LOCALENTITIES); - localentityfreetime = (float *)CGVM_Malloc(sizeof(*localentityfreetime) * MAX_LOCALENTITIES); - phys_entity = (cgphysentity_t *)CGVM_Malloc(sizeof(*phys_entity) * MAX_LOCALENTITIES); - CGVM_RegisterNetworkCode(1, net_explosion); - CGVM_RegisterNetworkCode(2, net_gibshower); - gametime = 0; -} - -// called by engine -void CG_Frame(double time) -{ - cg_gravity = -CGVM_GetCvarFloat("sv_gravity"); - frametime = time - gametime; - gametime = time; - phys_updateentities(); -} - diff --git a/cgame_api.h b/cgame_api.h deleted file mode 100644 index 01eb847f..00000000 --- a/cgame_api.h +++ /dev/null @@ -1,70 +0,0 @@ - -#ifndef CGAME_API_H -#define CGAME_API_H - -// the CG state is reset quite harshly each time the client -// connects/disconnects (to enforce the idea of cgame dying between levels), -// and the Pre/PostNetworkFrame functions are only called while connected -// (this does mean that all memory is freed, Init will be called again, etc) - -typedef struct cgdrawentity_s -{ - float origin[3]; - float angles[3]; - float alpha; - float scale; - int model; // index gotten from engine using CGVM_Model - int frame1; - int frame2; - float framelerp; - int skinnum; -} -cgdrawentity_t; - -typedef struct cgdrawlight_s -{ - float origin[3]; - float color[3]; - float radius; -} -cgdrawlight_t; - -typedef struct cgphysentity_s -{ - int entnum; // reported by tracing, for use by cgame code - int padding; // unused - float mins[3]; - float maxs[3]; -} -cgphysentity_t; - -// engine functions the CG code can call -void CGVM_RegisterNetworkCode(const unsigned char num, void (*netcode)(unsigned char num)); -unsigned char CGVM_MSG_ReadByte(void); -short CGVM_MSG_ReadShort(void); -int CGVM_MSG_ReadLong(void); -float CGVM_MSG_ReadFloat(void); -float CGVM_MSG_ReadCoord(void); -float CGVM_MSG_ReadAngle(void); -float CGVM_MSG_ReadPreciseAngle(void); -void CGVM_Draw_Entity(const cgdrawentity_t *e); -void CGVM_Draw_Light(const cgdrawlight_t *l); -void *CGVM_Malloc(const int size); -void CGVM_Free(void *mem); -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 CGVM_GetCvarFloat(const char *name); -int CGVM_GetCvarInt(const char *name); -char *CGVM_GetCvarString(const char *name); -double CGVM_Time(void); -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); -// more will be added - -// engine called functions -void CG_Init(void); -void CG_Frame(double time); -// more might be added - -#endif - diff --git a/cgamevm.c b/cgamevm.c deleted file mode 100644 index 0d3026ce..00000000 --- a/cgamevm.c +++ /dev/null @@ -1,278 +0,0 @@ - -#include "quakedef.h" -#include "cgame_api.h" -#include "cl_collision.h" - -#define CGVM_RENDERENTITIES 1024 - -static entity_render_t cgvm_renderentities[CGVM_RENDERENTITIES]; -static int cgvm_renderentity; - -static mempool_t *cgvm_mempool; - -static void (*cgvm_networkcode[256])(unsigned char num); - -static unsigned char *cgvm_netbuffer; -static int cgvm_netbufferlength; -static int cgvm_netbufferpos; - -#define MAX_CGVM_MODELS 128 -#define MAX_CGVM_MODELNAME 32 -static char cgvm_modelname[MAX_CGVM_MODELS][MAX_CGVM_MODELNAME]; -static model_t *cgvm_model[MAX_CGVM_MODELS]; - -void CL_CGVM_Init(void) -{ - cgvm_mempool = Mem_AllocPool("CGVM", 0, NULL); -} - -void CL_CGVM_Shutdown(void) -{ - Mem_FreePool (&cgvm_mempool); -} - -void CL_CGVM_Clear(void) -{ - Mem_EmptyPool(cgvm_mempool); - memset(cgvm_networkcode, 0, sizeof(cgvm_networkcode)); - memset(cgvm_modelname, 0, sizeof(cgvm_modelname)); - memset(cgvm_model, 0, sizeof(cgvm_model)); -} - -void CL_CGVM_Frame(void) -{ - cgvm_renderentity = 0; - CG_Frame(cl.time); // API call -} - -// starts the cgame code -void CL_CGVM_Start(void) -{ - CL_CGVM_Clear(); - CG_Init(); // API call -} - -void CL_CGVM_ParseNetwork(unsigned char *netbuffer, int length) -{ - int num; - cgvm_netbuffer = netbuffer; - cgvm_netbufferlength = length; - cgvm_netbufferpos = 0; - while (cgvm_netbufferpos < cgvm_netbufferlength) - { - num = CGVM_MSG_ReadByte(); - if (cgvm_networkcode[num]) - cgvm_networkcode[num]((unsigned char)num); - else - Host_Error("CL_CGVM_ParseNetwork: unregistered network code %i", num); - } -} - - - - - - - - -void CGVM_RegisterNetworkCode(const unsigned char num, void (*netcode)(unsigned char num)) -{ - if (cgvm_networkcode[num]) - Host_Error("CGVM_RegisterNetworkCode: value %i already registered", num); - cgvm_networkcode[num] = netcode; -} - -unsigned char CGVM_MSG_ReadByte(void) -{ - if (cgvm_netbufferpos < cgvm_netbufferlength) - return cgvm_netbuffer[cgvm_netbufferpos++]; - else - return 0; -} - -short CGVM_MSG_ReadShort(void) -{ - short num; - num = CGVM_MSG_ReadByte() | (CGVM_MSG_ReadByte() << 8); - return num; -} - -int CGVM_MSG_ReadLong(void) -{ - int num; - num = CGVM_MSG_ReadByte() | (CGVM_MSG_ReadByte() << 8) | (CGVM_MSG_ReadByte() << 16) | (CGVM_MSG_ReadByte() << 24); - return num; -} - -float CGVM_MSG_ReadFloat(void) -{ - unsigned int num; - num = CGVM_MSG_ReadByte() | (CGVM_MSG_ReadByte() << 8) | (CGVM_MSG_ReadByte() << 16) | (CGVM_MSG_ReadByte() << 24); - return *((float *)&num); -} - -float CGVM_MSG_ReadCoord(void) -{ - return CGVM_MSG_ReadFloat(); -} - -float CGVM_MSG_ReadAngle(void) -{ - return CGVM_MSG_ReadByte() * 360.0f / 256.0f; -} - -float CGVM_MSG_ReadPreciseAngle(void) -{ - return ((unsigned short)CGVM_MSG_ReadShort()) * 360.0f / 65536.0f; -} - -void CGVM_Draw_Entity(const cgdrawentity_t *e) -{ - entity_render_t *r; - //Con_Printf("CGVM_Draw_Entity: origin %f %f %f angles %f %f %f alpha %f scale %f model %i frame1 %i frame2 %i framelerp %f skinnum %i\n", e->origin[0], e->origin[1], e->origin[2], e->angles[0], e->angles[1], e->angles[2], e->alpha, e->scale, e->model, e->frame1, e->frame2, e->framelerp, e->skinnum); - - if (!e->model) - return; - - if (cgvm_renderentity >= CGVM_RENDERENTITIES - || r_refdef.numentities >= r_refdef.maxentities) - return; - - r = cgvm_renderentities + cgvm_renderentity; - VectorCopy(e->origin, r->origin); - VectorCopy(e->angles, r->angles); - r->alpha = e->alpha; - r->scale = e->scale; - if (e->model < 0 || e->model >= MAX_CGVM_MODELS || !cgvm_model[e->model]) - { - Con_Printf("CGVM_Draw_Entity: invalid model index %i\n", e->model); - return; - } - r->model = cgvm_model[e->model]; - - r->frame = e->frame2; - // FIXME: support colormapping? - r->colormap = -1; - // FIXME: support effects? - r->effects = 0; - r->skinnum = e->skinnum; - // FIXME: any flags worth setting? - r->flags = 0; - - r->frame1 = e->frame1; - r->frame2 = e->frame2; - r->framelerp = e->framelerp; - r->frame1time = 0; - r->frame2time = 0; - - r_refdef.entities[r_refdef.numentities++] = r; - - cgvm_renderentity++; -} - -void CGVM_Draw_Light(const cgdrawlight_t *l) -{ - 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) -{ - return Mem_Alloc(cgvm_mempool, size); -} - -void CGVM_Free(void *mem) -{ - Mem_Free(mem); -} - -float CGVM_RandomRange(const float r1, const float r2) -{ - return lhrandom(r1, 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) -{ - trace_t trace; - // FIXME: do tracing agains network entities and physentities here - 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 trace.fraction; -} - -char *CGVM_GetCvarString(const char *name) -{ - cvar_t *cvar; - // fast path for common cvars - if (!strcmp(name, "sv_gravity")) - return sv_gravity.string; - cvar = Cvar_FindVar((char *)name); - if (cvar) - return cvar->string; - else - return 0; -} - -float CGVM_GetCvarFloat(const char *name) -{ - cvar_t *cvar; - // fast path for common cvars - if (!strcmp(name, "sv_gravity")) - return sv_gravity.value; - cvar = Cvar_FindVar((char *)name); - if (cvar) - return cvar->value; - else - return 0; -} - -int CGVM_GetCvarInt(const char *name) -{ - cvar_t *cvar; - // fast path for common cvars - if (!strcmp(name, "sv_gravity")) - return sv_gravity.integer; - cvar = Cvar_FindVar((char *)name); - if (cvar) - return cvar->integer; - else - return 0; -} - -double CGVM_Time(void) -{ - return cl.time; -} - -int CGVM_Model(const char *name) -{ - int i; - model_t *model; - if (strlen(name) > (MAX_CGVM_MODELNAME - 1)) - return 0; - for (i = 1;i < MAX_CGVM_MODELS;i++) - { - if (!cgvm_modelname[i][0]) - break; - if (!strcmp(name, cgvm_modelname[i])) - return i; - } - if (i >= MAX_CGVM_MODELS) - return 0; - model = Mod_ForName(name, false, false, false); - if (!model) - return 0; - strcpy(cgvm_modelname[i], name); - cgvm_model[i] = model; - return i; -} - -void CGVM_Stain(const float *origin, float radius, int cr1, int cg1, int cb1, int ca1, int cr2, int cg2, int cb2, int ca2) -{ - if (cl_stainmaps.integer) - R_Stain((float *)origin, radius, cr1, cg1, cb1, ca1, cr2, cg2, cb2, ca2); -} - diff --git a/cgamevm.h b/cgamevm.h deleted file mode 100644 index 76f0c1a0..00000000 --- a/cgamevm.h +++ /dev/null @@ -1,13 +0,0 @@ - -#ifndef CGAMEVM_H -#define CGAMEVM_H - -void CL_CGVM_Init(void); -void CL_CGVM_Shutdown(void); -void CL_CGVM_Clear(void); -void CL_CGVM_Frame(void); -void CL_CGVM_Start(void); -void CL_CGVM_ParseNetwork(unsigned char *netbuffer, int length); - -#endif - diff --git a/cl_main.c b/cl_main.c index c05ff07c..cb78f39b 100644 --- a/cl_main.c +++ b/cl_main.c @@ -245,7 +245,6 @@ void CL_ClearState(void) CL_Screen_NewMap(); CL_Particles_Clear(); - CL_CGVM_Clear(); } void CL_ExpandEntities(int num) @@ -1659,9 +1658,6 @@ int CL_ReadFromServer(void) else csqc_frame = true; - // run cgame code (which can add more entities) - CL_CGVM_Frame(); - CL_UpdateLights(); // update view blend @@ -1734,7 +1730,6 @@ CL_Shutdown */ void CL_Shutdown (void) { - CL_CGVM_Shutdown(); CL_Particles_Shutdown(); CL_Parse_Shutdown(); @@ -1828,7 +1823,6 @@ void CL_Init (void) CL_Parse_Init(); CL_Particles_Init(); CL_Screen_Init(); - CL_CGVM_Init(); CL_Video_Init(); } diff --git a/cl_parse.c b/cl_parse.c index 7430363d..60474a74 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -83,7 +83,7 @@ char *svc_strings[128] = "", // 47 "", // 48 "", // 49 - "svc_cgame", // 50 // [short] length [bytes] data + "svc_unusedlh1", // 50 // "svc_updatestatubyte", // 51 // [byte] stat [byte] value "svc_effect", // 52 // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate "svc_effect2", // 53 // [vector] org [short] modelindex [short] startframe [byte] framecount [byte] framerate @@ -494,7 +494,6 @@ static void QW_CL_RequestNextDownload(void) CL_BoundingBoxForEntity(&cl_entities[0].render); R_Modules_NewMap(); - CL_CGVM_Start(); // done checking sounds and models, send a prespawn command now MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd); @@ -1154,7 +1153,6 @@ void CL_ParseServerInfo (void) cl_entities[0].render.model = cl.worldmodel = cl.model_precache[1]; CL_BoundingBoxForEntity(&cl_entities[0].render); R_Modules_NewMap(); - CL_CGVM_Start(); } // check memory integrity @@ -2149,8 +2147,6 @@ void CL_VM_Parse_StuffCmd (const char *msg); void CL_VM_Parse_CenterPrint (const char *msg); void CSQC_AddPrintText (const char *msg); void CSQC_ReadEntities (void); -// -static unsigned char cgamenetbuffer[65536]; /* ===================== @@ -2887,16 +2883,6 @@ void CL_ParseServerMessage(void) case svc_skybox: R_SetSkyBox(MSG_ReadString()); break; - case svc_cgame: - { - int length; - length = (int) ((unsigned short) MSG_ReadShort()); - for (i = 0;i < length;i++) - cgamenetbuffer[i] = MSG_ReadByte(); - if (!msg_badread) - CL_CGVM_ParseNetwork(cgamenetbuffer, length); - } - break; case svc_entities: if (cls.signon == SIGNONS - 1) { diff --git a/cl_screen.c b/cl_screen.c index 861f181d..01ac7fa2 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -1528,9 +1528,7 @@ void CL_UpdateScreen(void) SCR_CheckDrawCenterString(); } MR_Draw(); - UI_Callback_Draw(); CL_DrawVideo(); - //ui_draw(); if (cls.signon == SIGNONS) { if (r_timereport_active) diff --git a/client.h b/client.h index 5268128c..540ed0d0 100644 --- a/client.h +++ b/client.h @@ -1072,7 +1072,5 @@ refdef_t; extern refdef_t r_refdef; -#include "cgamevm.h" - #endif diff --git a/gl_rmain.c b/gl_rmain.c index 2f262bc0..c756c53f 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -555,7 +555,6 @@ void Render_Init(void) R_Light_Init(); R_Particles_Init(); R_Explosion_Init(); - UI_Init(); Sbar_Init(); R_LightningBeams_Init(); Mod_RenderInit(); diff --git a/keys.c b/keys.c index 2d6fd69a..bec44c4c 100644 --- a/keys.c +++ b/keys.c @@ -920,10 +920,7 @@ Key_Event (int key, char ascii, qboolean down) MR_ToggleMenu_f (); break; default: - if(UI_Callback_IsSlotUsed(key_dest - 3)) - UI_Callback_KeyDown (key, ascii); - else - Con_Printf ("Key_Event: Bad key_dest\n"); + Con_Printf ("Key_Event: Bad key_dest\n"); } return; } @@ -985,10 +982,7 @@ Key_Event (int key, char ascii, qboolean down) } break; default: - if(UI_Callback_IsSlotUsed(key_dest - 3)) - UI_Callback_KeyDown (key, ascii); - else - Con_Printf ("Key_Event: Bad key_dest\n"); + Con_Printf ("Key_Event: Bad key_dest\n"); } } diff --git a/makefile.inc b/makefile.inc index 427f9379..4ee18875 100644 --- a/makefile.inc +++ b/makefile.inc @@ -55,8 +55,6 @@ OBJ_NOCD=cd_null.o # Common objects OBJ_COMMON= \ cd_shared.o \ - cgame.o \ - cgamevm.o \ cl_collision.o \ cl_demo.o \ cl_input.o \ @@ -123,7 +121,6 @@ OBJ_COMMON= \ sv_user.o \ svvm_cmds.o \ sys_shared.o \ - ui.o \ vid_shared.o \ view.o \ wad.o \ diff --git a/protocol.h b/protocol.h index 46a9ea52..dc22ba79 100644 --- a/protocol.h +++ b/protocol.h @@ -225,7 +225,7 @@ void Protocol_Names(char *buffer, size_t buffersize); #define svc_skybox 37 // [string] skyname // LordHavoc: my svc_ range, 50-59 -#define svc_cgame 50 // [short] length [bytes] data +#define svc_unusedlh1 50 // #define svc_updatestatubyte 51 // [byte] stat [byte] value #define svc_effect 52 // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate #define svc_effect2 53 // [vector] org [short] modelindex [short] startframe [byte] framecount [byte] framerate diff --git a/quakedef.h b/quakedef.h index cdbe32cd..57d2e537 100644 --- a/quakedef.h +++ b/quakedef.h @@ -221,7 +221,6 @@ extern char engineversion[128]; #include "glquake.h" -#include "ui.h" #include "palette.h" extern qboolean noclip_anglehack; diff --git a/ui.c b/ui.c deleted file mode 100644 index bcb46b8a..00000000 --- a/ui.c +++ /dev/null @@ -1,283 +0,0 @@ - -#include "quakedef.h" - -// here is the real ui drawing engine - -/* -#define FRAME_THICKNESS 2 -#define FRAME_COLOR1 0.2, 0.2, 0.5, 0, 0 -#define FRAME_COLOR2 0, 0, 0, 0.6, 0 -#define TEXT_FONTSIZE_X 10 -#define TEXT_FONTSIZE_Y 10 - -static void UIG_DrawFrame(float x, float y, float w, float h) -{ - // bottom - DrawQ_Fill(x - FRAME_THICKNESS, y - FRAME_THICKNESS, w + 2 * FRAME_THICKNESS, FRAME_THICKNESS, FRAME_COLOR1); - // top - DrawQ_Fill(x - FRAME_THICKNESS, y + h, w + 2 * FRAME_THICKNESS, FRAME_THICKNESS, FRAME_COLOR1); - // left - DrawQ_Fill(x - FRAME_THICKNESS, y, FRAME_THICKNESS, h, FRAME_COLOR1); - // right - DrawQ_Fill(x + w, y, FRAME_THICKNESS, h, FRAME_COLOR1); - // area - DrawQ_Fill(x, y, w, h, FRAME_COLOR2); -} - -static void UIG_DrawText(const char *text, float x, float y, float w, float h, float r, float g, float b, float a, float f) -{ - if(w != 0 && h != 0) - DrawQ_SetClipArea(x, y, w, h); - DrawQ_String(x, y, text, 0, TEXT_FONTSIZE_X, TEXT_FONTSIZE_Y, r, g, b, a, f); - if(w != 0 && h != 0) - DrawQ_ResetClipArea(); -} - -#define UIG_DrawPicture DrawQ_Pic -#define UIG_Fill DrawQ_Fill - -static void UIG_DrawCursor(float x, float y, float r, float g, float b, float a, float f) -{ - DrawQ_Fill(x,y,1, TEXT_FONTSIZE_Y, r, g, b, a, f); -} -*/ - -//#define UI_MEM_SIZE (1 << 10) << 9 // 512 KByte -#define UI_MEM_SIZE 1 - -void UI_Init(void) -{ -} - -#define UI_Alloc(size) Mem_Alloc(cl_mempool, size) -#define UI_Free(ptr) Mem_Free(ptr) - -void UI_Event(ui_itemlist_t list, ui_message_t *in) -{ - ui_message_queue_t out; - ui_item_t item; - int processed = true; - - if(list->list) - for(item = list->list; item != 0 && !processed; item = item->next) - { - unsigned int i; - - processed = item->eventhandler(list, item, in, &out); - - // process posted messages - for(i = 0; i < out.used; i++) - list->eventhandler(list, &out.queue[i]); - - if(in->type == UI_EVENT_FRAME) - processed = false; - } - - if(!processed) - list->eventhandler(list, in); -} - -void UI_Draw(ui_itemlist_t list) -{ - // firstly we create the frame event here - ui_message_t msg; - ui_item_t item; - - msg.type = UI_EVENT_FRAME; - - UI_Event(list, &msg); - - // now draw everything - if(list->list) - { - unsigned int depth = 0, nextdepth = ~0; - - while(depth != nextdepth) - { - for(item = list->list; item != 0; item = item->next) - { - if(item->zorder == depth) - item->draw(list, item); - if(item->zorder > depth && item->zorder < nextdepth) - nextdepth = item->zorder; - } - depth = nextdepth; - nextdepth = ~0; - } - } -} - -void UI_Mouse(ui_itemlist_t list, float x, float y) -{ - ui_message_t msg; - - msg.type = UI_EVENT_MOUSE; - - msg.data.mouse.x = x; - msg.data.mouse.y = y; - - UI_Event(list, &msg); -} - -void UI_Key(ui_itemlist_t list, int key, int ascii) -{ - ui_message_t msg; - - msg.type = UI_EVENT_KEY; - - msg.data.key.key = key; - msg.data.key.ascii = ascii; - - UI_Event(list, &msg); -} - - -// item stuff -ui_item_t UI_CloneItem(ui_item_t item) -{ - ui_item_t clone; - clone = (ui_item_t)UI_Alloc(item->size); - memcpy(clone, item, item->size); - - return clone; -} - -ui_item_t UI_FindItemByName(ui_itemlist_t list, const char *name) -{ - ui_item_t item, found = 0; - - if(list->list) - for(item = list->list; item != 0; item = item->next) - if(!strcmp(name, item->name)) - { - found = item; - break; - } - - return found; -} - -void UI_FreeItem(ui_itemlist_t list, ui_item_t item) -{ - if(!item->prev) - { - // this is the first item - list->list = item->next; - } - - item->prev->next = item->next; - item->next->prev = item->prev; - - UI_Free(item); -} - -void UI_FreeItemByName(ui_itemlist_t list, const char *name) -{ - ui_item_t item; - - item = UI_FindItemByName(list, name); - if(item) - UI_Free(item); -} - - -// itemlist stuff -ui_itemlist_t UI_CreateItemList(void) -{ - return (ui_itemlist_t)UI_Alloc(sizeof(ui_itemlist_t)); -} - -ui_itemlist_t UI_CloneItemList(ui_itemlist_t list) -{ - ui_itemlist_t clone; - ui_item_t item; - - clone = UI_CreateItemList(); - - if(list->list) - for(item = list->list; item != 0; item = item->next) - UI_AddItem(clone, UI_CloneItem(item)); - - return clone; -} - - -void UI_FreeItemList(ui_itemlist_t list) -{ - UI_Free((void*)list); -} - -void UI_AddItem(ui_itemlist_t list, ui_item_t item) -{ - item->prev = 0; - item->next = list->list; - list->list->prev = item; - list->list = item; -} - -// controls -ui_item_t UI_CreateButton(void) -{ - return NULL; -} - -ui_item_t UI_CreateLabel(void) -{ - return NULL; -} - -ui_item_t UI_CreateText(void) -{ - return NULL; -} -// AK: callback system stuff -static ui_callback_t ui_callback_list[UI_MAX_CALLBACK_COUNT]; - -void UI_Callback_Init(void) -{ - memset(ui_callback_list, 0, sizeof(ui_callback_list)); -} - -int UI_Callback_GetFreeSlot(void) -{ - int i; - for(i = 0; ui_callback_list[i].flag & UI_SLOTUSED && i < UI_MAX_CALLBACK_COUNT; i++); - - if(i == UI_MAX_CALLBACK_COUNT) - return -1; - else - return i; -} - -int UI_Callback_IsSlotUsed(int slotnr) -{ - if(slotnr < 0 || slotnr >= UI_MAX_CALLBACK_COUNT) - return false; - return (ui_callback_list[slotnr].flag & UI_SLOTUSED); -} - -void UI_Callback_SetupSlot(int slotnr, void(*keydownf)(int num, char ascii), void(*drawf)(void)) -{ - ui_callback_list[slotnr].flag = UI_SLOTUSED; - ui_callback_list[slotnr].draw = drawf; - ui_callback_list[slotnr].keydown = keydownf; -} - -void UI_Callback_ResetSlot(int slotnr) -{ - ui_callback_list[slotnr].flag = 0; -} - -void UI_Callback_Draw(void) -{ - int i; - for(i = 0; i < UI_MAX_CALLBACK_COUNT; i++) - if(ui_callback_list[i].flag & UI_SLOTUSED && ui_callback_list[i].draw) - ui_callback_list[i].draw(); -} - -void UI_Callback_KeyDown(int num, char ascii) -{ - if(ui_callback_list[key_dest - 3].flag & UI_SLOTUSED && ui_callback_list[key_dest - 3].keydown) - ui_callback_list[key_dest - 3].keydown(num, ascii); -} diff --git a/ui.h b/ui.h deleted file mode 100644 index 1c442fee..00000000 --- a/ui.h +++ /dev/null @@ -1,173 +0,0 @@ - -#ifndef UI_H -#define UI_H - -// AK: new passive ui (like the menu stuff) -/* some ideas: -1. two different structs (one for the ui core code and one for the rest) -2. each item has a size field -*/ - -#define UI_EVENT_QUEUE_SIZE 32 - -typedef enum ui_control_type_e { UI_BUTTON, UI_LABEL } ui_control_type; - -typedef struct ui_message_s ui_message_t; -typedef struct ui_item_s *ui_item_t; -typedef struct ui_itemlist_s *ui_itemlist_t; -typedef struct ui_message_queue_s ui_message_queue_t; - -struct ui_item_s -{ - unsigned int size; - - ui_control_type type; - - const char *name; // used for debugging purposes and to identify an object - -//private: - // used to build the item list - struct ui_item_s *prev, *next; // items are allowed to be freed everywhere - - // called for system events (true means message processed) - int (*eventhandler)(ui_itemlist_t list, ui_item_t self, ui_message_t *in, ui_message_queue_t *out); - - // z-order (the higher, the later it is drawn) - unsigned int zorder; - - // called to draw the object - void (*draw)(ui_itemlist_t list, struct ui_item_s * self); - -}; - -struct ui_message_s; - -struct ui_itemlist_s -{ - float org_x, org_y; - - ui_item_t selected; - - void (*eventhandler)(struct ui_itemlist_s * list, struct ui_message_s *msg); - -// private: - ui_item_t list; -}; - -// this is structure contains *all* possible messages -enum ui_message_type_e { UI_EVENT_FRAME, UI_EVENT_KEY, UI_EVENT_MOUSE, UI_BUTTON_PRESSED }; - -struct ui_ev_key_s -{ - int key, ascii; -}; - -// in_mouse_x and in_mouse_y can be also used... -struct ui_ev_mouse_s -{ - float x, y; -}; - -union ui_message_data_u -{ - unsigned char reserved; - struct ui_ev_key_s key; - struct ui_ev_mouse_s mouse; -}; - -struct ui_message_s -{ - // empty for input messages, but contains a valid item for all other events - ui_item_t target; - - // used to determine which data struct was used - enum ui_message_type_e type; - - union ui_message_data_u data; -}; - -struct ui_message_queue_s -{ - unsigned int used; - ui_message_t queue[UI_EVENT_QUEUE_SIZE]; -}; - -void UI_Init(void); - -#define UI_MOUSEEVENT 1 -#define UI_KEYEVENT 2 -#define UI_FRAME 4 -void UI_Draw(ui_itemlist_t list); - -void UI_Mouse(ui_itemlist_t list, float x, float y); -void UI_Key(ui_itemlist_t list, int key, int ascii); - -// item stuff -#define UI_ITEM(item) ((ui_item_t*)item) - -ui_item_t UI_CloneItem(ui_item_t); - -ui_item_t UI_FindItemByName(ui_itemlist_t, const char *); - -void UI_FreeItem(ui_itemlist_t, ui_item_t); -void UI_FreeItemByName(ui_itemlist_t, const char *); - -// itemlist stuff -ui_itemlist_t UI_CreateItemList(); -ui_itemlist_t UI_CloneItemList(ui_itemlist_t); -void UI_FreeItemList(ui_itemlist_t); - -void UI_AddItem(ui_itemlist_t list, ui_item_t item); - -// controls -#define UI_TEXT_DEFAULT_LENGTH 255 - -typedef struct ui_button_s *ui_button_t; -typedef struct ui_label_s *ui_label_t; -typedef struct ui_text_s *ui_text_t; - -struct ui_label_s -{ - struct ui_item_s item; - - const char *text; - float x, y; - float r, g, b, a, f; -}; - -struct ui_button -{ - struct ui_item_s item; - - const char *caption; -}; - -ui_item_t UI_CreateButton(void); -ui_item_t UI_CreateLabel(void); -ui_item_t UI_CreateText(void); - -// AK: new callback system -#define UI_MAX_CALLBACK_COUNT 10 - -#define UI_SLOTUSED 1 -typedef struct ui_callback_s -{ - unsigned int flag; - void (*keydown) (int num, char ascii); - void (*draw) (void); -} ui_callback_t; - -// functions which should be used -void UI_Callback_Init(void); -void UI_Callback_Reset(void); - -void UI_Callback_SetupSlot(int slotnr, void(*keydownf)(int num, char ascii), void(*drawf)(void)); -void UI_Callback_ResetSlot(int slotnr); -int UI_Callback_GetFreeSlot(void); -int UI_Callback_IsSlotUsed(int slotnr); - -void UI_Callback_Draw(void); -void UI_Callback_KeyDown(int num, char ascii); - -#endif -