2021-03-11 02:25:04 +00:00
|
|
|
/*
|
|
|
|
cl_effect.c
|
|
|
|
|
|
|
|
Client side effect management
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2021 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2021/3/11
|
|
|
|
|
|
|
|
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
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/render.h"
|
|
|
|
|
|
|
|
#include "QF/plugin/vid_render.h" //FIXME
|
2021-07-24 05:19:52 +00:00
|
|
|
#include "QF/scene/entity.h"
|
2023-08-04 05:56:16 +00:00
|
|
|
#include "QF/scene/light.h"
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
#include "QF/scene/scene.h"
|
2021-03-11 02:25:04 +00:00
|
|
|
|
|
|
|
#include "client/entities.h"
|
|
|
|
#include "client/effects.h"
|
2021-12-19 04:08:39 +00:00
|
|
|
#include "client/particles.h"
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
#include "client/world.h"
|
2021-03-11 02:25:04 +00:00
|
|
|
|
|
|
|
void
|
2023-08-04 05:56:16 +00:00
|
|
|
CL_NewDlight (entity_t ent, vec4f_t org, int effects, byte glow_size,
|
2021-03-11 02:25:04 +00:00
|
|
|
byte glow_color, double time)
|
|
|
|
{
|
2023-08-04 05:56:16 +00:00
|
|
|
static vec4f_t normal = {0.4, 0.2, 0.05, 0.7};
|
|
|
|
static vec4f_t red = {0.5, 0.05, 0.05, 0.7};
|
|
|
|
static vec4f_t blue = {0.05, 0.05, 0.5, 0.7};
|
|
|
|
static vec4f_t purple = {0.5, 0.05, 0.5, 0.7};
|
2021-03-11 02:25:04 +00:00
|
|
|
|
|
|
|
effects &= EF_BLUE | EF_RED | EF_BRIGHTLIGHT | EF_DIMLIGHT;
|
|
|
|
if (!effects) {
|
|
|
|
if (!glow_size)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-04 05:56:16 +00:00
|
|
|
float radius = 0;
|
|
|
|
float die = time + 0.1;
|
|
|
|
vec4f_t color = normal;
|
2021-03-11 02:25:04 +00:00
|
|
|
|
|
|
|
if (effects & (EF_BLUE | EF_RED | EF_BRIGHTLIGHT | EF_DIMLIGHT)) {
|
|
|
|
radius = 200 + (rand () & 31);
|
|
|
|
if (effects & EF_BRIGHTLIGHT) {
|
|
|
|
radius += 200;
|
2023-08-04 05:56:16 +00:00
|
|
|
org[2] += 16;
|
2021-03-11 02:25:04 +00:00
|
|
|
}
|
|
|
|
if (effects & EF_DIMLIGHT)
|
|
|
|
if (effects & ~EF_DIMLIGHT)
|
|
|
|
radius -= 100;
|
2023-08-04 05:56:16 +00:00
|
|
|
radius = radius;
|
2021-03-11 02:25:04 +00:00
|
|
|
|
|
|
|
switch (effects & (EF_RED | EF_BLUE)) {
|
2023-08-04 05:56:16 +00:00
|
|
|
case EF_RED | EF_BLUE: color = purple; break;
|
|
|
|
case EF_RED: color = red; break;
|
|
|
|
case EF_BLUE: color = blue; break;
|
|
|
|
default: color = normal; break;
|
2021-03-11 02:25:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glow_size) {
|
2023-08-04 05:56:16 +00:00
|
|
|
radius += glow_size < 128 ? glow_size * 8.0 : (glow_size - 256) * 8.0;
|
2021-03-11 02:25:04 +00:00
|
|
|
if (glow_color) {
|
|
|
|
if (glow_color == 255) {
|
2023-08-04 05:56:16 +00:00
|
|
|
color = (vec4f_t) { 1, 1, 1, 0.7 };
|
2021-03-11 02:25:04 +00:00
|
|
|
} else {
|
|
|
|
byte *tempcolor;
|
|
|
|
|
|
|
|
tempcolor = (byte *) &d_8to24table[glow_color];
|
2023-08-04 05:56:16 +00:00
|
|
|
VectorScale (tempcolor, 1 / 255.0, color);
|
|
|
|
color[3] = 0.7;
|
2021-03-11 02:25:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-04 05:56:16 +00:00
|
|
|
|
|
|
|
Ent_SetComponent (ent.id, scene_dynlight, ent.reg, &(dlight_t) {
|
|
|
|
.origin = org,
|
|
|
|
.color = color,
|
|
|
|
.radius = radius,
|
|
|
|
.die = die,
|
|
|
|
});
|
|
|
|
Light_LinkLight (cl_world.scene->lights, ent.id);
|
2021-03-11 02:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-08-04 05:56:16 +00:00
|
|
|
CL_ModelEffects (entity_t ent, int glow_color, double time)
|
2021-03-11 02:25:04 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
transform_t transform = Entity_Transform (ent);
|
|
|
|
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
|
|
|
|
model_t *model = renderer->model;
|
|
|
|
vec4f_t *old_origin = Ent_GetComponent (ent.id, scene_old_origin, cl_world.scene->reg);
|
|
|
|
vec4f_t ent_origin = Transform_GetWorldPosition (transform);
|
2021-03-11 02:25:04 +00:00
|
|
|
|
|
|
|
// add automatic particle trails
|
|
|
|
if (model->flags & EF_ROCKET) {
|
2023-08-04 05:56:16 +00:00
|
|
|
Ent_SetComponent (ent.id, scene_dynlight, ent.reg, &(dlight_t) {
|
|
|
|
.origin = ent_origin,
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
//FIXME VectorCopy (r_firecolor, dl->color);
|
2023-08-04 05:56:16 +00:00
|
|
|
.color = { 0.9, 0.7, 0.0, 0.7 },
|
|
|
|
.radius = 200,
|
|
|
|
.die = time + 0.1,
|
|
|
|
});
|
|
|
|
Light_LinkLight (cl_world.scene->lights, ent.id);
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
clp_funcs->RocketTrail (*old_origin, ent_origin);
|
2021-03-11 02:25:04 +00:00
|
|
|
} else if (model->flags & EF_GRENADE)
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
clp_funcs->GrenadeTrail (*old_origin, ent_origin);
|
2021-03-11 02:25:04 +00:00
|
|
|
else if (model->flags & EF_GIB)
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
clp_funcs->BloodTrail (*old_origin, ent_origin);
|
2021-03-11 02:25:04 +00:00
|
|
|
else if (model->flags & EF_ZOMGIB)
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
clp_funcs->SlightBloodTrail (*old_origin, ent_origin);
|
2021-03-11 02:25:04 +00:00
|
|
|
else if (model->flags & EF_TRACER)
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
clp_funcs->WizTrail (*old_origin, ent_origin);
|
2021-03-11 02:25:04 +00:00
|
|
|
else if (model->flags & EF_TRACER2)
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
clp_funcs->FlameTrail (*old_origin, ent_origin);
|
2021-03-11 02:25:04 +00:00
|
|
|
else if (model->flags & EF_TRACER3)
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
clp_funcs->VoorTrail (*old_origin, ent_origin);
|
2021-03-11 02:25:04 +00:00
|
|
|
else if (model->flags & EF_GLOWTRAIL)
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
clp_funcs->GlowTrail (*old_origin, ent_origin, glow_color);
|
2021-03-11 02:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-08-04 05:56:16 +00:00
|
|
|
CL_MuzzleFlash (entity_t ent, vec4f_t position, vec4f_t fv, float zoffset,
|
2021-03-11 06:23:35 +00:00
|
|
|
double time)
|
2021-03-11 02:25:04 +00:00
|
|
|
{
|
2023-08-04 05:56:16 +00:00
|
|
|
Ent_SetComponent (ent.id, scene_dynlight, ent.reg, &(dlight_t) {
|
|
|
|
.origin = position + 18 * fv + zoffset * (vec4f_t) {0, 0, 1, 0},
|
|
|
|
.color = { 0.2, 0.1, 0.05, 0.7 },
|
|
|
|
.radius = 200 + (rand () & 31),
|
|
|
|
.die = time + 0.1,
|
|
|
|
.minlight = 32,
|
|
|
|
});
|
|
|
|
Light_LinkLight (cl_world.scene->lights, ent.id);
|
2021-03-11 06:23:35 +00:00
|
|
|
}
|
2021-03-11 02:25:04 +00:00
|
|
|
|
2021-03-11 06:23:35 +00:00
|
|
|
void
|
2023-08-04 05:56:16 +00:00
|
|
|
CL_EntityEffects (entity_t ent, entity_state_t *state, double time)
|
2021-03-11 06:23:35 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
transform_t transform = Entity_Transform (ent);
|
|
|
|
vec4f_t position = Transform_GetWorldPosition (transform);
|
2021-03-11 02:25:04 +00:00
|
|
|
if (state->effects & EF_BRIGHTFIELD)
|
2021-12-19 04:08:39 +00:00
|
|
|
clp_funcs->EntityParticles (position);
|
2021-03-11 02:25:04 +00:00
|
|
|
if (state->effects & EF_MUZZLEFLASH) {
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
vec4f_t fv = Transform_Forward (transform);
|
2023-08-04 05:56:16 +00:00
|
|
|
CL_MuzzleFlash (ent, position, fv, 16, time);
|
2021-03-11 02:25:04 +00:00
|
|
|
}
|
|
|
|
}
|