2011-06-19 11:02:00 +00:00
|
|
|
/*
|
2011-08-27 01:25:41 +00:00
|
|
|
cl_ents.c
|
2011-06-19 11:02:00 +00:00
|
|
|
|
|
|
|
entity parsing and management
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cbuf.h"
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
2021-03-09 14:52:40 +00:00
|
|
|
#include "QF/entity.h"
|
2011-06-19 11:02:00 +00:00
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/msg.h"
|
|
|
|
#include "QF/qfplist.h"
|
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/screen.h"
|
|
|
|
#include "QF/skin.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "QF/plugin/vid_render.h"
|
|
|
|
|
2011-06-19 11:02:00 +00:00
|
|
|
#include "compat.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
2021-03-11 02:25:04 +00:00
|
|
|
#include "client/effects.h"
|
2021-03-10 09:00:16 +00:00
|
|
|
#include "client/temp_entities.h"
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "nq/include/chase.h"
|
|
|
|
#include "nq/include/client.h"
|
|
|
|
#include "nq/include/host.h"
|
|
|
|
#include "nq/include/host.h"
|
|
|
|
#include "nq/include/server.h"
|
2011-06-19 11:02:00 +00:00
|
|
|
|
2012-06-26 06:12:17 +00:00
|
|
|
entity_t cl_entities[MAX_EDICTS];
|
|
|
|
double cl_msgtime[MAX_EDICTS];
|
|
|
|
byte cl_forcelink[MAX_EDICTS];
|
|
|
|
|
2011-06-19 11:02:00 +00:00
|
|
|
void
|
|
|
|
CL_ClearEnts (void)
|
|
|
|
{
|
2011-08-27 01:25:41 +00:00
|
|
|
size_t i;
|
2011-06-19 11:02:00 +00:00
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// clear other arrays
|
2011-06-19 11:02:00 +00:00
|
|
|
memset (cl_entities, 0, sizeof (cl_entities));
|
2012-07-01 02:36:47 +00:00
|
|
|
i = nq_entstates.num_frames * nq_entstates.num_entities;
|
|
|
|
memset (nq_entstates.frame[0], 0, i * sizeof (entity_state_t));
|
2012-06-26 06:12:17 +00:00
|
|
|
memset (cl_msgtime, 0, sizeof (cl_msgtime));
|
|
|
|
memset (cl_forcelink, 0, sizeof (cl_forcelink));
|
2011-06-19 11:02:00 +00:00
|
|
|
|
2012-06-26 06:12:17 +00:00
|
|
|
for (i = 0; i < MAX_EDICTS; i++)
|
2011-06-19 11:02:00 +00:00
|
|
|
CL_Init_Entity (cl_entities + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CL_LerpPoint
|
|
|
|
|
2011-08-27 01:25:41 +00:00
|
|
|
Determines the fraction between the last two messages at which the
|
|
|
|
objects should be put.
|
2011-06-19 11:02:00 +00:00
|
|
|
*/
|
|
|
|
static float
|
|
|
|
CL_LerpPoint (void)
|
|
|
|
{
|
|
|
|
float f, frac;
|
|
|
|
|
|
|
|
f = cl.mtime[0] - cl.mtime[1];
|
|
|
|
|
|
|
|
if (!f || cl_nolerp->int_val || cls.timedemo || sv.active) {
|
|
|
|
cl.time = cl.mtime[0];
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f > 0.1) { // dropped packet, or start of demo
|
|
|
|
cl.mtime[1] = cl.mtime[0] - 0.1;
|
|
|
|
f = 0.1;
|
|
|
|
}
|
|
|
|
frac = (cl.time - cl.mtime[1]) / f;
|
|
|
|
|
|
|
|
if (frac < 0) {
|
|
|
|
if (frac < -0.01)
|
|
|
|
cl.time = cl.mtime[1];
|
|
|
|
frac = 0;
|
|
|
|
} else if (frac > 1) {
|
|
|
|
if (frac > 1.01)
|
|
|
|
cl.time = cl.mtime[0];
|
|
|
|
frac = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return frac;
|
|
|
|
}
|
|
|
|
|
2012-06-26 06:12:17 +00:00
|
|
|
static void
|
|
|
|
set_entity_model (entity_t *ent, int modelindex)
|
|
|
|
{
|
|
|
|
int i = ent - cl_entities;
|
2021-03-09 14:52:40 +00:00
|
|
|
renderer_t *renderer = &ent->renderer;
|
|
|
|
animation_t *animation = &ent->animation;
|
|
|
|
renderer->model = cl.model_precache[modelindex];
|
2012-06-26 06:12:17 +00:00
|
|
|
// automatic animation (torches, etc) can be either all together
|
|
|
|
// or randomized
|
2021-03-09 14:52:40 +00:00
|
|
|
if (renderer->model) {
|
|
|
|
if (renderer->model->synctype == ST_RAND) {
|
|
|
|
animation->syncbase = (float) (rand () & 0x7fff) / 0x7fff;
|
|
|
|
} else {
|
|
|
|
animation->syncbase = 0.0;
|
|
|
|
}
|
2012-06-26 06:12:17 +00:00
|
|
|
} else {
|
|
|
|
cl_forcelink[i] = true; // hack to make null model players work
|
|
|
|
}
|
2021-03-09 14:52:40 +00:00
|
|
|
animation->nolerp = 1; // don't try to lerp when the model has changed
|
|
|
|
if (i <= cl.maxclients) {
|
|
|
|
renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin, i);
|
|
|
|
}
|
2012-06-26 06:12:17 +00:00
|
|
|
}
|
|
|
|
|
2011-06-19 11:02:00 +00:00
|
|
|
void
|
|
|
|
CL_RelinkEntities (void)
|
|
|
|
{
|
|
|
|
entity_t *ent;
|
2012-06-26 06:12:17 +00:00
|
|
|
entity_state_t *new, *old;
|
2021-03-09 14:52:40 +00:00
|
|
|
renderer_t *renderer;
|
|
|
|
animation_t *animation;
|
2021-03-19 11:18:45 +00:00
|
|
|
float bobjrotate, frac, f;
|
2011-06-19 11:02:00 +00:00
|
|
|
int i, j;
|
2012-07-21 06:39:11 +00:00
|
|
|
int entvalid;
|
2013-11-27 07:08:30 +00:00
|
|
|
int model_flags;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
r_data->player_entity = &cl_entities[cl.viewentity];
|
2011-06-19 11:02:00 +00:00
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// determine partial update time
|
2011-06-19 11:02:00 +00:00
|
|
|
frac = CL_LerpPoint ();
|
|
|
|
|
|
|
|
// interpolate player info
|
2021-03-19 11:18:45 +00:00
|
|
|
cl.viewstate.velocity = cl.frameVelocity[1]
|
2021-03-11 07:19:49 +00:00
|
|
|
+ frac * (cl.frameVelocity[0] - cl.frameVelocity[1]);
|
2011-06-19 11:02:00 +00:00
|
|
|
|
|
|
|
if (cls.demoplayback) {
|
2012-05-21 23:23:22 +00:00
|
|
|
// interpolate the angles
|
2021-03-19 11:18:45 +00:00
|
|
|
vec3_t d;
|
|
|
|
VectorSubtract (cl.frameViewAngles[0], cl.frameViewAngles[1], d);
|
2011-06-19 11:02:00 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2021-03-19 11:18:45 +00:00
|
|
|
if (d[j] > 180) {
|
|
|
|
d[j] -= 360;
|
|
|
|
} else if (d[j] < -180) {
|
|
|
|
d[j] += 360;
|
|
|
|
}
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorMultAdd (cl.frameViewAngles[1], frac, d, cl.viewstate.angles);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bobjrotate = anglemod (100 * cl.time);
|
|
|
|
|
|
|
|
// start on the entity after the world
|
2012-06-26 06:12:17 +00:00
|
|
|
for (i = 1; i < cl.num_entities; i++) {
|
2021-03-11 07:19:49 +00:00
|
|
|
new = &nq_entstates.frame[0 + cl.frameIndex][i];
|
|
|
|
old = &nq_entstates.frame[1 - cl.frameIndex][i];
|
2012-06-26 06:12:17 +00:00
|
|
|
ent = &cl_entities[i];
|
2021-03-09 14:52:40 +00:00
|
|
|
renderer = &ent->renderer;
|
|
|
|
animation = &ent->animation;
|
|
|
|
|
2011-06-19 11:02:00 +00:00
|
|
|
// if the object wasn't included in the last packet, remove it
|
2012-07-21 06:39:11 +00:00
|
|
|
entvalid = cl_msgtime[i] == cl.mtime[0];
|
|
|
|
if (entvalid && !new->modelindex) {
|
2021-03-19 11:18:45 +00:00
|
|
|
CL_TransformEntity (ent, new->scale / 16.0, new->angles,
|
|
|
|
new->origin);
|
2012-07-21 06:39:11 +00:00
|
|
|
entvalid = 0;
|
|
|
|
}
|
|
|
|
if (!entvalid) {
|
2021-03-09 14:52:40 +00:00
|
|
|
renderer->model = NULL;
|
|
|
|
animation->pose1 = animation->pose2 = -1;
|
|
|
|
if (ent->visibility.efrag) {
|
2012-02-14 08:28:09 +00:00
|
|
|
r_funcs->R_RemoveEfrags (ent); // just became empty
|
2021-03-09 14:52:40 +00:00
|
|
|
}
|
2011-06-19 11:02:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-06-26 11:45:47 +00:00
|
|
|
if (cl_forcelink[i])
|
|
|
|
*old = *new;
|
|
|
|
|
2012-06-26 06:12:17 +00:00
|
|
|
if (cl_forcelink[i] || new->modelindex != old->modelindex) {
|
|
|
|
old->modelindex = new->modelindex;
|
|
|
|
set_entity_model (ent, new->modelindex);
|
|
|
|
}
|
2021-03-09 14:52:40 +00:00
|
|
|
animation->frame = new->frame;
|
2012-06-28 05:36:05 +00:00
|
|
|
if (cl_forcelink[i] || new->colormap != old->colormap) {
|
|
|
|
old->colormap = new->colormap;
|
2021-03-09 14:52:40 +00:00
|
|
|
renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin,
|
|
|
|
new->colormap);
|
2012-06-26 06:12:17 +00:00
|
|
|
}
|
|
|
|
if (cl_forcelink[i] || new->skinnum != old->skinnum) {
|
|
|
|
old->skinnum = new->skinnum;
|
2021-03-09 14:52:40 +00:00
|
|
|
renderer->skinnum = new->skinnum;
|
2012-06-26 06:12:17 +00:00
|
|
|
if (i <= cl.maxclients) {
|
2021-03-09 14:52:40 +00:00
|
|
|
renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin,
|
|
|
|
i);
|
2012-07-02 10:24:39 +00:00
|
|
|
mod_funcs->Skin_SetTranslation (i, cl.scores[i - 1].topcolor,
|
|
|
|
cl.scores[i - 1].bottomcolor);
|
2012-06-26 06:12:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
VectorCopy (ent_colormod[new->colormod], renderer->colormod);
|
|
|
|
renderer->colormod[3] = ENTALPHA_DECODE (new->alpha);
|
2011-06-19 11:02:00 +00:00
|
|
|
|
2013-11-27 07:08:30 +00:00
|
|
|
model_flags = 0;
|
2021-03-09 14:52:40 +00:00
|
|
|
if (renderer->model) {
|
|
|
|
model_flags = renderer->model->flags;
|
|
|
|
}
|
2011-06-19 11:02:00 +00:00
|
|
|
|
2012-06-26 06:12:17 +00:00
|
|
|
if (cl_forcelink[i]) {
|
2011-06-19 11:02:00 +00:00
|
|
|
// The entity was not updated in the last message so move to the
|
|
|
|
// final spot
|
2021-03-09 14:52:40 +00:00
|
|
|
animation->pose1 = animation->pose2 = -1;
|
2021-03-19 11:18:45 +00:00
|
|
|
CL_TransformEntity (ent, new->scale / 16.0, new->angles,
|
|
|
|
new->origin);
|
2011-06-19 11:02:00 +00:00
|
|
|
if (i != cl.viewentity || chase_active->int_val) {
|
2021-03-09 14:52:40 +00:00
|
|
|
if (ent->visibility.efrag) {
|
2012-02-14 08:28:09 +00:00
|
|
|
r_funcs->R_RemoveEfrags (ent);
|
2021-03-09 14:52:40 +00:00
|
|
|
}
|
2021-02-01 10:31:11 +00:00
|
|
|
r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
2021-03-19 11:18:45 +00:00
|
|
|
ent->old_origin = new->origin;
|
2011-06-19 11:02:00 +00:00
|
|
|
} else {
|
2021-03-19 11:18:45 +00:00
|
|
|
vec4f_t delta = new->origin - old->origin;
|
2011-06-19 11:02:00 +00:00
|
|
|
f = frac;
|
2021-03-19 11:18:45 +00:00
|
|
|
ent->old_origin = Transform_GetWorldPosition (ent->transform);
|
2012-07-05 10:06:35 +00:00
|
|
|
// If the delta is large, assume a teleport and don't lerp
|
2011-06-19 11:02:00 +00:00
|
|
|
if (fabs (delta[0]) > 100 || fabs (delta[1] > 100)
|
|
|
|
|| fabs (delta[2]) > 100) {
|
|
|
|
// assume a teleportation, not a motion
|
2021-03-19 11:18:45 +00:00
|
|
|
CL_TransformEntity (ent, new->scale / 16.0, new->angles,
|
|
|
|
new->origin);
|
2021-03-09 14:52:40 +00:00
|
|
|
animation->pose1 = animation->pose2 = -1;
|
2011-06-19 11:02:00 +00:00
|
|
|
} else {
|
2011-12-13 07:57:45 +00:00
|
|
|
// interpolate the origin and angles
|
2021-03-19 11:18:45 +00:00
|
|
|
vec3_t angles, d;
|
|
|
|
vec4f_t origin = old->origin + f * delta;
|
2013-11-27 07:08:30 +00:00
|
|
|
if (!(model_flags & EF_ROTATE)) {
|
2012-06-26 06:12:17 +00:00
|
|
|
VectorSubtract (new->angles, old->angles, d);
|
2011-12-15 03:06:03 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
if (d[j] > 180)
|
|
|
|
d[j] -= 360;
|
|
|
|
else if (d[j] < -180)
|
|
|
|
d[j] += 360;
|
|
|
|
}
|
2012-06-26 06:12:17 +00:00
|
|
|
VectorMultAdd (old->angles, f, d, angles);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
2021-03-19 11:18:45 +00:00
|
|
|
CL_TransformEntity (ent, new->scale / 16.0, angles, origin);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
|
|
|
if (i != cl.viewentity || chase_active->int_val) {
|
2021-03-09 14:52:40 +00:00
|
|
|
if (ent->visibility.efrag) {
|
2021-03-19 11:18:45 +00:00
|
|
|
vec4f_t org
|
|
|
|
= Transform_GetWorldPosition (ent->transform);
|
|
|
|
if (!VectorCompare (org, ent->old_origin)) {//FIXME
|
2012-02-14 08:28:09 +00:00
|
|
|
r_funcs->R_RemoveEfrags (ent);
|
2021-02-01 10:31:11 +00:00
|
|
|
r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-02-01 10:31:11 +00:00
|
|
|
r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// rotate binary objects locally
|
2013-11-27 07:08:30 +00:00
|
|
|
if (model_flags & EF_ROTATE) {
|
2011-12-15 03:06:03 +00:00
|
|
|
vec3_t angles;
|
2012-06-26 06:12:17 +00:00
|
|
|
VectorCopy (new->angles, angles);
|
2011-12-15 03:06:03 +00:00
|
|
|
angles[YAW] = bobjrotate;
|
2021-03-19 11:18:45 +00:00
|
|
|
CL_TransformEntity (ent, new->scale / 16.0, angles, new->origin);
|
2011-12-15 03:06:03 +00:00
|
|
|
}
|
2021-03-11 02:25:04 +00:00
|
|
|
CL_EntityEffects (i, ent, new, cl.time);
|
2021-03-19 11:18:45 +00:00
|
|
|
vec4f_t org = Transform_GetWorldPosition (ent->transform);
|
2021-03-11 07:19:49 +00:00
|
|
|
CL_NewDlight (i, org, new->effects, new->glow_size,
|
2021-03-11 02:25:04 +00:00
|
|
|
new->glow_color, cl.time);
|
2021-03-19 11:18:45 +00:00
|
|
|
if (VectorDistance_fast (old->origin, org) > (256 * 256)) {
|
|
|
|
old->origin = org;
|
|
|
|
}
|
2013-11-27 07:08:30 +00:00
|
|
|
if (model_flags & ~EF_ROTATE)
|
2021-03-11 02:25:04 +00:00
|
|
|
CL_ModelEffects (ent, i, new->glow_color, cl.time);
|
2011-06-19 11:02:00 +00:00
|
|
|
|
2012-06-26 06:12:17 +00:00
|
|
|
cl_forcelink[i] = false;
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
2021-03-19 11:18:45 +00:00
|
|
|
cl.viewstate.origin
|
|
|
|
= Transform_GetWorldPosition (cl_entities[cl.viewentity].transform);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|