From 25cad97b0b265885d6abc56fefb3f6d58984bc0a Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 17 Feb 2024 14:47:48 -0800 Subject: Fix constness of node. --- gfx/include/gfx/scene/model.h | 4 +--- gfx/include/gfx/scene/node.h | 26 +++++++++++++------------- gfx/src/renderer/renderer.c | 6 +++--- gfx/src/scene/model.c | 2 +- gfx/src/scene/node.c | 35 ++++++++++++++++++++++++++++++----- 5 files changed, 48 insertions(+), 25 deletions(-) diff --git a/gfx/include/gfx/scene/model.h b/gfx/include/gfx/scene/model.h index c55fc8c..42f85d4 100644 --- a/gfx/include/gfx/scene/model.h +++ b/gfx/include/gfx/scene/model.h @@ -9,6 +9,4 @@ Anima* gfx_get_model_anima(Model*); /// Return the model's root node. const SceneNode* gfx_get_model_root(const Model*); - -/// Return the model's root node. -SceneNode* gfx_get_model_root_mut(Model*); +SceneNode* gfx_get_model_root_mut(Model*); diff --git a/gfx/include/gfx/scene/node.h b/gfx/include/gfx/scene/node.h index 77db85c..a2c2836 100644 --- a/gfx/include/gfx/scene/node.h +++ b/gfx/include/gfx/scene/node.h @@ -80,50 +80,50 @@ void gfx_destroy_node(SceneNode**); // Getters. // ----------------------------------------------------------------------------- -// TODO: Review constness of getters here. - /// Get the node's type. NodeType gfx_get_node_type(const SceneNode*); /// Get the node's anima. /// /// The node must be of type AnimaNode. -Anima* gfx_get_node_anima(const SceneNode*); +const Anima* gfx_get_node_anima(const SceneNode*); +Anima* gfx_get_node_anima_mut(SceneNode*); /// Get the node's camera. /// /// The node must be of type CameraNode. -SceneCamera* gfx_get_node_camera(const SceneNode* node); +const SceneCamera* gfx_get_node_camera(const SceneNode* node); +SceneCamera* gfx_get_node_camera_mut(SceneNode* node); /// Get the node's light. /// /// The node must be of type LightNode. -Light* gfx_get_node_light(const SceneNode*); +const Light* gfx_get_node_light(const SceneNode*); +Light* gfx_get_node_light_mut(SceneNode*); /// Get the node's model. /// /// The node must be of type ModelNode. -Model* gfx_get_node_model(const SceneNode*); +const Model* gfx_get_node_model(const SceneNode*); +Model* gfx_get_node_model_mut(SceneNode*); /// Get the node's scene object. /// /// The node must be of type ObjectNode. -SceneObject* gfx_get_node_object(const SceneNode*); +const SceneObject* gfx_get_node_object(const SceneNode*); +SceneObject* gfx_get_node_object_mut(SceneNode*); /// Get the node's parent. const SceneNode* gfx_get_node_parent(const SceneNode*); +SceneNode* gfx_get_node_parent_mut(SceneNode*); /// Get the node's first child. const SceneNode* gfx_get_node_child(const SceneNode*); - -/// Get the node's first child. -SceneNode* gfx_get_node_child_mut(SceneNode*); +SceneNode* gfx_get_node_child_mut(SceneNode*); /// Get the node's immediate sibling. const SceneNode* gfx_get_node_sibling(const SceneNode*); - -/// Get the node's immediate sibling. -SceneNode* gfx_get_node_sibling_mut(SceneNode*); +SceneNode* gfx_get_node_sibling_mut(SceneNode*); /// Get the node's (local) transform. mat4 gfx_get_node_transform(const SceneNode*); diff --git a/gfx/src/renderer/renderer.c b/gfx/src/renderer/renderer.c index c72f719..dbfc62b 100644 --- a/gfx/src/renderer/renderer.c +++ b/gfx/src/renderer/renderer.c @@ -180,7 +180,7 @@ typedef struct RenderState { const float fovy; const float aspect; Light* environment_light; - Anima* anima; + const Anima* anima; size_t num_joints; mat4 joint_matrices[GFX_MAX_NUM_JOINTS]; } RenderState; @@ -373,10 +373,10 @@ static void update_rec(SceneNode* node, const SceneCamera* camera, R t) { // TODO: Models do not need to be animated if they are not visible to the // camera. if (node_type == AnimaNode) { - Anima* anima = gfx_get_node_anima(node); + Anima* anima = gfx_get_node_anima_mut(node); gfx_update_animation(anima, (R)t); } else if (node_type == ModelNode) { - Model* model = gfx_get_node_model(node); + Model* model = gfx_get_node_model_mut(node); SceneNode* root = gfx_get_model_root_mut(model); update_rec(root, camera, t); } diff --git a/gfx/src/scene/model.c b/gfx/src/scene/model.c index 507c478..cc41a9a 100644 --- a/gfx/src/scene/model.c +++ b/gfx/src/scene/model.c @@ -29,7 +29,7 @@ Anima* gfx_get_model_anima(Model* model) { SceneNode* root = mem_get_node(model->root); if (gfx_get_node_type(root) == AnimaNode) { - return gfx_get_node_anima(root); + return gfx_get_node_anima_mut(root); } else { return 0; } diff --git a/gfx/src/scene/node.c b/gfx/src/scene/node.c index 05f6428..67ce93c 100644 --- a/gfx/src/scene/node.c +++ b/gfx/src/scene/node.c @@ -209,23 +209,43 @@ NodeType gfx_get_node_type(const SceneNode* node) { return mem_get_##field(node->field); \ } -Anima* gfx_get_node_anima(const SceneNode* node) { +const Anima* gfx_get_node_anima(const SceneNode* node) { NODE_GET(node, anima, AnimaNode); } -SceneCamera* gfx_get_node_camera(const SceneNode* node) { +Anima* gfx_get_node_anima_mut(SceneNode* node) { + NODE_GET(node, anima, AnimaNode); +} + +const SceneCamera* gfx_get_node_camera(const SceneNode* node) { + NODE_GET(node, camera, CameraNode); +} + +SceneCamera* gfx_get_node_camera_mut(SceneNode* node) { NODE_GET(node, camera, CameraNode); } -Light* gfx_get_node_light(const SceneNode* node) { +const Light* gfx_get_node_light(const SceneNode* node) { NODE_GET(node, light, LightNode); } -Model* gfx_get_node_model(const SceneNode* node) { +Light* gfx_get_node_light_mut(SceneNode* node) { + NODE_GET(node, light, LightNode); +} + +const Model* gfx_get_node_model(const SceneNode* node) { NODE_GET(node, model, ModelNode); } -SceneObject* gfx_get_node_object(const SceneNode* node) { +Model* gfx_get_node_model_mut(SceneNode* node) { + NODE_GET(node, model, ModelNode); +} + +const SceneObject* gfx_get_node_object(const SceneNode* node) { + NODE_GET(node, object, ObjectNode); +} + +SceneObject* gfx_get_node_object_mut(SceneNode* node) { NODE_GET(node, object, ObjectNode); } @@ -234,6 +254,11 @@ const SceneNode* gfx_get_node_parent(const SceneNode* node) { return mem_get_node(node->parent); } +SceneNode* gfx_get_node_parent_mut(SceneNode* node) { + assert(node); + return mem_get_node(node->parent); +} + const SceneNode* gfx_get_node_child(const SceneNode* node) { assert(node); if (node->child.val) { -- cgit v1.2.3