Skip to content

Commit

Permalink
Fixing bugs related to render interpolation with initial transform, '…
Browse files Browse the repository at this point in the history
…animation_finished' event for animated sprite nodes, and node component setup (#228)
  • Loading branch information
Chukobyte authored Aug 12, 2024
1 parent 0904479 commit 05ddd24
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions engine/src/core/ecs/components/node_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions engine/src/core/scene/scene_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
11 changes: 5 additions & 6 deletions engine/test/resources/test_custom_nodes.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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)

0 comments on commit 05ddd24

Please sign in to comment.