2001-04-04 21:53:09 +00:00
|
|
|
/*
|
|
|
|
r_efrag.c
|
|
|
|
|
2001-05-15 20:03:56 +00:00
|
|
|
(description)
|
2001-04-04 21:53:09 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2004-11-02 07:42:00 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-05-20 01:58:59 +00:00
|
|
|
#include "QF/render.h"
|
2001-04-04 21:53:09 +00:00
|
|
|
#include "QF/sys.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
|
2021-07-24 05:19:52 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2021-03-03 07:21:37 +00:00
|
|
|
#include "qfalloca.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-04-04 21:53:09 +00:00
|
|
|
|
2004-11-02 07:42:00 +00:00
|
|
|
typedef struct s_efrag_list {
|
|
|
|
struct s_efrag_list *next;
|
|
|
|
efrag_t efrags[MAX_EFRAGS];
|
|
|
|
} t_efrag_list;
|
|
|
|
|
|
|
|
static efrag_t *r_free_efrags;
|
|
|
|
static t_efrag_list *efrag_list;
|
2001-04-04 21:53:09 +00:00
|
|
|
|
2022-03-07 04:40:04 +00:00
|
|
|
entqueue_t *r_ent_queue;
|
|
|
|
|
2001-09-09 21:41:35 +00:00
|
|
|
/* ENTITY FRAGMENT FUNCTIONS */
|
2001-04-04 21:53:09 +00:00
|
|
|
|
2004-11-02 07:42:00 +00:00
|
|
|
static inline void
|
|
|
|
init_efrag_list (t_efrag_list *efl)
|
|
|
|
{
|
|
|
|
int i;
|
2001-04-04 21:53:09 +00:00
|
|
|
|
2004-11-02 07:42:00 +00:00
|
|
|
for (i = 0; i < MAX_EFRAGS - 1; i++)
|
|
|
|
efl->efrags[i].entnext = &efl->efrags[i + 1];
|
2012-01-03 14:19:21 +00:00
|
|
|
efl->efrags[i].entnext = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efrag_t *
|
|
|
|
new_efrag (void)
|
|
|
|
{
|
|
|
|
efrag_t *ef;
|
|
|
|
|
|
|
|
if (__builtin_expect (!r_free_efrags, 0)) {
|
|
|
|
t_efrag_list *efl = calloc (1, sizeof (t_efrag_list));
|
|
|
|
SYS_CHECKMEM (efl);
|
|
|
|
efl->next = efrag_list;
|
|
|
|
efrag_list = efl;
|
|
|
|
init_efrag_list (efl);
|
|
|
|
r_free_efrags = &efl->efrags[0];
|
|
|
|
}
|
|
|
|
ef = r_free_efrags;
|
|
|
|
r_free_efrags = ef->entnext;
|
|
|
|
ef->entnext = 0;
|
|
|
|
return ef;
|
2004-11-02 07:42:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_ClearEfrags (void)
|
|
|
|
{
|
|
|
|
t_efrag_list *efl;
|
|
|
|
|
|
|
|
if (!efrag_list)
|
|
|
|
efrag_list = calloc (1, sizeof (t_efrag_list));
|
|
|
|
|
2021-01-09 11:42:23 +00:00
|
|
|
r_free_efrags = efrag_list->efrags;
|
2004-11-02 07:42:00 +00:00
|
|
|
for (efl = efrag_list; efl; efl = efl->next) {
|
|
|
|
init_efrag_list (efl);
|
|
|
|
if (efl->next)
|
|
|
|
efl->efrags[MAX_EFRAGS - 1].entnext = &efl->next->efrags[0];
|
|
|
|
}
|
|
|
|
}
|
2001-04-04 21:53:09 +00:00
|
|
|
|
|
|
|
void
|
2022-11-13 06:08:18 +00:00
|
|
|
R_ClearEfragChain (efrag_t *ef)
|
2001-04-04 21:53:09 +00:00
|
|
|
{
|
2022-11-13 06:08:18 +00:00
|
|
|
efrag_t *old, *walk, **prev;
|
2001-04-04 21:53:09 +00:00
|
|
|
|
|
|
|
while (ef) {
|
|
|
|
prev = &ef->leaf->efrags;
|
2022-11-17 12:57:53 +00:00
|
|
|
while ((walk = *prev)) {
|
2001-04-04 21:53:09 +00:00
|
|
|
if (walk == ef) { // remove this fragment
|
|
|
|
*prev = ef->leafnext;
|
|
|
|
break;
|
2022-11-17 12:57:53 +00:00
|
|
|
} else {
|
2001-04-04 21:53:09 +00:00
|
|
|
prev = &walk->leafnext;
|
2022-11-17 12:57:53 +00:00
|
|
|
}
|
2001-04-04 21:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
old = ef;
|
|
|
|
ef = ef->entnext;
|
|
|
|
|
|
|
|
// put it on the free list
|
2001-05-20 01:58:59 +00:00
|
|
|
old->entnext = r_free_efrags;
|
|
|
|
r_free_efrags = old;
|
2001-04-04 21:53:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
[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
|
|
|
R_SplitEntityOnNode (mod_brush_t *brush, entity_t ent, uint32_t queue,
|
|
|
|
visibility_t *visibility, vec3_t emins, vec3_t emaxs)
|
2001-04-04 21:53:09 +00:00
|
|
|
{
|
|
|
|
efrag_t *ef;
|
2011-11-14 02:18:22 +00:00
|
|
|
plane_t *splitplane;
|
2001-04-04 21:53:09 +00:00
|
|
|
mleaf_t *leaf;
|
|
|
|
int sides;
|
2021-03-03 07:21:37 +00:00
|
|
|
efrag_t **lastlink;
|
2022-05-22 02:18:32 +00:00
|
|
|
int *node_stack;
|
|
|
|
int *node_ptr;
|
2021-03-03 07:21:37 +00:00
|
|
|
|
|
|
|
node_stack = alloca ((brush->depth + 2) * sizeof (mnode_t *));
|
|
|
|
node_ptr = node_stack;
|
|
|
|
|
[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
|
|
|
lastlink = &visibility->efrag;
|
2001-04-04 21:53:09 +00:00
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
*node_ptr++ = brush->numnodes;
|
2002-04-25 04:32:55 +00:00
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
int node_id = 0;
|
|
|
|
while (node_id != (int) brush->numnodes) {
|
2002-04-25 04:32:55 +00:00
|
|
|
// add an efrag if the node is a leaf
|
2022-05-22 02:18:32 +00:00
|
|
|
if (__builtin_expect (node_id < 0, 0)) {
|
[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
|
|
|
if (visibility->topnode_id == -1) {
|
|
|
|
visibility->topnode_id = node_id;
|
2021-03-03 07:21:37 +00:00
|
|
|
}
|
2002-04-25 04:32:55 +00:00
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
leaf = brush->leafs + ~node_id;
|
2002-04-25 04:32:55 +00:00
|
|
|
|
2012-01-03 14:19:21 +00:00
|
|
|
ef = new_efrag (); // ensures ef->entnext is 0
|
2002-04-25 04:32:55 +00:00
|
|
|
|
2012-01-03 14:19:21 +00:00
|
|
|
// add the link to the chain of links on the entity
|
2021-03-03 07:21:37 +00:00
|
|
|
ef->entity = ent;
|
[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
|
|
|
ef->queue_num = queue;
|
2002-04-25 04:32:55 +00:00
|
|
|
*lastlink = ef;
|
|
|
|
lastlink = &ef->entnext;
|
|
|
|
|
2012-01-03 14:19:21 +00:00
|
|
|
// add the link too the chain of links on the leaf
|
2002-04-25 04:32:55 +00:00
|
|
|
ef->leaf = leaf;
|
|
|
|
ef->leafnext = leaf->efrags;
|
|
|
|
leaf->efrags = ef;
|
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = *--node_ptr;
|
2002-04-25 04:32:55 +00:00
|
|
|
} else {
|
2022-05-22 02:18:32 +00:00
|
|
|
mnode_t *node = brush->nodes + node_id;
|
2002-04-25 04:32:55 +00:00
|
|
|
// NODE_MIXED
|
2022-05-22 02:18:32 +00:00
|
|
|
splitplane = (plane_t *) &node->plane;
|
2021-03-03 07:21:37 +00:00
|
|
|
sides = BOX_ON_PLANE_SIDE (emins, emaxs, splitplane);
|
2002-04-25 04:32:55 +00:00
|
|
|
|
|
|
|
if (sides == 3) {
|
|
|
|
// split on this plane
|
|
|
|
// if this is the first splitter of this bmodel, remember it
|
[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
|
|
|
if (visibility->topnode_id == -1) {
|
|
|
|
visibility->topnode_id = node_id;
|
2021-03-03 07:21:37 +00:00
|
|
|
}
|
2002-04-25 04:32:55 +00:00
|
|
|
}
|
|
|
|
// recurse down the contacted sides
|
2022-05-22 02:18:32 +00:00
|
|
|
if (sides & 1) {
|
|
|
|
if (sides & 2)
|
2021-03-03 07:21:37 +00:00
|
|
|
*node_ptr++ = node->children[1];
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = node->children[0];
|
2002-04-25 04:32:55 +00:00
|
|
|
} else {
|
2022-05-22 02:18:32 +00:00
|
|
|
if (sides & 2)
|
|
|
|
node_id = node->children[1];
|
2002-04-25 04:32:55 +00:00
|
|
|
else
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = *--node_ptr;
|
2002-04-25 04:32:55 +00:00
|
|
|
}
|
2001-04-04 21:53:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
[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
|
|
|
R_AddEfrags (mod_brush_t *brush, entity_t ent)
|
2001-04-04 21:53:09 +00:00
|
|
|
{
|
|
|
|
model_t *entmodel;
|
2021-03-03 07:21:37 +00:00
|
|
|
vec3_t emins, emaxs;
|
[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 *rend = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
|
2001-04-04 21:53:09 +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
|
|
|
if (!rend->model) {
|
2022-11-13 06:08:18 +00:00
|
|
|
Ent_RemoveComponent (ent.id, scene_visibility, ent.reg);
|
2001-04-04 21:53:09 +00:00
|
|
|
return;
|
2022-03-07 04:40:04 +00:00
|
|
|
}
|
2022-11-13 06:08:18 +00:00
|
|
|
visibility_t *vis;
|
|
|
|
if (Ent_HasComponent (ent.id, scene_visibility, ent.reg)) {
|
|
|
|
vis = Ent_GetComponent (ent.id, scene_visibility, ent.reg);
|
|
|
|
R_ClearEfragChain (vis->efrag);
|
|
|
|
} else {
|
|
|
|
vis = Ent_AddComponent (ent.id, scene_visibility, ent.reg);
|
|
|
|
}
|
|
|
|
vis->efrag = 0;
|
2001-04-04 21:53:09 +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
|
|
|
entmodel = rend->model;
|
2001-04-04 21:53:09 +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
|
|
|
vec4f_t org = Transform_GetWorldPosition (transform);
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorAdd (org, entmodel->mins, emins);
|
|
|
|
VectorAdd (org, entmodel->maxs, emaxs);
|
2001-04-04 21:53:09 +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
|
|
|
vis->topnode_id = -1; // leaf 0 (solid space)
|
|
|
|
R_SplitEntityOnNode (brush, ent, rend->model->type, vis, emins, emaxs);
|
2001-04-04 21:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-03-09 02:37:47 +00:00
|
|
|
R_StoreEfrags (const efrag_t *efrag)
|
2001-04-04 21:53:09 +00:00
|
|
|
{
|
2021-03-09 02:37:47 +00:00
|
|
|
while (efrag) {
|
[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
|
|
|
entity_t ent = efrag->entity;
|
|
|
|
EntQueue_AddEntity (r_ent_queue, ent, efrag->queue_num);
|
2022-03-30 02:05:16 +00:00
|
|
|
efrag = efrag->leafnext;
|
2001-04-04 21:53:09 +00:00
|
|
|
}
|
|
|
|
}
|