[ecs] Implement hierarchies as components

The main goal of this change was to make it easier to tell when a
hierarchy has been deleted, but as a side benefit, it got rid of the use
of PR_RESMAP. Also, it's easy to track the number of hierarchies.

Unfortunately, it showed how brittle the component side of the ECS is
(scene and canvas registries assumed their components were the first (no
long the case), thus the sweeping changes).

Centerprint doesn't work (but it hasn't for a while).
This commit is contained in:
Bill Currie 2024-01-01 20:21:07 +09:00
parent fc9c2fa544
commit 35eec0b2e5
77 changed files with 1196 additions and 979 deletions

View file

@ -36,7 +36,6 @@
#include "QF/darray.h"
#include "QF/qtypes.h"
#include "QF/progs.h"//FIXME for PR_RESMAP
#include "QF/ecs/component.h"
#include "QF/ecs/hierarchy.h"
@ -77,6 +76,14 @@ typedef struct ecs_subpool_s {
uint32_t max_ranges;
} ecs_subpool_t;
/// components that are available in every registry
enum {
ecs_name, ///< const char *
ecs_hierarchy, ///< hierarchy_t
ecs_comp_count
};
typedef struct ecs_registry_s {
const char *name;
ecs_pool_t *comp_pools;
@ -87,7 +94,6 @@ typedef struct ecs_registry_s {
uint32_t num_entities;
uint32_t max_entities;
componentset_t components;
PR_RESMAP (hierarchy_t) hierarchies;//FIXME find a better way
int locked;
} ecs_registry_t;

View file

@ -35,7 +35,6 @@
#include <stdlib.h>
#include "QF/qtypes.h"
#include "QF/progs.h"//FIXME for PR_RESMAP
/** \defgroup ecs_component Entity Component System components
\ingroup utils

View file

@ -46,8 +46,8 @@ typedef struct hierarchy_type_s {
} hierarchy_type_t;
typedef struct hierref_s {
struct hierarchy_s *hierarchy;
uint32_t index; ///< index in hierarchy
uint32_t id; ///< entity holding hierarchy object
uint32_t index; ///< index in hierarchy
} hierref_t;
typedef struct hierarchy_s {
@ -67,22 +67,27 @@ typedef struct hierarchy_s {
} hierarchy_t;
#define nullindex (~0u)
#define nullhref (hierref_t) { .id = nullent, .index = nullindex }
void Hierarchy_Create (hierarchy_t *hierarchy);
void Hierarchy_Destroy (hierarchy_t *hierarchy);
uint32_t Hierarchy_New (struct ecs_registry_s *reg, uint32_t href_comp,
const hierarchy_type_t *type, bool createRoot);
void Hierarchy_Delete (uint32_t hierarchy, struct ecs_registry_s *reg);
hierarchy_t *Hierarchy_New (struct ecs_registry_s *reg, uint32_t href_comp,
const hierarchy_type_t *type, int createRoot);
void Hierarchy_Reserve (hierarchy_t *hierarchy, uint32_t count);
hierarchy_t *Hierarchy_Copy (struct ecs_registry_s *reg, uint32_t href_comp,
const hierarchy_t *src);
void Hierarchy_Delete (hierarchy_t *hierarchy);
uint32_t Hierarchy_Copy (struct ecs_registry_s *reg, uint32_t href_comp,
const hierarchy_t *src);
void Hierarchy_SetTreeMode (hierarchy_t *hierarchy, bool tree_mode);
uint32_t Hierarchy_InsertHierarchy (hierarchy_t *dst, const hierarchy_t *src,
uint32_t dstParent, uint32_t srcRoot);
hierref_t Hierarchy_InsertHierarchy (hierref_t dref, hierref_t sref,
struct ecs_registry_s *reg);
void Hierarchy_RemoveHierarchy (hierarchy_t *hierarchy, uint32_t index,
int delEntities);
hierref_t Hierarchy_SetParent (hierarchy_t *dst, uint32_t dstParent,
hierarchy_t *src, uint32_t srcIndex);
hierref_t Hierarchy_SetParent (hierref_t dref, hierref_t sref,
struct ecs_registry_s *reg);
void Hierref_DestroyComponent (void *href);
///@}

View file

@ -178,6 +178,7 @@ typedef struct {
int ambientlight;
int drawflat;
struct scene_s *scene;
struct ecs_registry_s *registry;
struct model_s *worldmodel;
} refdef_t;

View file

@ -48,6 +48,7 @@
typedef struct entity_s {
ecs_registry_t *reg;
uint32_t id;
uint32_t base;
} entity_t;
#define nullentity ((entity_t) { .id = nullent })
@ -149,7 +150,11 @@ Entity_Transform (entity_t ent)
{
// The transform hierarchy reference is a component on the entity thus
// the entity id is the transform id.
return (transform_t) { .reg = ent.reg, .id = ent.id, .comp = scene_href };
return (transform_t) {
.reg = ent.reg,
.id = ent.id,
.comp = ent.base + scene_href,
};
}
struct mod_brush_s;

View file

@ -69,6 +69,7 @@ enum scene_components {
typedef struct scene_s {
struct ecs_registry_s *reg;
uint32_t base;
struct model_s *worldmodel;
int num_models;

View file

@ -69,12 +69,12 @@ typedef struct transform_s {
XFORMINLINE int Transform_Valid (transform_t transform);
transform_t Transform_New (ecs_registry_t *reg, transform_t parent);
transform_t Transform_New (ecs_system_t ssys, transform_t parent);
/* Deletes all child transforms, and transform names */
void Transform_Delete (transform_t transform);
transform_t Transform_NewNamed (ecs_registry_t *reg, transform_t parent,
transform_t Transform_NewNamed (ecs_system_t ssys, transform_t parent,
const char *name);
XFORMINLINE hierref_t *Transform_GetRef (transform_t transform);
XFORMINLINE hierref_t Transform_GetRef (transform_t transform);
XFORMINLINE uint32_t Transform_ChildCount (transform_t transform);
XFORMINLINE transform_t Transform_GetChild (transform_t transform,
uint32_t childIndex);
@ -129,33 +129,34 @@ Transform_Valid (transform_t transform)
}
XFORMINLINE
hierref_t *
hierref_t
Transform_GetRef (transform_t transform)
{
return Ent_GetComponent (transform.id, transform.comp, transform.reg);
return *(hierref_t *) Ent_GetComponent (transform.id, transform.comp,
transform.reg);
}
XFORMINLINE
uint32_t
Transform_ChildCount (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
return h->childCount[ref->index];
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
return h->childCount[ref.index];
}
XFORMINLINE
transform_t
Transform_GetChild (transform_t transform, uint32_t childIndex)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
if (childIndex >= h->childCount[ref->index]) {
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
if (childIndex >= h->childCount[ref.index]) {
return nulltransform;
}
return (transform_t) {
.reg = transform.reg,
.id = h->ent[h->childIndex[ref->index] + childIndex],
.id = h->ent[h->childIndex[ref.index] + childIndex],
.comp = transform.comp,
};
}
@ -164,14 +165,14 @@ XFORMINLINE
transform_t
Transform_GetParent (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
if (ref->index == 0) {
auto ref = Transform_GetRef (transform);
if (ref.index == 0) {
return nulltransform;
}
hierarchy_t *h = ref->hierarchy;
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
return (transform_t) {
.reg = transform.reg,
.id = h->ent[h->parentIndex[ref->index]],
.id = h->ent[h->parentIndex[ref.index]],
.comp = transform.comp,
};
}
@ -180,30 +181,30 @@ XFORMINLINE
const char *
Transform_GetName (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
char **name = h->components[transform_type_name];
return name[ref->index];
return name[ref.index];
}
XFORMINLINE
uint32_t
Transform_GetTag (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
uint32_t *tag = h->components[transform_type_tag];
return tag[ref->index];
return tag[ref.index];
}
XFORMINLINE
void
Transform_GetLocalMatrix (transform_t transform, mat4f_t mat)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
vec4f_t *src = localMatrix[ref->index];
vec4f_t *src = localMatrix[ref.index];
mat[0] = src[0];
mat[1] = src[1];
mat[2] = src[2];
@ -214,10 +215,10 @@ XFORMINLINE
void
Transform_GetLocalInverse (transform_t transform, mat4f_t mat)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *localInverse = h->components[transform_type_localInverse];
vec4f_t *src = localInverse[ref->index];
vec4f_t *src = localInverse[ref.index];
mat[0] = src[0];
mat[1] = src[1];
mat[2] = src[2];
@ -228,10 +229,10 @@ XFORMINLINE
void
Transform_GetWorldMatrix (transform_t transform, mat4f_t mat)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
vec4f_t *src = worldMatrix[ref->index];
vec4f_t *src = worldMatrix[ref.index];
mat[0] = src[0];
mat[1] = src[1];
mat[2] = src[2];
@ -242,20 +243,20 @@ XFORMINLINE
const vec4f_t *
Transform_GetWorldMatrixPtr (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return worldMatrix[ref->index];
return worldMatrix[ref.index];
}
XFORMINLINE
void
Transform_GetWorldInverse (transform_t transform, mat4f_t mat)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *worldInverse = h->components[transform_type_worldInverse];
vec4f_t *src = worldInverse[ref->index];
vec4f_t *src = worldInverse[ref.index];
mat[0] = src[0];
mat[1] = src[1];
mat[2] = src[2];
@ -266,60 +267,60 @@ XFORMINLINE
vec4f_t
Transform_GetLocalPosition (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
return localMatrix[ref->index][3];
return localMatrix[ref.index][3];
}
XFORMINLINE
vec4f_t
Transform_GetLocalRotation (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
vec4f_t *localRotation = h->components[transform_type_localRotation];
return localRotation[ref->index];
return localRotation[ref.index];
}
XFORMINLINE
vec4f_t
Transform_GetLocalScale (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
vec4f_t *localScale = h->components[transform_type_localScale];
return localScale[ref->index];
return localScale[ref.index];
}
XFORMINLINE
vec4f_t
Transform_GetWorldPosition (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return worldMatrix[ref->index][3];
return worldMatrix[ref.index][3];
}
XFORMINLINE
vec4f_t
Transform_GetWorldRotation (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
vec4f_t *worldRotation = h->components[transform_type_worldRotation];
return worldRotation[ref->index];
return worldRotation[ref.index];
}
XFORMINLINE
vec4f_t
Transform_GetWorldScale (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
vec4f_t *m = worldMatrix[ref->index];
vec4f_t *m = worldMatrix[ref.index];
vec4f_t s = {
dotf (m[0], m[0])[0],
dotf (m[1], m[1])[0],
@ -333,30 +334,30 @@ XFORMINLINE
vec4f_t
Transform_Forward (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return worldMatrix[ref->index][0];
return worldMatrix[ref.index][0];
}
XFORMINLINE
vec4f_t
Transform_Right (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return -worldMatrix[ref->index][1];
return -worldMatrix[ref.index][1];
}
XFORMINLINE
vec4f_t
Transform_Up (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return worldMatrix[ref->index][2];
return worldMatrix[ref.index][2];
}
///@}

View file

@ -63,7 +63,7 @@ typedef struct passage_s {
struct ecs_registry_s *reg; ///< Owning ECS registry
uint32_t comp_base; ///< Passage base component
struct hierarchy_s *hierarchy; ///< hierarchy of text objects
uint32_t hierarchy; ///< hierarchy of text objects
} passage_t;
void Passage_ParseText (passage_t *passage, const char *text);

View file

@ -154,7 +154,7 @@ void view_flow_up_right (view_t view, view_pos_t len);
void view_flow_down_left (view_t view, view_pos_t len);
void view_flow_up_left (view_t view, view_pos_t len);
VIEWINLINE hierref_t *View_GetRef (view_t view);
VIEWINLINE hierref_t View_GetRef (view_t view);
VIEWINLINE int View_Valid (view_t view);
VIEWINLINE view_t View_GetRoot (view_t view);
@ -196,10 +196,10 @@ View_FromEntity (ecs_system_t viewsys, uint32_t ent)
}
VIEWINLINE
hierref_t *
hierref_t
View_GetRef (view_t view)
{
return Ent_GetComponent (view.id, view.comp, view.reg);
return *(hierref_t *) Ent_GetComponent (view.id, view.comp, view.reg);
}
VIEWINLINE
@ -213,10 +213,11 @@ VIEWINLINE
void
View_Delete (view_t view)
{
__auto_type ref = *View_GetRef (view);
Hierarchy_RemoveHierarchy (ref.hierarchy, ref.index, 1);
if (!ref.hierarchy->num_objects) {
Hierarchy_Delete (ref.hierarchy);
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
Hierarchy_RemoveHierarchy (h, ref.index, 1);
if (!h->num_objects) {
Hierarchy_Delete (ref.id, view.reg);
}
}
@ -224,8 +225,8 @@ VIEWINLINE
view_t
View_GetRoot (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
return (view_t) {
.reg = view.reg,
.id = h->ent[0],
@ -237,14 +238,14 @@ VIEWINLINE
view_t
View_GetParent (view_t view)
{
__auto_type ref = View_GetRef (view);
if (ref->index == 0) {
auto ref = View_GetRef (view);
if (ref.index == 0) {
return nullview;
}
hierarchy_t *h = ref->hierarchy;
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
return (view_t) {
.reg = view.reg,
.id = h->ent[h->parentIndex[ref->index]],
.id = h->ent[h->parentIndex[ref.index]],
.comp = view.comp,
};
}
@ -253,23 +254,23 @@ VIEWINLINE
uint32_t
View_ChildCount (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
return h->childCount[ref->index];
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
return h->childCount[ref.index];
}
VIEWINLINE
view_t
View_GetChild (view_t view, uint32_t childIndex)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
if (childIndex >= h->childCount[ref->index]) {
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
if (childIndex >= h->childCount[ref.index]) {
return nullview;
}
return (view_t) {
.reg = view.reg,
.id = h->ent[h->childIndex[ref->index] + childIndex],
.id = h->ent[h->childIndex[ref.index] + childIndex],
.comp = view.comp,
};
}
@ -279,151 +280,151 @@ VIEWINLINE
void
View_SetPos (view_t view, int x, int y)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
byte *modified = h->components[view_modified];
pos[ref->index] = (view_pos_t) { x, y };
modified[ref->index] |= 1;
pos[ref.index] = (view_pos_t) { x, y };
modified[ref.index] |= 1;
}
VIEWINLINE
view_pos_t
View_GetPos (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
return pos[ref->index];
return pos[ref.index];
}
VIEWINLINE
view_pos_t
View_GetAbs (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *abs = h->components[view_abs];
return abs[ref->index];
return abs[ref.index];
}
VIEWINLINE
view_pos_t
View_GetRel (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *rel = h->components[view_rel];
return rel[ref->index];
return rel[ref.index];
}
VIEWINLINE
void
View_SetLen (view_t view, int x, int y)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *len = h->components[view_len];
view_pos_t *oldlen = h->components[view_oldlen];
byte *modified = h->components[view_modified];
if (!(modified[ref->index] & 2)) {
oldlen[ref->index] = len[ref->index];
if (!(modified[ref.index] & 2)) {
oldlen[ref.index] = len[ref.index];
}
len[ref->index] = (view_pos_t) { x, y };
modified[ref->index] |= 2;
len[ref.index] = (view_pos_t) { x, y };
modified[ref.index] |= 2;
}
VIEWINLINE
view_pos_t
View_GetLen (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *len = h->components[view_len];
return len[ref->index];
return len[ref.index];
}
VIEWINLINE
viewcont_t *
View_Control (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
viewcont_t *cont = h->components[view_control];
return &cont[ref->index];
return &cont[ref.index];
}
VIEWINLINE
void
View_SetGravity (view_t view, grav_t grav)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
viewcont_t *cont = h->components[view_control];
byte *modified = h->components[view_modified];
cont[ref->index].gravity = grav;
modified[ref->index] |= 1;
cont[ref.index].gravity = grav;
modified[ref.index] |= 1;
}
VIEWINLINE
grav_t
View_GetGravity (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
viewcont_t *cont = h->components[view_control];
return cont[ref->index].gravity;
return cont[ref.index].gravity;
}
VIEWINLINE
void
View_SetVisible (view_t view, int visible)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
viewcont_t *cont = h->components[view_control];
cont[ref->index].visible = !!visible;
cont[ref.index].visible = !!visible;
}
VIEWINLINE
int
View_GetVisible (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
viewcont_t *cont = h->components[view_control];
return cont[ref->index].visible;
return cont[ref.index].visible;
}
VIEWINLINE
void
View_SetResize (view_t view, int resize_x, int resize_y)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
viewcont_t *cont = h->components[view_control];
cont[ref->index].resize_x = resize_x;
cont[ref->index].resize_y = resize_y;
cont[ref.index].resize_x = resize_x;
cont[ref.index].resize_y = resize_y;
}
VIEWINLINE
void
View_SetOnResize (view_t view, view_resize_f onresize)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_resize_f *resize = h->components[view_onresize];
resize[ref->index] = onresize;
resize[ref.index] = onresize;
}
VIEWINLINE
void
View_SetOnMove (view_t view, view_move_f onmove)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_move_f *move = h->components[view_onmove];
move[ref->index] = onmove;
move[ref.index] = onmove;
}
///@}

View file

@ -21,7 +21,7 @@ extern vid_render_funcs_t *vid_render_funcs;
#define vr_funcs vid_render_funcs
extern refdef_t r_refdef;
#define SW_COMP(comp, id) ((void *)((byte *)r_refdef.registry->comp_pools[comp].data + (id) * r_refdef.registry->components.a[comp].size))
#define SW_COMP(comp, id) ((void *)((byte *)r_refdef.registry->comp_pools[r_refdef.scene->base + comp].data + (id) * r_refdef.registry->components.a[r_refdef.scene->base + comp].size))
extern int r_viewsize;
void R_LineGraph (int x, int y, int *h_vals, int count, int height);

View file

@ -187,7 +187,7 @@ CL_NewDlight (entity_t ent, vec4f_t org, int effects, byte glow_size,
}
uint32_t light = attach_light_ent (ent);
Ent_SetComponent (light, scene_dynlight, ent.reg, &(dlight_t) {
Ent_SetComponent (light, ent.base + scene_dynlight, ent.reg, &(dlight_t) {
.origin = org,
.color = color,
.radius = radius,
@ -200,15 +200,15 @@ void
CL_ModelEffects (entity_t ent, int glow_color, double time)
{
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (ent.id, + ent.base + scene_renderer, ent.reg);
model_t *model = renderer->model;
vec4f_t *old_origin = Ent_GetComponent (ent.id, scene_old_origin, cl_world.scene->reg);
vec4f_t *old_origin = Ent_GetComponent (ent.id, + ent.base + scene_old_origin, ent.reg);
vec4f_t ent_origin = Transform_GetWorldPosition (transform);
// add automatic particle trails
if (model->effects & ME_ROCKET) {
uint32_t light = attach_light_ent (ent);
Ent_SetComponent (light, scene_dynlight, ent.reg, &(dlight_t) {
Ent_SetComponent (light, ent.base + scene_dynlight, ent.reg, &(dlight_t) {
.origin = ent_origin,
//FIXME VectorCopy (r_firecolor, dl->color);
.color = { 0.9, 0.7, 0.0, 0.7 },

View file

@ -368,7 +368,7 @@ CL_TransformEntity (entity_t ent, float scale, const vec3_t angles,
} else {
vec3_t ang;
VectorCopy (angles, ang);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
ent.reg);
if (renderer->model && renderer->model->type == mod_alias) {
// stupid quake bug

View file

@ -329,8 +329,8 @@ CL_LoadLights (plitem_t *entities, scene_t *scene)
}
PL_Release (targets);
auto lights = &scene->reg->comp_pools[scene_light];
auto lefrags = &scene->reg->comp_pools[scene_efrags];
auto lights = &scene->reg->comp_pools[scene->base + scene_light];
auto lefrags = &scene->reg->comp_pools[scene->base + scene_efrags];
for (uint32_t i = 0; i < lights->count; i++) {
auto light = &((light_t *)lights->data)[i];
auto efrags = ((efrag_t **)lefrags->data)[i];

View file

@ -122,19 +122,19 @@ clscr_view (int x, int y, int w, int h, grav_t gravity)
static void
clscr_set_pic (view_t view, qpic_t *pic)
{
Ent_SetComponent (view.id, canvas_pic, view.reg, &pic);
Ent_SetComponent (view.id, cl_canvas_sys.base + canvas_pic, view.reg, &pic);
}
static void
clscr_set_cachepic (view_t view, const char *name)
{
Ent_SetComponent (view.id, canvas_cachepic, view.reg, &name);
Ent_SetComponent (view.id, cl_canvas_sys.base + canvas_cachepic, view.reg, &name);
}
static void
clscr_set_canvas_func (view_t view, canvas_func_f func)
{
Ent_SetComponent (view.id, canvas_func, view.reg, &func);
Ent_SetComponent (view.id, cl_canvas_sys.base + canvas_func, view.reg, &func);
}
static void

View file

@ -159,10 +159,10 @@ CL_TEnts_Init (void)
void
CL_Init_Entity (entity_t ent)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
byte *active = Ent_GetComponent (ent.id, scene_active, cl_world.scene->reg);
vec4f_t *old_origin = Ent_GetComponent (ent.id, scene_old_origin, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
byte *active = Ent_GetComponent (ent.id, ent.base + scene_active, ent.reg);
vec4f_t *old_origin = Ent_GetComponent (ent.id, ent.base + scene_old_origin, ent.reg);
memset (animation, 0, sizeof (*animation));
memset (renderer, 0, sizeof (*renderer));
*active = 1;
@ -270,7 +270,7 @@ beam_setup (beam_t *b, bool settransform, double time, TEntContext_t *ctx)
vec4f_t position = org + d * dist;
d += 1.0;
transform_t transform = Entity_Transform (tent->ent);
renderer_t *renderer = Ent_GetComponent (tent->ent.id, scene_renderer, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (tent->ent.id, tent->ent.base + scene_renderer, tent->ent.reg);
renderer->model = b->model;
if (settransform) {
seed = seed * BEAM_SEED_PRIME;
@ -337,7 +337,7 @@ free_stale_entities (void)
size_t i, j;
for (i = 0, j = 0; i < light_entities.size; i++) {
auto ent = light_entities.a[i];
if (Ent_HasComponent (ent.id, scene_dynlight, ent.reg)) {
if (Ent_HasComponent (ent.id, ent.base + scene_dynlight, ent.reg)) {
if (j != i) {
light_entities.a[j] = ent;
}
@ -356,10 +356,11 @@ spawn_light (vec4f_t position, vec4f_t color, float radius, float die,
entity_t ent = {
.reg = cl_world.scene->reg,
.id = ECS_NewEntity (cl_world.scene->reg),
.base = cl_world.scene->base,
};
DARRAY_APPEND (&light_entities, ent);
Ent_SetComponent (ent.id, scene_dynlight, ent.reg, &(dlight_t) {
Ent_SetComponent (ent.id, ent.base + scene_dynlight, ent.reg, &(dlight_t) {
.origin = position,
.color = color,
.radius = radius,
@ -409,7 +410,7 @@ parse_tent (qmsg_t *net_message, double time, TEntContext_t *ctx,
cl_spr_explod = Mod_ForName ("progs/s_explod.spr", true);
}
transform_t transform = Entity_Transform (ex->tent->ent);
renderer_t *renderer = Ent_GetComponent (ex->tent->ent.id, scene_renderer, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (ex->tent->ent.id, ex->tent->ent.base + scene_renderer, ex->tent->ent.reg);
renderer->model = cl_spr_explod;
Transform_SetLocalPosition (transform, position);
color = (vec4f_t) {0.86, 0.31, 0.24, 0.7};
@ -648,8 +649,8 @@ CL_UpdateExplosions (double time, TEntContext_t *ctx)
ex = &(*to)->to.ex;
ent = ex->tent->ent;
f = 10 * (time - ex->start);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
if (f >= renderer->model->numframes) {
tent_obj_t *_to;
free_temp_entities (ex->tent);
@ -736,7 +737,7 @@ CL_ParseProjectiles (qmsg_t *net_message, bool nail2, TEntContext_t *ctx)
tail = &tent->next;
pr = tent->ent;
renderer_t *renderer = Ent_GetComponent (pr.id, scene_renderer, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (pr.id, pr.base + scene_renderer, pr.reg);
renderer->model = cl_spike;
renderer->skin = 0;
position[0] = ((bits[0] + ((bits[1] & 15) << 8)) << 1) - 4096;
@ -787,9 +788,13 @@ CL_MuzzleFlash (entity_t ent, vec4f_t position, vec4f_t fv, float zoffset,
light = ECS_NewEntity (ent.reg);
set_muzzleflash (ent, light);
}
DARRAY_APPEND (&light_entities, ((entity_t) {.reg = ent.reg, .id = light}));
DARRAY_APPEND (&light_entities, ((entity_t) {
.reg = ent.reg,
.id = light,
.base = ent.base,
}));
Ent_SetComponent (light, scene_dynlight, ent.reg, &(dlight_t) {
Ent_SetComponent (light, ent.base + 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),

View file

@ -780,7 +780,7 @@ V_CalcIntermissionRefdef (viewstate_t *vs)
Transform_SetWorldPosition (vs->camera_transform, origin);
Transform_SetWorldRotation (vs->camera_transform, rotation);
renderer_t *renderer = Ent_GetComponent (view.id, scene_renderer, view.reg);
renderer_t *renderer = Ent_GetComponent (view.id, view.base + scene_renderer, view.reg);
renderer->model = NULL;
// always idle in intermission
@ -801,8 +801,8 @@ V_CalcRefdef (viewstate_t *vs)
vec4f_t origin = vs->player_origin;
vec_t *viewangles = vs->player_angles;
renderer_t *renderer = Ent_GetComponent (view.id, scene_renderer, view.reg);
animation_t *animation = Ent_GetComponent (view.id, scene_animation, view.reg);
renderer_t *renderer = Ent_GetComponent (view.id, view.base + scene_renderer, view.reg);
animation_t *animation = Ent_GetComponent (view.id, view.base + scene_animation, view.reg);
V_DriftPitch (vs);
@ -960,8 +960,8 @@ V_RenderView (viewstate_t *vs)
void
V_NewScene (viewstate_t *viewstate, scene_t *scene)
{
viewstate->camera_transform = Transform_New (cl_world.scene->reg,
nulltransform);
ecs_system_t ssys = { .reg = cl_world.scene->reg, .base = cl_world.scene->base };
viewstate->camera_transform = Transform_New (ssys, nulltransform);
}
void

View file

@ -43,6 +43,7 @@
#include "QF/idparse.h"
#include "QF/quakefs.h"
#include "QF/plist.h"
#include "QF/progs.h"
#include "QF/scene/light.h"
@ -118,8 +119,8 @@ CL_ParseStatic (qmsg_t *msg, int version)
CL_ParseBaseline (msg, &es, version);
DARRAY_APPEND (&cl_static_entities, es);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
// copy it to the current state
renderer->model = cl_world.models.a[es.modelindex];

View file

@ -282,25 +282,25 @@ sbar_view (int x, int y, int w, int h, grav_t gravity, view_t parent)
static inline void
sbar_setcomponent (view_t view, uint32_t comp, const void *data)
{
Ent_SetComponent (view.id, comp, view.reg, data);
Ent_SetComponent (view.id, cl_canvas_sys.base + comp, view.reg, data);
}
static inline int
sbar_hascomponent (view_t view, uint32_t comp)
{
return Ent_HasComponent (view.id, comp, view.reg);
return Ent_HasComponent (view.id, cl_canvas_sys.base + comp, view.reg);
}
static inline void *
sbar_getcomponent (view_t view, uint32_t comp)
{
return Ent_GetComponent (view.id, comp, view.reg);
return Ent_GetComponent (view.id, cl_canvas_sys.base + comp, view.reg);
}
static inline void
sbar_remcomponent (view_t view, uint32_t comp)
{
Ent_RemoveComponent (view.id, comp, view.reg);
Ent_RemoveComponent (view.id, cl_canvas_sys.base + comp, view.reg);
}
static inline void
@ -1669,7 +1669,7 @@ draw_fps (view_t view)
/* CENTER PRINTING */
static dstring_t center_string = {&dstring_default_mem};
static passage_t center_passage;
static passage_t center_passage = { .hierarchy = nullent };
static float centertime_start; // for slow victory printing
static float centertime_off;
static int center_lines;
@ -1698,7 +1698,9 @@ Sbar_CenterPrint (const char *str)
Passage_ParseText (&center_passage, center_string.str);
// Standard centerprint strings are pre-flowed so each line in the message
// is a paragraph in the passage.
center_lines = center_passage.hierarchy->childCount[0];
hierarchy_t *h = Ent_GetComponent (center_passage.hierarchy, ecs_hierarchy,
center_passage.reg);
center_lines = h->childCount[0];
}
static void
@ -1714,7 +1716,8 @@ Sbar_DrawCenterString (view_t view, unsigned remaining)
else
y = abs.y + 48;
__auto_type h = center_passage.hierarchy;
hierarchy_t *h = Ent_GetComponent (center_passage.hierarchy, ecs_hierarchy,
center_passage.reg);
psg_text_t *line = h->components[passage_type_text_obj];
int line_count = center_lines;
while (line_count-- > 0 && remaining > 0) {
@ -2281,7 +2284,8 @@ hud_time_f (void *data, const cvar_t *cvar)
static void
hud_add_outlines (view_t view, byte color)
{
Ent_SetComponent (view.id, canvas_outline, view.reg, &color);
Ent_SetComponent (view.id, cl_canvas_sys.base + canvas_outline, view.reg,
&color);
uint32_t count = View_ChildCount (view);
for (uint32_t i = 0; i < count; i++) {
hud_add_outlines (View_GetChild (view, i), color);
@ -2291,7 +2295,7 @@ hud_add_outlines (view_t view, byte color)
static void
hud_remove_outlines (view_t view)
{
Ent_RemoveComponent (view.id, canvas_outline, view.reg);
Ent_RemoveComponent (view.id, cl_canvas_sys.base + canvas_outline, view.reg);
uint32_t count = View_ChildCount (view);
for (uint32_t i = 0; i < count; i++) {
hud_remove_outlines (View_GetChild (view, i));

View file

@ -387,8 +387,9 @@ color_window (void)
static transform_t
create_debug_camera (void)
{
debug_camera_pivot = Transform_New (debug_scene->reg, nulltransform);
debug_camera = Transform_New (debug_scene->reg, debug_camera_pivot);
ecs_system_t ssys = { .reg = debug_scene->reg, .base = debug_scene->base };
debug_camera_pivot = Transform_New (ssys, nulltransform);
debug_camera = Transform_New (ssys, debug_camera_pivot);
return debug_camera;
}

View file

@ -79,7 +79,30 @@
#include "compat.h"
#include "sv_console.h"
static console_data_t sv_con_data;
static const component_t server_components[server_comp_count] = {
[server_href] = {
.size = sizeof (hierref_t),
.name = "href",
.destroy = Hierref_DestroyComponent,
},
[server_view] = {
.size = sizeof (sv_view_t),
.name = "sv_view",
},
[server_window] = {
.size = sizeof (sv_view_t),
.name = "sv_window",
},
};
static console_data_t sv_con_data = {
.components = server_components,
.num_components = server_comp_count,
};
#define server_base sv_con_data.component_base
#define s_href (server_base + server_href)
#define s_view (server_base + server_view)
#define s_window (server_base + server_window)
static QFile *log_file;
static char *sv_logfile;
@ -157,7 +180,6 @@ static volatile sig_atomic_t interrupted;
static int batch_print;
static ecs_registry_t *server_reg;
static uint32_t server_base;
static uint32_t view_base;
#define MAXCMDLINE 256
@ -216,23 +238,6 @@ static const byte attr_map[256] = {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
};
static const component_t server_components[server_comp_count] = {
[server_href] = {
.size = sizeof (hierref_t),
.name = "href",
.destroy = Hierref_DestroyComponent,
},
[server_view] = {
.size = sizeof (sv_view_t),
.name = "sv_view",
},
[server_window] = {
.size = sizeof (sv_view_t),
.name = "sv_window",
},
};
static inline void
draw_fun_char (WINDOW *win, byte c, int blue)
{
@ -245,9 +250,8 @@ draw_fun_char (WINDOW *win, byte c, int blue)
static inline void
sv_refresh_windows (void)
{
uint32_t window_comp = server_base + server_window;
sv_view_t *window = server_reg->comp_pools[window_comp].data;
uint32_t count = server_reg->comp_pools[window_comp].count;
sv_view_t *window = server_reg->comp_pools[s_window].data;
uint32_t count = server_reg->comp_pools[s_window].count;
while (count-- > 0) {
wnoutrefresh ((WINDOW *) (window++)->win);
}
@ -257,14 +261,14 @@ sv_refresh_windows (void)
static inline int
sv_getch (view_t view)
{
sv_view_t *window = Ent_GetComponent (view.id, server_window, view.reg);
sv_view_t *window = Ent_GetComponent (view.id, s_window, view.reg);
return wgetch ((WINDOW *) window->win);
}
static inline void
sv_draw (view_t view)
{
sv_view_t *window = Ent_GetComponent (view.id, server_window, view.reg);
sv_view_t *window = Ent_GetComponent (view.id, s_window, view.reg);
if (window->draw)
window->draw (view);
wnoutrefresh ((WINDOW *) window->win);
@ -274,7 +278,7 @@ sv_draw (view_t view)
static void
sv_setgeometry (view_t view, view_pos_t foo)
{
sv_view_t *window = Ent_GetComponent (view.id, server_window, view.reg);
sv_view_t *window = Ent_GetComponent (view.id, s_window, view.reg);
WINDOW *win = window->win;
view_pos_t pos = View_GetAbs (view);
@ -298,7 +302,7 @@ sv_complete (inputline_t *il)
static void
draw_output (view_t view)
{
sv_view_t *window = Ent_GetComponent (view.id, server_window, view.reg);
sv_view_t *window = Ent_GetComponent (view.id, s_window, view.reg);
WINDOW *win = window->win;
con_buffer_t *output_buffer = window->obj;
view_pos_t len = View_GetLen (view);
@ -346,7 +350,7 @@ draw_output (view_t view)
static void
draw_status (view_t view)
{
sv_view_t *window = Ent_GetComponent (view.id, server_window, view.reg);
sv_view_t *window = Ent_GetComponent (view.id, s_window, view.reg);
WINDOW *win = window->win;
sv_sbar_t *sb = window->obj;
char *old = alloca (sb->width);
@ -354,7 +358,7 @@ draw_status (view_t view)
memcpy (old, sb->text, sb->width);
memset (sb->text, ' ', sb->width);
ecs_pool_t *pool = &server_reg->comp_pools[server_view];
ecs_pool_t *pool = &server_reg->comp_pools[s_view];
sv_view_t *sv_view = pool->data;
for (uint32_t i = 0; i < pool->count; i++) {
view_t v = { .reg = view.reg, .id = pool->dense[i],
@ -374,7 +378,7 @@ static void
draw_input_line (inputline_t *il)
{
view_t view = *(view_t *) il->user_data;
sv_view_t *window = Ent_GetComponent (view.id, server_window, view.reg);
sv_view_t *window = Ent_GetComponent (view.id, s_window, view.reg);
WINDOW *win = window->win;
size_t i;
const char *text;
@ -406,14 +410,14 @@ draw_input_line (inputline_t *il)
static void
draw_input (view_t view)
{
sv_view_t *window = Ent_GetComponent (view.id, server_window, view.reg);
sv_view_t *window = Ent_GetComponent (view.id, s_window, view.reg);
draw_input_line (window->obj);
}
static void
setgeometry_input (view_t view)
{
sv_view_t *window = Ent_GetComponent (view.id, server_window, view.reg);
sv_view_t *window = Ent_GetComponent (view.id, s_window, view.reg);
view_pos_t len = View_GetLen (view);
inputline_t *il = window->obj;
il->width = len.x;
@ -422,7 +426,7 @@ setgeometry_input (view_t view)
static void
setgeometry_status (view_t view)
{
sv_view_t *window = Ent_GetComponent (view.id, server_window, view.reg);
sv_view_t *window = Ent_GetComponent (view.id, s_window, view.reg);
sv_sbar_t *sb = window->obj;
view_pos_t len = View_GetLen (view);
sb->width = len.x;
@ -569,7 +573,7 @@ key_event (knum_t key, short unicode, bool down)
switch (key) {
case QFK_PAGEUP:
view_offset -= 10;
window = Ent_GetComponent (output.id, server_window, output.reg);
window = Ent_GetComponent (output.id, s_window, output.reg);
buffer = window->obj;
num_lines = (buffer->line_head - buffer->line_tail
+ buffer->max_lines) % buffer->max_lines;
@ -589,7 +593,7 @@ key_event (knum_t key, short unicode, bool down)
sv_draw (output);
break;
default:
window = Ent_GetComponent (input.id, server_window, input.reg);
window = Ent_GetComponent (input.id, s_window, input.reg);
Con_ProcessInputLine (window->obj, key);
sv_refresh_windows ();
break;
@ -599,7 +603,7 @@ key_event (knum_t key, short unicode, bool down)
static void
print (char *txt)
{
sv_view_t *window = Ent_GetComponent (output.id, server_window,
sv_view_t *window = Ent_GetComponent (output.id, s_window,
output.reg);
Con_BufferAddText (window->obj, txt);
if (!view_offset) {
@ -631,7 +635,7 @@ create_window (view_t parent, int xpos, int ypos, int xlen, int ylen,
.draw = draw,
.setgeometry = setgeometry,
};
Ent_SetComponent (view.id, server_window, view.reg, &window);
Ent_SetComponent (view.id, s_window, view.reg, &window);
scrollok (window.win, (opts & sv_scroll) ? TRUE : FALSE);
leaveok (window.win, (opts & sv_cursor) ? FALSE : TRUE);

View file

@ -34,6 +34,38 @@
#define IMPLEMENT_ECS_Funcs
#include "QF/ecs.h"
static void
ecs_name_destroy (void *name)
{
free (name);
}
static void
ecs_hierarchy_create (void *hierarchy)
{
Hierarchy_Create (hierarchy);
}
static void
ecs_hierarchy_destroy (void *hierarchy)
{
Hierarchy_Destroy (hierarchy);
}
static const component_t ecs_components[ecs_comp_count] = {
[ecs_name] = {
.size = sizeof (char *),
.name = "name",
.destroy = ecs_name_destroy,
},
[ecs_hierarchy] = {
.size = sizeof (hierarchy_t),
.name = "hierarchy",
.create = ecs_hierarchy_create,
.destroy = ecs_hierarchy_destroy,
},
};
VISIBLE ecs_registry_t *
ECS_NewRegistry (const char *name)
{
@ -41,6 +73,7 @@ ECS_NewRegistry (const char *name)
reg->name = name;
reg->components = (componentset_t) DARRAY_STATIC_INIT (32);
reg->next = Ent_Index (nullent);
ECS_RegisterComponents (reg, ecs_components, ecs_comp_count);
return reg;
}
@ -70,7 +103,6 @@ ECS_DelRegistry (ecs_registry_t *registry)
DARRAY_CLEAR (&registry->components);
free (registry->subpools);
free (registry->comp_pools);
PR_RESDELMAP (registry->hierarchies);
free (registry);
}
@ -265,9 +297,18 @@ ECS_PrintEntity (ecs_registry_t *registry, uint32_t ent)
VISIBLE void
ECS_PrintRegistry (ecs_registry_t *registry)
{
printf ("%s\n", registry->name);
printf ("%s %d\n", registry->name, registry->num_entities);
for (size_t i = 0; i < registry->components.size; i++) {
printf ("%3zd %7d %s\n", i, registry->comp_pools[i].count,
registry->components.a[i].name);
auto subpool = &registry->subpools[i];
if (subpool->num_ranges) {
printf (" ");
for (uint32_t j = 0; j < subpool->num_ranges; j++) {
uint32_t range = subpool->ranges[j];
printf (" %d", range);
}
printf ("\n");
}
}
}

View file

@ -71,8 +71,8 @@ hierarchy_InvalidateReferences (hierarchy_t *hierarchy, uint32_t start,
for (size_t i = start; count-- > 0; i++) {
if (ECS_EntValid (hierarchy->ent[i], reg)) {
hierref_t *ref = Ent_GetComponent (hierarchy->ent[i], href, reg);
ref->hierarchy = 0;
ref->index = -1;
ref->id = nullent;
ref->index = nullindex;
}
}
}
@ -189,7 +189,7 @@ hierarchy_close (hierarchy_t *hierarchy, uint32_t index, uint32_t count)
}
static void
hierarchy_move (hierarchy_t *dst, const hierarchy_t *src,
hierarchy_move (hierarchy_t *dst, uint32_t dstid, const hierarchy_t *src,
uint32_t dstIndex, uint32_t srcIndex, uint32_t count)
{
ecs_registry_t *reg = dst->reg;
@ -206,7 +206,7 @@ hierarchy_move (hierarchy_t *dst, const hierarchy_t *src,
if (dst->ent[dstIndex + i] != nullent) {
uint32_t ent = dst->ent[dstIndex + i];
hierref_t *ref = Ent_GetComponent (ent, href, reg);
ref->hierarchy = dst;
ref->id = dstid;
ref->index = dstIndex + i;
}
}
@ -240,7 +240,7 @@ hierarchy_init (hierarchy_t *dst, uint32_t index,
}
static uint32_t
hierarchy_insert_flat (hierarchy_t *dst, const hierarchy_t *src,
hierarchy_insert_flat (hierarchy_t *dst, uint32_t dstid, const hierarchy_t *src,
uint32_t dstParent, uint32_t *srcRoot, uint32_t count)
{
uint32_t insertIndex; // where the objects will be inserted
@ -277,7 +277,7 @@ hierarchy_insert_flat (hierarchy_t *dst, const hierarchy_t *src,
*srcRoot += count;
}
if (src) {
hierarchy_move (dst, src, insertIndex, *srcRoot, count);
hierarchy_move (dst, dstid, src, insertIndex, *srcRoot, count);
} else {
hierarchy_init (dst, insertIndex, dstParent, childIndex, count);
}
@ -292,7 +292,7 @@ hierarchy_insert_flat (hierarchy_t *dst, const hierarchy_t *src,
}
static uint32_t
hierarchy_insert_tree (hierarchy_t *dst, const hierarchy_t *src,
hierarchy_insert_tree (hierarchy_t *dst, uint32_t dstid, const hierarchy_t *src,
uint32_t dstParent, uint32_t *srcRoot, uint32_t count)
{
uint32_t insertIndex;
@ -328,7 +328,7 @@ hierarchy_insert_tree (hierarchy_t *dst, const hierarchy_t *src,
dst->nextIndex[insertIndex] = nullindex;
if (src) {
hierarchy_move (dst, src, insertIndex, *srcRoot, count);
hierarchy_move (dst, dstid, src, insertIndex, *srcRoot, count);
} else {
hierarchy_init (dst, insertIndex, dstParent, nullindex, count);
}
@ -337,18 +337,21 @@ hierarchy_insert_tree (hierarchy_t *dst, const hierarchy_t *src,
}
static uint32_t
hierarchy_insert (hierarchy_t *dst, const hierarchy_t *src,
hierarchy_insert (hierarchy_t *dst, uint32_t dstid, const hierarchy_t *src,
uint32_t dstParent, uint32_t *srcRoot, uint32_t count)
{
if (dst->tree_mode) {
return hierarchy_insert_tree (dst, src, dstParent, srcRoot, count);
return hierarchy_insert_tree (dst, dstid, src, dstParent, srcRoot,
count);
} else {
return hierarchy_insert_flat (dst, src, dstParent, srcRoot, count);
return hierarchy_insert_flat (dst, dstid, src, dstParent, srcRoot,
count);
}
}
static void
hierarchy_insert_children (hierarchy_t *dst, const hierarchy_t *src,
hierarchy_insert_children (hierarchy_t *dst, uint32_t dstid,
const hierarchy_t *src,
uint32_t dstParent, uint32_t *srcRoot)
{
uint32_t insertIndex;
@ -356,19 +359,21 @@ hierarchy_insert_children (hierarchy_t *dst, const hierarchy_t *src,
uint32_t childCount = src->childCount[*srcRoot];
if (childCount) {
insertIndex = hierarchy_insert (dst, src, dstParent,
insertIndex = hierarchy_insert (dst, dstid, src, dstParent,
&childIndex, childCount);
if (dst == src && insertIndex <= *srcRoot) {
*srcRoot += childCount;
}
for (uint32_t i = 0; i < childCount; i++, childIndex++) {
hierarchy_insert_children (dst, src, insertIndex + i, &childIndex);
hierarchy_insert_children (dst, dstid, src, insertIndex + i,
&childIndex);
}
}
}
static uint32_t
hierarchy_insertHierarchy (hierarchy_t *dst, const hierarchy_t *src,
static hierref_t
hierarchy_insertHierarchy (hierarchy_t *dst, uint32_t dstid,
const hierarchy_t *src,
uint32_t dstParent, uint32_t *srcRoot)
{
uint32_t insertIndex;
@ -379,7 +384,7 @@ hierarchy_insertHierarchy (hierarchy_t *dst, const hierarchy_t *src,
}
hierarchy_open (dst, 0, 1);
if (src) {
hierarchy_move (dst, src, 0, *srcRoot, 1);
hierarchy_move (dst, dstid, src, 0, *srcRoot, 1);
}
dst->parentIndex[0] = nullindex;
dst->childIndex[0] = 1;
@ -389,20 +394,25 @@ hierarchy_insertHierarchy (hierarchy_t *dst, const hierarchy_t *src,
if (!dst->num_objects) {
Sys_Error ("attempt to insert non-root in empty hierarchy");
}
insertIndex = hierarchy_insert (dst, src, dstParent, srcRoot, 1);
insertIndex = hierarchy_insert (dst, dstid, src, dstParent, srcRoot, 1);
}
// if src is null, then inserting a new object which has no children
if (src) {
hierarchy_insert_children (dst, src, insertIndex, srcRoot);
hierarchy_insert_children (dst, dstid, src, insertIndex, srcRoot);
}
return insertIndex;
return (hierref_t) { .id = dstid, .index = insertIndex };
}
uint32_t
Hierarchy_InsertHierarchy (hierarchy_t *dst, const hierarchy_t *src,
uint32_t dstParent, uint32_t srcRoot)
hierref_t
Hierarchy_InsertHierarchy (hierref_t dref, hierref_t sref, ecs_registry_t *reg)
{
return hierarchy_insertHierarchy (dst, src, dstParent, &srcRoot);
hierarchy_t *dst = Ent_GetComponent (dref.id, ecs_hierarchy, reg);
hierarchy_t *src = 0;
if (ECS_EntValid (sref.id, reg)) {
src = Ent_GetComponent (sref.id, ecs_hierarchy, reg);
}
return hierarchy_insertHierarchy (dst, dref.id, src,
dref.index, &sref.index);
}
static void
@ -456,31 +466,16 @@ Hierarchy_RemoveHierarchy (hierarchy_t *hierarchy, uint32_t index,
}
}
hierarchy_t *
Hierarchy_New (ecs_registry_t *reg, uint32_t href_comp,
const hierarchy_type_t *type, int createRoot)
void
Hierarchy_Create (hierarchy_t *hierarchy)
{
hierarchy_t *hierarchy = PR_RESNEW (reg->hierarchies);
hierarchy->reg = reg;
hierarchy->href_comp = href_comp;
hierarchy->components = 0;
hierarchy->type = type;
if (type) {
hierarchy->components = calloc (hierarchy->type->num_components,
sizeof (void *));
if (hierarchy) {
Sys_Error ("Hierarchy_Create");
}
if (createRoot) {
hierarchy_open (hierarchy, 0, 1);
hierarchy_init (hierarchy, 0, nullindex, 1, 1);
}
return hierarchy;
}
static void
hierarchy_delete (hierarchy_t *hierarchy)
void
Hierarchy_Destroy (hierarchy_t *hierarchy)
{
free (hierarchy->ent);
free (hierarchy->childCount);
@ -494,16 +489,35 @@ hierarchy_delete (hierarchy_t *hierarchy)
}
free (hierarchy->components);
}
}
ecs_registry_t *reg = hierarchy->reg;
PR_RESFREE (reg->hierarchies, hierarchy);
uint32_t
Hierarchy_New (ecs_registry_t *reg, uint32_t href_comp,
const hierarchy_type_t *type, bool createRoot)
{
hierarchy_t hierarchy = {
.reg = reg,
.href_comp = href_comp,
.type = type,
.components = type ? calloc (type->num_components, sizeof (void *)) : 0,
};
if (createRoot) {
hierarchy_open (&hierarchy, 0, 1);
hierarchy_init (&hierarchy, 0, nullindex, 1, 1);
}
uint32_t hent = ECS_NewEntity (reg);
Ent_SetComponent (hent, ecs_hierarchy, reg, &hierarchy);
return hent;
}
void
Hierarchy_Delete (hierarchy_t *hierarchy)
Hierarchy_Delete (uint32_t hierarchy, ecs_registry_t *reg)
{
hierarchy_InvalidateReferences (hierarchy, 0, hierarchy->num_objects);
hierarchy_delete (hierarchy);
hierarchy_t *h = Ent_GetComponent (hierarchy, ecs_hierarchy, reg);
hierarchy_InvalidateReferences (h, 0, h->num_objects);
ECS_DelEntity (reg, hierarchy);
}
static uint32_t
@ -588,59 +602,68 @@ Hierarchy_SetTreeMode (hierarchy_t *hierarchy, bool tree_mode)
}
auto src = hierarchy;
auto tmp = Hierarchy_New (src->reg, src->href_comp, src->type, 0);
Hierarchy_Reserve (tmp, src->num_objects);
tmp->num_objects = src->num_objects;
hierarchy_t tmp = {
.reg = src->reg,
.href_comp = src->href_comp,
.type = src->type,
.components = src->type
? calloc (src->type->num_components, sizeof (void *)) : 0,
};
Hierarchy_Reserve (&tmp, src->num_objects);
tmp.num_objects = src->num_objects;
// treat parentIndex as a queue for breadth-first traversal
tmp->parentIndex[0] = 0; // start at root of src
tmp.parentIndex[0] = 0; // start at root of src
uint32_t queueIndex = 1;
for (uint32_t i = 0; i < src->num_objects; i++) {
copy_tree_nodes (tmp, src, i, &queueIndex);
copy_tree_nodes (&tmp, src, i, &queueIndex);
}
tmp->parentIndex[0] = nullindex;
tmp.parentIndex[0] = nullindex;
for (uint32_t i = 0; i < src->num_objects; i++) {
for (uint32_t j = 0; j < tmp->childCount[i]; j++) {
tmp->parentIndex[tmp->childIndex[i] + j] = i;
for (uint32_t j = 0; j < tmp.childCount[i]; j++) {
tmp.parentIndex[tmp.childIndex[i] + j] = i;
}
}
auto href_comp = src->href_comp;
for (uint32_t i = 0; i < src->num_objects; i++) {
hierref_t *ref = Ent_GetComponent (tmp->ent[i], href_comp, tmp->reg);
hierref_t *ref = Ent_GetComponent (tmp.ent[i], href_comp, src->reg);
ref->index = i;
}
swap_pointers (&tmp->ent, &src->ent);
swap_pointers (&tmp->childCount, &src->childCount);
swap_pointers (&tmp->childIndex, &src->childIndex);
swap_pointers (&tmp->parentIndex, &src->parentIndex);
swap_pointers (&tmp->nextIndex, &src->nextIndex);
swap_pointers (&tmp->lastIndex, &src->lastIndex);
swap_pointers (&tmp.ent, &src->ent);
swap_pointers (&tmp.childCount, &src->childCount);
swap_pointers (&tmp.childIndex, &src->childIndex);
swap_pointers (&tmp.parentIndex, &src->parentIndex);
swap_pointers (&tmp.nextIndex, &src->nextIndex);
swap_pointers (&tmp.lastIndex, &src->lastIndex);
if (src->type) {
for (uint32_t i = 0; i < src->type->num_components; i++) {
swap_pointers (&tmp->components[i], &src->components[i]);
swap_pointers (&tmp.components[i], &src->components[i]);
}
}
hierarchy_delete (tmp);
Hierarchy_Destroy (&tmp);
}
hierarchy_t *
uint32_t
Hierarchy_Copy (ecs_registry_t *dstReg, uint32_t href_comp,
const hierarchy_t *src)
{
if (src->tree_mode) {
Sys_Error ("Hierarchy_Copy tree mode not implemented");
}
hierarchy_t *dst = Hierarchy_New (dstReg, href_comp, src->type, 0);
uint32_t copy = Hierarchy_New (dstReg, href_comp, src->type, 0);
hierarchy_t *dst = Ent_GetComponent (copy, ecs_hierarchy, dstReg);
size_t count = src->num_objects;
Hierarchy_Reserve (dst, count);
for (size_t i = 0; i < count; i++) {
dst->ent[i] = ECS_NewEntity (dstReg);
hierref_t *ref = Ent_AddComponent (dst->ent[i], href_comp, dstReg);
ref->hierarchy = dst;
ref->index = i;
hierref_t ref = {
.id = copy,
.index = i,
};
Ent_SetComponent (dst->ent[i], href_comp, dstReg, &ref);
}
Component_CopyElements (&childCount_component,
@ -660,34 +683,35 @@ Hierarchy_Copy (ecs_registry_t *dstReg, uint32_t href_comp,
src->components[i], 0, count);
}
}
return dst;
return copy;
}
hierref_t
Hierarchy_SetParent (hierarchy_t *dst, uint32_t dstParent,
hierarchy_t *src, uint32_t srcRoot)
Hierarchy_SetParent (hierref_t dref, hierref_t sref, ecs_registry_t *reg)
{
hierarchy_t *src = Ent_GetComponent (sref.id, ecs_hierarchy, reg);
if (src->tree_mode) {
Sys_Error ("Hierarchy_SetParent tree mode not implemented");
}
hierref_t r = {};
if (dst && dstParent != nullindex) {
if (ECS_EntValid (dref.id, reg)) {
hierarchy_t *dst = Ent_GetComponent (dref.id, ecs_hierarchy, reg);
if (dst->type != src->type) {
Sys_Error ("Can't set parent in hierarchy of different type");
}
} else {
if (!srcRoot) {
r.hierarchy = src;
r.index = 0;
return r;
if (!sref.index) {
return sref;
}
dst = Hierarchy_New (src->reg, src->href_comp, src->type, 0);
dref.id = Hierarchy_New (src->reg, src->href_comp, src->type, 0);
dref.index = nullindex;
}
r.hierarchy = dst;
r.index = hierarchy_insertHierarchy (dst, src, dstParent, &srcRoot);
Hierarchy_RemoveHierarchy (src, srcRoot, 0);
hierarchy_t *dst = Ent_GetComponent (dref.id, ecs_hierarchy, reg);
dref = hierarchy_insertHierarchy (dst, dref.id, src,
dref.index, &sref.index);
Hierarchy_RemoveHierarchy (src, sref.index, 0);
if (!src->num_objects) {
Hierarchy_Delete (src);
Hierarchy_Delete (sref.id, reg);
}
return r;
}
@ -695,6 +719,7 @@ Hierarchy_SetParent (hierarchy_t *dst, uint32_t dstParent,
void
Hierref_DestroyComponent (void *href)
{
#if 0
hierref_t ref = *(hierref_t *) href;
if (ref.hierarchy) {
ref.hierarchy->ent[ref.index] = -1;
@ -703,4 +728,5 @@ Hierref_DestroyComponent (void *href)
Hierarchy_Delete (ref.hierarchy);
}
}
#endif
}

View file

@ -18,6 +18,11 @@ enum test_components {
test_num_components
};
static uint32_t comp_base;
#define t_position (comp_base + test_position)
#define t_scale (comp_base + test_scale)
#define t_rotation (comp_base + test_rotation)
static void
create_position (void *data)
{
@ -105,28 +110,29 @@ int
main (void)
{
ecs_registry_t *reg = ECS_NewRegistry ("components");
ECS_RegisterComponents (reg, test_components, test_num_components);
comp_base = ECS_RegisterComponents (reg, test_components,
test_num_components);
ECS_CreateComponentPools (reg);
uint32_t enta = ECS_NewEntity (reg);
uint32_t entb = ECS_NewEntity (reg);
uint32_t entc = ECS_NewEntity (reg);
Ent_AddComponent (enta, test_position, reg);
Ent_AddComponent (entb, test_position, reg);
Ent_AddComponent (entc, test_position, reg);
Ent_AddComponent (enta, test_rotation, reg);
Ent_AddComponent (entb, test_rotation, reg);
Ent_AddComponent (enta, test_scale, reg);
Ent_AddComponent (enta, t_position, reg);
Ent_AddComponent (entb, t_position, reg);
Ent_AddComponent (entc, t_position, reg);
Ent_AddComponent (enta, t_rotation, reg);
Ent_AddComponent (entb, t_rotation, reg);
Ent_AddComponent (enta, t_scale, reg);
if (!check_ent_components ((uint32_t[]){enta, entb, entc}, 3,
test_position, reg)) {
t_position, reg)) {
return 1;
}
if (!check_ent_components ((uint32_t[]){enta, entb}, 2,
test_rotation, reg)) {
t_rotation, reg)) {
return 1;
}
if (!check_ent_components ((uint32_t[]){enta}, 1, test_scale, reg)) {
if (!check_ent_components ((uint32_t[]){enta}, 1, t_scale, reg)) {
return 1;
}

View file

@ -16,6 +16,11 @@ enum {
test_num_components
};
static uint32_t comp_base;
#define t_href (comp_base + test_href)
#define t_name (comp_base + test_name)
#define t_highlight (comp_base + test_highlight)
static const component_t test_components[] = {
[test_href] = {
.size = sizeof (hierref_t),
@ -46,19 +51,29 @@ ecs_registry_t *test_reg;
#define WHT "\e[37;40m"
static int
check_hierarchy_size (hierarchy_t *h, uint32_t size)
check_hierarchy_size (hierref_t href, uint32_t size)
{
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, test_reg);
if (h->num_objects != size) {
printf ("hierarchy does not have exactly %u transform\n", size);
return 0;
}
ecs_registry_t *reg = h->reg;
for (uint32_t i = 0; i < h->num_objects; i++) {
hierref_t *ref = Ent_GetComponent (h->ent[i], test_href, reg);
char **name = Ent_GetComponent (h->ent[i], test_name, reg);;
if (ref->hierarchy != h) {
if (!ECS_EntValid (h->ent[i], test_reg)) {
printf ("invalid entity in hierarchy: %d\n", i);
return 0;
}
if (!Ent_HasComponent (h->ent[i], t_href, test_reg)) {
printf ("entity has no href: %d\n", i);
return 0;
}
auto ref = *(hierref_t *) Ent_GetComponent (h->ent[i], t_href,
test_reg);
char **name = Ent_GetComponent (h->ent[i], t_name, test_reg);;
if (ref.id != href.id) {
printf ("transform %d (%s) does not point to hierarchy\n",
i, *name);
return 0;
}
}
return 1;
@ -123,9 +138,9 @@ highlight_color (hierarchy_t *h, uint32_t i)
{
uint32_t ent = h->ent[i];
if (ECS_EntValid (ent, test_reg)
&& Ent_HasComponent (ent, test_highlight, test_reg)) {
&& Ent_HasComponent (ent, t_highlight, test_reg)) {
static char color_str[] = "\e[3.;4.m";
byte *color = Ent_GetComponent (ent, test_highlight, test_reg);
byte *color = Ent_GetComponent (ent, t_highlight, test_reg);
if (*color) {
byte fg = *color & 0x0f;
byte bg = *color >> 4;
@ -138,8 +153,9 @@ highlight_color (hierarchy_t *h, uint32_t i)
}
static void
dump_hierarchy (hierarchy_t *h)
dump_hierarchy (hierref_t href)
{
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, test_reg);
ecs_registry_t *reg = h->reg;
puts ("in: ri pa ci cc en name");
for (uint32_t i = 0; i < h->num_objects; i++) {
@ -148,10 +164,10 @@ dump_hierarchy (hierarchy_t *h)
static char *fake_nameptr = fake_name;
char **name = &fake_nameptr;
if (ECS_EntValid (h->ent[i], reg)) {
hierref_t *ref = Ent_GetComponent (h->ent[i], test_href, reg);
hierref_t *ref = Ent_GetComponent (h->ent[i], t_href, reg);
rind = ref->index;
if (Ent_HasComponent (h->ent[i], test_name, reg)) {
name = Ent_GetComponent (h->ent[i], test_name, reg);
if (Ent_HasComponent (h->ent[i], t_name, reg)) {
name = Ent_GetComponent (h->ent[i], t_name, reg);
}
}
printf ("%2d: %s%2d %s%2d %s%2d %s%2d %s%2d"DFL" %s%s"DFL"\n", i,
@ -166,8 +182,10 @@ dump_hierarchy (hierarchy_t *h)
}
static void
dump_tree (hierarchy_t *h, uint32_t ind, int level)
dump_tree (hierref_t href, int level)
{
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, test_reg);
uint32_t ind = href.index;
if (ind >= h->num_objects) {
printf ("index %d out of bounds (%d)\n", ind, h->num_objects);
return;
@ -180,8 +198,8 @@ dump_tree (hierarchy_t *h, uint32_t ind, int level)
char **name = &fake_nameptr;
ecs_registry_t *reg = h->reg;
if (ECS_EntValid (h->ent[ind], reg)
&& Ent_HasComponent (h->ent[ind], test_name, reg)) {
name = Ent_GetComponent (h->ent[ind], test_name, reg);;
&& Ent_HasComponent (h->ent[ind], t_name, reg)) {
name = Ent_GetComponent (h->ent[ind], t_name, reg);;
}
printf ("%2d: %s%2d %s%2d %s%2d %s%2d"DFL"|%*s%s%s"DFL"\n", ind,
parent_index_color (h, ind), h->parentIndex[ind],
@ -195,7 +213,11 @@ dump_tree (hierarchy_t *h, uint32_t ind, int level)
if (h->childIndex[ind] + i >= h->num_objects) {
break;
}
dump_tree (h, h->childIndex[ind] + i, level + 1);
hierref_t cref = {
.id = href.id,
.index = h->childIndex[ind] + i,
};
dump_tree (cref, level + 1);
}
}
if (!level) {
@ -208,14 +230,14 @@ check_indices (uint32_t ent, uint32_t index, uint32_t parentIndex,
uint32_t childIndex, uint32_t childCount)
{
ecs_registry_t *reg = test_reg;
char **entname = Ent_GetComponent (ent, test_name, reg);;
hierref_t *ref = Ent_GetComponent (ent, test_href, reg);
hierarchy_t *h = ref->hierarchy;
if (ref->index != index) {
char **name = Ent_GetComponent (h->ent[index], test_name, reg);;
char **entname = Ent_GetComponent (ent, t_name, reg);;
auto href = *(hierref_t *) Ent_GetComponent (ent, t_href, reg);
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
if (href.index != index) {
char **name = Ent_GetComponent (h->ent[index], t_name, reg);;
printf ("%s/%s index incorrect: expect %u got %u\n",
*entname, *name,
index, ref->index);
index, href.index);
return 0;
}
if (h->parentIndex[index] != parentIndex) {
@ -240,39 +262,36 @@ static uint32_t
create_ent (uint32_t parent, const char *name)
{
uint32_t ent = ECS_NewEntity (test_reg);
Ent_SetComponent (ent, test_name, test_reg, &name);
hierref_t *ref = Ent_AddComponent (ent, test_href, test_reg);
Ent_SetComponent (ent, t_name, test_reg, &name);
hierref_t *ref = Ent_AddComponent (ent, t_href, test_reg);
if (parent != nullent) {
hierref_t *pref = Ent_GetComponent (parent, test_href, test_reg);
ref->hierarchy = pref->hierarchy;
ref->index = Hierarchy_InsertHierarchy (pref->hierarchy, 0,
pref->index, 0);
auto pref = *(hierref_t *) Ent_GetComponent (parent, t_href, test_reg);
*ref = Hierarchy_InsertHierarchy (pref, nullhref, test_reg);
} else {
ref->hierarchy = Hierarchy_New (test_reg, test_href, 0, 1);
ref->id = Hierarchy_New (test_reg, t_href, 0, 1);
ref->index = 0;
}
ref->hierarchy->ent[ref->index] = ent;
hierarchy_t *h = Ent_GetComponent (ref->id, ecs_hierarchy, test_reg);
h->ent[ref->index] = ent;
return ent;
}
static void
highlight_ent (uint32_t ent, byte color)
{
Ent_SetComponent (ent, test_highlight, test_reg, &color);
Ent_SetComponent (ent, t_highlight, test_reg, &color);
}
static void
set_parent (uint32_t child, uint32_t parent)
{
auto cref = *(hierref_t *) Ent_GetComponent (child, t_href, test_reg);
if (parent != nullent) {
hierref_t *pref = Ent_GetComponent (parent, test_href, test_reg);
hierref_t *cref = Ent_GetComponent (child, test_href, test_reg);
Hierarchy_SetParent (pref->hierarchy, pref->index,
cref->hierarchy, cref->index);
auto pref = *(hierref_t *) Ent_GetComponent (parent, t_href, test_reg);
Hierarchy_SetParent (pref, cref, test_reg);
} else {
hierref_t *cref = Ent_GetComponent (child, test_href, test_reg);
Hierarchy_SetParent (0, nullent, cref->hierarchy, cref->index);
Hierarchy_SetParent (nullhref, cref, test_reg);
}
}
@ -280,26 +299,25 @@ static int
test_single_transform (void)
{
uint32_t ent = create_ent (nullent, "test");
hierarchy_t *h;
if (ent == nullent) {
printf ("create_ent returned null\n");
return 1;
}
hierref_t *ref = Ent_GetComponent (ent, test_href, test_reg);
hierref_t *ref = Ent_GetComponent (ent, t_href, test_reg);
if (!ref) {
printf ("Ent_GetComponent(test_href) returned null\n");
return 1;
}
if (!(h = ref->hierarchy)) {
printf ("New entity has no hierarchy\n");
if (!ECS_EntValid (ref->id, test_reg)) {
printf ("New entity has invalid hierarchy reference\n");
return 1;
}
if (!check_hierarchy_size (h, 1)) { return 1; }
if (!check_hierarchy_size (*ref, 1)) { return 1; }
if (!check_indices (ent, 0, nullent, 1, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (h);
Hierarchy_Delete (ref->id, test_reg);
return 0;
}
@ -310,22 +328,20 @@ test_parent_child_init (void)
uint32_t parent = create_ent (nullent, "parent");
uint32_t child = create_ent (parent, "child");
hierref_t *pref = Ent_GetComponent (parent, test_href, test_reg);
hierref_t *cref = Ent_GetComponent (child, test_href, test_reg);
if (pref->hierarchy != cref->hierarchy) {
auto pref = *(hierref_t *) Ent_GetComponent (parent, t_href, test_reg);
auto cref = *(hierref_t *) Ent_GetComponent (child, t_href, test_reg);
if (pref.id != cref.id) {
printf ("parent and child transforms have separate hierarchies\n");
return 1;
}
hierarchy_t *h = pref->hierarchy;
if (!check_hierarchy_size (h, 2)) { return 1; }
if (!check_hierarchy_size (pref, 2)) { return 1; }
if (!check_indices (parent, 0, nullent, 1, 1)) { return 1; }
if (!check_indices (child, 1, 0, 2, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (h);
Hierarchy_Delete (pref.id, test_reg);
return 0;
}
@ -339,9 +355,9 @@ test_parent_child_setparent (void)
if (!check_indices (parent, 0, nullent, 1, 0)) { return 1; }
if (!check_indices (child, 0, nullent, 1, 0)) { return 1; }
hierref_t *pref = Ent_GetComponent (parent, test_href, test_reg);
hierref_t *cref = Ent_GetComponent (child, test_href, test_reg);
if (pref->hierarchy == cref->hierarchy) {
auto pref = *(hierref_t *) Ent_GetComponent (parent, t_href, test_reg);
auto cref = *(hierref_t *) Ent_GetComponent (child, t_href, test_reg);
if (pref.id == cref.id) {
printf ("parent and child entities have same hierarchy before"
" set paret\n");
return 1;
@ -349,20 +365,20 @@ test_parent_child_setparent (void)
set_parent (child, parent);
if (pref->hierarchy != cref->hierarchy) {
pref = *(hierref_t *) Ent_GetComponent (parent, t_href, test_reg);
cref = *(hierref_t *) Ent_GetComponent (child, t_href, test_reg);
if (pref.id != cref.id) {
printf ("parent and child transforms have separate hierarchies\n");
return 1;
}
hierarchy_t *h = pref->hierarchy;
if (!check_hierarchy_size (h, 2)) { return 1; }
if (!check_hierarchy_size (pref, 2)) { return 1; }
if (!check_indices (parent, 0, nullent, 1, 1)) { return 1; }
if (!check_indices (child, 1, 0, 2, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (h);
Hierarchy_Delete (pref.id, test_reg);
return 0;
}
@ -377,7 +393,7 @@ test_build_hierarchy (void)
uint32_t B = create_ent (root, "B");
uint32_t C = create_ent (root, "C");
hierref_t *ref = Ent_GetComponent (root, test_href, test_reg);
hierref_t *ref = Ent_GetComponent (root, t_href, test_reg);
if (!check_indices (root, 0, nullent, 1, 3)) { return 1; }
if (!check_indices (A, 1, 0, 4, 0)) { return 1; }
@ -406,7 +422,7 @@ test_build_hierarchy (void)
uint32_t B3 = create_ent (B, "B3");
uint32_t B2a = create_ent (B2, "B2a");
if (!check_hierarchy_size (ref->hierarchy, 11)) { return 1; }
if (!check_hierarchy_size (*ref, 11)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 3)) { return 1; }
if (!check_indices ( A, 1, 0, 4, 2)) { return 1; }
@ -422,7 +438,7 @@ test_build_hierarchy (void)
uint32_t D = create_ent (root, "D");
if (!check_hierarchy_size (ref->hierarchy, 12)) { return 1; }
if (!check_hierarchy_size (*ref, 12)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -437,10 +453,10 @@ test_build_hierarchy (void)
if (!check_indices (A1a, 10, 5, 12, 0)) { return 1; }
if (!check_indices (B2a, 11, 8, 12, 0)) { return 1; }
dump_hierarchy (ref->hierarchy);
dump_hierarchy (*ref);
uint32_t C1 = create_ent (C, "C1");
dump_hierarchy (ref->hierarchy);
if (!check_hierarchy_size (ref->hierarchy, 13)) { return 1; }
dump_hierarchy (*ref);
if (!check_hierarchy_size (*ref, 13)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -457,7 +473,7 @@ test_build_hierarchy (void)
if (!check_indices (B2a, 12, 8, 13, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (ref->hierarchy);
Hierarchy_Delete (ref->id, test_reg);
return 0;
}
@ -481,9 +497,9 @@ test_build_hierarchy2 (void)
uint32_t D = create_ent (root, "D");
uint32_t C1 = create_ent (C, "C1");
hierref_t *ref = Ent_GetComponent (root, test_href, test_reg);
hierref_t *ref = Ent_GetComponent (root, t_href, test_reg);
if (!check_hierarchy_size (ref->hierarchy, 13)) { return 1; }
if (!check_hierarchy_size (*ref, 13)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -513,9 +529,9 @@ test_build_hierarchy2 (void)
uint32_t Z1 = create_ent (Z, "Z1");
hierref_t *Tref = Ent_GetComponent (T, test_href, test_reg);
dump_hierarchy (Tref->hierarchy);
if (!check_hierarchy_size (Tref->hierarchy, 12)) { return 1; }
hierref_t *Tref = Ent_GetComponent (T, t_href, test_reg);
dump_hierarchy (*Tref);
if (!check_hierarchy_size (*Tref, 12)) { return 1; }
if (!check_indices ( T, 0, nullent, 1, 3)) { return 1; }
if (!check_indices ( X, 1, 0, 4, 2)) { return 1; }
@ -532,9 +548,9 @@ test_build_hierarchy2 (void)
set_parent (T, B);
dump_hierarchy (ref->hierarchy);
dump_hierarchy (*ref);
if (!check_hierarchy_size (ref->hierarchy, 25)) { return 1; }
if (!check_hierarchy_size (*ref, 25)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -564,11 +580,11 @@ test_build_hierarchy2 (void)
set_parent (Y, nullent);
dump_hierarchy (ref->hierarchy);
hierref_t *Yref = Ent_GetComponent (Y, test_href, test_reg);
dump_hierarchy (Yref->hierarchy);
if (!check_hierarchy_size (ref->hierarchy, 20)) { return 1; }
if (!check_hierarchy_size (Yref->hierarchy, 5)) { return 1; }
dump_hierarchy (*ref);
hierref_t *Yref = Ent_GetComponent (Y, t_href, test_reg);
dump_hierarchy (*Yref);
if (!check_hierarchy_size (*ref, 20)) { return 1; }
if (!check_hierarchy_size (*Yref, 5)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -598,8 +614,8 @@ test_build_hierarchy2 (void)
if (!check_indices (Y2a, 4, 2, 5, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (ref->hierarchy);
Hierarchy_Delete (Yref->hierarchy);
Hierarchy_Delete (ref->id, test_reg);
Hierarchy_Delete (Yref->id, test_reg);
return 0;
}
@ -623,11 +639,11 @@ test_build_hierarchy3 (void)
uint32_t D = create_ent (root, "D");
uint32_t C1 = create_ent (C, "C1");
hierref_t *ref = Ent_GetComponent (root, test_href, test_reg);
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
hierref_t *ref = Ent_GetComponent (root, t_href, test_reg);
dump_hierarchy (*ref);
dump_tree (*ref, 0);
if (!check_hierarchy_size (ref->hierarchy, 13)) { return 1; }
if (!check_hierarchy_size (*ref, 13)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
if (!check_indices ( B, 2, 0, 7, 3)) { return 1; }
@ -643,10 +659,10 @@ test_build_hierarchy3 (void)
if (!check_indices (B2a, 12, 8, 13, 0)) { return 1; }
set_parent (B2, C1);
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
dump_hierarchy (*ref);
dump_tree (*ref, 0);
if (!check_hierarchy_size (ref->hierarchy, 13)) { return 1; }
if (!check_hierarchy_size (*ref, 13)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -670,10 +686,10 @@ test_build_hierarchy3 (void)
uint32_t B2b1 = create_ent (B2b, "B2b1");
uint32_t B2b2 = create_ent (B2b, "B2b2");
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
dump_hierarchy (*ref);
dump_tree (*ref, 0);
if (!check_hierarchy_size (ref->hierarchy, 20)) { return 1; }
if (!check_hierarchy_size (*ref, 20)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -697,10 +713,10 @@ test_build_hierarchy3 (void)
if (!check_indices (B2b2, 19, 15, 20, 0)) { return 1; }
set_parent (B2, root);
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
dump_hierarchy (*ref);
dump_tree (*ref, 0);
if (!check_hierarchy_size (ref->hierarchy, 20)) { return 1; }
if (!check_hierarchy_size (*ref, 20)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 5)) { return 1; }
if (!check_indices ( A, 1, 0, 6, 2)) { return 1; }
@ -724,7 +740,7 @@ test_build_hierarchy3 (void)
if (!check_indices (B2b2, 19, 12, 20, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (ref->hierarchy);
Hierarchy_Delete (ref->id, test_reg);
return 0;
}
@ -789,11 +805,11 @@ test_build_hierarchy4 (void)
highlight_ent (main_S_a_n, 0x01);
highlight_ent (main_i_f_b4, 0x01);
hierref_t *ref = Ent_GetComponent (hud, test_href, test_reg);
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
hierref_t *ref = Ent_GetComponent (hud, t_href, test_reg);
dump_hierarchy (*ref);
dump_tree (*ref, 0);
if (!check_hierarchy_size (ref->hierarchy, 37)) { return 1; }
if (!check_hierarchy_size (*ref, 37)) { return 1; }
if (!check_indices (hud, 0, nullent, 1, 2)) { return 1; }
if (!check_indices (mt, 1, 0, 3, 1)) { return 1; }
@ -834,8 +850,8 @@ test_build_hierarchy4 (void)
if (!check_indices (main_i_a_ma4, 36, 29, 37, 0)) { return 1; }
set_parent (main_i_a, hud);
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
dump_hierarchy (*ref);
dump_tree (*ref, 0);
if (!check_indices (hud, 0, nullent, 1, 3)) { return 1; }
if (!check_indices (mt, 1, 0, 4, 1)) { return 1; }
@ -876,7 +892,7 @@ test_build_hierarchy4 (void)
if (!check_indices (main_i_f_b4, 36, 29, 37, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (ref->hierarchy);
Hierarchy_Delete (ref->id, test_reg);
return 0;
}
@ -885,7 +901,8 @@ int
main (void)
{
test_reg = ECS_NewRegistry ("hierarchy");
ECS_RegisterComponents (test_reg, test_components, test_num_components);
comp_base = ECS_RegisterComponents (test_reg, test_components,
test_num_components);
ECS_CreateComponentPools (test_reg);
if (test_single_transform ()) { return 1; }

View file

@ -12,6 +12,8 @@ static int
test_new_del (void)
{
ecs_registry_t *reg = ECS_NewRegistry ("new del");
ECS_CreateComponentPools (reg);
if (!reg) {
printf ("could not create registry\n");
return 0;
@ -46,6 +48,7 @@ static int
test_entities (void)
{
ecs_registry_t *reg = ECS_NewRegistry ("entities");
ECS_CreateComponentPools (reg);
uint32_t entities[NUM_ENTS];

View file

@ -61,14 +61,14 @@ set_ent_name (uint32_t ent, uint32_t base, ecs_registry_t *reg,
}
static void
dump_sp_ids (ecs_registry_t *reg, uint32_t comp)
dump_sp_ids (ecs_registry_t *reg, uint32_t comp, uint32_t t_name)
{
ecs_pool_t *pool = &reg->comp_pools[comp];
uint32_t *ent = pool->dense;
uint32_t *id = pool->data;
for (uint32_t i = 0; i < pool->count; i++) {
const char **n = Ent_GetComponent (ent[i], test_name, reg);
const char **n = Ent_GetComponent (ent[i], t_name, reg);
printf ("ent[%d]: %2d, %2d %s\n", i, ent[i], id[i], *n);
}
}
@ -121,14 +121,15 @@ check_subpool_sorted (ecs_subpool_t *subpool)
}
static int
check_obj_comps (ecs_registry_t *reg, uint32_t comp, uint32_t *expect)
check_obj_comps (ecs_registry_t *reg, uint32_t comp, uint32_t *expect,
uint32_t t_name)
{
ecs_pool_t *pool = &reg->comp_pools[comp];
uint32_t *val = pool->data;
int fail = 0;
for (uint32_t i = 0; i < pool->count; i++) {
const char **n = Ent_GetComponent (pool->dense[i], test_name, reg);
const char **n = Ent_GetComponent (pool->dense[i], t_name, reg);
printf ("val[%d]: %2d %2d %s\n", i, val[i], expect[i], *n);
if (val[i] != expect[i]) {
fail = 1;
@ -199,7 +200,7 @@ main (void)
set_ent_name (entg, base, reg, ONG"g"DFL);
set_ent_name (enth, base, reg, MAG"h"DFL);
dump_sp_ids (reg, base + test_subpool);
dump_sp_ids (reg, base + test_subpool, base + test_name);
if (check_subpool_ranges (&reg->subpools[base + test_obj],
(uint32_t[]) { 0, 0, 0 })) {
printf ("oops\n");
@ -222,7 +223,8 @@ main (void)
return 1;
}
if (check_obj_comps (reg, base + test_obj,
(uint32_t[]) { 0, 1, 7, 5, 6, 2, 4, 3 })) {
(uint32_t[]) { 0, 1, 7, 5, 6, 2, 4, 3 },
base + test_name)) {
printf ("oops\n");
return 1;
}
@ -234,7 +236,8 @@ main (void)
return 1;
}
if (check_obj_comps (reg, base + test_obj,
(uint32_t[]) { 0, 7, 2, 5, 6, 3, 4 })) {
(uint32_t[]) { 0, 7, 2, 5, 6, 3, 4 },
base + test_name)) {
printf ("oops\n");
return 1;
}
@ -246,7 +249,8 @@ main (void)
return 1;
}
if (check_obj_comps (reg, base + test_obj,
(uint32_t[]) { 0, 7, 2, 5, 6, 4 })) {
(uint32_t[]) { 0, 7, 2, 5, 6, 4 },
base + test_name)) {
printf ("oops\n");
return 1;
}
@ -258,7 +262,8 @@ main (void)
return 1;
}
if (check_obj_comps (reg, base + test_obj,
(uint32_t[]) { 0, 7, 2, 5, 6 })) {
(uint32_t[]) { 0, 7, 2, 5, 6 },
base + test_name)) {
printf ("oops\n");
return 1;
}
@ -271,7 +276,8 @@ main (void)
return 1;
}
if (check_obj_comps (reg, base + test_obj,
(uint32_t[]) { 0, 7, 2, 5, 6, 8, 9 })) {
(uint32_t[]) { 0, 7, 2, 5, 6, 8, 9 },
base + test_name)) {
printf ("oops\n");
return 1;
}
@ -285,7 +291,8 @@ main (void)
return 1;
}
if (check_obj_comps (reg, base + test_obj,
(uint32_t[]) { 0, 7, 9, 8 })) {
(uint32_t[]) { 0, 7, 9, 8 },
base + test_name)) {
printf ("oops\n");
return 1;
}
@ -316,7 +323,8 @@ main (void)
return 1;
}
if (check_obj_comps (reg, base + test_obj,
(uint32_t[]) { 0, 7, 9, 8, 10, 11, 12 })) {
(uint32_t[]) { 0, 7, 9, 8, 10, 11, 12 },
base + test_name)) {
printf ("oops\n");
return 1;
}
@ -336,7 +344,8 @@ main (void)
return 1;
}
if (check_obj_comps (reg, base + test_obj,
(uint32_t[]) { 0, 7, 10, 11, 12, 9, 8 })) {
(uint32_t[]) { 0, 7, 10, 11, 12, 9, 8 },
base + test_name)) {
printf ("oops\n");
return 1;
}

View file

@ -16,6 +16,11 @@ enum {
test_num_components
};
static uint32_t comp_base;
#define t_href (comp_base + test_href)
#define t_name (comp_base + test_name)
#define t_highlight (comp_base + test_highlight)
static const component_t test_components[] = {
[test_href] = {
.size = sizeof (hierref_t),
@ -46,17 +51,18 @@ ecs_registry_t *test_reg;
#define WHT "\e[37;40m"
static int
check_hierarchy_size (hierarchy_t *h, uint32_t size)
check_hierarchy_size (hierref_t href, uint32_t size)
{
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, test_reg);
if (h->num_objects != size) {
printf ("hierarchy does not have exactly %u transform\n", size);
return 0;
}
ecs_registry_t *reg = h->reg;
for (uint32_t i = 0; i < h->num_objects; i++) {
hierref_t *ref = Ent_GetComponent (h->ent[i], test_href, reg);
char **name = Ent_GetComponent (h->ent[i], test_name, reg);;
if (ref->hierarchy != h) {
auto ref = *(hierref_t *) Ent_GetComponent (h->ent[i], t_href,
test_reg);
char **name = Ent_GetComponent (h->ent[i], t_name, test_reg);
if (ref.id != href.id) {
printf ("transform %d (%s) does not point to hierarchy\n",
i, *name);
}
@ -133,8 +139,9 @@ child_count_color (hierarchy_t *h, uint32_t i)
}
static bool
check_for_loops (hierarchy_t *h)
check_for_loops (hierref_t href)
{
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, test_reg);
for (uint32_t i = 0; i < h->num_objects; i++) {
if (!h->childCount[i]) {
continue;
@ -226,9 +233,9 @@ highlight_color (hierarchy_t *h, uint32_t i)
{
uint32_t ent = h->ent[i];
if (ECS_EntValid (ent, test_reg)
&& Ent_HasComponent (ent, test_highlight, test_reg)) {
&& Ent_HasComponent (ent, t_highlight, test_reg)) {
static char color_str[] = "\e[3.;4.m";
byte *color = Ent_GetComponent (ent, test_highlight, test_reg);
byte *color = Ent_GetComponent (ent, t_highlight, test_reg);
if (*color) {
byte fg = *color & 0x0f;
byte bg = *color >> 4;
@ -259,10 +266,10 @@ print_line (hierarchy_t *h, uint32_t ind, int level)
static char *fake_nameptr = fake_name;
char **name = &fake_nameptr;
if (ECS_EntValid (h->ent[ind], reg)) {
hierref_t *ref = Ent_GetComponent (h->ent[ind], test_href, reg);
hierref_t *ref = Ent_GetComponent (h->ent[ind], t_href, reg);
rind = ref->index;
if (Ent_HasComponent (h->ent[ind], test_name, reg)) {
name = Ent_GetComponent (h->ent[ind], test_name, reg);
if (Ent_HasComponent (h->ent[ind], t_name, reg)) {
name = Ent_GetComponent (h->ent[ind], t_name, reg);
}
}
printf ("%2d: %s%2d %s%2d %s%2d %s%2d", ind,
@ -281,8 +288,9 @@ print_line (hierarchy_t *h, uint32_t ind, int level)
}
static void
dump_hierarchy (hierarchy_t *h)
dump_hierarchy (hierref_t href)
{
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, test_reg);
print_header (h);
for (uint32_t i = 0; i < h->num_objects; i++) {
print_line (h, i, 0);
@ -291,8 +299,11 @@ dump_hierarchy (hierarchy_t *h)
}
static void
dump_tree (hierarchy_t *h, uint32_t ind, int level)
dump_tree (hierref_t href, int level)
{
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, test_reg);
uint32_t ind = href.index;
if (ind >= h->num_objects) {
printf ("index %d out of bounds (%d)\n", ind, h->num_objects);
return;
@ -307,7 +318,11 @@ dump_tree (hierarchy_t *h, uint32_t ind, int level)
uint32_t child;
for (child = h->childIndex[ind]; count && child != nullindex;
child = h->nextIndex[child], count--) {
dump_tree (h, child, level + 1);
hierref_t cref = {
.id = href.id,
.index = child,
};
dump_tree (cref, level + 1);
}
} else {
if (h->childIndex[ind] > ind) {
@ -315,7 +330,11 @@ dump_tree (hierarchy_t *h, uint32_t ind, int level)
if (h->childIndex[ind] + i >= h->num_objects) {
break;
}
dump_tree (h, h->childIndex[ind] + i, level + 1);
hierref_t cref = {
.id = href.id,
.index = h->childIndex[ind] + i,
};
dump_tree (cref, level + 1);
}
}
}
@ -329,14 +348,14 @@ check_indices (uint32_t ent, uint32_t index, uint32_t parentIndex,
uint32_t childIndex, uint32_t childCount)
{
ecs_registry_t *reg = test_reg;
char **entname = Ent_GetComponent (ent, test_name, reg);;
hierref_t *ref = Ent_GetComponent (ent, test_href, reg);
hierarchy_t *h = ref->hierarchy;
if (ref->index != index) {
char **name = Ent_GetComponent (h->ent[index], test_name, reg);;
char **entname = Ent_GetComponent (ent, t_name, reg);;
auto href = *(hierref_t *) Ent_GetComponent (ent, t_href, reg);
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
if (href.index != index) {
char **name = Ent_GetComponent (h->ent[index], t_name, reg);;
printf ("%s/%s index incorrect: expect %u got %u\n",
*entname, *name,
index, ref->index);
index, href.index);
return 0;
}
if (h->parentIndex[index] != parentIndex) {
@ -358,8 +377,9 @@ check_indices (uint32_t ent, uint32_t index, uint32_t parentIndex,
}
static bool
check_next_last_indices (hierarchy_t *h)
check_next_last_indices (hierref_t href)
{
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, test_reg);
for (uint32_t i = 0; i < h->num_objects; i++) {
if (!check_next_index (h, i)) {
printf ("incorrect next index at %d: %d\n", i, h->nextIndex[i]);
@ -377,38 +397,44 @@ static uint32_t
create_ent (uint32_t parent, const char *name)
{
uint32_t ent = ECS_NewEntity (test_reg);
Ent_SetComponent (ent, test_name, test_reg, &name);
hierref_t *ref = Ent_AddComponent (ent, test_href, test_reg);
Ent_SetComponent (ent, t_name, test_reg, &name);
hierref_t *ref = Ent_AddComponent (ent, t_href, test_reg);
if (parent != nullindex) {
hierref_t *pref = Ent_GetComponent (parent, test_href, test_reg);
ref->hierarchy = pref->hierarchy;
ref->index = Hierarchy_InsertHierarchy (pref->hierarchy, 0,
pref->index, 0);
auto pref = *(hierref_t *) Ent_GetComponent (parent, t_href, test_reg);
*ref = Hierarchy_InsertHierarchy (pref, nullhref, test_reg);
} else {
ref->hierarchy = Hierarchy_New (test_reg, test_href, 0, 1);
ref->id = Hierarchy_New (test_reg, t_href, 0, 1);
ref->index = 0;
}
ref->hierarchy->ent[ref->index] = ent;
hierarchy_t *h = Ent_GetComponent (ref->id, ecs_hierarchy, test_reg);
h->ent[ref->index] = ent;
return ent;
}
static void
set_tree_mode (hierref_t href, bool tree_mode)
{
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, test_reg);
Hierarchy_SetTreeMode (h, tree_mode);
}
#if 0
static void
highlight_ent (uint32_t ent, byte color)
{
Ent_SetComponent (ent, test_highlight, test_reg, &color);
Ent_SetComponent (ent, t_highlight, test_reg, &color);
}
static void
set_parent (uint32_t child, uint32_t parent)
{
if (parent != nullindex) {
hierref_t *pref = Ent_GetComponent (parent, test_href, test_reg);
hierref_t *cref = Ent_GetComponent (child, test_href, test_reg);
hierref_t *pref = Ent_GetComponent (parent, t_href, test_reg);
hierref_t *cref = Ent_GetComponent (child, t_href, test_reg);
Hierarchy_SetParent (pref->hierarchy, pref->index,
cref->hierarchy, cref->index);
} else {
hierref_t *cref = Ent_GetComponent (child, test_href, test_reg);
hierref_t *cref = Ent_GetComponent (child, t_href, test_reg);
Hierarchy_SetParent (0, nullindex, cref->hierarchy, cref->index);
}
}
@ -423,7 +449,7 @@ test_build_hierarchy (void)
uint32_t B = create_ent (root, "B");
uint32_t C = create_ent (root, "C");
hierref_t *ref = Ent_GetComponent (root, test_href, test_reg);
hierref_t *ref = Ent_GetComponent (root, t_href, test_reg);
if (!check_indices (root, 0, nullindex, 1, 3)) { return 1; }
if (!check_indices (A, 1, 0, 4, 0)) { return 1; }
@ -452,7 +478,7 @@ test_build_hierarchy (void)
uint32_t B3 = create_ent (B, "B3");
uint32_t B2a = create_ent (B2, "B2a");
if (!check_hierarchy_size (ref->hierarchy, 11)) { return 1; }
if (!check_hierarchy_size (*ref, 11)) { return 1; }
if (!check_indices (root, 0, nullindex, 1, 3)) { return 1; }
if (!check_indices ( A, 1, 0, 4, 2)) { return 1; }
@ -468,7 +494,7 @@ test_build_hierarchy (void)
uint32_t D = create_ent (root, "D");
if (!check_hierarchy_size (ref->hierarchy, 12)) { return 1; }
if (!check_hierarchy_size (*ref, 12)) { return 1; }
if (!check_indices (root, 0, nullindex, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -483,10 +509,10 @@ test_build_hierarchy (void)
if (!check_indices (A1a, 10, 5, 12, 0)) { return 1; }
if (!check_indices (B2a, 11, 8, 12, 0)) { return 1; }
dump_hierarchy (ref->hierarchy);
dump_hierarchy (*ref);
uint32_t C1 = create_ent (C, "C1");
dump_hierarchy (ref->hierarchy);
if (!check_hierarchy_size (ref->hierarchy, 13)) { return 1; }
dump_hierarchy (*ref);
if (!check_hierarchy_size (*ref, 13)) { return 1; }
if (!check_indices (root, 0, nullindex, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -502,24 +528,24 @@ test_build_hierarchy (void)
if (!check_indices (A1a, 11, 5, 13, 0)) { return 1; }
if (!check_indices (B2a, 12, 8, 13, 0)) { return 1; }
dump_tree (ref->hierarchy, 0, 0);
Hierarchy_SetTreeMode (ref->hierarchy, true);
dump_tree (*ref, 0);
set_tree_mode (*ref, true);
//ref->hierarchy->tree_mode = true;
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
if (!check_for_loops (ref->hierarchy)) { return 1; }
if (!check_next_last_indices (ref->hierarchy)) { return 1; }
dump_hierarchy (*ref);
dump_tree (*ref, 0);
if (!check_for_loops (*ref)) { return 1; }
if (!check_next_last_indices (*ref)) { return 1; }
create_ent (root, "E");
create_ent (B1, "B1a");
create_ent (A2, "A2a");
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
if (!check_for_loops (ref->hierarchy)) { return 1; }
if (!check_next_last_indices (ref->hierarchy)) { return 1; }
dump_hierarchy (*ref);
dump_tree (*ref, 0);
if (!check_for_loops (*ref)) { return 1; }
if (!check_next_last_indices (*ref)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (ref->hierarchy);
Hierarchy_Delete (ref->id, test_reg);
return 0;
}
@ -530,8 +556,8 @@ test_build_hierarchy2 (void)
printf ("test_build_hierarchy2\n");
uint32_t root = create_ent (nullent, "root");
hierref_t *ref = Ent_GetComponent (root, test_href, test_reg);
Hierarchy_SetTreeMode (ref->hierarchy, true);
hierref_t *ref = Ent_GetComponent (root, t_href, test_reg);
set_tree_mode (*ref, true);
uint32_t A = create_ent (root, "A");
uint32_t A1 = create_ent (A, "A1");
uint32_t A1a = create_ent (A1, "A1a");
@ -560,12 +586,12 @@ test_build_hierarchy2 (void)
if (!check_indices ( C, 10, 0, 11, 1)) { return 1; }
if (!check_indices ( C1, 11, 10, ni, 0)) { return 1; }
if (!check_indices ( D, 12, 0, ni, 0)) { return 1; }
if (!check_next_last_indices (ref->hierarchy)) { return 1; }
if (!check_for_loops (ref->hierarchy)) { return 1; }
if (!check_next_last_indices (*ref)) { return 1; }
if (!check_for_loops (*ref)) { return 1; }
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
Hierarchy_SetTreeMode (ref->hierarchy, true);// shouldn't do anything
dump_hierarchy (*ref);
dump_tree (*ref, 0);
set_tree_mode (*ref, true);// shouldn't do anything
if (!check_indices (root, 0, ni, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 2, 2)) { return 1; }
if (!check_indices ( A1, 2, 1, 3, 1)) { return 1; }
@ -579,13 +605,13 @@ test_build_hierarchy2 (void)
if (!check_indices ( C, 10, 0, 11, 1)) { return 1; }
if (!check_indices ( C1, 11, 10, ni, 0)) { return 1; }
if (!check_indices ( D, 12, 0, ni, 0)) { return 1; }
if (!check_next_last_indices (ref->hierarchy)) { return 1; }
if (!check_for_loops (ref->hierarchy)) { return 1; }
if (!check_next_last_indices (*ref)) { return 1; }
if (!check_for_loops (*ref)) { return 1; }
Hierarchy_SetTreeMode (ref->hierarchy, false);
puts("Hierarchy_SetTreeMode");
dump_hierarchy (ref->hierarchy);
dump_tree (ref->hierarchy, 0, 0);
set_tree_mode (*ref, false);
puts("set_tree_mode");
dump_hierarchy (*ref);
dump_tree (*ref, 0);
if (!check_indices (root, 0, nullindex, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -602,7 +628,7 @@ puts("Hierarchy_SetTreeMode");
if (!check_indices (B2a, 12, 8, 13, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (ref->hierarchy);
Hierarchy_Delete (ref->id, test_reg);
return 0;
}
@ -611,7 +637,8 @@ int
main (void)
{
test_reg = ECS_NewRegistry ("tree");
ECS_RegisterComponents (test_reg, test_components, test_num_components);
comp_base = ECS_RegisterComponents (test_reg, test_components,
test_num_components);
ECS_CreateComponentPools (test_reg);
if (test_build_hierarchy ()) { return 1; }

View file

@ -279,7 +279,9 @@ bi (Passage_ChildCount)
rua_passage_t *psg = get_passage (res, P_INT (pr, 0));
uint32_t par = P_UINT (pr, 1);
R_UINT (pr) = psg->passage->hierarchy->childCount[par];
auto p = psg->passage;
hierarchy_t *h = Ent_GetComponent (p->hierarchy, ecs_hierarchy, p->reg);
R_UINT (pr) = h->childCount[par];
}
bi (Passage_GetChild)
@ -287,7 +289,8 @@ bi (Passage_GetChild)
gui_resources_t *res = _res;
rua_passage_t *psg = get_passage (res, P_INT (pr, 0));
hierarchy_t *h = psg->passage->hierarchy;
auto p = psg->passage;
hierarchy_t *h = Ent_GetComponent (p->hierarchy, ecs_hierarchy, p->reg);
uint32_t par = P_UINT (pr, 1);
uint32_t index = P_UINT (pr, 2);
R_UINT (pr) = h->ent[h->childIndex[par] + index];
@ -357,20 +360,20 @@ bi (Text_Draw)
// first paragraph's first child are all text views
view_t para_view = View_GetChild (psg_view, 0);
view_t text_view = View_GetChild (para_view, 0);
hierref_t *href = View_GetRef (text_view);
glyphset_t *gs = glyphset++;
hierarchy_t *h = href->hierarchy;
hierref_t href = View_GetRef (text_view);
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, res->reg);
view_pos_t *abs = h->components[view_abs];
view_pos_t *len = h->components[view_len];
for (uint32_t i = href->index; i < h->num_objects; i++) {
for (uint32_t i = href.index; i < h->num_objects; i++) {
glyphref_t *gref = Ent_GetComponent (h->ent[i], glyphs, res->reg);
draw_glyphs (&abs[i], gs, gref);
if (0) draw_box (abs, len, i, 253);
}
if (0) {
for (uint32_t i = 1; i < href->index; i++) {
for (uint32_t i = 1; i < href.index; i++) {
draw_box (abs, len, i, 251);
}
}

View file

@ -121,6 +121,7 @@ rua__entity_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
pr_int_t entity_id = id >> 32;
ent.id = entity_id;
ent.reg = scene->scene->reg;
ent.base = scene->scene->base;
}
if (!Entity_Valid (ent)) {
@ -138,7 +139,11 @@ rua__transform_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
rua_scene_t *scene = rua_scene_get (res, scene_id);
if (scene) {
entity_t transform_id = { .reg = scene->scene->reg, .id = id >> 32 };
entity_t transform_id = {
.reg = scene->scene->reg,
.id = id >> 32,
.base = scene->scene->base,
};
transform = Entity_Transform (transform_id);
}
@ -300,7 +305,7 @@ bi_Entity_SetModel (progs_t *pr, void *_res)
// bad scene caught above
rua_scene_t *scene = rua_scene_get (res, scene_id);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
renderer->model = model;
R_AddEfrags (&scene->scene->worldmodel->brush, ent);
}

View file

@ -213,18 +213,18 @@ R_AddEfrags (mod_brush_t *brush, entity_t ent)
model_t *entmodel;
vec3_t emins, emaxs;
transform_t transform = Entity_Transform (ent);
renderer_t *rend = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *rend = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
if (!rend->model) {
Ent_RemoveComponent (ent.id, scene_visibility, ent.reg);
Ent_RemoveComponent (ent.id, ent.base + scene_visibility, ent.reg);
return;
}
visibility_t *vis;
if (Ent_HasComponent (ent.id, scene_visibility, ent.reg)) {
vis = Ent_GetComponent (ent.id, scene_visibility, ent.reg);
if (Ent_HasComponent (ent.id, ent.base + scene_visibility, ent.reg)) {
vis = Ent_GetComponent (ent.id, ent.base + scene_visibility, ent.reg);
R_ClearEfragChain (vis->efrag);
} else {
vis = Ent_AddComponent (ent.id, scene_visibility, ent.reg);
vis = Ent_AddComponent (ent.id, ent.base + scene_visibility, ent.reg);
}
vis->efrag = 0;

View file

@ -107,7 +107,7 @@ link_light (lightingdata_t *ldata, const light_t *light, entity_t ent)
// ambient light
Mod_LeafPVS_set (model->brush.leafs, &model->brush, 0xff, pvs);
}
Ent_SetComponent (ent.id, scene_lightleaf, ent.reg, &leafnum);
Ent_SetComponent (ent.id, ent.base + scene_lightleaf, ent.reg, &leafnum);
efrag_t *efrags = 0;
efrag_t **lastlink = &efrags;
@ -117,10 +117,10 @@ link_light (lightingdata_t *ldata, const light_t *light, entity_t ent)
lastlink = R_LinkEfrag (leaf, ent, mod_light, lastlink);
}
}
if (Ent_HasComponent (ent.id, scene_efrags, ent.reg)) {
Ent_RemoveComponent (ent.id, scene_efrags, ent.reg);
if (Ent_HasComponent (ent.id, ent.base + scene_efrags, ent.reg)) {
Ent_RemoveComponent (ent.id, ent.base + scene_efrags, ent.reg);
}
Ent_SetComponent (ent.id, scene_efrags, ent.reg, &efrags);
Ent_SetComponent (ent.id, ent.base + scene_efrags, ent.reg, &efrags);
}
void
@ -131,10 +131,11 @@ Light_AddLight (lightingdata_t *ldata, const light_t *light, uint32_t style)
entity_t ent = {
.reg = scene->reg,
.id = ECS_NewEntity (scene->reg),
.base = scene->base,
};
Ent_SetComponent (ent.id, scene_light, ent.reg, light);
Ent_SetComponent (ent.id, scene_lightstyle, ent.reg, &style);
Ent_SetComponent (ent.id, ent.base + scene_light, ent.reg, light);
Ent_SetComponent (ent.id, ent.base + scene_lightstyle, ent.reg, &style);
link_light (ldata, light, ent);
}
@ -147,8 +148,9 @@ Light_LinkLight (lightingdata_t *ldata, uint32_t entid)
entity_t ent = {
.reg = scene->reg,
.id = entid,
.base = scene->base,
};
dlight_t *dlight = Ent_GetComponent (ent.id, scene_dynlight, ent.reg);
dlight_t *dlight = Ent_GetComponent (ent.id, ent.base + scene_dynlight, ent.reg);
if (!dlight) {
Sys_Error ("no dlight on entity to link");
}
@ -189,8 +191,9 @@ Light_EnableSun (lightingdata_t *ldata)
void
Light_DecayLights (lightingdata_t *ldata, float frametime, double realtime)
{
auto reg = ldata->scene->reg;
auto dlight_pool = &reg->comp_pools[scene_dynlight];
auto scene = ldata->scene;
auto reg = scene->reg;
auto dlight_pool = &reg->comp_pools[scene->base + scene_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
@ -198,11 +201,11 @@ Light_DecayLights (lightingdata_t *ldata, float frametime, double realtime)
dlight->radius -= frametime * dlight->decay;
if (dlight->radius <= 0 || dlight->die < realtime) {
uint32_t ent = dlight_pool->dense[i];
Ent_RemoveComponent (ent, scene_dynlight, reg);
if (!Ent_HasComponent (ent, scene_efrags, reg)) {
Ent_RemoveComponent (ent, scene->base + scene_dynlight, reg);
if (!Ent_HasComponent (ent, scene->base + scene_efrags, reg)) {
Sys_Error ("dlight with no efrags");
}
Ent_RemoveComponent (ent, scene_efrags, reg);
Ent_RemoveComponent (ent, scene->base + scene_efrags, reg);
i--;
}
}

View file

@ -260,7 +260,8 @@ Scene_NewScene (scene_system_t *extra_systems)
scene_t *scene = calloc (1, sizeof (scene_t));
scene->reg = ECS_NewRegistry ("scene");
ECS_RegisterComponents (scene->reg, scene_components, scene_comp_count);
scene->base = ECS_RegisterComponents (scene->reg, scene_components,
scene_comp_count);
for (auto extra = extra_systems; extra && extra->system; extra++) {
uint32_t base = ECS_RegisterComponents (scene->reg,
extra->components,
@ -288,18 +289,19 @@ Scene_CreateEntity (scene_t *scene)
{
// Transform_New creates an entity and adds a scene_href component to the
// entity
transform_t trans = Transform_New (scene->reg, nulltransform);
ecs_system_t ssys = { .reg = scene->reg, .base = scene->base };
transform_t trans = Transform_New (ssys, nulltransform);
uint32_t id = trans.id;
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);
Ent_SetComponent (id, scene->base + scene_animation, scene->reg, 0);
Ent_SetComponent (id, scene->base + scene_renderer, scene->reg, 0);
Ent_SetComponent (id, scene->base + scene_active, scene->reg, 0);
Ent_SetComponent (id, scene->base + scene_old_origin, scene->reg, 0);
renderer_t *renderer = Ent_GetComponent (id, scene_renderer, scene->reg);
renderer_t *renderer = Ent_GetComponent (id, scene->base + scene_renderer, scene->reg);
QuatSet (1, 1, 1, 1, renderer->colormod);
return (entity_t) { .reg = scene->reg, .id = id };
return (entity_t) { .reg = scene->reg, .id = id, .base = scene->base };
}
void

View file

@ -11,7 +11,7 @@
#include "QF/scene/scene.h"
#include "QF/scene/transform.h"
ecs_registry_t *reg;
ecs_system_t ssys;
// NOTE: these are the columns of the matrix! (not that it matters for a
// symmetrical matrix, but...)
@ -44,16 +44,16 @@ mat4_equal (const mat4f_t a, const mat4f_t b)
static int
check_hierarchy_size (transform_t t, uint32_t size)
{
hierarchy_t *h = Transform_GetRef (t)->hierarchy;
auto href = Transform_GetRef (t);
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, t.reg);
if (h->num_objects != size) {
printf ("hierarchy does not have exactly %u transform\n", size);
return 0;
}
char **name = h->components[transform_type_name];
ecs_registry_t *reg = h->reg;
for (uint32_t i = 0; i < h->num_objects; i++) {
hierref_t *ref = Ent_GetComponent (h->ent[i], scene_href, reg);
if (ref->hierarchy != h) {
auto ref = *(hierref_t *) Ent_GetComponent (h->ent[i], ssys.base + scene_href, ssys.reg);
if (ref.id != href.id) {
printf ("transform %d (%s) does not point to hierarchy\n",
i, name[i]);
}
@ -65,13 +65,13 @@ static int
check_indices (transform_t transform, uint32_t index, uint32_t parentIndex,
uint32_t childIndex, uint32_t childCount)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto href = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, ssys.reg);
char **name = h->components[transform_type_name];
if (ref->index != index) {
if (href.index != index) {
printf ("%s/%s index incorrect: expect %u got %u\n",
name[ref->index], name[index],
index, ref->index);
name[href.index], name[index],
index, href.index);
return 0;
}
if (h->parentIndex[index] != parentIndex) {
@ -95,21 +95,19 @@ check_indices (transform_t transform, uint32_t index, uint32_t parentIndex,
static int
test_single_transform (void)
{
transform_t transform = Transform_New (reg, (transform_t) {});
hierarchy_t *h;
transform_t transform = Transform_New (ssys, (transform_t) {});
if (!transform.reg || transform.id == nullent) {
printf ("Transform_New returned null\n");
return 1;
}
if (!Transform_GetRef (transform)) {
printf ("Transform_GetRef returned null\n");
return 1;
}
if (!(h = Transform_GetRef (transform)->hierarchy)) {
printf ("New transform has no hierarchy\n");
auto href = Transform_GetRef (transform);
if (!ECS_EntValid (href.id, ssys.reg)) {
printf ("New transform has invalid hierarchy reference\n");
return 1;
}
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, ssys.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
mat4f_t *localInverse = h->components[transform_type_localInverse];
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
@ -134,7 +132,7 @@ test_single_transform (void)
}
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (h);
Hierarchy_Delete (href.id, ssys.reg);
return 0;
}
@ -142,11 +140,10 @@ test_single_transform (void)
static int
test_parent_child_init (void)
{
transform_t parent = Transform_New (reg, (transform_t) {});
transform_t child = Transform_New (reg, parent);
transform_t parent = Transform_New (ssys, (transform_t) {});
transform_t child = Transform_New (ssys, parent);
if (Transform_GetRef (parent)->hierarchy
!= Transform_GetRef (child)->hierarchy) {
if (Transform_GetRef (parent).id != Transform_GetRef (child).id) {
printf ("parent and child transforms have separate hierarchies\n");
return 1;
}
@ -156,7 +153,8 @@ test_parent_child_init (void)
if (!check_indices (parent, 0, nullent, 1, 1)) { return 1; }
if (!check_indices (child, 1, 0, 2, 0)) { return 1; }
hierarchy_t *h = Transform_GetRef (parent)->hierarchy;
auto pref = Transform_GetRef (parent);
hierarchy_t *h = Ent_GetComponent (pref.id, ecs_hierarchy, ssys.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
mat4f_t *localInverse = h->components[transform_type_localInverse];
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
@ -192,7 +190,7 @@ test_parent_child_init (void)
}
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (Transform_GetRef (parent)->hierarchy);
Hierarchy_Delete (Transform_GetRef (parent).id, ssys.reg);
return 0;
}
@ -200,8 +198,8 @@ test_parent_child_init (void)
static int
test_parent_child_setparent (void)
{
transform_t parent = Transform_New (reg, (transform_t) {});
transform_t child = Transform_New (reg, (transform_t) {});
transform_t parent = Transform_New (ssys, (transform_t) {});
transform_t child = Transform_New (ssys, (transform_t) {});
Transform_SetName (parent, "parent");
Transform_SetName (child, "child");
@ -209,8 +207,7 @@ test_parent_child_setparent (void)
if (!check_indices (parent, 0, nullent, 1, 0)) { return 1; }
if (!check_indices (child, 0, nullent, 1, 0)) { return 1; }
if (Transform_GetRef (parent)->hierarchy
== Transform_GetRef (child)->hierarchy) {
if (Transform_GetRef (parent).id == Transform_GetRef (child).id) {
printf ("parent and child transforms have same hierarchy before"
" set paret\n");
return 1;
@ -218,8 +215,7 @@ test_parent_child_setparent (void)
Transform_SetParent (child, parent);
if (Transform_GetRef (parent)->hierarchy
!= Transform_GetRef (child)->hierarchy) {
if (Transform_GetRef (parent).id != Transform_GetRef (child).id) {
printf ("parent and child transforms have separate hierarchies\n");
return 1;
}
@ -229,7 +225,8 @@ test_parent_child_setparent (void)
if (!check_indices (parent, 0, nullent, 1, 1)) { return 1; }
if (!check_indices (child, 1, 0, 2, 0)) { return 1; }
hierarchy_t *h = Transform_GetRef (parent)->hierarchy;
auto pref = Transform_GetRef (parent);
hierarchy_t *h = Ent_GetComponent (pref.id, ecs_hierarchy, ssys.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
mat4f_t *localInverse = h->components[transform_type_localInverse];
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
@ -265,7 +262,7 @@ test_parent_child_setparent (void)
}
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (Transform_GetRef (parent)->hierarchy);
Hierarchy_Delete (Transform_GetRef (parent).id, ssys.reg);
return 0;
}
@ -288,11 +285,11 @@ check_vector (transform_t transform,
static int
test_frames (void)
{
transform_t root = Transform_NewNamed (reg, (transform_t) {}, "root");
transform_t A = Transform_NewNamed (reg, root, "A");
transform_t B = Transform_NewNamed (reg, root, "B");
transform_t A1 = Transform_NewNamed (reg, A, "A1");
transform_t B1 = Transform_NewNamed (reg, B, "B1");
transform_t root = Transform_NewNamed (ssys, (transform_t) {}, "root");
transform_t A = Transform_NewNamed (ssys, root, "A");
transform_t B = Transform_NewNamed (ssys, root, "B");
transform_t A1 = Transform_NewNamed (ssys, A, "A1");
transform_t B1 = Transform_NewNamed (ssys, B, "B1");
Transform_SetLocalPosition (root, (vec4f_t) { 0, 0, 1, 1 });
Transform_SetLocalPosition (A, (vec4f_t) { 1, 0, 0, 1 });
@ -304,7 +301,8 @@ test_frames (void)
Transform_SetLocalPosition (B1, (vec4f_t) { 0, 1, 0, 1 });
Transform_SetLocalRotation (B1, (vec4f_t) { -0.5, 0.5, -0.5, 0.5 });
hierarchy_t *h = Transform_GetRef (root)->hierarchy;
auto rref = Transform_GetRef (root);
hierarchy_t *h = Ent_GetComponent (rref.id, ecs_hierarchy, ssys.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
mat4f_t *localInverse = h->components[transform_type_localInverse];
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
@ -483,7 +481,8 @@ int
main (void)
{
scene_t *scene = Scene_NewScene (NULL);
reg = scene->reg;
ssys.reg = scene->reg;
ssys.base = scene->base;
if (test_single_transform ()) { return 1; }
if (test_parent_child_init ()) { return 1; }

View file

@ -202,42 +202,47 @@ Transform_UpdateMatrices (hierarchy_t *h)
}
transform_t
Transform_New (ecs_registry_t *reg, transform_t parent)
Transform_New (ecs_system_t ssys, transform_t parent)
{
uint32_t transform = ECS_NewEntity (reg);
hierref_t *ref = Ent_AddComponent (transform, scene_href, reg);
uint32_t transform = ECS_NewEntity (ssys.reg);
hierref_t *ref = Ent_AddComponent (transform, ssys.base + scene_href,
ssys.reg);
if (parent.reg && parent.id != nullent) {
hierref_t *pref = Transform_GetRef (parent);
ref->hierarchy = pref->hierarchy;
ref->index = Hierarchy_InsertHierarchy (pref->hierarchy, 0,
pref->index, 0);
hierref_t pref = Transform_GetRef (parent);
*ref = Hierarchy_InsertHierarchy (pref, nullhref, ssys.reg);
} else {
ref->hierarchy = Hierarchy_New (reg, scene_href, &transform_type, 1);
ref->id = Hierarchy_New (ssys.reg, ssys.base + scene_href,
&transform_type, 1);
ref->index = 0;
}
ref->hierarchy->ent[ref->index] = transform;
Transform_UpdateMatrices (ref->hierarchy);
return (transform_t) { .reg = reg, .id = transform, .comp = scene_href };
hierarchy_t *h = Ent_GetComponent (ref->id, ecs_hierarchy, ssys.reg);
h->ent[ref->index] = transform;
Transform_UpdateMatrices (h);
return (transform_t) {
.reg = ssys.reg,
.id = transform,
.comp = ssys.base + scene_href,
};
}
void
Transform_Delete (transform_t transform)
{
hierref_t *ref = Transform_GetRef (transform);
if (ref->index != 0) {
hierref_t ref = Transform_GetRef (transform);
if (ref.index != 0) {
// The transform is not the root, so pull it out of its current
// hierarchy so deleting it is easier
Transform_SetParent (transform, (transform_t) {});
}
// Takes care of freeing the transforms
Hierarchy_Delete (ref->hierarchy);
Hierarchy_Delete (ref.id, transform.reg);
}
transform_t
Transform_NewNamed (ecs_registry_t *reg, transform_t parent, const char *name)
Transform_NewNamed (ecs_system_t ssys, transform_t parent, const char *name)
{
transform_t transform = Transform_New (reg, parent);
transform_t transform = Transform_New (ssys, parent);
Transform_SetName (transform, name);
return transform;
}
@ -245,115 +250,106 @@ Transform_NewNamed (ecs_registry_t *reg, transform_t parent, const char *name)
void
Transform_SetParent (transform_t transform, transform_t parent)
{
hierarchy_t *dst = 0;
uint32_t dstParent = nullent;
hierarchy_t *src = 0;
uint32_t srcIndex = 0;
hierref_t dref = nullhref;
hierref_t sref = Transform_GetRef (transform);
if (Transform_Valid (parent)) {
__auto_type ref = Transform_GetRef (parent);
dst = ref->hierarchy;
dstParent = ref->index;
dref = Transform_GetRef (parent);
}
{
__auto_type ref = Transform_GetRef (transform);
src = ref->hierarchy;
srcIndex = ref->index;
}
Hierarchy_SetParent (dst, dstParent, src, srcIndex);
Hierarchy_SetParent (dref, sref, transform.reg);
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
byte *modified = h->components[transform_type_modified];
modified[ref->index] = 1;
modified[ref.index] = 1;
Transform_UpdateMatrices (h);
}
void
Transform_SetName (transform_t transform, const char *_name)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
char **name = h->components[transform_type_name];
//FIXME create a string pool (similar to qfcc's, or even move that to util)
if (name[ref->index]) {
free (name[ref->index]);
if (name[ref.index]) {
free (name[ref.index]);
}
name[ref->index] = strdup (_name);
name[ref.index] = strdup (_name);
}
void
Transform_SetTag (transform_t transform, uint32_t _tag)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
uint32_t *tag = h->components[transform_type_tag];
tag[ref->index] = _tag;
tag[ref.index] = _tag;
}
void
Transform_SetLocalPosition (transform_t transform, vec4f_t position)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
byte *modified = h->components[transform_type_modified];
localMatrix[ref->index][3] = position;
modified[ref->index] = 1;
localMatrix[ref.index][3] = position;
modified[ref.index] = 1;
Transform_UpdateMatrices (h);
}
void
Transform_SetLocalRotation (transform_t transform, vec4f_t rotation)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
vec4f_t *localRotation = h->components[transform_type_localRotation];
vec4f_t *localScale = h->components[transform_type_localScale];
byte *modified = h->components[transform_type_modified];
vec4f_t scale = localScale[ref->index];
vec4f_t scale = localScale[ref.index];
mat4f_t mat;
mat4fquat (mat, rotation);
localRotation[ref->index] = rotation;
localMatrix[ref->index][0] = mat[0] * scale[0];
localMatrix[ref->index][1] = mat[1] * scale[1];
localMatrix[ref->index][2] = mat[2] * scale[2];
modified[ref->index] = 1;
localRotation[ref.index] = rotation;
localMatrix[ref.index][0] = mat[0] * scale[0];
localMatrix[ref.index][1] = mat[1] * scale[1];
localMatrix[ref.index][2] = mat[2] * scale[2];
modified[ref.index] = 1;
Transform_UpdateMatrices (h);
}
void
Transform_SetLocalScale (transform_t transform, vec4f_t scale)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
vec4f_t *localRotation = h->components[transform_type_localRotation];
vec4f_t *localScale = h->components[transform_type_localScale];
byte *modified = h->components[transform_type_modified];
vec4f_t rotation = localRotation[ref->index];
vec4f_t rotation = localRotation[ref.index];
mat4f_t mat;
mat4fquat (mat, rotation);
localScale[ref->index] = scale;
localMatrix[ref->index][0] = mat[0] * scale[0];
localMatrix[ref->index][1] = mat[1] * scale[1];
localMatrix[ref->index][2] = mat[2] * scale[2];
modified[ref->index] = 1;
localScale[ref.index] = scale;
localMatrix[ref.index][0] = mat[0] * scale[0];
localMatrix[ref.index][1] = mat[1] * scale[1];
localMatrix[ref.index][2] = mat[2] * scale[2];
modified[ref.index] = 1;
Transform_UpdateMatrices (h);
}
void
Transform_SetWorldPosition (transform_t transform, vec4f_t position)
{
__auto_type ref = Transform_GetRef (transform);
if (ref->index) {
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
if (ref.index) {
mat4f_t *worldInverse = h->components[transform_type_worldInverse];
uint32_t parent = h->parentIndex[ref->index];
uint32_t parent = h->parentIndex[ref.index];
position = mvmulf (worldInverse[parent], position);
}
Transform_SetLocalPosition (transform, position);
@ -362,11 +358,11 @@ Transform_SetWorldPosition (transform_t transform, vec4f_t position)
void
Transform_SetWorldRotation (transform_t transform, vec4f_t rotation)
{
__auto_type ref = Transform_GetRef (transform);
if (ref->index) {
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
if (ref.index) {
vec4f_t *worldRotation = h->components[transform_type_worldRotation];
uint32_t parent = h->parentIndex[ref->index];
uint32_t parent = h->parentIndex[ref.index];
rotation = qmulf (qconjf (worldRotation[parent]), rotation);
}
Transform_SetLocalRotation (transform, rotation);
@ -376,8 +372,8 @@ void
Transform_SetLocalTransform (transform_t transform, vec4f_t scale,
vec4f_t rotation, vec4f_t position)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
auto ref = Transform_GetRef (transform);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, transform.reg);
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
vec4f_t *localRotation = h->components[transform_type_localRotation];
vec4f_t *localScale = h->components[transform_type_localScale];
@ -386,12 +382,12 @@ Transform_SetLocalTransform (transform_t transform, vec4f_t scale,
mat4fquat (mat, rotation);
position[3] = 1;
localRotation[ref->index] = rotation;
localScale[ref->index] = scale;
localMatrix[ref->index][0] = mat[0] * scale[0];
localMatrix[ref->index][1] = mat[1] * scale[1];
localMatrix[ref->index][2] = mat[2] * scale[2];
localMatrix[ref->index][3] = position;
modified[ref->index] = 1;
localRotation[ref.index] = rotation;
localScale[ref.index] = scale;
localMatrix[ref.index][0] = mat[0] * scale[0];
localMatrix[ref.index][1] = mat[1] * scale[1];
localMatrix[ref.index][2] = mat[2] * scale[2];
localMatrix[ref.index][3] = position;
modified[ref.index] = 1;
Transform_UpdateMatrices (h);
}

View file

@ -46,9 +46,10 @@ _canvas_rangeid (ecs_registry_t *reg, uint32_t ent, uint32_t comp, uint32_t c)
uint32_t ccomp = comp - c + canvas_canvas;
// view components come immediately after canvas components
uint32_t vcomp = view_href + canvas_comp_count + comp - c;
hierref_t *href = Ent_GetComponent (ent, vcomp, reg);
auto href = *(hierref_t *) Ent_GetComponent (ent, vcomp, reg);
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
// the root entity of the hierarchy has the canvasref or canvas component
uint32_t cent = href->hierarchy->ent[0];
uint32_t cent = h->ent[0];
cent = *(uint32_t *) Ent_GetComponent (cent, rcomp, reg);
canvas_t *canvas = Ent_GetComponent (cent, ccomp, reg);
return canvas->range[c];
@ -438,13 +439,13 @@ draw_passage_glyphs (canvas_system_t *canvas_sys, ecs_pool_t *pool,
// first paragraph's first child are all text views
view_t para_view = View_GetChild (psg_view, 0);
view_t text_view = View_GetChild (para_view, 0);
hierref_t *href = View_GetRef (text_view);
hierref_t href = View_GetRef (text_view);
glyphset_t *gs = glyphset++;
hierarchy_t *h = href->hierarchy;
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
view_pos_t *abs = h->components[view_abs];
view_pos_t *len = h->components[view_len];
for (uint32_t i = href->index; i < h->num_objects; i++) {
for (uint32_t i = href.index; i < h->num_objects; i++) {
glyphref_t *gref = Ent_GetComponent (h->ent[i], glyphs, reg);
uint32_t *c = Ent_SafeGetComponent (h->ent[i], color, reg);
draw_glyph_refs (&abs[i], gs, gref, c ? *c : 254);
@ -452,7 +453,7 @@ draw_passage_glyphs (canvas_system_t *canvas_sys, ecs_pool_t *pool,
if (0) draw_box (abs, len, i, 253);
}
if (0) {
for (uint32_t i = 1; i < href->index; i++) {
for (uint32_t i = 1; i < href.index; i++) {
draw_box (abs, len, i, 251);
}
}
@ -512,8 +513,9 @@ Canvas_Draw (canvas_system_t canvas_sys)
}
r_funcs->Draw_ResetClip ();
{
ecs_pool_t *pool = &reg->comp_pools[canvas_updateonce];
ecs_subpool_t *subpool = &reg->subpools[canvas_updateonce];
uint32_t comp = canvas_sys.base + canvas_updateonce;
ecs_pool_t *pool = &reg->comp_pools[comp];
ecs_subpool_t *subpool = &reg->subpools[comp];
pool->count = 0;
uint32_t rcount = subpool->num_ranges - subpool->available;
memset (subpool->ranges, 0, rcount * sizeof (*subpool->ranges));
@ -575,12 +577,12 @@ canvas_href_cmp (const void *_a, const void *_b, void *arg)
canvas_system_t *canvas_sys = arg;
ecs_registry_t *reg = canvas_sys->reg;
uint32_t href = canvas_sys->view_base + view_href;
hierref_t *ref_a = Ent_GetComponent (enta, href, reg);
hierref_t *ref_b = Ent_GetComponent (entb, href, reg);
if (ref_a->hierarchy == ref_b->hierarchy) {
return ref_a->index - ref_b->index;
auto ref_a = *(hierref_t *) Ent_GetComponent (enta, href, reg);
auto ref_b = *(hierref_t *) Ent_GetComponent (entb, href, reg);
if (ref_a.id == ref_b.id) {
return ref_a.index - ref_b.index;
}
ptrdiff_t diff = ref_a->hierarchy - ref_b->hierarchy;
int32_t diff = ref_a.id - ref_b.id;
return diff > 0 ? 1 : diff < 0 ? -1 : 0;
}

View file

@ -381,19 +381,19 @@ IMUI_GetIO (imui_ctx_t *ctx)
}
static void
set_hierarchy_tree_mode (imui_ctx_t *ctx, hierarchy_t *h, bool tree)
set_hierarchy_tree_mode (imui_ctx_t *ctx, hierref_t ref, bool tree)
{
auto reg = ctx->csys.reg;
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, reg);
Hierarchy_SetTreeMode (h, tree);
auto reg = ctx->csys.reg;
viewcont_t *cont = h->components[view_control];
uint32_t *ent = h->ent;
for (uint32_t i = 0; i < h->num_objects; i++) {
if (cont[i].is_link) {
imui_reference_t *sub = Ent_GetComponent (ent[i], c_reference, reg);
auto sub_view = View_FromEntity (ctx->vsys, sub->ref_id);
auto href = View_GetRef (sub_view);
set_hierarchy_tree_mode (ctx, href->hierarchy, tree);
set_hierarchy_tree_mode (ctx, View_GetRef (sub_view), tree);
}
}
}
@ -408,8 +408,7 @@ IMUI_BeginFrame (imui_ctx_t *ctx)
// delete and recreate the root view (but not the root entity)
Ent_RemoveComponent (root_ent, ctx->root_view.comp, ctx->root_view.reg);
ctx->root_view = View_AddToEntity (root_ent, ctx->vsys, nullview);
auto ref = View_GetRef (ctx->root_view);
set_hierarchy_tree_mode (ctx, ref->hierarchy, true);
set_hierarchy_tree_mode (ctx, View_GetRef (ctx->root_view), true);
View_SetLen (ctx->root_view, root_size.x, root_size.y);
ctx->frame_start = Sys_LongTime ();
@ -478,8 +477,11 @@ view_color (hierarchy_t *h, uint32_t ind, imui_ctx_t *ctx, bool for_y)
}
static void __attribute__((used))
dump_tree (hierarchy_t *h, uint32_t ind, int level, imui_ctx_t *ctx)
dump_tree (hierref_t href, int level, imui_ctx_t *ctx)
{
auto reg = ctx->csys.reg;
uint32_t ind = href.index;
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
view_pos_t *len = h->components[view_len];
auto c = ((viewcont_t *)h->components[view_control])[ind];
uint32_t e = h->ent[ind];
@ -509,7 +511,7 @@ dump_tree (hierarchy_t *h, uint32_t ind, int level, imui_ctx_t *ctx)
imui_reference_t *sub = Ent_GetComponent (ent, c_reference, reg);
auto sub_view = View_FromEntity (ctx->vsys, sub->ref_id);
auto href = View_GetRef (sub_view);
dump_tree (href->hierarchy, 0, level + 1, ctx);
dump_tree (href, level + 1, ctx);
printf (RED"%2d: %*slink"DFL"\n", ind, level * 3, "");
}
if (h->childIndex[ind] > ind) {
@ -517,7 +519,8 @@ dump_tree (hierarchy_t *h, uint32_t ind, int level, imui_ctx_t *ctx)
if (h->childIndex[ind] + i >= h->num_objects) {
break;
}
dump_tree (h, h->childIndex[ind] + i, level + 1, ctx);
hierref_t cref = { .id = href.id, .index = h->childIndex[ind] + i };
dump_tree (cref, level + 1, ctx);
}
}
if (!level) {
@ -531,10 +534,11 @@ typedef struct {
} downdep_t;
static void
calc_upwards_dependent (imui_ctx_t *ctx, hierarchy_t *h,
calc_upwards_dependent (imui_ctx_t *ctx, hierref_t href,
downdep_t *down_depend)
{
auto reg = ctx->csys.reg;
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
uint32_t *ent = h->ent;
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
@ -581,7 +585,7 @@ calc_upwards_dependent (imui_ctx_t *ctx, hierarchy_t *h,
// control logic was propagated from the linked hierarcy, so
// propagate down_depend to the linked hierarcy.
side_depend[0] = down_depend[i];
calc_upwards_dependent (ctx, href->hierarchy, side_depend);
calc_upwards_dependent (ctx, href, side_depend);
down_depend[0].num_views += side_depend[0].num_views;
side_depend += side_depend[0].num_views;
}
@ -589,9 +593,10 @@ calc_upwards_dependent (imui_ctx_t *ctx, hierarchy_t *h,
}
static void
calc_downwards_dependent (imui_ctx_t *ctx, hierarchy_t *h)
calc_downwards_dependent (imui_ctx_t *ctx, hierref_t href)
{
auto reg = ctx->csys.reg;
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
uint32_t *ent = h->ent;
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
@ -599,8 +604,7 @@ calc_downwards_dependent (imui_ctx_t *ctx, hierarchy_t *h)
if (cont[i].is_link) {
imui_reference_t *sub = Ent_GetComponent (ent[i], c_reference, reg);
auto sub_view = View_FromEntity (ctx->vsys, sub->ref_id);
auto href = View_GetRef (sub_view);
calc_downwards_dependent (ctx, href->hierarchy);
calc_downwards_dependent (ctx, View_GetRef (sub_view));
len[i] = View_GetLen (sub_view);
}
view_pos_t clen = len[i];
@ -639,9 +643,10 @@ calc_downwards_dependent (imui_ctx_t *ctx, hierarchy_t *h)
}
static void
calc_expansions (imui_ctx_t *ctx, hierarchy_t *h)
calc_expansions (imui_ctx_t *ctx, hierref_t href)
{
auto reg = ctx->csys.reg;
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
uint32_t *ent = h->ent;
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
@ -724,20 +729,20 @@ calc_expansions (imui_ctx_t *ctx, hierarchy_t *h)
if (cont[i].is_link) {
imui_reference_t *sub = Ent_GetComponent (ent[i], c_reference, reg);
auto sub_view = View_FromEntity (ctx->vsys, sub->ref_id);
auto href = View_GetRef (sub_view);
View_SetLen (sub_view, len[i].x, len[i].y);
calc_expansions (ctx, href->hierarchy);
calc_expansions (ctx, View_GetRef (sub_view));
}
}
}
static uint32_t __attribute__((pure))
count_views (imui_ctx_t *ctx, hierarchy_t *h)
count_views (imui_ctx_t *ctx, hierref_t href)
{
auto reg = ctx->csys.reg;
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
uint32_t count = h->num_objects;
viewcont_t *cont = h->components[view_control];
uint32_t *ent = h->ent;
auto reg = h->reg;
// the root object is never a link (if it has a reference component, it's
// to the pseudo-parent of the hierarchy)
@ -745,8 +750,7 @@ count_views (imui_ctx_t *ctx, hierarchy_t *h)
if (cont[i].is_link) {
imui_reference_t *sub = Ent_GetComponent (ent[i], c_reference, reg);
auto sub_view = View_FromEntity (ctx->vsys, sub->ref_id);
auto href = View_GetRef (sub_view);
count += count_views (ctx, href->hierarchy);
count += count_views (ctx, View_GetRef (sub_view));
}
}
return count;
@ -755,8 +759,9 @@ count_views (imui_ctx_t *ctx, hierarchy_t *h)
static void
position_views (imui_ctx_t *ctx, view_t root_view)
{
auto ref = View_GetRef (root_view);
auto h = ref->hierarchy;
auto reg = ctx->vsys.reg;
auto href = View_GetRef (root_view);
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
uint32_t *ent = h->ent;
view_pos_t *pos = h->components[view_pos];
@ -766,7 +771,6 @@ position_views (imui_ctx_t *ctx, view_t root_view)
if (Ent_HasComponent (root_view.id, c_reference, ctx->vsys.reg)) {
auto ent = root_view.id;
auto reg = ctx->vsys.reg;
imui_reference_t *reference = Ent_GetComponent (ent, c_reference, reg);
auto anchor = View_FromEntity (ctx->vsys, reference->ref_id);
pos[0] = View_GetAbs (anchor);
@ -807,16 +811,15 @@ position_views (imui_ctx_t *ctx, view_t root_view)
static void
layout_objects (imui_ctx_t *ctx, view_t root_view)
{
auto ref = View_GetRef (root_view);
auto h = ref->hierarchy;
auto href = View_GetRef (root_view);
downdep_t down_depend[count_views (ctx, h)];
downdep_t down_depend[count_views (ctx, href)];
// the root view size is always explicit
down_depend[0] = (downdep_t) { };
calc_upwards_dependent (ctx, h, down_depend);
calc_downwards_dependent (ctx, h);
calc_expansions (ctx, h);
calc_upwards_dependent (ctx, href, down_depend);
calc_downwards_dependent (ctx, href);
calc_expansions (ctx, href);
//dump_tree (h, 0, 0, ctx);
// resolve conflicts
//fflush (stdout);
@ -827,8 +830,9 @@ layout_objects (imui_ctx_t *ctx, view_t root_view)
static void
check_inside (imui_ctx_t *ctx, view_t root_view)
{
auto ref = View_GetRef (root_view);
auto h = ref->hierarchy;
auto reg = ctx->vsys.reg;
auto href = View_GetRef (root_view);
hierarchy_t *h = Ent_GetComponent (href.id, ecs_hierarchy, reg);
uint32_t *entity = h->ent;
view_pos_t *abs = h->components[view_abs];
@ -880,12 +884,11 @@ IMUI_Draw (imui_ctx_t *ctx)
ctx->mouse_pressed = 0;
ctx->mouse_released = 0;
sort_windows (ctx);
auto ref = View_GetRef (ctx->root_view);
set_hierarchy_tree_mode (ctx, ref->hierarchy, false);
auto href = View_GetRef (ctx->root_view);
set_hierarchy_tree_mode (ctx, href, false);
for (uint32_t i = 0; i < ctx->windows.size; i++) {
auto window = View_FromEntity (ctx->vsys, ctx->windows.a[i]->entity);
auto ref = View_GetRef (window);
set_hierarchy_tree_mode (ctx, ref->hierarchy, false);
set_hierarchy_tree_mode (ctx, View_GetRef (window), false);
}
Canvas_DrawSort (ctx->csys);
@ -1402,8 +1405,7 @@ IMUI_StartPanel (imui_ctx_t *ctx, imui_window_t *panel)
DARRAY_APPEND (&ctx->parent_stack, ctx->current_parent);
auto ref = View_GetRef (panel_view);
Hierarchy_SetTreeMode (ref->hierarchy, true);
set_hierarchy_tree_mode (ctx, View_GetRef (panel_view), true);
grav_t gravity = grav_northwest;
if (panel->reference) {
@ -1677,8 +1679,7 @@ IMUI_StartScrollBox (imui_ctx_t *ctx, const char *name)
DARRAY_APPEND (&ctx->parent_stack, ctx->current_parent);
auto ref = View_GetRef (scroll_box);
Hierarchy_SetTreeMode (ref->hierarchy, true);
set_hierarchy_tree_mode (ctx, View_GetRef (scroll_box), true);
View_Control (anchor_view)->is_link = 1;
imui_reference_t link = {

View file

@ -92,21 +92,22 @@ Passage_IsSpace (const char *text)
}
static void
add_entity (hierarchy_t *h, uint32_t parent)
add_entity (uint32_t hent, uint32_t parent, ecs_registry_t *reg)
{
uint32_t i = Hierarchy_InsertHierarchy (h, 0, parent, 0);
h->ent[i] = ECS_NewEntity (h->reg);
hierref_t *ref = Ent_AddComponent (h->ent[i], h->href_comp, h->reg);
ref->hierarchy = h;
ref->index = i;
hierarchy_t *h = Ent_GetComponent (hent, ecs_hierarchy, reg);
auto ref = Hierarchy_InsertHierarchy ((hierref_t) { hent, parent},
(hierref_t) { nullent, nullindex },
reg);
h->ent[ref.index] = ECS_NewEntity (reg);
Ent_SetComponent (h->ent[ref.index], h->href_comp, reg, &ref);
}
VISIBLE void
Passage_ParseText (passage_t *passage, const char *text)
{
if (passage->hierarchy) {//FIXME just empty hierarchy
Hierarchy_Delete (passage->hierarchy);
}
auto reg = passage->reg;
//FIXME just empty hierarchy
ECS_DelEntity (reg, passage->hierarchy);
if (!*text) {
return;
}
@ -140,33 +141,32 @@ Passage_ParseText (passage_t *passage, const char *text)
passage->hierarchy = Hierarchy_New (passage->reg,
passage->comp_base + passage_href,
&passage_type, 0);
Hierarchy_Reserve (passage->hierarchy,
1 + num_paragraphs + num_text_objects);
hierarchy_t *h = Ent_GetComponent (passage->hierarchy, ecs_hierarchy, reg);
Hierarchy_Reserve (h, 1 + num_paragraphs + num_text_objects);
#if 0
printf ("num_paragraphs %d, num_text_objects %d\n", num_paragraphs,
passage->num_text_objects);
#endif
add_entity (passage->hierarchy, nullent);
add_entity (passage->hierarchy, nullent, reg);
for (unsigned i = 0; i < num_paragraphs; i++) {
add_entity (passage->hierarchy, 0);
add_entity (passage->hierarchy, 0, reg);
}
num_paragraphs = 0;
hierarchy_t *h = passage->hierarchy;
psg_text_t *passage_obj = h->components[passage_type_text_obj];
psg_text_t *par_obj = &passage_obj[h->childIndex[0]];
psg_text_t *text_obj = &passage_obj[h->childIndex[1]];
*par_obj = *text_obj = (psg_text_t) { };
*passage_obj = root_text;
add_entity (passage->hierarchy, par_obj - passage_obj);
add_entity (passage->hierarchy, par_obj - passage_obj, reg);
parsing_space = Passage_IsSpace (text);
for (const char *c = text; *c; c++) {
int size;
if ((size = Passage_IsSpace (c))) {
if (!parsing_space) {
add_entity (passage->hierarchy, par_obj - passage_obj);
add_entity (passage->hierarchy, par_obj - passage_obj, reg);
text_obj->size = c - text - text_obj->text;
(++text_obj)->text = c - text;
}
@ -177,13 +177,13 @@ Passage_ParseText (passage_t *passage, const char *text)
par_obj->size = c - text - par_obj->text;
if (c[1]) {
(++par_obj)->text = c + 1 - text;
add_entity (passage->hierarchy, par_obj - passage_obj);
add_entity (passage->hierarchy, par_obj - passage_obj, reg);
(++text_obj)->text = c + 1 - text;
parsing_space = Passage_IsSpace (c + 1);
}
} else {
if (parsing_space) {
add_entity (passage->hierarchy, par_obj - passage_obj);
add_entity (passage->hierarchy, par_obj - passage_obj, reg);
text_obj->size = c - text - text_obj->text;
(++text_obj)->text = c - text;
}
@ -210,18 +210,18 @@ VISIBLE passage_t *
Passage_New (ecs_system_t passage_sys)
{
passage_t *passage = malloc (sizeof (passage_t));
passage->text = 0;
passage->reg = passage_sys.reg;
passage->comp_base = passage_sys.base;
passage->hierarchy = 0;
*passage = (passage_t) {
.reg = passage_sys.reg,
.comp_base = passage_sys.base,
.hierarchy = nullent,
};
return passage;
}
VISIBLE void
Passage_Delete (passage_t *passage)
{
if (passage->hierarchy) {
Hierarchy_Delete (passage->hierarchy);
}
auto reg = passage->reg;
ECS_DelEntity (reg, passage->hierarchy);
free (passage);
}

View file

@ -246,17 +246,17 @@ test_flow (testdata_t *child_views, int count, void (flow) (view_t, view_pos_t))
View_UpdateHierarchy (flow_view);
int ret = 0;
__auto_type ref = View_GetRef (flow_view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (flow_view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, flow_view.reg);
uint32_t *childIndex = h->childIndex;
uint32_t *childCount = h->childCount;
uint32_t *ent = h->ent;
view_pos_t *pos = h->components[view_pos];
view_pos_t *rel = h->components[view_rel];
view_pos_t *abs = h->components[view_abs];
for (uint32_t i = 0; i < childCount[ref->index]; i++) {
for (uint32_t i = 0; i < childCount[ref.index]; i++) {
testdata_t *td = &child_views[i];
uint32_t child = childIndex[ref->index] + i;
uint32_t child = childIndex[ref.index] + i;
if (pos[child].x != td->expect.xpos
|| pos[child].y != td->expect.ypos
|| rel[child].x != td->expect.xrel

View file

@ -246,17 +246,17 @@ test_flow (testdata_t *child_views, int count,
View_UpdateHierarchy (flow_view);
int ret = 0;
__auto_type ref = View_GetRef (flow_view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (flow_view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, flow_view.reg);
uint32_t *childIndex = h->childIndex;
uint32_t *childCount = h->childCount;
uint32_t *ent = h->ent;
view_pos_t *pos = h->components[view_pos];
view_pos_t *rel = h->components[view_rel];
view_pos_t *abs = h->components[view_abs];
for (uint32_t i = 0; i < childCount[ref->index]; i++) {
for (uint32_t i = 0; i < childCount[ref.index]; i++) {
testdata_t *td = &child_views[i];
uint32_t child = childIndex[ref->index] + i;
uint32_t child = childIndex[ref.index] + i;
if (pos[child].x != td->expect.xpos
|| pos[child].y != td->expect.ypos
|| rel[child].x != td->expect.xrel

View file

@ -59,33 +59,33 @@ main (void)
passage_t *passage = Passage_New (psg_sys);
Passage_ParseText (passage, test_text);
if (passage->hierarchy->childCount[0] != 3) {
hierarchy_t *h = Ent_GetComponent (passage->hierarchy, ecs_hierarchy,
passage->reg);
if (h->childCount[0] != 3) {
ret = 1;
printf ("incorrect number of paragraphs: %d\n",
passage->hierarchy->childCount[0]);
printf ("incorrect number of paragraphs: %d\n", h->childCount[0]);
}
if (passage->hierarchy->num_objects != 144) {
if (h->num_objects != 144) {
ret = 1;
printf ("incorrect number of text objects: %d\n",
passage->hierarchy->num_objects);
printf ("incorrect number of text objects: %d\n", h->num_objects);
}
if (passage->hierarchy->childCount[1] != 49) {
if (h->childCount[1] != 49) {
ret = 1;
printf ("incorrect number of text objects in first paragraph: %d\n",
passage->hierarchy->childCount[1]);
h->childCount[1]);
}
if (passage->hierarchy->childCount[2] != 90) {
if (h->childCount[2] != 90) {
ret = 1;
printf ("incorrect number of text objects in second paragraph: %d\n",
passage->hierarchy->childCount[2]);
h->childCount[2]);
}
if (passage->hierarchy->childCount[3] != 1) {
if (h->childCount[3] != 1) {
ret = 1;
printf ("incorrect number of text objects in third paragraph: %d\n",
passage->hierarchy->childCount[3]);
h->childCount[3]);
}
uint32_t *childIndex = passage->hierarchy->childIndex;
psg_text_t *text_objs = passage->hierarchy->components[0];
uint32_t *childIndex = h->childIndex;
psg_text_t *text_objs = h->components[0];
psg_text_t *to = &text_objs[childIndex[2] + 0];
if (to->size != 2 && (passage->text[to->text] != ' '
&& passage->text[to->text + 1] != ' ')) {
@ -97,8 +97,8 @@ main (void)
// ret = 1;
// printf ("second paragram indent suppressed\n");
//}
for (uint32_t i = 0; i < passage->hierarchy->childCount[0]; i++) {
for (uint32_t j = 0; j < passage->hierarchy->childCount[1 + i]; j++) {
for (uint32_t i = 0; i < h->childCount[0]; i++) {
for (uint32_t j = 0; j < h->childCount[1 + i]; j++) {
psg_text_t *to = &text_objs[childIndex[1 + i] + j];
unsigned is_space = Passage_IsSpace (passage->text + to->text);
if (i == 1 && j == 0) {

View file

@ -188,7 +188,7 @@ Text_PassageView (text_system_t textsys, view_t parent,
uint32_t c_features = textsys.text_base + text_features;
uint32_t c_glyphs = textsys.text_base + text_glyphs;
uint32_t c_passage_glyphs = textsys.text_base + text_passage_glyphs;
hierarchy_t *h = passage->hierarchy;
hierarchy_t *h = Ent_GetComponent (passage->hierarchy, ecs_hierarchy, reg);
psg_text_t *text_objects = h->components[passage_type_text_obj];
glyphnode_t *glyph_nodes = 0;
glyphnode_t **head = &glyph_nodes;

View file

@ -150,15 +150,14 @@ View_AddToEntity (uint32_t ent, ecs_system_t viewsys, view_t parent)
hierref_t *ref = Ent_AddComponent (ent, href_comp, viewsys.reg);
if (parent.reg && parent.id != nullent) {
hierref_t *pref = View_GetRef (parent);
ref->hierarchy = pref->hierarchy;
ref->index = Hierarchy_InsertHierarchy (pref->hierarchy, 0,
pref->index, 0);
hierref_t pref = View_GetRef (parent);
*ref = Hierarchy_InsertHierarchy (pref, nullhref, viewsys.reg);
} else {
ref->hierarchy = Hierarchy_New (viewsys.reg, href_comp, &view_type, 1);
ref->id = Hierarchy_New (viewsys.reg, href_comp, &view_type, 1);
ref->index = 0;
}
ref->hierarchy->ent[ref->index] = ent;
hierarchy_t *h = Ent_GetComponent (ref->id, ecs_hierarchy, viewsys.reg);
h->ent[ref->index] = ent;
return (view_t) { .reg = viewsys.reg, .id = ent, .comp = href_comp };
}
@ -172,8 +171,8 @@ View_New (ecs_system_t viewsys, view_t parent)
void
View_UpdateHierarchy (view_t view)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
byte *modified = h->components[view_modified];
view_pos_t *pos = h->components[view_pos];
@ -281,26 +280,17 @@ View_UpdateHierarchy (view_t view)
void
View_SetParent (view_t view, view_t parent)
{
hierarchy_t *dst = 0;
uint32_t dstParent = nullent;
hierarchy_t *src = 0;
uint32_t srcIndex = 0;
hierref_t dref = nullhref;
hierref_t sref = View_GetRef (view);
if (View_Valid (parent)) {
__auto_type ref = View_GetRef (parent);
dst = ref->hierarchy;
dstParent = ref->index;
dref = View_GetRef (parent);
}
{
__auto_type ref = View_GetRef (view);
src = ref->hierarchy;
srcIndex = ref->index;
}
Hierarchy_SetParent (dst, dstParent, src, srcIndex);
Hierarchy_SetParent (dref, sref, view.reg);
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
byte *modified = h->components[view_modified];
modified[ref->index] = 1;
modified[ref.index] = 1;
View_UpdateHierarchy (view);
}
@ -324,14 +314,14 @@ typedef struct flowline_s {
static void
flow_right (view_t view, void (*set_rows) (view_t, flowline_t *))
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
uint32_t vind = ref->index;
uint32_t vind = ref.index;
flowline_t flowline = { .first_child = h->childIndex[ref->index] };
flowline_t flowline = { .first_child = h->childIndex[ref.index] };
flowline_t *line = &flowline;
for (uint32_t i = 0; i < h->childCount[vind]; i++) {
uint32_t child = h->childIndex[vind] + i;
@ -352,18 +342,18 @@ flow_right (view_t view, void (*set_rows) (view_t, flowline_t *))
static void
flow_left (view_t view, void (*set_rows) (view_t, flowline_t *))
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
uint32_t vind = ref->index;
uint32_t vind = ref.index;
flowline_t flowline = { .first_child = h->childIndex[ref->index] };
flowline_t flowline = { .first_child = h->childIndex[ref.index] };
flowline_t *line = &flowline;
line->cursor = len[vind].x;
for (uint32_t i = 0; i < h->childCount[vind]; i++) {
uint32_t child = h->childIndex[ref->index] + i;
uint32_t child = h->childIndex[ref.index] + i;
if (line->cursor < len[vind].x && line->cursor - len[child].x < 0) {
NEXT_LINE(line, child);
line->cursor = len[vind].x;
@ -382,14 +372,14 @@ flow_left (view_t view, void (*set_rows) (view_t, flowline_t *))
static void
flow_down (view_t view, void (*set_rows) (view_t, flowline_t *))
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
uint32_t vind = ref->index;
uint32_t vind = ref.index;
flowline_t flowline = { .first_child = h->childIndex[ref->index] };
flowline_t flowline = { .first_child = h->childIndex[ref.index] };
flowline_t *line = &flowline;
for (uint32_t i = 0; i < h->childCount[vind]; i++) {
uint32_t child = h->childIndex[vind] + i;
@ -410,18 +400,18 @@ flow_down (view_t view, void (*set_rows) (view_t, flowline_t *))
static void
flow_up (view_t view, void (*set_rows) (view_t, flowline_t *))
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
uint32_t vind = ref->index;
uint32_t vind = ref.index;
flowline_t flowline = { .first_child = h->childIndex[ref->index] };
flowline_t flowline = { .first_child = h->childIndex[ref.index] };
flowline_t *line = &flowline;
line->cursor = len[vind].y;
for (uint32_t i = 0; i < h->childCount[vind]; i++) {
uint32_t child = h->childIndex[ref->index] + i;
uint32_t child = h->childIndex[ref.index] + i;
if (line->cursor < len[vind].y && line->cursor - len[child].y < 0) {
NEXT_LINE(line, child);
line->cursor = len[vind].y;
@ -458,16 +448,16 @@ flow_view_width (view_pos_t *len, flowline_t *flowlines)
static void
set_rows_down (view_t view, flowline_t *flowlines)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
view_pos_t *rel = h->components[view_rel];
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
uint32_t vind = ref->index;
uint32_t vind = ref.index;
if (cont[vind].flow_size) {
flow_view_height (&len[ref->index], flowlines);
flow_view_height (&len[ref.index], flowlines);
}
int cursor = 0;
@ -486,16 +476,16 @@ set_rows_down (view_t view, flowline_t *flowlines)
static void
set_rows_up (view_t view, flowline_t *flowlines)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
view_pos_t *rel = h->components[view_rel];
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
uint32_t vind = ref->index;
uint32_t vind = ref.index;
if (cont[vind].flow_size) {
flow_view_height (&len[ref->index], flowlines);
flow_view_height (&len[ref.index], flowlines);
}
int cursor = len[vind].y;
@ -514,16 +504,16 @@ set_rows_up (view_t view, flowline_t *flowlines)
static void
set_columns_right (view_t view, flowline_t *flowlines)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
view_pos_t *rel = h->components[view_rel];
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
uint32_t vind = ref->index;
uint32_t vind = ref.index;
if (cont[vind].flow_size) {
flow_view_width (&len[ref->index], flowlines);
flow_view_width (&len[ref.index], flowlines);
}
int cursor = 0;
@ -542,16 +532,16 @@ set_columns_right (view_t view, flowline_t *flowlines)
static void
set_columns_left (view_t view, flowline_t *flowlines)
{
__auto_type ref = View_GetRef (view);
hierarchy_t *h = ref->hierarchy;
auto ref = View_GetRef (view);
hierarchy_t *h = Ent_GetComponent (ref.id, ecs_hierarchy, view.reg);
view_pos_t *pos = h->components[view_pos];
view_pos_t *rel = h->components[view_rel];
view_pos_t *len = h->components[view_len];
viewcont_t *cont = h->components[view_control];
uint32_t vind = ref->index;
uint32_t vind = ref.index;
if (cont[vind].flow_size) {
flow_view_width (&len[ref->index], flowlines);
flow_view_width (&len[ref.index], flowlines);
}
int cursor = len[vind].x;

View file

@ -46,6 +46,8 @@
#include "r_internal.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
float gl_bubble_sintable[33], gl_bubble_costable[33];
@ -117,7 +119,7 @@ gl_R_RenderDlights (void)
qfglBlendFunc (GL_ONE, GL_ONE);
qfglShadeModel (GL_SMOOTH);
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto dlight = &dlight_data[i];

View file

@ -57,6 +57,8 @@
#include "compat.h"
#include "r_internal.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
static scrap_t *light_scrap;
static int dlightdivtable[8192];
static int gl_internalformat; // 1 or 3
@ -113,7 +115,7 @@ R_AddDynamicLights_1 (const vec4f_t *transform, msurface_t *surf)
entorigin = transform[3];
}
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto dlight = &dlight_data[i];
@ -187,7 +189,7 @@ R_AddDynamicLights_3 (const vec4f_t *transform, msurface_t *surf)
entorigin = transform[3];
}
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t k = 0; k < dlight_pool->count; k++) {
auto dlight = &dlight_data[k];

View file

@ -55,6 +55,8 @@
#include "r_internal.h"
#include "vid_gl.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
typedef struct {
vec3_t normal;
vec3_t vert;
@ -272,7 +274,7 @@ GL_DrawAliasShadow (transform_t transform, const aliashdr_t *paliashdr,
static inline vert_order_t *
GL_GetAliasFrameVerts16 (aliashdr_t *paliashdr, entity_t e)
{
animation_t *animation = Ent_GetComponent (e.id, scene_animation, e.reg);
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation, e.reg);
float blend = R_AliasGetLerpedFrames (animation, paliashdr);
int count, i;
trivertx16_t *verts;
@ -337,7 +339,7 @@ GL_GetAliasFrameVerts16 (aliashdr_t *paliashdr, entity_t e)
static inline vert_order_t *
GL_GetAliasFrameVerts (aliashdr_t *paliashdr, entity_t e)
{
animation_t *animation = Ent_GetComponent (e.id, scene_animation, e.reg);
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation, e.reg);
float blend = R_AliasGetLerpedFrames (animation, paliashdr);
int count, i;
trivertx_t *verts;
@ -412,7 +414,7 @@ gl_R_DrawAliasModel (entity_t e)
vec3_t dist, scale;
vec4f_t origin;
vert_order_t *vo;
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer, e.reg);
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
model_t *model = renderer->model;
if (renderer->onlyshadows) {
@ -461,7 +463,7 @@ gl_R_DrawAliasModel (entity_t e)
}
if (gl_vector_light) {
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto l = &dlight_data[i];
@ -513,7 +515,7 @@ gl_R_DrawAliasModel (entity_t e)
} else {
VectorCopy (ambientcolor, emission);
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto l = &dlight_data[i];
@ -564,7 +566,7 @@ gl_R_DrawAliasModel (entity_t e)
}
} else {
maliasskindesc_t *skindesc;
animation_t *animation = Ent_GetComponent (e.id, scene_animation,
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation,
e.reg);
skindesc = R_AliasGetSkindesc (animation, renderer->skinnum, paliashdr);
texture = skindesc->texnum;

View file

@ -88,7 +88,7 @@ gl_draw_iqm_frame (iqm_t *iqm, gliqm_t *gl, iqmframe_t *frame, iqmmesh *mesh)
void
gl_R_DrawIQMModel (entity_t ent)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
model_t *model = renderer->model;
iqm_t *iqm = (iqm_t *) model->aliashdr;
gliqm_t *gl = (gliqm_t *) iqm->extra_data;
@ -96,7 +96,7 @@ gl_R_DrawIQMModel (entity_t ent)
iqmframe_t *frame;
int i;
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
blend = R_IQMGetLerpedFrames (animation, iqm);
frame = R_IQMBlendPalette (iqm, animation->pose1, animation->pose2,

View file

@ -58,7 +58,7 @@ void (*gl_R_DrawSpriteModel) (struct entity_s ent);
static void
R_DrawSpriteModel_f (entity_t e)
{
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer, e.reg);
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
msprite_t *sprite = renderer->model->cache.data;
float modelalpha, color[4];
vec4f_t cameravec = {};
@ -71,7 +71,7 @@ R_DrawSpriteModel_f (entity_t e)
cameravec = r_refdef.frame.position - origin;
// don't bother culling, it's just a single polygon without a surface cache
animation_t *animation = Ent_GetComponent (e.id, scene_animation, e.reg);
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation, e.reg);
frame = R_GetSpriteFrame (sprite, animation);
if (!R_BillboardFrame (transform, sprite->type, cameravec,
@ -118,7 +118,7 @@ R_DrawSpriteModel_f (entity_t e)
static void
R_DrawSpriteModel_VA_f (entity_t e)
{
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer, e.reg);
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
msprite_t *psprite = renderer->model->cache.data;
unsigned char modelalpha, color[4];
vec4f_t up = {}, right = {};
@ -131,7 +131,7 @@ R_DrawSpriteModel_VA_f (entity_t e)
VA = gl_spriteVertexArray; // FIXME: Despair
// don't bother culling, it's just a single polygon without a surface cache
animation_t *animation = Ent_GetComponent (e.id, scene_animation, e.reg);
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation, e.reg);
frame = R_GetSpriteFrame (psprite, animation);
qfglBindTexture (GL_TEXTURE_2D, frame->gl_texturenum); // FIXME: DESPAIR

View file

@ -163,7 +163,7 @@ R_DrawViewModel (void)
if (!Entity_Valid (ent)) {
return;
}
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
if (vr_data.inhibit_viewmodel
|| !r_drawviewmodel
|| !r_drawentities

View file

@ -60,6 +60,8 @@
#include "r_internal.h"
#include "vid_gl.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
static struct DARRAY_TYPE (mat4f_t) ent_transforms = DARRAY_STATIC_INIT (16);
static instsurf_t *waterchain = NULL;
@ -505,12 +507,12 @@ gl_R_DrawBrushModel (entity_t e)
bool rotated;
vec3_t mins, maxs;
mat4f_t worldMatrix;
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer, e.reg);
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
model_t *model = renderer->model;
mod_brush_t *brush = &model->brush;
glbspctx_t bspctx = {
brush,
Ent_GetComponent (e.id, scene_animation, e.reg),
Ent_GetComponent (e.id, e.base + scene_animation, e.reg),
ent_transforms.a[ent_transforms.size++],
renderer->colormod,
};
@ -552,7 +554,7 @@ gl_R_DrawBrushModel (entity_t e)
// calculate dynamic lighting for bmodel if it's not an instanced model
if (brush->firstmodelsurface != 0 && r_dlight_lightmap) {
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto dlight = &dlight_data[i];

View file

@ -54,6 +54,8 @@
#include "r_internal.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
static const char *alias_vert_effects[] =
{
"QuakeForge.Vertex.mdl",
@ -161,12 +163,12 @@ calc_lighting (entity_t ent, float *ambient, float *shadelight,
VectorSet ( -1, 0, 0, lightvec); //FIXME
light = R_LightPoint (&r_refdef.worldmodel->brush, entorigin);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
*ambient = max (light, max (renderer->model->min_light,
renderer->min_light) * 128);
*shadelight = *ambient;
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto dlight = &dlight_data[i];
@ -241,7 +243,7 @@ glsl_R_DrawAlias (entity_t ent)
calc_lighting (ent, &ambient, &shadelight, lightvec);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
if (renderer->onlyshadows) {
return;
}
@ -267,7 +269,7 @@ glsl_R_DrawAlias (entity_t ent)
mmulf (mvp_mat, worldMatrix, mvp_mat);
mmulf (mvp_mat, alias_vp, mvp_mat);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
colormap = glsl_colormap;
if (renderer->skin && renderer->skin->auxtex)

View file

@ -59,6 +59,8 @@
#include "r_internal.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
typedef struct {
GLushort count;
GLushort indices[1];
@ -651,7 +653,7 @@ static void
R_DrawBrushModel (entity_t e)
{
float dot, radius;
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer, e.reg);
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
model_t *model = renderer->model;
mod_brush_t *brush = &model->brush;
plane_t *plane;
@ -661,7 +663,7 @@ R_DrawBrushModel (entity_t e)
vec4f_t org;
glslbspctx_t bctx = {
brush,
Ent_GetComponent (e.id, scene_animation, e.reg),
Ent_GetComponent (e.id, e.base + scene_animation, e.reg),
Transform_GetWorldMatrixPtr (Entity_Transform (e)),
renderer->colormod,
};
@ -691,7 +693,7 @@ R_DrawBrushModel (entity_t e)
}
// calculate dynamic lighting for bmodel if it's not an instanced model
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
if (brush->firstmodelsurface != 0 && r_dlight_lightmap) {
for (uint32_t i = 0; i < dlight_pool->count; i++) {

View file

@ -204,7 +204,7 @@ set_arrays (iqm_t *iqm)
void
glsl_R_DrawIQM (entity_t ent)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
model_t *model = renderer->model;
static quat_t color = { 1, 1, 1, 1};
iqm_t *iqm = (iqm_t *) model->aliashdr;
@ -231,7 +231,7 @@ glsl_R_DrawIQM (entity_t ent)
VectorScale (ambientcolor, 1/255.0, ambientcolor);
R_FindNearLights (entorigin, MAX_IQM_LIGHTS, lights);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
blend = R_IQMGetLerpedFrames (animation, iqm);
frame = R_IQMBlendFrames (iqm, animation->pose1, animation->pose2,

View file

@ -54,6 +54,8 @@
#include "r_internal.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
#define BLOCK_SIZE (BLOCK_WIDTH * BLOCK_HEIGHT)
static scrap_t *light_scrap;
@ -83,7 +85,7 @@ R_AddDynamicLights_1 (const vec4f_t *transform, msurface_t *surf)
entorigin = transform[3];
}
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto dlight = &dlight_data[i];

View file

@ -119,7 +119,7 @@ R_DrawViewModel (void)
if (!Entity_Valid (ent)) {
return;
}
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
if (vr_data.inhibit_viewmodel
|| !r_drawviewmodel
|| !r_drawentities

View file

@ -131,7 +131,7 @@ static void
R_GetSpriteFrames (entity_t ent, msprite_t *sprite, mspriteframe_t **frame1,
mspriteframe_t **frame2, float *blend)
{
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
int framenum = animation->frame;
int pose;
@ -209,7 +209,7 @@ make_quad (mspriteframe_t *frame, vec4f_t origin, vec4f_t sright, vec4f_t sup, f
void
glsl_R_DrawSprite (entity_t ent)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
msprite_t *sprite = (msprite_t *) renderer->model->cache.data;
mspriteframe_t *frame1, *frame2;
float blend;

View file

@ -46,6 +46,8 @@
#include "compat.h"
#include "r_internal.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
vec3_t ambientcolor;
unsigned int r_maxdlights;
@ -59,7 +61,7 @@ R_FindNearLights (vec4f_t pos, int count, dlight_t **lights)
int num = 0;
vec3_t d;
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto dlight = &dlight_data[i];
@ -306,7 +308,7 @@ R_PushDlights (const vec3_t entorigin, const visstate_t *visstate)
if (!r_dlight_lightmap)
return;
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto dlight = &dlight_data[i];

View file

@ -74,7 +74,6 @@ static framebuffer_t *warp_buffer;
static float fov_x, fov_y;
static float tan_fov_x, tan_fov_y;
static scene_t *scr_scene;//FIXME don't want this here
static mat4f_t box_rotations[] = {
[BOX_FRONT] = {
@ -324,19 +323,19 @@ SCR_UpdateScreen (transform_t camera, double realtime, SCR_Func *scr_funcs)
}
R_AnimateLight ();
if (!r_lock_viewleaf && scr_scene && scr_scene->worldmodel) {
scr_scene->viewleaf = 0;
if (!r_lock_viewleaf && r_refdef.scene && r_refdef.scene->worldmodel) {
r_refdef.scene->viewleaf = 0;
vec4f_t position = refdef->frame.position;
auto brush = &scr_scene->worldmodel->brush;
scr_scene->viewleaf = Mod_PointInLeaf (position, brush);
auto brush = &r_refdef.scene->worldmodel->brush;
r_refdef.scene->viewleaf = Mod_PointInLeaf (position, brush);
r_dowarpold = r_dowarp;
if (r_waterwarp) {
r_dowarp = scr_scene->viewleaf->contents <= CONTENTS_WATER;
r_dowarp = r_refdef.scene->viewleaf->contents <= CONTENTS_WATER;
}
R_MarkLeaves (&r_visstate, scr_scene->viewleaf);
R_MarkLeaves (&r_visstate, r_refdef.scene->viewleaf);
}
r_framecount++;
if (scr_scene) {
if (r_refdef.scene) {
R_PushDlights (vec3_origin, &r_visstate);
}
r_funcs->UpdateScreen (scr_funcs);
@ -498,9 +497,9 @@ void
SCR_NewScene (scene_t *scene)
{
qfZoneScoped (true);
scr_scene = scene;
r_refdef.scene = scene;
if (scene) {
mod_brush_t *brush = &scr_scene->worldmodel->brush;
mod_brush_t *brush = &r_refdef.scene->worldmodel->brush;
int count = brush->numnodes + brush->modleafs
+ brush->numsurfaces;
int size = count * sizeof (int);

View file

@ -108,7 +108,8 @@ R_Trail_Create (psystem_t *system, int num_points, vec4f_t start)
.base = block_ind * 64,
.count = num_points,
};
Ent_SetComponent (trail, trails_pointset, trails_system.reg, &pointset);
Ent_SetComponent (trail, trails_system.base + trails_pointset,
trails_system.reg, &pointset);
for (uint32_t i = 0; i < pointset.count; i++) {
static float bary[] = {0, 0, 1, 0, 0, 1, 0, 0};
auto p = trail_point_buffer + pointset.base + i;
@ -128,7 +129,8 @@ R_Trail_Create (psystem_t *system, int num_points, vec4f_t start)
void
R_Trail_Update (psystem_t *system, uint32_t trailid, vec4f_t pos)
{
pointset_t *p = Ent_GetComponent (trailid, trails_pointset,
pointset_t *p = Ent_GetComponent (trailid,
trails_system.base + trails_pointset,
trails_system.reg);
trailpnt_t *points = trail_point_buffer + p->base;

View file

@ -99,11 +99,14 @@ R_AliasCheckBBox (entity_t ent)
int minz;
// expand, rotate, and translate points into worldspace
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
visibility_t *visibility = Ent_GetComponent (ent.id,
ent.base + scene_visibility,
ent.reg);
visibility->trivial_accept = 0;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id,
ent.base + scene_renderer,
ent.reg);
pmodel = renderer->model;
if (!(pahdr = pmodel->aliashdr))
pahdr = Cache_Get (&pmodel->cache);
@ -112,7 +115,8 @@ R_AliasCheckBBox (entity_t ent)
R_AliasSetUpTransform (ent, 0);
// construct the base bounding box for this frame
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id,
ent.base + scene_animation,
ent.reg);
frame = animation->frame;
// TODO: don't repeat this check when drawing?
@ -529,7 +533,9 @@ R_AliasPrepareUnclippedPoints (void)
static void
R_AliasSetupSkin (entity_t ent)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id,
ent.base + scene_renderer,
ent.reg);
int skinnum = renderer->skinnum;
if ((skinnum >= pmdl->numskins) || (skinnum < 0)) {
Sys_MaskPrintf (SYS_dev, "R_AliasSetupSkin: no such skin # %d\n",
@ -537,7 +543,8 @@ R_AliasSetupSkin (entity_t ent)
skinnum = 0;
}
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id,
ent.base + scene_animation,
ent.reg);
pskindesc = R_AliasGetSkindesc (animation, skinnum, paliashdr);
@ -601,7 +608,8 @@ R_AliasSetupFrame (entity_t ent)
{
maliasframedesc_t *frame;
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id,
ent.base + scene_animation,
ent.reg);
frame = R_AliasGetFramedesc (animation, paliashdr);
r_apverts = (trivertx_t *) ((byte *) paliashdr + frame->frame);
@ -616,7 +624,9 @@ R_AliasDrawModel (entity_t ent, alight_t *lighting)
r_amodels_drawn++;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id,
ent.base + scene_renderer,
ent.reg);
if (renderer->onlyshadows) {
return;
}
@ -637,7 +647,8 @@ R_AliasDrawModel (entity_t ent, alight_t *lighting)
pauxverts = (auxvert_t *) &pfinalverts[pmdl->numverts + 1];
R_AliasSetupSkin (ent);
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
visibility_t *visibility = Ent_GetComponent (ent.id,
ent.base + scene_visibility,
ent.reg);
R_AliasSetUpTransform (ent, visibility->trivial_accept);
R_AliasSetupLighting (lighting);

View file

@ -290,7 +290,7 @@ R_IQMSetUpTransform (entity_t ent, int trivial_accept)
void
R_IQMDrawModel (entity_t ent, alight_t *plighting)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
model_t *model = renderer->model;
iqm_t *iqm = (iqm_t *) model->aliashdr;
swiqm_t *sw = (swiqm_t *) iqm->extra_data;
@ -302,7 +302,7 @@ R_IQMDrawModel (entity_t ent, alight_t *plighting)
+ sizeof (finalvert_t) * (iqm->num_verts + 1)
+ sizeof (auxvert_t) * iqm->num_verts;
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
blend = R_IQMGetLerpedFrames (animation, iqm);
frame = R_IQMBlendPalette (iqm, animation->pose1, animation->pose2,
@ -314,7 +314,7 @@ R_IQMDrawModel (entity_t ent, alight_t *plighting)
(((intptr_t) &pfinalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
pauxverts = (auxvert_t *) &pfinalverts[iqm->num_verts + 1];
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
visibility_t *visibility = Ent_GetComponent (ent.id, ent.base + scene_visibility,
ent.reg);
R_IQMSetUpTransform (ent, visibility->trivial_accept);

View file

@ -50,6 +50,9 @@
#include "vid_internal.h"
#include "vid_sw.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
#define s_sw_matrix (r_refdef.scene->base + scene_sw_matrix)
#ifdef PIC
# undef USE_INTEL_ASM //XXX asm pic hack
#endif
@ -153,17 +156,17 @@ SW_AddEntity (entity_t ent)
// the pool count can be used as a render id which can in turn be used to
// index the components within the pools.
ecs_registry_t *reg = ent.reg;
ecs_pool_t *pool = &reg->comp_pools[scene_sw_matrix];
ecs_pool_t *pool = &reg->comp_pools[s_sw_matrix];
uint32_t render_id = pool->count;
transform_t transform = Entity_Transform (ent);
Ent_SetComponent (ent.id, scene_sw_matrix, reg,
Ent_SetComponent (ent.id, ent.base + scene_sw_matrix, reg,
Transform_GetWorldMatrixPtr (transform));
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, reg);
Ent_SetComponent (ent.id, scene_sw_frame, reg, &animation->frame);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, reg);
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, reg);
Ent_SetComponent (ent.id, ent.base + scene_sw_frame, reg, &animation->frame);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, reg);
mod_brush_t *brush = &renderer->model->brush;
Ent_SetComponent (ent.id, scene_sw_brush, reg, &brush);
Ent_SetComponent (ent.id, ent.base + scene_sw_brush, reg, &brush);
return render_id;
}
@ -178,13 +181,14 @@ reset_sw_components (ecs_registry_t *reg)
};
for (int i = 0; i < 3; i++) {
ecs_pool_t *pool = &reg->comp_pools[sw_comps[i]];
uint32_t comp = r_refdef.scene->base + sw_comps[i];
ecs_pool_t *pool = &reg->comp_pools[comp];
pool->count = 0; // remove component from every entity
// reserve first component object (render id 0) for the world
// pseudo-entity.
//FIXME takes advantage of the lack of checks for the validity of the
//entity id.
Ent_SetComponent (0, sw_comps[i], reg, 0);
Ent_SetComponent (0, comp, reg, 0);
// make sure entity 0 gets allocated a new component object as the
// world pseudo-entity currently has no actual entity (FIXME)
pool->dense[0] = nullent;
@ -271,7 +275,7 @@ setup_lighting (entity_t ent, alight_t *lighting)
float add;
float lightvec[3] = { -1, 0, 0 };
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
minlight = max (renderer->model->min_light, renderer->min_light);
// 128 instead of 255 due to clamping below
@ -283,7 +287,7 @@ setup_lighting (entity_t ent, alight_t *lighting)
VectorCopy (lightvec, lighting->lightvec);
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto dlight = &dlight_data[i];
@ -306,7 +310,7 @@ draw_alias_entity (entity_t ent)
{
// see if the bounding box lets us trivially reject, also
// sets trivial accept status
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
visibility_t *visibility = Ent_GetComponent (ent.id, ent.base + scene_visibility,
ent.reg);
visibility->trivial_accept = 0; //FIXME
if (R_AliasCheckBBox (ent)) {
@ -321,7 +325,7 @@ draw_iqm_entity (entity_t ent)
{
// see if the bounding box lets us trivially reject, also
// sets trivial accept status
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
visibility_t *visibility = Ent_GetComponent (ent.id, ent.base + scene_visibility,
ent.reg);
visibility->trivial_accept = 0; //FIXME
@ -376,16 +380,17 @@ R_DrawViewModel (void)
return;
}
renderer_t *renderer = Ent_GetComponent (viewent.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (viewent.id,
viewent.base + scene_renderer,
viewent.reg);
if (!renderer->model)
return;
if (!Ent_HasComponent (viewent.id, scene_visibility, viewent.reg)) {
if (!Ent_HasComponent (viewent.id, viewent.base + scene_visibility, viewent.reg)) {
// ensure the view model has a visibility component because one won't
// be added automatically, and the model rendering code expects there
// to be one
Ent_SetComponent (viewent.id, scene_visibility, viewent.reg, 0);
Ent_SetComponent (viewent.id, viewent.base + scene_visibility, viewent.reg, 0);
}
transform_t transform = Entity_Transform (viewent);
@ -402,7 +407,7 @@ R_DrawViewModel (void)
lighting.shadelight = j;
// add dynamic lights
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t i = 0; i < dlight_pool->count; i++) {
auto dl = &dlight_data[i];
@ -487,17 +492,17 @@ R_DrawBrushEntitiesOnList (entqueue_t *queue)
insubmodel = true;
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (size_t i = 0; i < queue->ent_queues[mod_brush].size; i++) {
entity_t ent = queue->ent_queues[mod_brush].a[i];
uint32_t render_id = SW_AddEntity (ent);
vec4f_t *transform = Ent_GetComponent (ent.id, scene_sw_matrix,
vec4f_t *transform = Ent_GetComponent (ent.id, ent.base + scene_sw_matrix,
ent.reg);
VectorCopy (transform[3], origin);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
ent.reg);
model_t *model = renderer->model;
@ -539,7 +544,7 @@ R_DrawBrushEntitiesOnList (entqueue_t *queue)
if (r_drawpolys | r_drawculledpolys) {
R_ZDrawSubmodelPolys (render_id, brush);
} else {
visibility_t *visibility = Ent_GetComponent (ent.id,
visibility_t *visibility = Ent_GetComponent (ent.id, ent.base +
scene_visibility,
ent.reg);
int topnode_id = visibility->topnode_id;

View file

@ -243,10 +243,10 @@ R_SetupAndDrawSprite (const vec3_t relvieworg)
void
R_DrawSprite (entity_t ent)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
msprite_t *sprite = renderer->model->cache.data;
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
r_spritedesc.pspriteframe = R_GetSpriteFrame (sprite, animation);

View file

@ -35,6 +35,8 @@
#include "r_internal.h"
#define s_dynlight (r_refdef.scene->base + scene_dynlight)
#ifdef PIC
# undef USE_INTEL_ASM //XXX asm pic hack
#endif
@ -95,7 +97,7 @@ R_AddDynamicLights (uint32_t render_id)
entorigin = transform[3];
}
auto dlight_pool = &r_refdef.registry->comp_pools[scene_dynlight];
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
auto dlight_data = (dlight_t *) dlight_pool->data;
for (uint32_t k = 0; k < dlight_pool->count; k++) {
auto dlight = &dlight_data[k];

View file

@ -70,19 +70,19 @@ typedef struct {
static renderer_t *
alias_get_renderer (entity_t ent)
{
return Ent_GetComponent (ent.id, scene_renderer, ent.reg);
return Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
}
static animation_t *
alias_get_animation (entity_t ent)
{
return Ent_GetComponent (ent.id, scene_animation, ent.reg);
return Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
}
static colormap_t *
alias_get_colormap (entity_t ent)
{
return Ent_GetComponent (ent.id, scene_colormap, ent.reg);
return Ent_GetComponent (ent.id, ent.base + scene_colormap, ent.reg);
}
static void
@ -206,7 +206,7 @@ alias_draw_ent (qfv_taskctx_t *taskctx, entity_t ent, bool pass,
byte colors[4];
QuatCopy (renderer->colormod, base_color);
QuatCopy (skin->colors, colors);
if (Ent_HasComponent (ent.id, scene_colormap, ent.reg)) {
if (Ent_HasComponent (ent.id, ent.base + scene_colormap, ent.reg)) {
auto colormap = alias_get_colormap (ent);
colors[0] = colormap->top * 16 + 8;
colors[1] = colormap->bottom * 16 + 8;

View file

@ -649,7 +649,7 @@ Vulkan_BuildDisplayLists (model_t **models, int num_models, vulkan_ctx_t *ctx)
static int
R_DrawBrushModel (entity_t ent, bsp_pass_t *pass, vulkan_ctx_t *ctx)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
model_t *model = renderer->model;
bspctx_t *bctx = ctx->bsp_context;
@ -657,7 +657,7 @@ R_DrawBrushModel (entity_t ent, bsp_pass_t *pass, vulkan_ctx_t *ctx)
return 0;
}
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
pass->ent_frame = animation->frame & 1;
pass->inst_id = model->render_id;

View file

@ -191,7 +191,7 @@ iqm_draw_ent (qfv_taskctx_t *taskctx, entity_t ent, bool pass)
auto ctx = taskctx->ctx;
auto device = ctx->device;
auto dfunc = device->funcs;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
auto model = renderer->model;
auto iqm = (iqm_t *) model->aliashdr;
qfv_iqm_t *mesh = iqm->extra_data;
@ -199,7 +199,7 @@ iqm_draw_ent (qfv_taskctx_t *taskctx, entity_t ent, bool pass)
iqmframe_t *frame;
uint16_t *matrix_base = taskctx->data;
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
iqm_push_constants_t constants = {
.blend = R_IQMGetLerpedFrames (animation, iqm),

View file

@ -118,45 +118,45 @@ static cvar_t dynlight_size_cvar = {
};
static const light_t *
get_light (uint32_t ent, ecs_registry_t *reg)
get_light (entity_t ent)
{
return Ent_GetComponent (ent, scene_light, reg);
return Ent_GetComponent (ent.id, ent.base + scene_light, ent.reg);
}
static const dlight_t *
get_dynlight (entity_t ent)
{
return Ent_GetComponent (ent.id, scene_dynlight, ent.reg);
return Ent_GetComponent (ent.id, ent.base + scene_dynlight, ent.reg);
}
static bool
has_dynlight (entity_t ent)
{
return Ent_HasComponent (ent.id, scene_dynlight, ent.reg);
return Ent_HasComponent (ent.id, ent.base + scene_dynlight, ent.reg);
}
static uint32_t
get_lightstyle (entity_t ent)
{
return *(uint32_t *) Ent_GetComponent (ent.id, scene_lightstyle, ent.reg);
return *(uint32_t *) Ent_GetComponent (ent.id, ent.base + scene_lightstyle, ent.reg);
}
static uint32_t
get_lightleaf (entity_t ent)
{
return *(uint32_t *) Ent_GetComponent (ent.id, scene_lightleaf, ent.reg);
return *(uint32_t *) Ent_GetComponent (ent.id, ent.base + scene_lightleaf, ent.reg);
}
static uint32_t
get_lightid (entity_t ent)
{
return *(uint32_t *) Ent_GetComponent (ent.id, scene_lightid, ent.reg);
return *(uint32_t *) Ent_GetComponent (ent.id, ent.base + scene_lightid, ent.reg);
}
static void
set_lightid (uint32_t ent, ecs_registry_t *reg, uint32_t id)
set_lightid (entity_t ent, uint32_t id)
{
Ent_SetComponent (ent, scene_lightid, reg, &id);
Ent_SetComponent (ent.id, ent.base + scene_lightid, ent.reg, &id);
}
static void
@ -627,12 +627,12 @@ lighting_update_lights (const exprval_t **params, exprval_t *result,
float light_radii[ST_COUNT][MaxLights];
uint32_t light_leafs[ST_COUNT][MaxLights];
vec4f_t light_positions[ST_COUNT][MaxLights];
uint32_t entids[ST_COUNT][MaxLights];
entity_t entids[ST_COUNT][MaxLights];
uint32_t light_count = 0;
auto queue = lframe->light_queue;
uint32_t dynamic_light_entities[MaxLights];
entity_t dynamic_light_entities[MaxLights];
uint32_t dynamic_light_leafs[MaxLights];
const dlight_t *dynamic_lights[MaxLights];
int ndlight = 0;
@ -641,7 +641,7 @@ lighting_update_lights (const exprval_t **params, exprval_t *result,
for (size_t i = 0; i < entqueue->ent_queues[mod_light].size; i++) {
entity_t ent = entqueue->ent_queues[mod_light].a[i];
if (has_dynlight (ent)) {
dynamic_light_entities[ndlight] = ent.id;
dynamic_light_entities[ndlight] = ent;
dynamic_light_leafs[ndlight] = get_lightleaf (ent);
dynamic_lights[ndlight] = get_dynlight (ent);
ndlight++;
@ -657,13 +657,13 @@ lighting_update_lights (const exprval_t **params, exprval_t *result,
auto r = &lctx->light_control.a[id];
int mode = r->mode;
auto light = get_light (ent.id, ent.reg);
auto light = get_light (ent);
uint32_t ind = queue[mode].count++;
light_ids[mode][ind] = id;
light_radii[mode][ind] = light_radius (light);
light_leafs[mode][ind] = get_lightleaf (ent);
light_positions[mode][ind] = light->position;
entids[mode][ind] = ent.id;
entids[mode][ind] = ent;
}
size_t packet_size = 0;
@ -711,7 +711,7 @@ lighting_update_lights (const exprval_t **params, exprval_t *result,
qfv_scatter_t scatter[queue[ST_CASCADE].count];
for (uint32_t i = 0; i < queue[ST_CASCADE].count; i++) {
auto r = &lctx->light_control.a[light_ids[ST_CASCADE][i]];
auto light = get_light (entids[ST_CASCADE][i], lctx->scene->reg);
auto light = get_light (entids[ST_CASCADE][i]);
cascade_mats (&mats[i * num_cascade], light->position, ctx);
scatter[i] = (qfv_scatter_t) {
.srcOffset = base + sizeof (mat4f_t[i * num_cascade]),
@ -760,7 +760,7 @@ lighting_update_lights (const exprval_t **params, exprval_t *result,
.attenuation = { 0, 0, 1, 1/dynamic_lights[i]->radius },
};
uint32_t id = lctx->dynamic_base + i;
set_lightid (dynamic_light_entities[i], lctx->scene->reg, id);
set_lightid (dynamic_light_entities[i], id);
uint32_t ind = queue[ST_CUBE].count++;
light_ids[ST_CUBE][ind] = id;
light_radii[ST_CUBE][ind] = light_radius (&light);
@ -2014,11 +2014,12 @@ static void
create_light_matrices (lightingctx_t *lctx)
{
auto reg = lctx->scene->reg;
auto light_pool = &reg->comp_pools[scene_light];
auto light_pool = &reg->comp_pools[lctx->scene->base + scene_light];
auto light_data = (light_t *) light_pool->data;
uint16_t mat_count = 0;
for (uint32_t i = 0; i < light_pool->count; i++) {
entity_t ent = { .reg = reg, .id = light_pool->dense[i] };
entity_t ent = { .reg = reg, .id = light_pool->dense[i],
.base = lctx->scene->base };
uint32_t id = get_lightid (ent);
auto r = &lctx->light_control.a[id];
r->matrix_id = mat_count;
@ -2032,7 +2033,8 @@ create_light_matrices (lightingctx_t *lctx)
}
for (uint32_t i = 0; i < light_pool->count; i++) {
light_t *light = &light_data[i];
entity_t ent = { .reg = reg, .id = light_pool->dense[i] };
entity_t ent = { .reg = reg, .id = light_pool->dense[i],
.base = lctx->scene->base };
uint32_t id = get_lightid (ent);
auto r = &lctx->light_control.a[id];
auto lm = &lctx->light_mats.a[r->matrix_id];
@ -2120,7 +2122,7 @@ static void
upload_light_data (lightingctx_t *lctx, vulkan_ctx_t *ctx)
{
auto reg = lctx->scene->reg;
auto light_pool = &reg->comp_pools[scene_light];
auto light_pool = &reg->comp_pools[lctx->scene->base + scene_light];
auto lights = (light_t *) light_pool->data;
uint32_t count = light_pool->count;
@ -2138,7 +2140,8 @@ upload_light_data (lightingctx_t *lctx, vulkan_ctx_t *ctx)
uint32_t r_size = sizeof (qfv_light_render_t[count]);
qfv_light_render_t *render = QFV_PacketExtend (packet, r_size);
for (uint32_t i = 0; i < count; i++) {
entity_t ent = { .reg = reg, .id = light_pool->dense[i] };
entity_t ent = { .reg = reg, .id = light_pool->dense[i],
.base = lctx->scene->base };
uint32_t id = get_lightid (ent);
if (id >= lctx->light_control.size) {
continue;
@ -2339,7 +2342,7 @@ build_shadow_maps (lightingctx_t *lctx, vulkan_ctx_t *ctx)
maxLayers = 2048;
}
auto reg = lctx->scene->reg;
auto light_pool = &reg->comp_pools[scene_light];
auto light_pool = &reg->comp_pools[lctx->scene->base + scene_light];
auto lights = (light_t *) light_pool->data;
int numLights = light_pool->count;
int totalLayers = 0;
@ -2361,7 +2364,9 @@ build_shadow_maps (lightingctx_t *lctx, vulkan_ctx_t *ctx)
.mode = light_shadow_type (&lights[li]),
.light_id = li,
};
set_lightid (light_pool->dense[li], reg, li);
entity_t ent = { .reg = reg, .id = light_pool->dense[li],
.base = lctx->scene->base };
set_lightid (ent, li);
// assume all lights have no shadows
imageMap[li] = -1;
}
@ -2807,14 +2812,14 @@ Vulkan_LoadLights (scene_t *scene, vulkan_ctx_t *ctx)
lctx->ldata = 0;
if (lctx->scene) {
auto reg = lctx->scene->reg;
reg->components.a[scene_dynlight].ui = light_dyn_light_ui;
reg->components.a[scene_light].ui = light_light_ui;
reg->components.a[scene_efrags].ui = scene_efrags_ui;
reg->components.a[scene_lightstyle].ui = scene_lightstyle_ui;
reg->components.a[scene_lightleaf].ui = scene_lightleaf_ui;
reg->components.a[scene_lightid].ui = scene_lightid_ui;
reg->components.a[lctx->scene->base + scene_dynlight].ui = light_dyn_light_ui;
reg->components.a[lctx->scene->base + scene_light].ui = light_light_ui;
reg->components.a[lctx->scene->base + scene_efrags].ui = scene_efrags_ui;
reg->components.a[lctx->scene->base + scene_lightstyle].ui = scene_lightstyle_ui;
reg->components.a[lctx->scene->base + scene_lightleaf].ui = scene_lightleaf_ui;
reg->components.a[lctx->scene->base + scene_lightid].ui = scene_lightid_ui;
auto light_pool = &reg->comp_pools[scene_light];
auto light_pool = &reg->comp_pools[lctx->scene->base + scene_light];
if (light_pool->count) {
lctx->dynamic_base = light_pool->count;
lctx->dynamic_count = 0;

View file

@ -89,13 +89,15 @@ Vulkan_Scene_AddEntity (vulkan_ctx_t *ctx, entity_t entity)
if (!Entity_Valid (entity)) {
return 0; //FIXME see below
} else {
renderer_t *renderer = Ent_GetComponent (entity.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (entity.id,
entity.base + scene_renderer,
entity.reg);
return renderer->render_id;
}
}
if (Entity_Valid (entity)) {
renderer_t *renderer = Ent_GetComponent (entity.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (entity.id,
entity.base + scene_renderer,
entity.reg);
renderer->render_id = render_id;
}
@ -105,7 +107,8 @@ Vulkan_Scene_AddEntity (vulkan_ctx_t *ctx, entity_t entity)
vec4f_t color;
if (Entity_Valid (entity)) { //FIXME give world entity an entity :P
transform_t transform = Entity_Transform (entity);
renderer_t *renderer = Ent_GetComponent (entity.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (entity.id,
entity.base + scene_renderer,
entity.reg);
mat4ftranspose (f, Transform_GetWorldMatrixPtr (transform));
entdata->xform[0] = f[0];
@ -149,7 +152,7 @@ scene_draw_viewmodel (const exprval_t **params, exprval_t *result,
if (!Entity_Valid (ent)) {
return;
}
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
if (vr_data.inhibit_viewmodel
|| !r_drawviewmodel
|| !r_drawentities

View file

@ -150,7 +150,7 @@ Vulkan_Sprite_FreeDescriptors (vulkan_ctx_t *ctx, qfv_sprite_t *sprite)
static void
sprite_draw_ent (qfv_taskctx_t *taskctx, entity_t ent)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
auto model = renderer->model;
msprite_t *sprite = model->cache.data;
@ -162,7 +162,7 @@ sprite_draw_ent (qfv_taskctx_t *taskctx, entity_t ent)
64, sizeof (frame), &frame },
};
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
frame = (ptrdiff_t) R_GetSpriteFrame (sprite, animation);

View file

@ -140,8 +140,8 @@ static void
set_entity_model (int ent_ind, int modelindex)
{
entity_t ent = cl_entities[ent_ind];
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
renderer->model = cl_world.models.a[modelindex];
// automatic animation (torches, etc) can be either all together
// or randomized
@ -219,9 +219,9 @@ CL_RelinkEntities (void)
SET_ADD (&cl_forcelink, i);
}
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, ent.reg);
vec4f_t *old_origin = Ent_GetComponent (ent.id, scene_old_origin, ent.reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
vec4f_t *old_origin = Ent_GetComponent (ent.id, ent.base + scene_old_origin, ent.reg);
if (SET_TEST_MEMBER (&cl_forcelink, i)) {
*old = *new;
@ -248,7 +248,7 @@ CL_RelinkEntities (void)
.top = cl.players[i - 1].topcolor,
.bottom = cl.players[i - 1].bottomcolor,
};
Ent_SetComponent (ent.id, scene_colormap, ent.reg, &colormap);
Ent_SetComponent (ent.id, ent.base + scene_colormap, ent.reg, &colormap);
renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin,
i);
mod_funcs->Skin_SetTranslation (i, cl.players[i - 1].topcolor,

View file

@ -297,7 +297,7 @@ CL_ClearState (void)
cl.viewstate.weapon_entity = Scene_CreateEntity (cl_world.scene);
CL_Init_Entity (cl.viewstate.weapon_entity);
renderer_t *renderer = Ent_GetComponent (cl.viewstate.weapon_entity.id,
scene_renderer,
cl_world.scene->base + scene_renderer,
cl_world.scene->reg);
renderer->depthhack = 1;
renderer->noshadows = cl_player_shadows;
@ -485,8 +485,8 @@ CL_PrintEntities_f (void)
for (i = 0; i < cl.num_entities; i++) {
entity_t ent = cl_entities[i];
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
Sys_Printf ("%3i:", i);
if (!Entity_Valid (ent) || !renderer->model) {
Sys_Printf ("EMPTY\n");

View file

@ -678,7 +678,7 @@ CL_ParseClientdata (void)
if (bits & SU_WEAPONFRAME2)
cl.stats[STAT_WEAPONFRAME] |= MSG_ReadByte (net_message) << 8;
renderer_t *renderer = Ent_GetComponent (cl.viewstate.weapon_entity.id, scene_renderer, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (cl.viewstate.weapon_entity.id, cl_world.scene->base + scene_renderer, cl_world.scene->reg);
if (bits & SU_WEAPONALPHA) {
byte alpha = MSG_ReadByte (net_message);
float a = ENTALPHA_DECODE (alpha);
@ -913,7 +913,7 @@ CL_ParseServerMessage (void)
"MAX_SCOREBOARD");
} else {
entity_t ent = CL_GetEntity (i + 1);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
byte col = MSG_ReadByte (net_message);
byte top = col >> 4;
byte bot = col & 0xf;

View file

@ -44,10 +44,14 @@
#include "qtv/include/server.h"
#include "qtv/include/qtv.h"
static uint32_t sv_base;
#define s_view (sv_base + server_view)
#define s_window (sv_base + server_window)
static void
draw_clients (view_t view)
{
sv_view_t *sv_view = Ent_GetComponent (view.id, server_view, view.reg);
sv_view_t *sv_view = Ent_GetComponent (view.id, s_view, view.reg);
sv_sbar_t *sb = sv_view->obj;
view_pos_t rel = View_GetRel (view);
const char *str;
@ -62,7 +66,7 @@ draw_clients (view_t view)
static void
draw_servers (view_t view)
{
sv_view_t *sv_view = Ent_GetComponent (view.id, server_view, view.reg);
sv_view_t *sv_view = Ent_GetComponent (view.id, s_view, view.reg);
sv_sbar_t *sb = sv_view->obj;
view_pos_t rel = View_GetRel (view);
const char *str;
@ -83,8 +87,9 @@ qtv_sbar_init (void)
if (!con_module || !con_module->data->console->status_view)
return;
sv_base = con_module->data->console->component_base;
status = *con_module->data->console->status_view;
void *comp = Ent_GetComponent (status.id, server_window, status.reg);
void *comp = Ent_GetComponent (status.id, s_window, status.reg);
sv_view_t sv_view = *(sv_view_t *) comp;
sv_view.setgeometry = 0;
@ -95,14 +100,14 @@ qtv_sbar_init (void)
View_SetLen (view, 8, 1);
View_SetGravity (view, grav_northwest);
sv_view.draw = draw_servers;
Ent_SetComponent (view.id, server_view, view.reg, &sv_view);
Ent_SetComponent (view.id, s_view, view.reg, &sv_view);
view = View_New (viewsys, status);
View_SetPos (view, 8, 0);
View_SetLen (view, 9, 1);
View_SetGravity (view, grav_northwest);
sv_view.draw = draw_clients;
Ent_SetComponent (view.id, server_view, view.reg, &sv_view);
Ent_SetComponent (view.id, s_view, view.reg, &sv_view);
View_UpdateHierarchy (status);
}

View file

@ -485,7 +485,7 @@ CL_ParsePlayerinfo (void)
entity_t ent;
ent = CL_GetEntity (num + 1);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
cl_world.scene->reg);
bits = MSG_ReadByte (net_message);
if (bits & PF_ALPHA) {

View file

@ -138,9 +138,9 @@ is_gib (entity_state_t *s1)
static void
set_entity_model (entity_t ent, int modelindex)
{
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
cl_world.scene->reg);
renderer->model = cl_world.models.a[modelindex];
// automatic animation (torches, etc) can be either all together
@ -187,11 +187,11 @@ CL_LinkPacketEntities (void)
forcelink = true;
}
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
ent.reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
ent.reg);
vec4f_t *old_origin = Ent_GetComponent (ent.id, scene_old_origin,
vec4f_t *old_origin = Ent_GetComponent (ent.id, ent.base + scene_old_origin,
ent.reg);
// spawn light flashes, even ones coming from invisible objects
@ -220,7 +220,7 @@ CL_LinkPacketEntities (void)
.top = player->topcolor,
.bottom = player->bottomcolor,
};
Ent_SetComponent (ent.id, scene_colormap, ent.reg, &colormap);
Ent_SetComponent (ent.id, ent.base + scene_colormap, ent.reg, &colormap);
renderer->skin
= mod_funcs->Skin_SetSkin (renderer->skin, new->colormap,
player->skinname->value);
@ -229,7 +229,7 @@ CL_LinkPacketEntities (void)
} else {
renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin,
0);
Ent_RemoveComponent (ent.id, scene_colormap, ent.reg);
Ent_RemoveComponent (ent.id, ent.base + scene_colormap, ent.reg);
}
}
@ -313,13 +313,13 @@ CL_UpdateFlagModels (entity_t ent, int key)
};
float f;
entity_t fent = CL_GetFlagEnt (key);
byte *active = Ent_GetComponent (fent.id, scene_active,
byte *active = Ent_GetComponent (fent.id, fent.base + scene_active,
cl_world.scene->reg);
if (!*active) {
return;
}
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
cl_world.scene->reg);
f = 14.0;
@ -348,7 +348,7 @@ CL_AddFlagModels (entity_t ent, int team, int key)
entity_t fent;
fent = CL_GetFlagEnt (key);
byte *active = Ent_GetComponent (fent.id, scene_active,
byte *active = Ent_GetComponent (fent.id, fent.base + scene_active,
cl_world.scene->reg);
if (cl_flagindex == -1) {
@ -365,7 +365,7 @@ CL_AddFlagModels (entity_t ent, int team, int key)
}
CL_UpdateFlagModels (ent, key);
renderer_t *renderer = Ent_GetComponent (fent.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (fent.id, fent.base + scene_renderer,
cl_world.scene->reg);
renderer->model = cl_world.models.a[cl_flagindex];
renderer->skinnum = team;
@ -379,7 +379,7 @@ CL_RemoveFlagModels (int key)
entity_t fent;
fent = CL_GetFlagEnt (key);
byte *active = Ent_GetComponent (fent.id, scene_active,
byte *active = Ent_GetComponent (fent.id, fent.base + scene_active,
cl_world.scene->reg);
transform_t transform = Entity_Transform (fent);
*active = 0;
@ -442,9 +442,9 @@ CL_LinkPlayers (void)
if (!Entity_Valid (ent)) {
ent = CL_GetEntity (j + 1);
}
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
cl_world.scene->reg);
// spawn light flashes, even ones coming from invisible objects
@ -457,7 +457,7 @@ CL_LinkPlayers (void)
clientplayer = false;
}
if (player->chat && player->chat->value[0] != '0') {
Ent_SetComponent (ent.id, scene_dynlight, ent.reg, &(dlight_t) {
Ent_SetComponent (ent.id, ent.base + scene_dynlight, ent.reg, &(dlight_t) {
.origin = org,
.color = {0.0, 1.0, 0.0, 1.0},
.radius = 100,
@ -488,7 +488,7 @@ CL_LinkPlayers (void)
.top = player->topcolor,
.bottom = player->bottomcolor,
};
Ent_SetComponent (ent.id, scene_colormap, ent.reg, &colormap);
Ent_SetComponent (ent.id, ent.base + scene_colormap, ent.reg, &colormap);
// predict only half the move to minimize overruns
msec = 500 * (playertime - state->state_time);
@ -547,7 +547,7 @@ CL_LinkPlayers (void)
int flag_state = state->pls.es.effects & (EF_FLAG1 | EF_FLAG2);
if (Entity_Valid (player->flag_ent) && !flag_state) {
CL_RemoveFlagModels (j);
player->flag_ent = (entity_t) nullentity;
player->flag_ent = nullentity;
} else if (!Entity_Valid (player->flag_ent) && flag_state) {
if (flag_state & EF_FLAG1)
player->flag_ent = CL_AddFlagModels (ent, 0, j);

View file

@ -166,7 +166,7 @@ CL_NetGraph_Init (void)
View_SetLen (cl_netgraph_view, NET_TIMINGS + 16, cl_netgraph_height + 25);
View_SetGravity (cl_netgraph_view, grav_southwest);
void *f = CL_NetGraph;
Ent_SetComponent (cl_netgraph_view.id, canvas_func,
Ent_SetComponent (cl_netgraph_view.id, cl_canvas_sys.base + canvas_func,
cl_netgraph_view.reg, &f);
View_SetVisible (cl_netgraph_view, cl_netgraph);
}

View file

@ -44,10 +44,14 @@
#include "qw/include/sv_progs.h"
#include "qw/include/sv_recorder.h"
static uint32_t sv_base;
#define s_view (sv_base + server_view)
#define s_window (sv_base + server_window)
static void
draw_cpu (view_t view)
{
sv_view_t *sv_view = Ent_GetComponent (view.id, server_view, view.reg);
sv_view_t *sv_view = Ent_GetComponent (view.id, s_view, view.reg);
sv_sbar_t *sb = sv_view->obj;
view_pos_t rel = View_GetRel (view);
double cpu;
@ -71,7 +75,7 @@ draw_cpu (view_t view)
static void
draw_rec (view_t view)
{
sv_view_t *sv_view = Ent_GetComponent (view.id, server_view, view.reg);
sv_view_t *sv_view = Ent_GetComponent (view.id, s_view, view.reg);
sv_sbar_t *sb = sv_view->obj;
view_pos_t rel = View_GetRel (view);
const char *str;
@ -86,7 +90,7 @@ draw_rec (view_t view)
static void
draw_mem (view_t view)
{
sv_view_t *sv_view = Ent_GetComponent (view.id, server_view, view.reg);
sv_view_t *sv_view = Ent_GetComponent (view.id, s_view, view.reg);
sv_sbar_t *sb = sv_view->obj;
view_pos_t rel = View_GetRel (view);
const char *str;
@ -113,8 +117,9 @@ SV_Sbar_Init (void)
if (!con_module || !con_module->data->console->status_view)
return;
sv_base = con_module->data->console->component_base;
status = *con_module->data->console->status_view;
void *comp = Ent_GetComponent (status.id, server_window, status.reg);
void *comp = Ent_GetComponent (status.id, s_window, status.reg);
sv_view_t sv_view = *(sv_view_t *) comp;
sv_view.setgeometry = 0;
@ -125,21 +130,21 @@ SV_Sbar_Init (void)
View_SetLen (view, 11, 1);
View_SetGravity (view, grav_northwest);
sv_view.draw = draw_cpu;
Ent_SetComponent (view.id, server_view, view.reg, &sv_view);
Ent_SetComponent (view.id, s_view, view.reg, &sv_view);
view = View_New (viewsys, status);
View_SetPos (view, 11, 0);
View_SetLen (view, 8, 1);
View_SetGravity (view, grav_northwest);
sv_view.draw = draw_rec;
Ent_SetComponent (view.id, server_view, view.reg, &sv_view);
Ent_SetComponent (view.id, s_view, view.reg, &sv_view);
view = View_New (viewsys, status);
View_SetPos (view, 19, 0);
View_SetLen (view, 18, 1);
View_SetGravity (view, grav_northwest);
sv_view.draw = draw_mem;
Ent_SetComponent (view.id, server_view, view.reg, &sv_view);
Ent_SetComponent (view.id, s_view, view.reg, &sv_view);
View_UpdateHierarchy (status);
}