Make nails use temp entities.

While reading the code, I noticed the comment stating that qw projectiles
(nails) are really temp entities, so I decided to make that true. The
client now supports unlimited projectiles.
This commit is contained in:
Bill Currie 2010-12-01 17:15:28 +09:00
parent 532e79bca6
commit d24837af4a
2 changed files with 62 additions and 85 deletions

View file

@ -69,12 +69,8 @@ static struct predicted_player {
} predicted_players[MAX_CLIENTS];
#define MAX_PROJECTILES 32
int cl_num_projectiles;
entity_t cl_player_ents[MAX_CLIENTS];
entity_t cl_flag_ents[MAX_CLIENTS];
entity_t cl_projectiles[MAX_PROJECTILES];
entity_t cl_packet_ents[512]; // FIXME: magic number
@ -560,79 +556,6 @@ CL_LinkPacketEntities (void)
}
}
// PROJECTILE PARSING / LINKING ===============================================
void
CL_ClearProjectiles (void)
{
cl_num_projectiles = 0;
}
/*
CL_ParseProjectiles
Nails are passed as efficient temporary entities
*/
void
CL_ParseProjectiles (qboolean nail2)
{
byte bits[6];
int i, c, d, j, num;
entity_t *pr;
c = MSG_ReadByte (net_message);
if ((cl_num_projectiles + c) >= MAX_PROJECTILES)
d = MAX_PROJECTILES - cl_num_projectiles;
else
d = c;
for (i = 0; i < d; i++) {
if (nail2)
num = MSG_ReadByte (net_message);
else
num = 0;
for (j = 0; j < 6; j++)
bits[j] = MSG_ReadByte (net_message);
pr = &cl_projectiles[cl_num_projectiles];
cl_num_projectiles++;
pr->model = cl.model_precache[cl_spikeindex];
pr->colormap = vid.colormap8;
pr->origin[0] = ((bits[0] + ((bits[1] & 15) << 8)) << 1) - 4096;
pr->origin[1] = (((bits[1] >> 4) + (bits[2] << 4)) << 1) - 4096;
pr->origin[2] = ((bits[3] + ((bits[4] & 15) << 8)) << 1) - 4096;
pr->angles[0] = (bits[4] >> 4) * (360.0 / 16.0);
pr->angles[1] = bits[5] * (360.0 / 256.0);
}
if (d < c) {
c = (c - d) * (nail2 ? 7 : 6);
for (i = 0; i < c; i++)
MSG_ReadByte (net_message);
}
}
static void
CL_LinkProjectiles (void)
{
int i;
entity_t **ent;
entity_t *pr;
for (i = 0, pr = cl_projectiles; i < cl_num_projectiles; i++, pr++) {
if (!pr->model)
continue;
// grab an entity to fill in
ent = R_NewEntity ();
if (!ent)
break; // object list is full
*ent = pr;
}
}
static int
TranslateFlags (int src)
{
@ -1157,7 +1080,6 @@ CL_EmitEntities (void)
CL_LinkPlayers ();
CL_LinkPacketEntities ();
CL_LinkProjectiles ();
CL_UpdateTEnts ();
if (!r_drawentities->int_val) {
@ -1193,9 +1115,5 @@ CL_EmitEntities (void)
void
CL_Ents_Init (void)
{
int i;
for (i = 0; i < MAX_PROJECTILES; i++)
CL_Init_Entity (&cl_projectiles[i]);
r_view_model = &cl.viewent;
}

View file

@ -49,6 +49,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "cl_ents.h"
#include "cl_main.h"
#include "cl_parse.h"
#include "cl_tent.h"
#include "client.h"
#include "compat.h"
@ -88,6 +89,7 @@ typedef struct tent_obj_s {
static tent_obj_t *tent_objects;
static tent_obj_t *cl_beams;
static tent_obj_t *cl_explosions;
static tent_t *cl_projectiles;
static sfx_t *cl_sfx_wizhit;
static sfx_t *cl_sfx_knighthit;
@ -138,10 +140,10 @@ CL_Init_Entity (entity_t *ent)
memset (ent, 0, sizeof (*ent));
ent->colormap = vid.colormap8;
ent->colormod[0] = ent->colormod[1] = ent->colormod[2] =
ent->colormod[3] = 1.0;
VectorSet (1.0, 1.0, 1.0, ent->colormod);
ent->colormod[3] = 1.0;
ent->scale = 1.0;
ent->lerpflags |= LERP_RESETMOVE|LERP_RESETANIM;
ent->lerpflags |= LERP_RESETMOVE | LERP_RESETANIM;
}
static tent_t *
@ -588,3 +590,60 @@ CL_UpdateTEnts (void)
CL_UpdateBeams ();
CL_UpdateExplosions ();
}
void
CL_ClearProjectiles (void)
{
tent_t *tent;
for (tent = cl_projectiles; tent; tent = tent->next) {
R_RemoveEfrags (&tent->ent);
tent->ent.efrag = 0;
}
free_temp_entities (cl_projectiles);
cl_projectiles = 0;
}
/*
Nails are passed as efficient temporary entities
*/
void
CL_ParseProjectiles (qboolean nail2)
{
tent_t *tent;
tent_t *head = 0, **tail = &head;
byte bits[6];
int i, c, j, num;
entity_t *pr;
c = MSG_ReadByte (net_message);
for (i = 0; i < c; i++) {
if (nail2)
num = MSG_ReadByte (net_message);
else
num = 0;
for (j = 0; j < 6; j++)
bits[j] = MSG_ReadByte (net_message);
tent = new_temp_entity ();
*tail = tent;
tail = &tent->next;
pr = &tent->ent;
pr->model = cl.model_precache[cl_spikeindex];
pr->colormap = vid.colormap8;
pr->origin[0] = ((bits[0] + ((bits[1] & 15) << 8)) << 1) - 4096;
pr->origin[1] = (((bits[1] >> 4) + (bits[2] << 4)) << 1) - 4096;
pr->origin[2] = ((bits[3] + ((bits[4] & 15) << 8)) << 1) - 4096;
pr->angles[0] = (bits[4] >> 4) * (360.0 / 16.0);
pr->angles[1] = bits[5] * (360.0 / 256.0);
pr->angles[2] = 0;
R_AddEfrags (&tent->ent);
}
*tail = cl_projectiles;
cl_projectiles = head;
}