mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
[scene] Manage scene roots in transform
Since transforms now know the scene to which they belong, and they know when they are root and when not, getting the transform code to manage the scene roots is the best way to keep the list of root transforms consistent.
This commit is contained in:
parent
54c3b4cc53
commit
b210f01837
3 changed files with 17 additions and 4 deletions
|
@ -11,4 +11,7 @@ typedef struct scene_resources_s {
|
||||||
PR_RESMAP (transform_t) transforms;
|
PR_RESMAP (transform_t) transforms;
|
||||||
} scene_resources_t;
|
} scene_resources_t;
|
||||||
|
|
||||||
|
void scene_add_root (scene_t *scene, transform_t *transform);
|
||||||
|
void scene_del_root (scene_t *scene, transform_t *transform);
|
||||||
|
|
||||||
#endif//__scn_internal_h
|
#endif//__scn_internal_h
|
||||||
|
|
|
@ -88,7 +88,6 @@ Scene_CreateEntity (scene_t *scene)
|
||||||
hierarchy_t *h = ent->transform->hierarchy;
|
hierarchy_t *h = ent->transform->hierarchy;
|
||||||
h->entity.a[ent->transform->index] = ent;
|
h->entity.a[ent->transform->index] = ent;
|
||||||
|
|
||||||
DARRAY_APPEND (&scene->roots, ent->transform);
|
|
||||||
return ent;
|
return ent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,8 +98,16 @@ Scene_GetEntity (scene_t *scene, int id)
|
||||||
return PR_RESGET (res->entities, id);
|
return PR_RESGET (res->entities, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
unroot_transform (scene_t *scene, transform_t *transform)
|
scene_add_root (scene_t *scene, transform_t *transform)
|
||||||
|
{
|
||||||
|
if (!Transform_GetParent (transform)) {
|
||||||
|
DARRAY_APPEND (&scene->roots, transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
scene_del_root (scene_t *scene, transform_t *transform)
|
||||||
{
|
{
|
||||||
if (!Transform_GetParent (transform)) {
|
if (!Transform_GetParent (transform)) {
|
||||||
for (size_t i = 0; i < scene->roots.size; i++) {
|
for (size_t i = 0; i < scene->roots.size; i++) {
|
||||||
|
@ -138,7 +145,6 @@ Scene_DestroyEntity (scene_t *scene, entity_t *ent)
|
||||||
if (PR_RESGET (res->entities, ent->id) != ent) {
|
if (PR_RESGET (res->entities, ent->id) != ent) {
|
||||||
Sys_Error ("Scene_DestroyEntity: entity not owned by scene");
|
Sys_Error ("Scene_DestroyEntity: entity not owned by scene");
|
||||||
}
|
}
|
||||||
unroot_transform (scene, ent->transform);
|
|
||||||
// pull the transform out of the hierarchy to make it easier to destory
|
// pull the transform out of the hierarchy to make it easier to destory
|
||||||
// all the child entities
|
// all the child entities
|
||||||
Transform_SetParent (ent->transform, 0);
|
Transform_SetParent (ent->transform, 0);
|
||||||
|
|
|
@ -58,6 +58,7 @@ Transform_New (scene_t *scene, transform_t *parent)
|
||||||
} else {
|
} else {
|
||||||
transform->hierarchy = Hierarchy_New (16, 1);//FIXME should be config
|
transform->hierarchy = Hierarchy_New (16, 1);//FIXME should be config
|
||||||
transform->index = 0;
|
transform->index = 0;
|
||||||
|
scene_add_root (scene, transform);
|
||||||
}
|
}
|
||||||
transform->hierarchy->transform.a[transform->index] = transform;
|
transform->hierarchy->transform.a[transform->index] = transform;
|
||||||
Hierarchy_UpdateMatrices (transform->hierarchy);
|
Hierarchy_UpdateMatrices (transform->hierarchy);
|
||||||
|
@ -72,6 +73,7 @@ Transform_Delete (transform_t *transform)
|
||||||
// hierarchy so deleting it is easier
|
// hierarchy so deleting it is easier
|
||||||
Transform_SetParent (transform, 0);
|
Transform_SetParent (transform, 0);
|
||||||
}
|
}
|
||||||
|
scene_del_root (transform->scene, transform);
|
||||||
Hierarchy_Delete (transform->hierarchy);
|
Hierarchy_Delete (transform->hierarchy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +89,7 @@ void
|
||||||
Transform_SetParent (transform_t *transform, transform_t *parent)
|
Transform_SetParent (transform_t *transform, transform_t *parent)
|
||||||
{
|
{
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
scene_del_root (transform->scene, transform);
|
||||||
hierarchy_t *hierarchy = transform->hierarchy;
|
hierarchy_t *hierarchy = transform->hierarchy;
|
||||||
uint32_t index = transform->index;
|
uint32_t index = transform->index;
|
||||||
Hierarchy_InsertHierarchy (parent->hierarchy, hierarchy,
|
Hierarchy_InsertHierarchy (parent->hierarchy, hierarchy,
|
||||||
|
@ -108,6 +111,7 @@ Transform_SetParent (transform_t *transform, transform_t *parent)
|
||||||
Hierarchy_InsertHierarchy (new_hierarchy, hierarchy, null_transform,
|
Hierarchy_InsertHierarchy (new_hierarchy, hierarchy, null_transform,
|
||||||
index);
|
index);
|
||||||
Hierarchy_RemoveHierarchy (hierarchy, index);
|
Hierarchy_RemoveHierarchy (hierarchy, index);
|
||||||
|
scene_add_root (transform->scene, transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue