a nother tiny optimisation: no nead to recalculate non-player beams every

frame
This commit is contained in:
Bill Currie 2002-04-27 04:08:30 +00:00
parent 8a8e62f4c2
commit b93f37fb00

View file

@ -198,8 +198,8 @@ CL_AllocBeam (int ent)
return 0; return 0;
} }
void static inline void
CL_ClearBeam (beam_t *b) clear_beam (beam_t *b)
{ {
if (b->ent_count) { if (b->ent_count) {
entity_t *e = b->ent_list + b->ent_count; entity_t *e = b->ent_list + b->ent_count;
@ -209,6 +209,54 @@ CL_ClearBeam (beam_t *b)
} }
} }
static inline void
setup_beam (beam_t *b)
{
entity_t *ent;
float forward, pitch, yaw, d;
int ent_count;
vec3_t dist, org;
// calculate pitch and yaw
VectorSubtract (b->end, b->start, dist);
if (dist[1] == 0 && dist[0] == 0) {
yaw = 0;
if (dist[2] > 0)
pitch = 90;
else
pitch = 270;
} else {
yaw = (int) (atan2 (dist[1], dist[0]) * 180 / M_PI);
if (yaw < 0)
yaw += 360;
forward = sqrt (dist[0] * dist[0] + dist[1] * dist[1]);
pitch = (int) (atan2 (dist[2], forward) * 180 / M_PI);
if (pitch < 0)
pitch += 360;
}
// add new entities for the lightning
VectorCopy (b->start, org);
d = VectorNormalize (dist);
VectorScale (dist, 30, dist);
ent_count = ceil (d / 30);
ent_count = min (ent_count, MAX_BEAM_ENTS);
b->ent_count = ent_count;
d = 0;
while (ent_count--) {
ent = &b->ent_list[ent_count];
VectorMA (org, d, dist, ent->origin);
d += 1;
ent->model = b->model;
ent->angles[0] = pitch;
ent->angles[1] = yaw;
if (!ent->efrag)
R_AddEfrags (ent);
}
}
void void
CL_ParseBeam (model_t *m) CL_ParseBeam (model_t *m)
{ {
@ -222,13 +270,17 @@ CL_ParseBeam (model_t *m)
MSG_ReadCoordV (net_message, end); MSG_ReadCoordV (net_message, end);
if ((b = CL_AllocBeam (ent))) { if ((b = CL_AllocBeam (ent))) {
CL_ClearBeam (b); clear_beam (b);
b->entity = ent; b->entity = ent;
b->model = m; b->model = m;
b->endtime = cl.time + 0.2; b->endtime = cl.time + 0.2;
b->seed = rand(); b->seed = rand();
VectorCopy (start, b->start);
VectorCopy (end, b->end); VectorCopy (end, b->end);
if (b->entity != cl.viewentity) {
// this will be done in CL_UpdateBeams
VectorCopy (start, b->start);
setup_beam (b);
}
} }
} }
@ -411,65 +463,31 @@ void
CL_UpdateBeams (void) CL_UpdateBeams (void)
{ {
beam_t *b; beam_t *b;
entity_t *ent;
float forward, pitch, yaw, d;
int i, ent_count; int i, ent_count;
vec3_t dist, org;
unsigned seed; unsigned seed;
// update lightning // update lightning
for (i = 0, b = cl_beams; i < MAX_BEAMS; i++, b++) { for (i = 0, b = cl_beams; i < MAX_BEAMS; i++, b++) {
if (!b->model || b->endtime < cl.time) { if (!b->model || b->endtime < cl.time) {
CL_ClearBeam (b); clear_beam (b);
continue; continue;
} }
// 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) {
CL_ClearBeam (b); clear_beam (b);
VectorCopy (cl.simorg, b->start); VectorCopy (cl.simorg, b->start);
} setup_beam (b);
// calculate pitch and yaw
VectorSubtract (b->end, b->start, dist);
if (dist[1] == 0 && dist[0] == 0) {
yaw = 0;
if (dist[2] > 0)
pitch = 90;
else
pitch = 270;
} else {
yaw = (int) (atan2 (dist[1], dist[0]) * 180 / M_PI);
if (yaw < 0)
yaw += 360;
forward = sqrt (dist[0] * dist[0] + dist[1] * dist[1]);
pitch = (int) (atan2 (dist[2], forward) * 180 / M_PI);
if (pitch < 0)
pitch += 360;
} }
seed = b->seed + ((int)(cl.time * BEAM_SEED_INTERVAL) % seed = b->seed + ((int)(cl.time * BEAM_SEED_INTERVAL) %
BEAM_SEED_INTERVAL); BEAM_SEED_INTERVAL);
// add new entities for the lightning // add new entities for the lightning
VectorCopy (b->start, org); ent_count = b->ent_count;
d = VectorNormalize (dist);
VectorScale (dist, 30, dist);
ent_count = ceil (d / 30);
ent_count = min (ent_count, MAX_BEAM_ENTS);
b->ent_count = ent_count;
d = 0;
while (ent_count--) { while (ent_count--) {
ent = &b->ent_list[ent_count]; seed = seed * BEAM_SEED_PRIME;
VectorMA (org, d, dist, ent->origin); b->ent_list[ent_count].angles[2] = seed % 360;
d += 1;
ent->model = b->model;
ent->angles[0] = pitch;
ent->angles[1] = yaw;
ent->angles[2] = (seed = seed * BEAM_SEED_PRIME) % 360;
if (!ent->efrag)
R_AddEfrags (ent);
} }
} }
} }