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"
|
|
|
|
|
2022-02-14 11:01:36 +00:00
|
|
|
#include "scn_internal.h"
|
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
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
|
[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 const component_t scene_components[] = {
|
|
|
|
[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,
|
|
|
|
.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-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 ();
|
|
|
|
ECS_RegisterComponents (scene->reg, scene_components, scene_num_components);
|
2022-10-26 06:22:09 +00:00
|
|
|
scene->reg->href_comp = scene_href;
|
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
|
|
|
scene_resources_t *res = calloc (1, sizeof (scene_resources_t));
|
2021-07-24 05:19:52 +00:00
|
|
|
*(scene_resources_t **)&scene->resources = res;
|
|
|
|
|
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->resources);
|
|
|
|
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_visibility, 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
|
|
|
}
|