From 05ddd243f469a04670977294b77e2052dfca878f Mon Sep 17 00:00:00 2001 From: Chukobyte Date: Mon, 12 Aug 2024 00:46:05 -0400 Subject: [PATCH] Fixing bugs related to render interpolation with initial transform, 'animation_finished' event for animated sprite nodes, and node component setup (#228) --- .../src/core/ecs/components/node_component.h | 16 ++++++++-------- .../animated_sprite_rendering_ec_system.c | 2 +- engine/src/core/scene/scene_manager.c | 5 +++-- .../python/pocketpy/api/cre_pkpy_api_node.c | 18 +++++++++--------- engine/test/resources/test_custom_nodes.py | 11 +++++------ 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/engine/src/core/ecs/components/node_component.h b/engine/src/core/ecs/components/node_component.h index 05da3784f..bd03689b0 100644 --- a/engine/src/core/ecs/components/node_component.h +++ b/engine/src/core/ecs/components/node_component.h @@ -38,14 +38,14 @@ typedef enum NodeBaseInheritanceType { NodeBaseInheritanceType_INVALID = -1, NodeBaseInheritanceType_NODE = NodeBaseType_NODE, NodeBaseInheritanceType_NODE2D = NodeBaseType_NODE | NodeBaseType_NODE2D, - NodeBaseInheritanceType_SPRITE = NodeBaseType_NODE | NodeBaseType_NODE2D | NodeBaseType_SPRITE, - NodeBaseInheritanceType_ANIMATED_SPRITE = NodeBaseType_NODE | NodeBaseType_NODE2D | NodeBaseType_ANIMATED_SPRITE, - NodeBaseInheritanceType_TEXT_LABEL = NodeBaseType_NODE | NodeBaseType_NODE2D | NodeBaseType_TEXT_LABEL, - NodeBaseInheritanceType_COLLIDER2D = NodeBaseType_NODE | NodeBaseType_NODE2D | NodeBaseType_COLLIDER2D, - NodeBaseInheritanceType_COLOR_RECT = NodeBaseType_NODE | NodeBaseType_NODE2D | NodeBaseType_COLOR_RECT, - NodeBaseInheritanceType_PARALLAX = NodeBaseType_NODE | NodeBaseType_NODE2D | NodeBaseType_PARALLAX, - NodeBaseInheritanceType_PARTICLES2D = NodeBaseType_NODE | NodeBaseType_NODE2D | NodeBaseType_PARTICLES2D, - NodeBaseInheritanceType_TILEMAP = NodeBaseType_NODE | NodeBaseType_NODE2D | NodeBaseType_TILEMAP, + NodeBaseInheritanceType_SPRITE = NodeBaseInheritanceType_NODE2D | NodeBaseType_SPRITE, + NodeBaseInheritanceType_ANIMATED_SPRITE = NodeBaseInheritanceType_NODE2D | NodeBaseType_ANIMATED_SPRITE, + NodeBaseInheritanceType_TEXT_LABEL = NodeBaseInheritanceType_NODE2D | NodeBaseType_TEXT_LABEL, + NodeBaseInheritanceType_COLLIDER2D = NodeBaseInheritanceType_NODE2D | NodeBaseType_COLLIDER2D, + NodeBaseInheritanceType_COLOR_RECT = NodeBaseInheritanceType_NODE2D | NodeBaseType_COLOR_RECT, + NodeBaseInheritanceType_PARALLAX = NodeBaseInheritanceType_NODE2D | NodeBaseType_PARALLAX, + NodeBaseInheritanceType_PARTICLES2D = NodeBaseInheritanceType_NODE2D | NodeBaseType_PARTICLES2D, + NodeBaseInheritanceType_TILEMAP = NodeBaseInheritanceType_NODE2D | NodeBaseType_TILEMAP, } NodeBaseInheritanceType; typedef struct NodeTimeDilation { diff --git a/engine/src/core/ecs/systems/animated_sprite_rendering_ec_system.c b/engine/src/core/ecs/systems/animated_sprite_rendering_ec_system.c index 85856a0e5..12029cb34 100644 --- a/engine/src/core/ecs/systems/animated_sprite_rendering_ec_system.c +++ b/engine/src/core/ecs/systems/animated_sprite_rendering_ec_system.c @@ -55,7 +55,7 @@ void animated_sprite_render(SkaECSSystem* system) { currentFrame = animatedSpriteComponent->currentAnimation.animationFrames[newIndex]; if (newIndex + 1 == animatedSpriteComponent->currentAnimation.frameCount) { // Notify the observers that the animation has finished - ska_event_notify_observers(&animatedSpriteComponent->onFrameChanged, &(SkaSubjectNotifyPayload){ + ska_event_notify_observers(&animatedSpriteComponent->onAnimationFinished, &(SkaSubjectNotifyPayload){ .data = &(AnimatedSpriteAnimationFinishedPayload){ .entity = entity, .animation = &animatedSpriteComponent->currentAnimation } }); if (!animatedSpriteComponent->currentAnimation.doesLoop) { diff --git a/engine/src/core/scene/scene_manager.c b/engine/src/core/scene/scene_manager.c index ac3a1afce..f17d16a0b 100644 --- a/engine/src/core/scene/scene_manager.c +++ b/engine/src/core/scene/scene_manager.c @@ -135,9 +135,10 @@ void cre_scene_manager_process_queued_creation_entities() { #ifdef CRE_SCENE_MANAGER_RENDER_INTERPOLATE_TRANSFORM2D_ALPHA - Transform2DComponent* transformComponent = (Transform2DComponent*)ska_ecs_component_manager_get_component(queuedEntity, TRANSFORM2D_COMPONENT_INDEX); + Transform2DComponent* transformComponent = (Transform2DComponent*)ska_ecs_component_manager_get_component_unchecked(queuedEntity, TRANSFORM2D_COMPONENT_INDEX); if (transformComponent) { - entityPrevGlobalTransforms[queuedEntity] = transformComponent->localTransform; // TODO: globalTransform isn't filled out yet, change that... + SkaTransformModel2D* globalTransform = cre_scene_manager_get_scene_node_global_transform(queuedEntity, transformComponent); + entityPrevGlobalTransforms[queuedEntity] = ska_transform2d_model_convert_to_transform(globalTransform); } #endif } diff --git a/engine/src/core/scripting/python/pocketpy/api/cre_pkpy_api_node.c b/engine/src/core/scripting/python/pocketpy/api/cre_pkpy_api_node.c index 8aeaf52a2..ee7458c57 100644 --- a/engine/src/core/scripting/python/pocketpy/api/cre_pkpy_api_node.c +++ b/engine/src/core/scripting/python/pocketpy/api/cre_pkpy_api_node.c @@ -33,31 +33,31 @@ static void set_node_component_from_type(SkaEntity entity, const char* classPath const NodeBaseInheritanceType inheritanceType = node_get_type_inheritance(baseType); - if (SKA_FLAG_CONTAINS(NodeBaseInheritanceType_NODE2D, inheritanceType)) { + if (SKA_FLAG_CONTAINS(inheritanceType, NodeBaseInheritanceType_NODE2D)) { ska_ecs_component_manager_set_component(entity, TRANSFORM2D_COMPONENT_INDEX, transform2d_component_create()); } - if (SKA_FLAG_CONTAINS(NodeBaseInheritanceType_SPRITE, inheritanceType)) { + if (SKA_FLAG_CONTAINS(inheritanceType, NodeBaseInheritanceType_SPRITE)) { ska_ecs_component_manager_set_component(entity, SPRITE_COMPONENT_INDEX, sprite_component_create()); } - if (SKA_FLAG_CONTAINS(NodeBaseInheritanceType_ANIMATED_SPRITE, inheritanceType)) { + if (SKA_FLAG_CONTAINS(inheritanceType, NodeBaseInheritanceType_ANIMATED_SPRITE)) { ska_ecs_component_manager_set_component(entity, ANIMATED_SPRITE_COMPONENT_INDEX, animated_sprite_component_create()); } - if (SKA_FLAG_CONTAINS(NodeBaseInheritanceType_TEXT_LABEL, inheritanceType)) { + if (SKA_FLAG_CONTAINS(inheritanceType, NodeBaseInheritanceType_TEXT_LABEL)) { ska_ecs_component_manager_set_component(entity, TEXT_LABEL_COMPONENT_INDEX, text_label_component_create()); } - if (SKA_FLAG_CONTAINS(NodeBaseInheritanceType_COLLIDER2D, inheritanceType)) { + if (SKA_FLAG_CONTAINS(inheritanceType, NodeBaseInheritanceType_COLLIDER2D)) { ska_ecs_component_manager_set_component(entity, COLLIDER2D_COMPONENT_INDEX, collider2d_component_create()); } - if (SKA_FLAG_CONTAINS(NodeBaseInheritanceType_COLOR_RECT, inheritanceType)) { + if (SKA_FLAG_CONTAINS(inheritanceType, NodeBaseInheritanceType_COLOR_RECT)) { ska_ecs_component_manager_set_component(entity, COLOR_RECT_COMPONENT_INDEX, color_rect_component_create()); } - if (SKA_FLAG_CONTAINS(NodeBaseInheritanceType_PARALLAX, inheritanceType)) { + if (SKA_FLAG_CONTAINS(inheritanceType, NodeBaseInheritanceType_PARALLAX)) { ska_ecs_component_manager_set_component(entity, PARALLAX_COMPONENT_INDEX, parallax_component_create()); } - if (SKA_FLAG_CONTAINS(NodeBaseInheritanceType_PARTICLES2D, inheritanceType)) { + if (SKA_FLAG_CONTAINS(inheritanceType, NodeBaseInheritanceType_PARTICLES2D)) { ska_ecs_component_manager_set_component(entity, PARTICLES2D_COMPONENT_INDEX, particles2d_component_create()); } - if (SKA_FLAG_CONTAINS(NodeBaseInheritanceType_TILEMAP, inheritanceType)) { + if (SKA_FLAG_CONTAINS(inheritanceType, NodeBaseInheritanceType_TILEMAP)) { ska_ecs_component_manager_set_component(entity, TILEMAP_COMPONENT_INDEX, tilemap_component_create()); } } diff --git a/engine/test/resources/test_custom_nodes.py b/engine/test/resources/test_custom_nodes.py index b66911e44..8b1e6b896 100644 --- a/engine/test/resources/test_custom_nodes.py +++ b/engine/test/resources/test_custom_nodes.py @@ -1,5 +1,5 @@ import crescent_internal -from crescent import Node, NodeType +from crescent import Node2D, NodeType start_call_count = 0 process_call_count = 0 @@ -21,8 +21,11 @@ def run_end_of_test_asserts() -> bool: return True -class TestNode(Node): +# TODO: Node breaks on not calling '_start', '_end', etc... look into later or don't user Node... + +class TestNode(Node2D): def _start(self) -> None: + print("No") global start_call_count start_call_count += 1 @@ -37,7 +40,3 @@ def _fixed_process(self, delta_time: float) -> None: def _end(self) -> None: global end_call_count end_call_count += 1 - - @staticmethod - def new() -> "TestNode": - return crescent_internal.node_new("test_custom_nodes", "TestNode", NodeType.Node)