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"
|
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/msg.h"
|
2021-03-21 07:13:03 +00:00
|
|
|
#include "QF/plist.h"
|
2011-06-19 11:02:00 +00:00
|
|
|
#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"
|
2021-07-24 05:19:52 +00:00
|
|
|
#include "QF/scene/entity.h"
|
2022-03-04 16:48:10 +00:00
|
|
|
#include "QF/scene/scene.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
|
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"
|
2022-03-04 16:48:10 +00:00
|
|
|
#include "client/world.h"
|
2021-03-10 09:00:16 +00:00
|
|
|
|
2022-02-22 06:23:09 +00:00
|
|
|
#include "client/chase.h"
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#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
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
entity_t *cl_entities[MAX_EDICTS];
|
|
|
|
double cl_msgtime[MAX_EDICTS];
|
|
|
|
static byte forcelink_bytes[SET_SIZE(MAX_EDICTS)];
|
|
|
|
#define alloc_forcelink(s) (set_bits_t *)forcelink_bytes
|
|
|
|
set_t cl_forcelink = SET_STATIC_INIT (MAX_EDICTS, alloc_forcelink);
|
|
|
|
#undef alloc_forcelink
|
2012-06-26 06:12:17 +00:00
|
|
|
|
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
|
|
|
|
2021-03-21 14:05:13 +00:00
|
|
|
for (i = 0; i < MAX_EDICTS; i++) {
|
2022-03-04 16:48:10 +00:00
|
|
|
if (cl_entities[i]) {
|
|
|
|
Scene_DestroyEntity (cl_world.scene, cl_entities[i]);
|
|
|
|
cl_entities[i] = 0;
|
|
|
|
}
|
2021-03-21 14:05:13 +00:00
|
|
|
}
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// clear other arrays
|
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));
|
2022-03-04 16:48:10 +00:00
|
|
|
set_empty (&cl_forcelink);
|
|
|
|
}
|
|
|
|
|
|
|
|
entity_t *
|
|
|
|
CL_GetEntity (int num)
|
|
|
|
{
|
|
|
|
if (!cl_entities[num]) {
|
|
|
|
cl_entities[num] = Scene_CreateEntity (cl_world.scene);
|
|
|
|
CL_Init_Entity (cl_entities[num]);
|
|
|
|
}
|
|
|
|
return cl_entities[num];
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
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
|
2022-03-04 16:48:10 +00:00
|
|
|
set_entity_model (int ent_ind, int modelindex)
|
2012-06-26 06:12:17 +00:00
|
|
|
{
|
2022-03-04 16:48:10 +00:00
|
|
|
entity_t *ent = cl_entities[ent_ind];
|
2021-03-09 14:52:40 +00:00
|
|
|
renderer_t *renderer = &ent->renderer;
|
|
|
|
animation_t *animation = &ent->animation;
|
2022-03-04 16:48:10 +00:00
|
|
|
renderer->model = cl_world.models.a[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 {
|
2022-03-04 16:48:10 +00:00
|
|
|
// hack to make null model players work
|
|
|
|
SET_ADD (&cl_forcelink, ent_ind);
|
2012-06-26 06:12:17 +00:00
|
|
|
}
|
2021-03-09 14:52:40 +00:00
|
|
|
animation->nolerp = 1; // don't try to lerp when the model has changed
|
2022-03-04 16:48:10 +00:00
|
|
|
if (ent_ind <= cl.maxclients) {
|
|
|
|
renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin, ent_ind);
|
2021-03-09 14:52:40 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
// 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
|
|
|
}
|
2022-03-01 02:43:23 +00:00
|
|
|
VectorMultAdd (cl.frameViewAngles[1], frac, d,
|
|
|
|
cl.viewstate.player_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];
|
2022-03-04 16:48:10 +00:00
|
|
|
ent = CL_GetEntity (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) {
|
2022-03-07 04:40:04 +00:00
|
|
|
R_RemoveEfrags (ent); // just became empty
|
2021-03-09 14:52:40 +00:00
|
|
|
}
|
2011-06-19 11:02:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
if (SET_TEST_MEMBER (&cl_forcelink, i)) {
|
2012-06-26 11:45:47 +00:00
|
|
|
*old = *new;
|
2022-03-04 16:48:10 +00:00
|
|
|
}
|
2012-06-26 11:45:47 +00:00
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
if (SET_TEST_MEMBER (&cl_forcelink, i)
|
|
|
|
|| new->modelindex != old->modelindex) {
|
2012-06-26 06:12:17 +00:00
|
|
|
old->modelindex = new->modelindex;
|
2022-03-04 16:48:10 +00:00
|
|
|
set_entity_model (i, new->modelindex);
|
2012-06-26 06:12:17 +00:00
|
|
|
}
|
2021-03-09 14:52:40 +00:00
|
|
|
animation->frame = new->frame;
|
2022-03-04 16:48:10 +00:00
|
|
|
if (SET_TEST_MEMBER (&cl_forcelink, i)
|
|
|
|
|| new->colormap != old->colormap) {
|
2012-06-28 05:36:05 +00:00
|
|
|
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
|
|
|
}
|
2022-03-04 16:48:10 +00:00
|
|
|
if (SET_TEST_MEMBER (&cl_forcelink, i)
|
|
|
|
|| new->skinnum != old->skinnum) {
|
2012-06-26 06:12:17 +00:00
|
|
|
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);
|
2013-02-02 07:54:05 +00:00
|
|
|
mod_funcs->Skin_SetTranslation (i, cl.players[i - 1].topcolor,
|
|
|
|
cl.players[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
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
if (SET_TEST_MEMBER (&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) {
|
2022-03-07 04:40:04 +00:00
|
|
|
R_RemoveEfrags (ent);
|
2021-03-09 14:52:40 +00:00
|
|
|
}
|
2022-03-07 04:40:04 +00:00
|
|
|
R_AddEfrags (&cl_world.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
|
2022-03-07 04:40:04 +00:00
|
|
|
R_RemoveEfrags (ent);
|
|
|
|
R_AddEfrags (&cl_world.worldmodel->brush, ent);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-03-07 04:40:04 +00:00
|
|
|
R_AddEfrags (&cl_world.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;
|
2011-12-15 03:06:03 +00:00
|
|
|
}
|
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
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
SET_REMOVE (&cl_forcelink, i);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|
2022-03-04 16:48:10 +00:00
|
|
|
r_data->player_entity = CL_GetEntity (cl.viewentity);
|
|
|
|
cl.viewstate.player_entity = CL_GetEntity (cl.viewentity);
|
2022-03-01 02:43:23 +00:00
|
|
|
cl.viewstate.player_origin
|
2022-03-04 16:48:10 +00:00
|
|
|
= Transform_GetWorldPosition (cl.viewstate.player_entity->transform);
|
2011-06-19 11:02:00 +00:00
|
|
|
}
|