mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
unlimited beams and explosions, and fix a few bugs missed due to testing the wrong version :P
This commit is contained in:
parent
2211f6fb1a
commit
296894252d
1 changed files with 109 additions and 92 deletions
|
@ -59,7 +59,7 @@ typedef struct tent_s {
|
||||||
entity_t ent;
|
entity_t ent;
|
||||||
} tent_t;
|
} tent_t;
|
||||||
|
|
||||||
#define TEMP_ENTITY_BATCH 64
|
#define TEMP_BATCH 64
|
||||||
static tent_t *temp_entities = 0;
|
static tent_t *temp_entities = 0;
|
||||||
|
|
||||||
#define MAX_BEAMS 8
|
#define MAX_BEAMS 8
|
||||||
|
@ -73,30 +73,37 @@ typedef struct {
|
||||||
int seed;
|
int seed;
|
||||||
} beam_t;
|
} beam_t;
|
||||||
|
|
||||||
beam_t cl_beams[MAX_BEAMS];
|
|
||||||
|
|
||||||
#define MAX_EXPLOSIONS 8
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float start;
|
float start;
|
||||||
tent_t *tent;
|
tent_t *tent;
|
||||||
} explosion_t;
|
} explosion_t;
|
||||||
|
|
||||||
explosion_t cl_explosions[MAX_EXPLOSIONS];
|
typedef struct tent_obj_s {
|
||||||
|
struct tent_obj_s *next;
|
||||||
|
union {
|
||||||
|
beam_t beam;
|
||||||
|
explosion_t ex;
|
||||||
|
} to;
|
||||||
|
} tent_obj_t;
|
||||||
|
|
||||||
sfx_t *cl_sfx_wizhit;
|
static tent_obj_t *tent_objects;
|
||||||
sfx_t *cl_sfx_knighthit;
|
static tent_obj_t *cl_beams;
|
||||||
sfx_t *cl_sfx_tink1;
|
static tent_obj_t *cl_explosions;
|
||||||
sfx_t *cl_sfx_ric1;
|
|
||||||
sfx_t *cl_sfx_ric2;
|
|
||||||
sfx_t *cl_sfx_ric3;
|
|
||||||
sfx_t *cl_sfx_r_exp3;
|
|
||||||
|
|
||||||
model_t *cl_mod_beam;
|
static sfx_t *cl_sfx_wizhit;
|
||||||
model_t *cl_mod_bolt;
|
static sfx_t *cl_sfx_knighthit;
|
||||||
model_t *cl_mod_bolt2;
|
static sfx_t *cl_sfx_tink1;
|
||||||
model_t *cl_mod_bolt3;
|
static sfx_t *cl_sfx_ric1;
|
||||||
model_t *cl_spr_explod;
|
static sfx_t *cl_sfx_ric2;
|
||||||
|
static sfx_t *cl_sfx_ric3;
|
||||||
|
static sfx_t *cl_sfx_r_exp3;
|
||||||
|
|
||||||
|
static model_t *cl_mod_beam;
|
||||||
|
static model_t *cl_mod_bolt;
|
||||||
|
static model_t *cl_mod_bolt2;
|
||||||
|
static model_t *cl_mod_bolt3;
|
||||||
|
static model_t *cl_spr_explod;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
CL_TEnts_Precache (int phase)
|
CL_TEnts_Precache (int phase)
|
||||||
|
@ -146,17 +153,16 @@ new_temp_entity (void)
|
||||||
if (!temp_entities) {
|
if (!temp_entities) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
temp_entities = malloc (TEMP_ENTITY_BATCH * sizeof (tent_t));
|
temp_entities = malloc (TEMP_BATCH * sizeof (tent_t));
|
||||||
for (i = 0; i < TEMP_ENTITY_BATCH - 1; i++) {
|
for (i = 0; i < TEMP_BATCH - 1; i++) {
|
||||||
temp_entities[i].next = &temp_entities[i + 1];
|
temp_entities[i].next = &temp_entities[i + 1];
|
||||||
CL_Init_Entity (&temp_entities[i].ent);
|
|
||||||
}
|
}
|
||||||
temp_entities[i].next = 0;
|
temp_entities[i].next = 0;
|
||||||
CL_Init_Entity (&temp_entities[i].ent);
|
|
||||||
}
|
}
|
||||||
tent = temp_entities;
|
tent = temp_entities;
|
||||||
temp_entities = tent->next;
|
temp_entities = tent->next;
|
||||||
tent->next = 0;
|
tent->next = 0;
|
||||||
|
CL_Init_Entity (&tent->ent);
|
||||||
return tent;
|
return tent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,67 +177,56 @@ free_temp_entities (tent_t *tents)
|
||||||
temp_entities = tents;
|
temp_entities = tents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static tent_obj_t *
|
||||||
|
new_tent_object (void)
|
||||||
|
{
|
||||||
|
tent_obj_t *tobj;
|
||||||
|
if (!tent_objects) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
tent_objects = malloc (TEMP_BATCH * sizeof (tent_t));
|
||||||
|
for (i = 0; i < TEMP_BATCH - 1; i++)
|
||||||
|
tent_objects[i].next = &tent_objects[i + 1];
|
||||||
|
tent_objects[i].next = 0;
|
||||||
|
}
|
||||||
|
tobj = tent_objects;
|
||||||
|
tent_objects = tobj->next;
|
||||||
|
tobj->next = 0;
|
||||||
|
return tobj;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_tent_objects (tent_obj_t *tobjs)
|
||||||
|
{
|
||||||
|
tent_obj_t **t = &tobjs;
|
||||||
|
|
||||||
|
while (*t)
|
||||||
|
t = &(*t)->next;
|
||||||
|
*t = tent_objects;
|
||||||
|
tent_objects = tobjs;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CL_ClearTEnts (void)
|
CL_ClearTEnts (void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
tent_t *t;
|
tent_t *t;
|
||||||
|
tent_obj_t *to;
|
||||||
|
|
||||||
for (i = 0; i < MAX_BEAMS; i++) {
|
for (to = cl_beams; to; to = to->next) {
|
||||||
for (t = cl_beams[i].tents; t; t = t->next)
|
for (t = to->to.beam.tents; t; t = t->next)
|
||||||
t->ent.efrag = 0;
|
t->ent.efrag = 0;
|
||||||
free_temp_entities (cl_beams[i].tents);
|
free_temp_entities (to->to.beam.tents);
|
||||||
memset (&cl_beams[i], 0, sizeof (cl_beams[i]));
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < MAX_EXPLOSIONS; i++) {
|
free_tent_objects (cl_beams);
|
||||||
for (t = cl_explosions[i].tent; t; t = t->next)
|
cl_beams = 0;
|
||||||
|
|
||||||
|
for (to = cl_explosions; to; to = to->next) {
|
||||||
|
for (t = to->to.ex.tent; t; t = t->next)
|
||||||
t->ent.efrag = 0;
|
t->ent.efrag = 0;
|
||||||
free_temp_entities (cl_explosions[i].tent);
|
free_temp_entities (to->to.ex.tent);
|
||||||
memset (&cl_explosions[i], 0, sizeof (cl_explosions[i]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static explosion_t *
|
|
||||||
CL_AllocExplosion (void)
|
|
||||||
{
|
|
||||||
float time;
|
|
||||||
int index, i;
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_EXPLOSIONS; i++)
|
|
||||||
if (!cl_explosions[i].tent) {
|
|
||||||
cl_explosions[i].tent = new_temp_entity ();
|
|
||||||
return &cl_explosions[i];
|
|
||||||
}
|
|
||||||
// find the oldest explosion
|
|
||||||
time = cl.time;
|
|
||||||
index = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_EXPLOSIONS; i++)
|
|
||||||
if (cl_explosions[i].start < time) {
|
|
||||||
time = cl_explosions[i].start;
|
|
||||||
index = i;
|
|
||||||
}
|
|
||||||
return &cl_explosions[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
static beam_t *
|
|
||||||
beam_alloc (int ent)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
beam_t *b;
|
|
||||||
|
|
||||||
// override any beam with the same entity
|
|
||||||
for (i = 0, b = cl_beams; i < MAX_BEAMS; i++, b++)
|
|
||||||
if (b->entity == ent)
|
|
||||||
return b;
|
|
||||||
// find a free beam
|
|
||||||
for (i = 0, b = cl_beams; i < MAX_BEAMS; i++, b++)
|
|
||||||
if (!b->model || b->endtime < cl.time)
|
|
||||||
return b;
|
|
||||||
Con_Printf ("beam list overflow!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
beam_clear (beam_t *b)
|
beam_clear (beam_t *b)
|
||||||
{
|
{
|
||||||
|
@ -298,6 +293,7 @@ beam_setup (beam_t *b)
|
||||||
static void
|
static void
|
||||||
CL_ParseBeam (model_t *m)
|
CL_ParseBeam (model_t *m)
|
||||||
{
|
{
|
||||||
|
tent_obj_t *to;
|
||||||
beam_t *b;
|
beam_t *b;
|
||||||
int ent;
|
int ent;
|
||||||
vec3_t start, end;
|
vec3_t start, end;
|
||||||
|
@ -307,18 +303,22 @@ CL_ParseBeam (model_t *m)
|
||||||
MSG_ReadCoordV (net_message, start);
|
MSG_ReadCoordV (net_message, start);
|
||||||
MSG_ReadCoordV (net_message, end);
|
MSG_ReadCoordV (net_message, end);
|
||||||
|
|
||||||
if ((b = beam_alloc (ent))) {
|
to = new_tent_object ();
|
||||||
beam_clear (b);
|
to->next = cl_beams;
|
||||||
b->entity = ent;
|
cl_beams = to;
|
||||||
b->model = m;
|
b = &to->to.beam;
|
||||||
b->endtime = cl.time + 0.2;
|
b->tents = 0;
|
||||||
b->seed = rand ();
|
|
||||||
VectorCopy (end, b->end);
|
beam_clear (b);
|
||||||
if (b->entity != cl.viewentity) {
|
b->entity = ent;
|
||||||
// this will be done in CL_UpdateBeams
|
b->model = m;
|
||||||
VectorCopy (start, b->start);
|
b->endtime = cl.time + 0.2;
|
||||||
beam_setup (b);
|
b->seed = rand ();
|
||||||
}
|
VectorCopy (end, b->end);
|
||||||
|
if (b->entity != cl.viewentity) {
|
||||||
|
// this will be done in CL_UpdateBeams
|
||||||
|
VectorCopy (start, b->start);
|
||||||
|
beam_setup (b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,6 +327,7 @@ CL_ParseTEnt (void)
|
||||||
{
|
{
|
||||||
byte type;
|
byte type;
|
||||||
dlight_t *dl;
|
dlight_t *dl;
|
||||||
|
tent_obj_t *to;
|
||||||
explosion_t *ex;
|
explosion_t *ex;
|
||||||
int colorStart, colorLength;
|
int colorStart, colorLength;
|
||||||
int cnt = -1;
|
int cnt = -1;
|
||||||
|
@ -403,7 +404,12 @@ CL_ParseTEnt (void)
|
||||||
S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
|
S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
|
||||||
|
|
||||||
// sprite
|
// sprite
|
||||||
ex = CL_AllocExplosion ();
|
to = new_tent_object ();
|
||||||
|
to->next = cl_explosions;
|
||||||
|
cl_explosions = to;
|
||||||
|
ex = &to->to.ex;
|
||||||
|
ex->tent = new_temp_entity ();
|
||||||
|
|
||||||
VectorCopy (pos, ex->tent->ent.origin);
|
VectorCopy (pos, ex->tent->ent.origin);
|
||||||
ex->start = cl.time;
|
ex->start = cl.time;
|
||||||
//FIXME need better model management
|
//FIXME need better model management
|
||||||
|
@ -509,20 +515,25 @@ CL_ParseTEnt (void)
|
||||||
static void
|
static void
|
||||||
CL_UpdateBeams (void)
|
CL_UpdateBeams (void)
|
||||||
{
|
{
|
||||||
|
tent_obj_t **to;
|
||||||
beam_t *b;
|
beam_t *b;
|
||||||
int i;
|
|
||||||
unsigned seed;
|
unsigned seed;
|
||||||
tent_t *t;
|
tent_t *t;
|
||||||
|
|
||||||
// update lightning
|
// update lightning
|
||||||
for (i = 0, b = cl_beams; i < MAX_BEAMS; i++, b++) {
|
for (to = &cl_beams; *to; ) {
|
||||||
if (!b->endtime)
|
b = &(*to)->to.beam;
|
||||||
continue;
|
|
||||||
if (!b->model || b->endtime < cl.time) {
|
if (!b->model || b->endtime < cl.time) {
|
||||||
|
tent_obj_t *_to;
|
||||||
b->endtime = 0;
|
b->endtime = 0;
|
||||||
beam_clear (b);
|
beam_clear (b);
|
||||||
|
_to = *to;
|
||||||
|
*to = _to->next;
|
||||||
|
_to->next = tent_objects;
|
||||||
|
tent_objects = _to;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
to = &(*to)->next;
|
||||||
|
|
||||||
// if coming from the player, update the start position
|
// if coming from the player, update the start position
|
||||||
if (b->entity == cl.viewentity) {
|
if (b->entity == cl.viewentity) {
|
||||||
|
@ -545,21 +556,27 @@ CL_UpdateBeams (void)
|
||||||
static void
|
static void
|
||||||
CL_UpdateExplosions (void)
|
CL_UpdateExplosions (void)
|
||||||
{
|
{
|
||||||
int f, i;
|
int f;
|
||||||
|
tent_obj_t **to;
|
||||||
explosion_t *ex;
|
explosion_t *ex;
|
||||||
|
|
||||||
for (i = 0, ex = cl_explosions; i < MAX_EXPLOSIONS; i++, ex++) {
|
for (to = &cl_explosions; *to; ) {
|
||||||
|
ex = &(*to)->to.ex;
|
||||||
entity_t *ent;
|
entity_t *ent;
|
||||||
if (!ex->tent)
|
|
||||||
continue;
|
|
||||||
ent = &ex->tent->ent;
|
ent = &ex->tent->ent;
|
||||||
f = 10 * (cl.time - ex->start);
|
f = 10 * (cl.time - ex->start);
|
||||||
if (f >= ent->model->numframes) {
|
if (f >= ent->model->numframes) {
|
||||||
|
tent_obj_t *_to;
|
||||||
R_RemoveEfrags (ent);
|
R_RemoveEfrags (ent);
|
||||||
ent->efrag = 0;
|
ent->efrag = 0;
|
||||||
free_temp_entities (ex->tent);
|
free_temp_entities (ex->tent);
|
||||||
|
_to = *to;
|
||||||
|
*to = _to->next;
|
||||||
|
_to->next = tent_objects;
|
||||||
|
tent_objects = _to;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
to = &(*to)->next;
|
||||||
|
|
||||||
ent->frame = f;
|
ent->frame = f;
|
||||||
if (!ent->efrag)
|
if (!ent->efrag)
|
||||||
|
|
Loading…
Reference in a new issue