X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=cgame.c;h=86da9a53d8074849f5d6ee6981eb276349164949;hp=e63f4c9c76811f15b913e6f2f6fb8bfb64561e42;hb=71f289b8f32b17fa244d42608af4282e75468c6a;hpb=dc7821879ae378aeaec685a301f1421bd2c48a88 diff --git a/cgame.c b/cgame.c index e63f4c9c..86da9a53 100644 --- a/cgame.c +++ b/cgame.c @@ -1,19 +1,13 @@ +#include #include "cgame_api.h" #include "cg_math.h" - -#ifndef NULL -#define NULL ((void *)0) -#endif - static double gametime, frametime; struct localentity_s; typedef struct localentity_s { - int active; // true if the entity is alive (not freed) - float freetime; // time this entity was freed float dietime; vec3_t velocity; vec3_t avelocity; @@ -26,8 +20,6 @@ typedef struct localentity_s float airfrictionscale; float gravityscale; void (*framethink)(struct localentity_s *e); - //int solid; - //void (*touch)(struct localentity_s *self, struct localentity_s *other); void (*touchnetwork)(struct localentity_s *self); cgdrawentity_t draw; } @@ -35,6 +27,10 @@ localentity_t; #define MAX_LOCALENTITIES 1024 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; @@ -50,35 +46,38 @@ static void readvector(vec3_t v) static localentity_t *entspawn(void) { - int i; - localentity_t *l; + int i, best; + float bestfreetime; + bestfreetime = (float) (gametime + 100.0); + best = -1; for (i = 0;i < MAX_LOCALENTITIES;i++) { - l = localentity + i; - if (!l->active && l->freetime < gametime) + if (!localentityactive[i] && bestfreetime > localentityfreetime[i]) { - memset(l, 0, sizeof(*l)); - l->active = true; - return l; + bestfreetime = localentityfreetime[i]; + best = i; + if (bestfreetime < gametime) + break; } } - for (i = 0;i < MAX_LOCALENTITIES;i++) + if (best >= 0) { - l = localentity + i; - if (!l->active) - { - memset(l, 0, sizeof(*l)); - l->active = true; - return l; - } + memset(localentity + best, 0, sizeof(*localentity)); + localentityactive[best] = true; + return localentity + best; } return NULL; } static void entremove(localentity_t *e) { - memset(e, 0, sizeof(*e)); - e->freetime = (float)gametime + 1.0f; + int i; + i = (e - localentity) / sizeof(localentity_t); + if (i < 0 || i >= MAX_LOCALENTITIES) + return; // this should be an error + //memset(e, 0, sizeof(*e)); + localentityactive[i] = false; + localentityfreetime[i] = (float)gametime + 1.0f; } static void phys_setupphysentities(void) @@ -87,9 +86,9 @@ static void phys_setupphysentities(void) /* for (i = 0;i < MAX_LOCALENTITIES;i++) { - l = localentities + i; - if (l->active && l->solid) + if (localentityactive[i] && localentities[i].solid) { + l = localentities + i; } } */ @@ -101,12 +100,16 @@ static void phys_moveentities(void) localentity_t *l; for (i = 0;i < MAX_LOCALENTITIES;i++) { - l = localentity + i; - if (l->active) + if (localentityactive[i]) { + l = localentity + i; if (l->framethink) + { l->framethink(l); - if (l->active && l->draw.model) + if (!localentityactive[i]) + continue; + } + if (l->draw.model) CGVM_Draw_Entity(&l->draw); } } @@ -184,7 +187,7 @@ static void explosiondebris_framethink(localentity_t *self) { if (gametime > self->dietime) { - self->draw.scale -= frametime * 3; + self->draw.scale -= (float)(frametime * 3.0); if (self->draw.scale < 0.05f) { entremove(self); @@ -285,7 +288,7 @@ static void net_gibshower(unsigned char num) time = CGVM_Time(); // read the network data count = CGVM_MSG_ReadByte(); - velocityscale = CGVM_MSG_ReadByte() * 100; + velocityscale = (float)(CGVM_MSG_ReadByte() * 100); readvector(org); for (i = 0;i < count;i++) @@ -300,7 +303,7 @@ static void net_gibshower(unsigned char num) e->draw.angles[2] = CGVM_RandomRange(0, 360); VectorRandom(e->velocity); VectorScale(e->velocity, velocityscale, e->velocity); - e->velocity[2] -= cg_gravity * 0.1; + 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); @@ -333,8 +336,10 @@ static void net_gibshower(unsigned char num) // called by engine void CG_Init(void) { - localentity = CGVM_Malloc(sizeof(localentity_t) * MAX_LOCALENTITIES); - phys_entity = CGVM_Malloc(sizeof(cgphysentity_t) * MAX_LOCALENTITIES); + localentity = CGVM_Malloc(sizeof(*localentity) * MAX_LOCALENTITIES); + localentityactive = CGVM_Malloc(sizeof(*localentityactive) * MAX_LOCALENTITIES); + localentityfreetime = CGVM_Malloc(sizeof(*localentityfreetime) * MAX_LOCALENTITIES); + phys_entity = CGVM_Malloc(sizeof(*phys_entity) * MAX_LOCALENTITIES); CGVM_RegisterNetworkCode(1, net_explosion); CGVM_RegisterNetworkCode(2, net_gibshower); gametime = 0;