2021-07-24 05:19:52 +00:00
|
|
|
/*
|
|
|
|
scene.c
|
|
|
|
|
|
|
|
General scene handling
|
|
|
|
|
|
|
|
Copyright (C) 2021 Bill Currke
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-05-04 09:00:35 +00:00
|
|
|
#include "QF/mathlib.h"
|
2022-02-14 07:41:38 +00:00
|
|
|
#include "QF/sys.h"
|
2022-05-05 12:30:14 +00:00
|
|
|
#include "QF/model.h"
|
2021-07-24 05:19:52 +00:00
|
|
|
|
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
#include "QF/scene/scene.h"
|
|
|
|
#include "QF/scene/transform.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
|
|
|
static void
|
|
|
|
create_active (void *_active)
|
|
|
|
{
|
|
|
|
byte *active = _active;
|
|
|
|
*active = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_old_origin (void *_old_origin)
|
|
|
|
{
|
|
|
|
vec4f_t *old_origin = _old_origin;
|
|
|
|
*old_origin = (vec4f_t) {0, 0, 0, 1};
|
|
|
|
}
|
|
|
|
|
2022-11-15 06:21:20 +00:00
|
|
|
static void
|
|
|
|
create_colormap (void *_colormap)
|
|
|
|
{
|
|
|
|
colormap_t *colormap = _colormap;
|
|
|
|
*colormap = (colormap_t) {1, 6};
|
|
|
|
}
|
|
|
|
|
2022-11-13 06:08:18 +00:00
|
|
|
static void
|
|
|
|
destroy_visibility (void *_visibility)
|
|
|
|
{
|
|
|
|
visibility_t *visibility = _visibility;
|
|
|
|
if (visibility->efrag) {
|
|
|
|
R_ClearEfragChain (visibility->efrag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-25 10:36:09 +00:00
|
|
|
static void
|
|
|
|
sw_identity_matrix (void *_mat)
|
|
|
|
{
|
|
|
|
mat4f_t *mat = _mat;
|
|
|
|
mat4fidentity (*mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sw_frame_0 (void *_frame)
|
|
|
|
{
|
|
|
|
byte *frame = _frame;
|
|
|
|
*frame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sw_null_brush (void *_brush)
|
|
|
|
{
|
|
|
|
struct mod_brush_s **brush = _brush;
|
|
|
|
*brush = 0;
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:37:01 +00:00
|
|
|
static const component_t scene_components[scene_comp_count] = {
|
[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
|
|
|
[scene_href] = {
|
|
|
|
.size = sizeof (hierref_t),
|
|
|
|
.create = 0,//create_href,
|
|
|
|
.name = "href",
|
|
|
|
},
|
|
|
|
[scene_animation] = {
|
|
|
|
.size = sizeof (animation_t),
|
|
|
|
.create = 0,//create_animation,
|
|
|
|
.name = "animation",
|
|
|
|
},
|
|
|
|
[scene_visibility] = {
|
|
|
|
.size = sizeof (visibility_t),
|
|
|
|
.create = 0,//create_visibility,
|
2022-11-13 06:08:18 +00:00
|
|
|
.destroy = destroy_visibility,
|
[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
|
|
|
.name = "visibility",
|
|
|
|
},
|
|
|
|
[scene_renderer] = {
|
|
|
|
.size = sizeof (renderer_t),
|
|
|
|
.create = 0,//create_renderer,
|
|
|
|
.name = "renderer",
|
|
|
|
},
|
|
|
|
[scene_active] = {
|
|
|
|
.size = sizeof (byte),
|
|
|
|
.create = create_active,
|
|
|
|
.name = "active",
|
|
|
|
},
|
|
|
|
[scene_old_origin] = {
|
|
|
|
.size = sizeof (vec4f_t),
|
|
|
|
.create = create_old_origin,
|
|
|
|
.name = "old_origin",
|
|
|
|
},
|
2022-11-15 06:21:20 +00:00
|
|
|
[scene_colormap] = {
|
|
|
|
.size = sizeof (colormap_t),
|
|
|
|
.create = create_colormap,
|
|
|
|
.name = "colormap",
|
|
|
|
},
|
2022-10-25 10:36:09 +00:00
|
|
|
|
|
|
|
[scene_sw_matrix] = {
|
|
|
|
.size = sizeof (mat4f_t),
|
|
|
|
.create = sw_identity_matrix,
|
|
|
|
.name = "sw world transform",
|
|
|
|
},
|
|
|
|
[scene_sw_frame] = {
|
|
|
|
.size = sizeof (byte),
|
|
|
|
.create = sw_frame_0,
|
|
|
|
.name = "sw brush model animation frame",
|
|
|
|
},
|
|
|
|
[scene_sw_brush] = {
|
|
|
|
.size = sizeof (struct mod_brush_s *),
|
|
|
|
.create = sw_null_brush,
|
|
|
|
.name = "sw brush model data pointer",
|
|
|
|
},
|
[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
|
|
|
};
|
|
|
|
|
2022-05-05 14:45:21 +00:00
|
|
|
static byte empty_visdata[] = { 0x01 };
|
|
|
|
|
2022-05-05 12:30:14 +00:00
|
|
|
static mleaf_t empty_leafs[] = {
|
|
|
|
[1] = {
|
|
|
|
.contents = CONTENTS_EMPTY,
|
|
|
|
.mins = {-INFINITY, -INFINITY, -INFINITY},
|
|
|
|
.maxs = { INFINITY, INFINITY, INFINITY},
|
2022-05-05 14:45:21 +00:00
|
|
|
.compressed_vis = empty_visdata,
|
2022-05-05 12:30:14 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-05-22 16:32:33 +00:00
|
|
|
static mnode_t empty_nodes[] = {
|
|
|
|
[0] = {
|
|
|
|
.plane = { 0, 0, 0, -1 },
|
|
|
|
.type = 3,
|
|
|
|
.children = { ~0, ~1 },
|
|
|
|
.minmaxs = {-INFINITY, -INFINITY, -INFINITY,
|
|
|
|
INFINITY, INFINITY, INFINITY},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int empty_node_parents[] = {
|
|
|
|
[0] = -1,
|
|
|
|
};
|
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
static int empty_leaf_parents[] = {
|
2022-05-22 16:32:33 +00:00
|
|
|
[0] = 0,
|
|
|
|
[1] = 0,
|
2022-05-05 12:30:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int empty_leaf_flags[] = {
|
2022-05-05 14:45:21 +00:00
|
|
|
[1] = SURF_DRAWSKY,
|
2022-05-05 12:30:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static char empty_entities[] = { 0 };
|
|
|
|
|
|
|
|
static model_t empty_world = {
|
|
|
|
.type = mod_brush,
|
|
|
|
.radius = INFINITY,
|
|
|
|
.mins = {-INFINITY, -INFINITY, -INFINITY},
|
|
|
|
.maxs = { INFINITY, INFINITY, INFINITY},
|
|
|
|
.brush = {
|
|
|
|
.modleafs = 2,
|
|
|
|
.visleafs = 1,
|
2022-05-22 16:32:33 +00:00
|
|
|
.numnodes = 1,
|
|
|
|
.nodes = empty_nodes,
|
2022-05-05 12:30:14 +00:00
|
|
|
.leafs = empty_leafs,
|
|
|
|
.entities = empty_entities,
|
2022-05-05 14:45:21 +00:00
|
|
|
.visdata = empty_visdata,
|
2022-05-22 16:32:33 +00:00
|
|
|
.node_parents = empty_node_parents,
|
2022-05-05 12:30:14 +00:00
|
|
|
.leaf_parents = empty_leaf_parents,
|
|
|
|
.leaf_flags = empty_leaf_flags,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-07-24 05:19:52 +00:00
|
|
|
scene_t *
|
|
|
|
Scene_NewScene (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
|
|
|
scene_t *scene = calloc (1, sizeof (scene_t));
|
|
|
|
|
|
|
|
scene->reg = ECS_NewRegistry ();
|
2022-12-12 04:37:01 +00:00
|
|
|
ECS_RegisterComponents (scene->reg, scene_components, scene_comp_count);
|
2022-12-13 13:58:44 +00:00
|
|
|
ECS_CreateComponentPools (scene->reg);
|
2021-07-24 05:19:52 +00:00
|
|
|
|
2022-05-05 12:30:14 +00:00
|
|
|
scene->worldmodel = &empty_world;
|
|
|
|
|
2021-07-24 05:19:52 +00:00
|
|
|
return scene;
|
|
|
|
}
|
|
|
|
|
2022-02-14 07:41:38 +00:00
|
|
|
void
|
|
|
|
Scene_DeleteScene (scene_t *scene)
|
|
|
|
{
|
[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
|
|
|
ECS_DelRegistry (scene->reg);
|
2022-02-14 07:41:38 +00:00
|
|
|
|
|
|
|
free (scene);
|
|
|
|
}
|
|
|
|
|
[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
|
2021-07-24 05:19:52 +00:00
|
|
|
Scene_CreateEntity (scene_t *scene)
|
|
|
|
{
|
2022-10-25 02:34:24 +00:00
|
|
|
// Transform_New creates an entity and adds a scene_href component to the
|
|
|
|
// entity
|
2022-10-26 06:22:09 +00:00
|
|
|
transform_t trans = Transform_New (scene->reg, nulltransform);
|
[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
|
|
|
uint32_t id = trans.id;
|
2022-02-14 07:41:38 +00:00
|
|
|
|
2022-10-25 02:34:24 +00:00
|
|
|
Ent_SetComponent (id, scene_animation, scene->reg, 0);
|
|
|
|
Ent_SetComponent (id, scene_renderer, scene->reg, 0);
|
|
|
|
Ent_SetComponent (id, scene_active, scene->reg, 0);
|
|
|
|
Ent_SetComponent (id, scene_old_origin, scene->reg, 0);
|
2021-07-24 05:19:52 +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
|
|
|
renderer_t *renderer = Ent_GetComponent (id, scene_renderer, scene->reg);
|
|
|
|
QuatSet (1, 1, 1, 1, renderer->colormod);
|
2022-02-14 07:41:38 +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
|
|
|
return (entity_t) { .reg = scene->reg, .id = id };
|
2022-02-14 07:41:38 +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
|
|
|
Scene_DestroyEntity (scene_t *scene, entity_t ent)
|
2022-02-14 07:41:38 +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
|
|
|
ECS_DelEntity (scene->reg, ent.id);
|
2022-02-14 07:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Scene_FreeAllEntities (scene_t *scene)
|
|
|
|
{
|
2022-02-14 15:06:39 +00:00
|
|
|
}
|