Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

refactor: Modernize component system with strict warnings

esenginef42f22df7742
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 41a89b739..c936198e4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -50,6 +50,14 @@ set(ESENGINE_HEADERS
src/esengine/ecs/Registry.hpp
src/esengine/ecs/SparseSet.hpp
src/esengine/ecs/View.hpp
+ src/esengine/ecs/TransformSystem.hpp
+ # ECS Components (split for modularity)
+ src/esengine/ecs/components/Transform.hpp
+ src/esengine/ecs/components/Hierarchy.hpp
+ src/esengine/ecs/components/Sprite.hpp
+ src/esengine/ecs/components/Camera.hpp
+ src/esengine/ecs/components/Velocity.hpp
+ src/esengine/ecs/components/Common.hpp
src/esengine/math/Math.hpp
src/esengine/resource/Handle.hpp
src/esengine/resource/ResourcePool.hpp
@@ -118,12 +126,8 @@ else()
)
endif()
-# Compiler warnings
-if(MSVC)
- target_compile_options(esengine PRIVATE /W4)
-else()
- target_compile_options(esengine PRIVATE -Wall -Wextra -Wpedantic)
-endif()
+# Strict compiler warnings
+esengine_set_strict_warnings(esengine)
# Examples
if(ES_BUILD_EXAMPLES)
diff --git a/cmake/ESEngineConfig.cmake b/cmake/ESEngineConfig.cmake
index 49a57c88a..92b3a2d23 100644
--- a/cmake/ESEngineConfig.cmake
+++ b/cmake/ESEngineConfig.cmake
@@ -29,6 +29,67 @@ endif()
# Export compile commands for IDE support
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+# =============================================================================
+# Strict Compiler Warnings
+# =============================================================================
+
+# Function to apply strict warnings to a target
+function(esengine_set_strict_warnings target)
+ if(MSVC)
+ target_compile_options(${target} PRIVATE
+ /W4 # Warning level 4
+ /permissive- # Strict conformance mode
+ /w14242 # Conversion warnings
+ /w14254 # Larger bitfield assigned
+ /w14263 # Member function hides virtual
+ /w14265 # Class has virtual but no virtual dtor
+ /w14287 # Unsigned/negative constant mismatch
+ /w14296 # Expression always false
+ /w14311 # Pointer truncation
+ /w14545 # Expression before comma is function
+ /w14546 # Function call before comma missing args
+ /w14547 # Operator before comma has no effect
+ /w14549 # Operator before comma no effect
+ /w14555 # Expression no effect, expected side-effect
+ /w14619 # pragma warning invalid
+ /w14640 # Thread unsafe static init
+ /w14826 # Conversion signed/unsigned is extended
+ /w14905 # Wide string literal cast to LPSTR
+ /w14906 # String literal cast to LPWSTR
+ /w14928 # Illegal copy-init
+ /wd4996 # Disable deprecated warnings (we handle these ourselves)
+ )
+ else()
+ target_compile_options(${target} PRIVATE
+ -Wall
+ -Wextra
+ -Wpedantic
+ -Wshadow
+ -Wnon-virtual-dtor
+ -Wold-style-cast
+ -Wcast-align
+ -Wunused
+ -Woverloaded-virtual
+ -Wconversion
+ -Wsign-conversion
+ -Wnull-dereference
+ -Wdouble-promotion
+ -Wformat=2
+ -Wimplicit-fallthrough
+ -Wno-deprecated-declarations # We handle deprecated ourselves
+ )
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ target_compile_options(${target} PRIVATE
+ -Wmisleading-indentation
+ -Wduplicated-cond
+ -Wduplicated-branches
+ -Wlogical-op
+ -Wuseless-cast
+ )
+ endif()
+ endif()
+endfunction()
+
# Message about current configuration
message(STATUS "ESEngine Configuration:")
message(STATUS " Build Type: ${CMAKE_BUILD_TYPE}")
diff --git a/src/esengine/ESEngine.hpp b/src/esengine/ESEngine.hpp
index b4ac33314..8c988e935 100644
--- a/src/esengine/ESEngine.hpp
+++ b/src/esengine/ESEngine.hpp
@@ -6,9 +6,9 @@
* access to all engine subsystems.
*
* @author ESEngine Team
- * @date 2025
+ * @date 2026
*
- * @copyright Copyright (c) 2025 ESEngine Team
+ * @copyright Copyright (c) 2026 ESEngine Team
* Licensed under the MIT License.
*/
#pragma once
@@ -26,6 +26,9 @@
// Math
#include "math/Math.hpp"
+// Resource
+#include "resource/Handle.hpp"
+
// ECS
#include "ecs/Entity.hpp"
#include "ecs/Component.hpp"
@@ -33,6 +36,7 @@
#include "ecs/SparseSet.hpp"
#include "ecs/View.hpp"
#include "ecs/Registry.hpp"
+#include "ecs/TransformSystem.hpp"
// Renderer
#include "renderer/Buffer.hpp"
diff --git a/src/esengine/ecs/Component.hpp b/src/esengine/ecs/Component.hpp
index a3c9e02eb..281aa7b9d 100644
--- a/src/esengine/ecs/Component.hpp
+++ b/src/esengine/ecs/Component.hpp
@@ -1,230 +1,33 @@
/**
* @file Component.hpp
- * @brief Built-in ECS components for ESEngine
- * @details Provides common components used in game development including
- * Transform, Velocity, Sprite, and tag components. Components
- * are plain data structures that contain no logic.
+ * @brief Unified header for all built-in ECS components
+ * @details This header aggregates all component types for convenience.
+ * Individual component headers can be included separately for
+ * reduced compile times in larger projects.
+ *
+ * Component files:
+ * - components/Transform.hpp - LocalTransform, WorldTransform, TransformDirty
+ * - components/Hierarchy.hpp - Parent, Children, HierarchyDepth
+ * - components/Sprite.hpp - Sprite
+ * - components/Camera.hpp - Camera, ProjectionType
+ * - components/Velocity.hpp - Velocity
+ * - components/Common.hpp - Name, UUID, Active, Visible, Static, MainEntity
*
* @author ESEngine Team
- * @date 2025
+ * @date 2026
*
- * @copyright Copyright (c) 2025 ESEngine Team
+ * @copyright Copyright (c) 2026 ESEngine Team
* Licensed under the MIT License.
*/
#pragma once
// =============================================================================
-// Includes
+// Component Includes
// =============================================================================
-// Project includes
-#include "../core/Types.hpp"
-#include "../math/Math.hpp"
-
-namespace esengine::ecs {
-
-// =============================================================================
-// Transform Component
-// =============================================================================
-
-/**
- * @brief 3D transform component for position, rotation, and scale
- *
- * @details Stores spatial transformation data for an entity.
- * Rotation is stored as Euler angles in radians (XYZ order).
- *
- * @code
- * Entity e = registry.create();
- * registry.emplace<Transform>(e, glm::vec3(10.0f, 0.0f, 0.0f));
- *
- * auto& transform = registry.get<Transform>(e);
- * transform.rotation.y = glm::radians(45.0f);
- * glm::mat4 model = transform.getMatrix();
- * @endcode
- */
-struct Transform {
- /** @brief World position */
- glm::vec3 position{0.0f, 0.0f, 0.0f};
- /** @brief Rotation as Euler angles in radians (pitch, yaw, roll) */
- glm::vec3 rotation{0.0f, 0.0f, 0.0f};
- /** @brief Scale factors */
- glm::vec3 scale{1.0f, 1.0f, 1.0f};
-
- /** @brief Default constructor (identity transform) */
- Transform() = default;
-
- /**
- * @brief Constructs transform with position only
- * @param pos Initial position
- */
- Transform(const glm::vec3& pos) : position(pos) {}
-
- /**
- * @brief Constructs transform with full parameters
- * @param pos Initial position
- * @param rot Initial rotation (Euler angles in radians)
- * @param scl Initial scale
- */
- Transform(const glm::vec3& pos, const glm::vec3& rot, const glm::vec3& scl)
- : position(pos), rotation(rot), scale(scl) {}
-
- /**
- * @brief Computes the 4x4 model matrix
- * @return Combined translation * rotation * scale matrix
- *
- * @details Rotation order is X (pitch), Y (yaw), Z (roll).
- */
- glm::mat4 getMatrix() const {
- glm::mat4 model = glm::mat4(1.0f);
- model = glm::translate(model, position);
- model = glm::rotate(model, rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
- model = glm::rotate(model, rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
- model = glm::rotate(model, rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
- model = glm::scale(model, scale);
- return model;
- }
-};
-
-// =============================================================================
-// Velocity Component
-// =============================================================================
-
-/**
- * @brief Velocity component for physics simulation
- *
- * @details Stores linear and angular velocity for movement and rotation.
- * Used by physics systems to update Transform components.
- */
-struct Velocity {
- /** @brief Linear velocity (units per second) */
- glm::vec3 linear{0.0f};
- /** @brief Angular velocity (radians per second) */
- glm::vec3 angular{0.0f};
-
- /** @brief Default constructor (zero velocity) */
- Velocity() = default;
-
- /**
- * @brief Constructs with linear velocity only
- * @param lin Linear velocity vector
- */
- Velocity(const glm::vec3& lin) : linear(lin) {}
-
- /**
- * @brief Constructs with both linear and angular velocity
- * @param lin Linear velocity vector
- * @param ang Angular velocity vector
- */
- Velocity(const glm::vec3& lin, const glm::vec3& ang) : linear(lin), angular(ang) {}
-};
-
-// =============================================================================
-// Sprite Component
-// =============================================================================
-
-/**
- * @brief 2D sprite component for rendering
- *
- * @details Contains all data needed to render a 2D sprite including
- * texture reference, color tint, size, UV coordinates, and
- * sorting layer.
- *
- * @code
- * Entity e = registry.create();
- * auto& sprite = registry.emplace<Sprite>(e, textureId);
- * sprite.color = glm::vec4(1.0f, 0.5f, 0.5f, 1.0f); // Red tint
- * sprite.layer = 10; // Render on top
- * @endcode
- */
-struct Sprite {
- /** @brief GPU texture handle (0 for no texture) */
- u32 textureId{0};
- /** @brief Color tint (RGBA, 0-1 range) */
- glm::vec4 color{1.0f, 1.0f, 1.0f, 1.0f};
- /** @brief Sprite size in world units */
- glm::vec2 size{1.0f, 1.0f};
- /** @brief UV coordinate offset for sprite sheets */
- glm::vec2 uvOffset{0.0f, 0.0f};
- /** @brief UV coordinate scale for sprite sheets */
- glm::vec2 uvScale{1.0f, 1.0f};
- /** @brief Sorting layer (higher = rendered on top) */
- i32 layer{0};
-
- /** @brief Default constructor (white, no texture) */
- Sprite() = default;
-
- /**
- * @brief Constructs sprite with texture
- * @param texId GPU texture handle
- */
- Sprite(u32 texId) : textureId(texId) {}
-
- /**
- * @brief Constructs sprite with texture and color tint
- * @param texId GPU texture handle
- * @param col Color tint
- */
- Sprite(u32 texId, const glm::vec4& col) : textureId(texId), color(col) {}
-};
-
-// =============================================================================
-// Tag Components
-// =============================================================================
-
-/**
- * @brief Tag component marking an entity as active
- * @details Empty component used for filtering. Entities without this
- * tag may be skipped by certain systems.
- */
-struct Active {};
-
-/**
- * @brief Tag component marking an entity as visible
- * @details Empty component used for filtering. Rendering systems
- * typically only process entities with this tag.
- */
-struct Visible {};
-
-/**
- * @brief Tag component marking an entity as static (non-moving)
- * @details Empty component used for filtering. Physics and transform
- * systems may skip entities with this tag for optimization.
- */
-struct Static {};
-
-// =============================================================================
-// Name Component
-// =============================================================================
-
-/**
- * @brief Name component for debugging and identification
- *
- * @details Attaches a human-readable name to an entity for debugging,
- * editor display, or lookup purposes.
- *
- * @code
- * Entity player = registry.create();
- * registry.emplace<Name>(player, "Player");
- * @endcode
- */
-struct Name {
- /** @brief The entity's name */
- std::string value;
-
- /** @brief Default constructor (empty name) */
- Name() = default;
-
- /**
- * @brief Constructs with name (copy)
- * @param name The name string
- */
- Name(const std::string& name) : value(name) {}
-
- /**
- * @brief Constructs with name (move)
- * @param name The name string (moved)
- */
- Name(std::string&& name) : value(std::move(name)) {}
-};
-
-} // namespace esengine::ecs
+#include "components/Transform.hpp"
+#include "components/Hierarchy.hpp"
+#include "components/Sprite.hpp"
+#include "components/Camera.hpp"
+#include "components/Velocity.hpp"
+#include "components/Common.hpp"
diff --git a/src/esengine/ecs/TransformSystem.hpp b/src/esengine/ecs/TransformSystem.hpp
new file mode 100644
index 000000000..93fb28ae8
--- /dev/null
+++ b/src/esengine/ecs/TransformSystem.hpp
@@ -0,0 +1,273 @@
+/**
+ * @file TransformSystem.hpp
+ * @brief System for computing hierarchical world transforms
+ * @details Manages the computation of WorldTransform matrices from
+ * LocalTransform components, respecting parent-child hierarchy.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+// Project includes
+#include "System.hpp"
+#include "Registry.hpp"
+#include "components/Transform.hpp"
+#include "components/Hierarchy.hpp"
+#include "../math/Math.hpp"
+
+// Standard library
+#include <algorithm>
+
+namespace esengine::ecs {
+
+// =============================================================================
+// TransformSystem
+// =============================================================================
+
+/**
+ * @brief System that computes world-space transforms from local transforms
+ *
+ * @details This system processes entities with LocalTransform and computes
+ * their WorldTransform matrices. It handles hierarchical transforms
+ * by processing parents before children.
+ *
+ * Features:
+ * - Respects Parent/Children hierarchy
+ * - Uses dirty flags for optimization
+ * - Caches world-space position/rotation/scale for convenience
+ *
+ * @code
+ * SystemGroup systems;
+ * systems.createSystem<TransformSystem>();
+ *
+ * // In game loop:
+ * systems.update(registry, deltaTime);
+ * // WorldTransform is now up-to-date for all entities
+ * @endcode
+ */
+class TransformSystem : public System {
+public:
+ TransformSystem() {
+ setPriority(-100); // Run early, before other systems need transforms
+ }
+
+ void init(Registry& registry) override {
+ (void)registry;
+ }
+
+ void update(Registry& registry, f32 deltaTime) override {
+ (void)deltaTime;
+
+ // Collect all entities that need updating
+ updateDirtyTransforms(registry);
+ }
+
+private:
+ /**
+ * @brief Updates all transforms respecting hierarchy
+ */
+ void updateDirtyTransforms(Registry& registry) {
+ // Strategy: Process all root entities (no Parent), then recurse to children
+ // This ensures parents are always processed before children
+
+ // First, ensure all entities with LocalTransform have WorldTransform
+ registry.each<LocalTransform>([&registry](Entity entity, LocalTransform&) {
+ if (!registry.has<WorldTransform>(entity)) {
+ registry.emplace<WorldTransform>(entity);
+ }
+ });
+
+ // Process root entities (those without Parent component)
+ registry.each<LocalTransform>([&registry, this](Entity entity, LocalTransform& local) {
+ if (!registry.has<Parent>(entity)) {
+ // Root entity - world transform equals local transform
+ updateEntityTransform(registry, entity, local, glm::mat4(1.0f));
+ }
+ });
+ }
+
+ /**
+ * @brief Recursively updates an entity and its children
+ * @param registry The ECS registry
+ * @param entity The entity to update
+ * @param local The entity's local transform
+ * @param parentWorldMatrix The parent's world matrix (identity for roots)
+ */
+ void updateEntityTransform(Registry& registry, Entity entity,
+ const LocalTransform& local,
+ const glm::mat4& parentWorldMatrix) {
+ // Compute local matrix from LocalTransform
+ glm::mat4 localMatrix = math::compose(local.position, local.rotation, local.scale);
+
+ // Compute world matrix
+ glm::mat4 worldMatrix = parentWorldMatrix * localMatrix;
+
+ // Update WorldTransform component
+ auto& world = registry.get<WorldTransform>(entity);
+ world.matrix = worldMatrix;
+
+ // Extract world-space components for convenience
+ math::decompose(worldMatrix, world.position, world.rotation, world.scale);
+
+ // Remove dirty flag if present
+ if (registry.has<TransformDirty>(entity)) {
+ registry.remove<TransformDirty>(entity);
+ }
+
+ // Recursively update children
+ if (registry.has<Children>(entity)) {
+ const auto& children = registry.get<Children>(entity);
+ for (Entity child : children.entities) {
+ if (registry.valid(child) && registry.has<LocalTransform>(child)) {
+ const auto& childLocal = registry.get<LocalTransform>(child);
+ updateEntityTransform(registry, child, childLocal, worldMatrix);
+ }
+ }
+ }
+ }
+};
+
+// =============================================================================
+// Hierarchy Utilities
+// =============================================================================
+
+/**
+ * @brief Sets the parent of an entity, updating both Parent and Children components
+ *
+ * @param registry The ECS registry
+ * @param child The child entity
+ * @param newParent The new parent entity (INVALID_ENTITY to unparent)
+ *
+ * @code
+ * Entity parent = registry.create();
+ * Entity child = registry.create();
+ * setParent(registry, child, parent);
+ * @endcode
+ */
+inline void setParent(Registry& registry, Entity child, Entity newParent) {
+ // Remove from old parent if exists
+ if (registry.has<Parent>(child)) {
+ Entity oldParent = registry.get<Parent>(child).entity;
+ if (registry.valid(oldParent) && registry.has<Children>(oldParent)) {
+ auto& oldChildren = registry.get<Children>(oldParent);
+ auto it = std::find(oldChildren.entities.begin(),
+ oldChildren.entities.end(), child);
+ if (it != oldChildren.entities.end()) {
+ oldChildren.entities.erase(it);
+ }
+ }
+
+ if (newParent == INVALID_ENTITY) {
+ registry.remove<Parent>(child);
+ }
+ }
+
+ // Set new parent
+ if (newParent != INVALID_ENTITY && registry.valid(newParent)) {
+ if (registry.has<Parent>(child)) {
+ registry.get<Parent>(child).entity = newParent;
+ } else {
+ registry.emplace<Parent>(child, newParent);
+ }
+
+ // Add to new parent's children list
+ if (!registry.has<Children>(newParent)) {
+ registry.emplace<Children>(newParent);
+ }
+ registry.get<Children>(newParent).entities.push_back(child);
+
+ // Update hierarchy depth
+ u32 parentDepth = 0;
+ if (registry.has<HierarchyDepth>(newParent)) {
+ parentDepth = registry.get<HierarchyDepth>(newParent).depth;
+ }
+ if (registry.has<HierarchyDepth>(child)) {
+ registry.get<HierarchyDepth>(child).depth = parentDepth + 1;
+ } else {
+ registry.emplace<HierarchyDepth>(child, parentDepth + 1);
+ }
+ }
+
+ // Mark transform as dirty
+ if (!registry.has<TransformDirty>(child)) {
+ registry.emplace<TransformDirty>(child);
+ }
+}
+
+/**
+ * @brief Gets the root ancestor of an entity
+ *
+ * @param registry The ECS registry
+ * @param entity The entity to find root for
+ * @return The root entity (entity itself if no parent)
+ */
+inline Entity getRoot(Registry& registry, Entity entity) {
+ while (registry.has<Parent>(entity)) {
+ Entity parent = registry.get<Parent>(entity).entity;
+ if (!registry.valid(parent)) break;
+ entity = parent;
+ }
+ return entity;
+}
+
+/**
+ * @brief Checks if an entity is a descendant of another
+ *
+ * @param registry The ECS registry
+ * @param entity The potential descendant
+ * @param ancestor The potential ancestor
+ * @return true if entity is a descendant of ancestor
+ */
+inline bool isDescendantOf(Registry& registry, Entity entity, Entity ancestor) {
+ while (registry.has<Parent>(entity)) {
+ Entity parent = registry.get<Parent>(entity).entity;
+ if (parent == ancestor) return true;
+ if (!registry.valid(parent)) break;
+ entity = parent;
+ }
+ return false;
+}
+
+/**
+ * @brief Destroys an entity and all its descendants
+ *
+ * @param registry The ECS registry
+ * @param entity The entity to destroy with its children
+ */
+inline void destroyWithChildren(Registry& registry, Entity entity) {
+ // Recursively destroy children first
+ if (registry.has<Children>(entity)) {
+ auto children = registry.get<Children>(entity).entities; // Copy to avoid iteration issues
+ for (Entity child : children) {
+ if (registry.valid(child)) {
+ destroyWithChildren(registry, child);
+ }
+ }
+ }
+
+ // Remove from parent's children list
+ if (registry.has<Parent>(entity)) {
+ Entity parent = registry.get<Parent>(entity).entity;
+ if (registry.valid(parent) && registry.has<Children>(parent)) {
+ auto& parentChildren = registry.get<Children>(parent);
+ auto it = std::find(parentChildren.entities.begin(),
+ parentChildren.entities.end(), entity);
+ if (it != parentChildren.entities.end()) {
+ parentChildren.entities.erase(it);
+ }
+ }
+ }
+
+ // Destroy the entity
+ registry.destroy(entity);
+}
+
+} // namespace esengine::ecs
diff --git a/src/esengine/ecs/components/Camera.hpp b/src/esengine/ecs/components/Camera.hpp
new file mode 100644
index 000000000..9a18ffb32
--- /dev/null
+++ b/src/esengine/ecs/components/Camera.hpp
@@ -0,0 +1,81 @@
+/**
+ * @file Camera.hpp
+ * @brief Camera component for rendering viewpoints
+ * @details Provides Camera component supporting perspective and orthographic projections.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+#include "../../core/Types.hpp"
+
+namespace esengine::ecs {
+
+// =============================================================================
+// Projection Type
+// =============================================================================
+
+/**
+ * @brief Camera projection type
+ */
+enum class ProjectionType : u8 {
+ Perspective, ///< 3D perspective projection
+ Orthographic ///< 2D orthographic projection
+};
+
+// =============================================================================
+// Camera Component
+// =============================================================================
+
+/**
+ * @brief Camera component for rendering viewpoints
+ *
+ * @details Defines a camera that can be used to render the scene.
+ * Supports both perspective and orthographic projections.
+ *
+ * @code
+ * Entity camera = registry.create();
+ * registry.emplace<LocalTransform>(camera, glm::vec3(0, 0, 10));
+ * auto& cam = registry.emplace<Camera>(camera);
+ * cam.projectionType = ProjectionType::Perspective;
+ * cam.fov = 60.0f;
+ * cam.isActive = true;
+ * @endcode
+ */
+struct Camera {
+ /** @brief Projection type */
+ ProjectionType projectionType{ProjectionType::Perspective};
+
+ /** @brief Field of view in degrees (perspective only) */
+ f32 fov{60.0f};
+
+ /** @brief Orthographic size (half-height in world units) */
+ f32 orthoSize{5.0f};
+
+ /** @brief Near clipping plane distance */
+ f32 nearPlane{0.1f};
+
+ /** @brief Far clipping plane distance */
+ f32 farPlane{1000.0f};
+
+ /** @brief Aspect ratio (width / height), 0 = auto from viewport */
+ f32 aspectRatio{0.0f};
+
+ /** @brief Whether this is the active camera */
+ bool isActive{false};
+
+ /** @brief Priority for determining active camera (higher = preferred) */
+ i32 priority{0};
+
+ Camera() = default;
+};
+
+} // namespace esengine::ecs
diff --git a/src/esengine/ecs/components/Common.hpp b/src/esengine/ecs/components/Common.hpp
new file mode 100644
index 000000000..1e338c349
--- /dev/null
+++ b/src/esengine/ecs/components/Common.hpp
@@ -0,0 +1,136 @@
+/**
+ * @file Common.hpp
+ * @brief Common tag and identifier components
+ * @details Provides Name, UUID, and various tag components for entity metadata.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+#include "../../core/Types.hpp"
+
+#include <string>
+
+namespace esengine::ecs {
+
+// =============================================================================
+// Tag Components
+// =============================================================================
+
+/**
+ * @brief Tag component marking an entity as active
+ *
+ * @details Empty component used for filtering. Entities without this
+ * tag may be skipped by certain systems.
+ */
+struct Active {};
+
+/**
+ * @brief Tag component marking an entity as visible
+ *
+ * @details Empty component used for filtering. Rendering systems
+ * typically only process entities with this tag.
+ */
+struct Visible {};
+
+/**
+ * @brief Tag component marking an entity as static (non-moving)
+ *
+ * @details Empty component used for optimization. Physics and transform
+ * systems may skip entities with this tag.
+ */
+struct Static {};
+
+/**
+ * @brief Tag component marking an entity as the main/primary entity
+ *
+ * @details Used for singleton-like entities (main camera, player, etc.)
+ */
+struct MainEntity {};
+
+// =============================================================================
+// Name Component
+// =============================================================================
+
+/**
+ * @brief Name component for debugging and identification
+ *
+ * @details Attaches a human-readable name to an entity for debugging,
+ * editor display, or lookup purposes.
+ *
+ * @code
+ * Entity player = registry.create();
+ * registry.emplace<Name>(player, "Player");
+ * @endcode
+ */
+struct Name {
+ /** @brief The entity's name */
+ std::string value;
+
+ /** @brief Default constructor (empty name) */
+ Name() = default;
+
+ /**
+ * @brief Constructs with name (copy)
+ * @param name The name string
+ */
+ explicit Name(const std::string& name) : value(name) {}
+
+ /**
+ * @brief Constructs with name (move)
+ * @param name The name string (moved)
+ */
+ explicit Name(std::string&& name) : value(std::move(name)) {}
+
+ /**
+ * @brief Constructs with C-string
+ * @param name The name string
+ */
+ explicit Name(const char* name) : value(name) {}
+};
+
+// =============================================================================
+// UUID Component
+// =============================================================================
+
+/**
+ * @brief Universally Unique Identifier component
+ *
+ * @details Provides a stable identifier for entities that persists across
+ * save/load cycles. Useful for serialization and cross-references.
+ */
+struct UUID {
+ /** @brief The unique identifier */
+ u64 value{0};
+
+ UUID() = default;
+ explicit UUID(u64 id) : value(id) {}
+
+ bool operator==(const UUID& other) const { return value == other.value; }
+ bool operator!=(const UUID& other) const { return value != other.value; }
+};
+
+} // namespace esengine::ecs
+
+// =============================================================================
+// Std Hash Support for UUID
+// =============================================================================
+
+namespace std {
+
+template<>
+struct hash<esengine::ecs::UUID> {
+ size_t operator()(const esengine::ecs::UUID& uuid) const noexcept {
+ return hash<esengine::u64>{}(uuid.value);
+ }
+};
+
+} // namespace std
diff --git a/src/esengine/ecs/components/Hierarchy.hpp b/src/esengine/ecs/components/Hierarchy.hpp
new file mode 100644
index 000000000..b97129cc4
--- /dev/null
+++ b/src/esengine/ecs/components/Hierarchy.hpp
@@ -0,0 +1,97 @@
+/**
+ * @file Hierarchy.hpp
+ * @brief Hierarchy components for parent-child relationships
+ * @details Provides Parent and Children components for building scene graphs.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+#include "../../core/Types.hpp"
+
+#include <vector>
+
+namespace esengine::ecs {
+
+// =============================================================================
+// Parent Component
+// =============================================================================
+
+/**
+ * @brief Parent reference component
+ *
+ * @details Links an entity to its parent in the scene hierarchy.
+ * Used together with Children component to form a tree structure.
+ *
+ * @code
+ * Entity parent = registry.create();
+ * Entity child = registry.create();
+ *
+ * registry.emplace<Parent>(child, parent);
+ * registry.get<Children>(parent).entities.push_back(child);
+ * @endcode
+ */
+struct Parent {
+ /** @brief Parent entity ID */
+ Entity entity = INVALID_ENTITY;
+
+ Parent() = default;
+ explicit Parent(Entity e) : entity(e) {}
+};
+
+// =============================================================================
+// Children Component
+// =============================================================================
+
+/**
+ * @brief Children list component
+ *
+ * @details Stores references to all child entities. Maintained in sync
+ * with Parent components by the hierarchy management system.
+ */
+struct Children {
+ /** @brief List of child entity IDs */
+ std::vector<Entity> entities;
+
+ Children() = default;
+
+ /**
+ * @brief Check if entity has any children
+ * @return true if has children
+ */
+ [[nodiscard]] bool empty() const { return entities.empty(); }
+
+ /**
+ * @brief Get number of children
+ * @return Child count
+ */
+ [[nodiscard]] usize count() const { return entities.size(); }
+};
+
+// =============================================================================
+// Hierarchy Depth Component
+// =============================================================================
+
+/**
+ * @brief Cached hierarchy depth for sorting
+ *
+ * @details Used by TransformSystem to process transforms in correct order
+ * (parents before children). Updated when hierarchy changes.
+ */
+struct HierarchyDepth {
+ /** @brief Depth level (0 = root, 1 = first level child, etc.) */
+ u32 depth = 0;
+
+ HierarchyDepth() = default;
+ explicit HierarchyDepth(u32 d) : depth(d) {}
+};
+
+} // namespace esengine::ecs
diff --git a/src/esengine/ecs/components/Sprite.hpp b/src/esengine/ecs/components/Sprite.hpp
new file mode 100644
index 000000000..909968f57
--- /dev/null
+++ b/src/esengine/ecs/components/Sprite.hpp
@@ -0,0 +1,86 @@
+/**
+ * @file Sprite.hpp
+ * @brief 2D sprite rendering component
+ * @details Provides Sprite component for 2D rendering with texture handles.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+#include "../../core/Types.hpp"
+#include "../../math/Math.hpp"
+#include "../../resource/Handle.hpp"
+
+namespace esengine::ecs {
+
+// =============================================================================
+// Sprite Component
+// =============================================================================
+
+/**
+ * @brief 2D sprite component for rendering
+ *
+ * @details Contains all data needed to render a 2D sprite including
+ * texture handle, color tint, size, UV coordinates, and
+ * sorting layer.
+ *
+ * @code
+ * Entity e = registry.create();
+ * auto& sprite = registry.emplace<Sprite>(e);
+ * sprite.texture = resourceManager.loadTexture("player.png");
+ * sprite.color = glm::vec4(1.0f, 0.5f, 0.5f, 1.0f); // Red tint
+ * sprite.layer = 10; // Render on top
+ * @endcode
+ */
+struct Sprite {
+ /** @brief Texture resource handle (type-safe) */
+ resource::TextureHandle texture;
+
+ /** @brief Color tint (RGBA, 0-1 range) */
+ glm::vec4 color{1.0f, 1.0f, 1.0f, 1.0f};
+
+ /** @brief Sprite size in world units */
+ glm::vec2 size{1.0f, 1.0f};
+
+ /** @brief UV coordinate offset for sprite sheets */
+ glm::vec2 uvOffset{0.0f, 0.0f};
+
+ /** @brief UV coordinate scale for sprite sheets */
+ glm::vec2 uvScale{1.0f, 1.0f};
+
+ /** @brief Sorting layer (higher = rendered on top) */
+ i32 layer{0};
+
+ /** @brief Flip sprite horizontally */
+ bool flipX{false};
+
+ /** @brief Flip sprite vertically */
+ bool flipY{false};
+
+ /** @brief Default constructor (white, no texture) */
+ Sprite() = default;
+
+ /**
+ * @brief Constructs sprite with texture handle
+ * @param tex Texture resource handle
+ */
+ explicit Sprite(resource::TextureHandle tex) : texture(tex) {}
+
+ /**
+ * @brief Constructs sprite with texture and color tint
+ * @param tex Texture resource handle
+ * @param col Color tint
+ */
+ Sprite(resource::TextureHandle tex, const glm::vec4& col)
+ : texture(tex), color(col) {}
+};
+
+} // namespace esengine::ecs
diff --git a/src/esengine/ecs/components/Transform.hpp b/src/esengine/ecs/components/Transform.hpp
new file mode 100644
index 000000000..47b1784c6
--- /dev/null
+++ b/src/esengine/ecs/components/Transform.hpp
@@ -0,0 +1,149 @@
+/**
+ * @file Transform.hpp
+ * @brief Transform components for spatial positioning
+ * @details Provides LocalTransform for relative positioning and WorldTransform
+ * for cached world-space matrices. Uses quaternions for rotation.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+#include "../../core/Types.hpp"
+#include "../../math/Math.hpp"
+
+namespace esengine::ecs {
+
+// =============================================================================
+// Local Transform Component
+// =============================================================================
+
+/**
+ * @brief Local transform relative to parent (or world if no parent)
+ *
+ * @details Stores spatial transformation data using quaternion for rotation
+ * to avoid gimbal lock. This component represents the transform
+ * relative to the entity's parent. If no Parent component exists,
+ * this is equivalent to world space.
+ *
+ * @note Rotation is stored as a quaternion. Use math::eulerToQuat() and
+ * math::quatToEuler() for conversion if needed.
+ *
+ * @code
+ * Entity e = registry.create();
+ * registry.emplace<LocalTransform>(e, glm::vec3(10.0f, 0.0f, 0.0f));
+ *
+ * auto& transform = registry.get<LocalTransform>(e);
+ * transform.rotation = glm::angleAxis(glm::radians(45.0f), glm::vec3(0, 1, 0));
+ * @endcode
+ */
+struct LocalTransform {
+ /** @brief Position relative to parent */
+ glm::vec3 position{0.0f, 0.0f, 0.0f};
+
+ /** @brief Rotation as quaternion (no gimbal lock) */
+ glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f}; // Identity quaternion (w, x, y, z)
+
+ /** @brief Scale factors */
+ glm::vec3 scale{1.0f, 1.0f, 1.0f};
+
+ /** @brief Default constructor (identity transform) */
+ LocalTransform() = default;
+
+ /**
+ * @brief Constructs transform with position only
+ * @param pos Initial position
+ */
+ explicit LocalTransform(const glm::vec3& pos) : position(pos) {}
+
+ /**
+ * @brief Constructs transform with position and rotation
+ * @param pos Initial position
+ * @param rot Initial rotation (quaternion)
+ */
+ LocalTransform(const glm::vec3& pos, const glm::quat& rot)
+ : position(pos), rotation(rot) {}
+
+ /**
+ * @brief Constructs transform with full parameters
+ * @param pos Initial position
+ * @param rot Initial rotation (quaternion)
+ * @param scl Initial scale
+ */
+ LocalTransform(const glm::vec3& pos, const glm::quat& rot, const glm::vec3& scl)
+ : position(pos), rotation(rot), scale(scl) {}
+};
+
+// =============================================================================
+// World Transform Component (Cached)
+// =============================================================================
+
+/**
+ * @brief Cached world-space transform matrix
+ *
+ * @details This component is managed by the TransformSystem. It stores
+ * the final world-space transformation matrix computed from the
+ * hierarchy of LocalTransform components.
+ *
+ * @note Do not modify this component directly - it will be overwritten
+ * by TransformSystem. Modify LocalTransform instead.
+ */
+struct WorldTransform {
+ /** @brief Combined world-space transformation matrix */
+ glm::mat4 matrix{1.0f};
+
+ /** @brief World-space position (extracted from matrix for convenience) */
+ glm::vec3 position{0.0f, 0.0f, 0.0f};
+
+ /** @brief World-space rotation (extracted from matrix) */
+ glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};
+
+ /** @brief World-space scale (extracted from matrix) */
+ glm::vec3 scale{1.0f, 1.0f, 1.0f};
+
+ WorldTransform() = default;
+};
+
+// =============================================================================
+// Transform Dirty Flag
+// =============================================================================
+
+/**
+ * @brief Tag component indicating transform needs recalculation
+ *
+ * @details Added when LocalTransform is modified. TransformSystem will
+ * recalculate WorldTransform for all entities with this tag
+ * and then remove the tag.
+ */
+struct TransformDirty {};
+
+// =============================================================================
+// Legacy Transform (Deprecated)
+// =============================================================================
+
+/**
+ * @brief Legacy transform component (deprecated)
+ *
+ * @deprecated Use LocalTransform and WorldTransform instead.
+ * This component is kept for backward compatibility and
+ * will be removed in a future version.
+ */
+struct [[deprecated("Use LocalTransform instead")]] Transform {
+ glm::vec3 position{0.0f, 0.0f, 0.0f};
+ glm::vec3 rotation{0.0f, 0.0f, 0.0f};
+ glm::vec3 scale{1.0f, 1.0f, 1.0f};
+
+ Transform() = default;
+ explicit Transform(const glm::vec3& pos) : position(pos) {}
+ Transform(const glm::vec3& pos, const glm::vec3& rot, const glm::vec3& scl)
+ : position(pos), rotation(rot), scale(scl) {}
+};
+
+} // namespace esengine::ecs
diff --git a/src/esengine/ecs/components/Velocity.hpp b/src/esengine/ecs/components/Velocity.hpp
new file mode 100644
index 000000000..4fa9f346a
--- /dev/null
+++ b/src/esengine/ecs/components/Velocity.hpp
@@ -0,0 +1,59 @@
+/**
+ * @file Velocity.hpp
+ * @brief Velocity component for physics simulation
+ * @details Provides Velocity component for linear and angular motion.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+#include "../../core/Types.hpp"
+#include "../../math/Math.hpp"
+
+namespace esengine::ecs {
+
+// =============================================================================
+// Velocity Component
+// =============================================================================
+
+/**
+ * @brief Velocity component for physics simulation
+ *
+ * @details Stores linear and angular velocity for movement and rotation.
+ * Used by physics systems to update LocalTransform components.
+ *
+ * @note Angular velocity is in radians per second around each axis.
+ */
+struct Velocity {
+ /** @brief Linear velocity (units per second) */
+ glm::vec3 linear{0.0f};
+
+ /** @brief Angular velocity (radians per second) */
+ glm::vec3 angular{0.0f};
+
+ /** @brief Default constructor (zero velocity) */
+ Velocity() = default;
+
+ /**
+ * @brief Constructs with linear velocity only
+ * @param lin Linear velocity vector
+ */
+ explicit Velocity(const glm::vec3& lin) : linear(lin) {}
+
+ /**
+ * @brief Constructs with both linear and angular velocity
+ * @param lin Linear velocity vector
+ * @param ang Angular velocity vector
+ */
+ Velocity(const glm::vec3& lin, const glm::vec3& ang) : linear(lin), angular(ang) {}
+};
+
+} // namespace esengine::ecs
diff --git a/src/esengine/math/Math.hpp b/src/esengine/math/Math.hpp
index f8a29aee5..5bd2524bc 100644
--- a/src/esengine/math/Math.hpp
+++ b/src/esengine/math/Math.hpp
@@ -2,12 +2,13 @@
* @file Math.hpp
* @brief Math utilities and GLM configuration for ESEngine
* @details Provides GLM configuration, math constants, and utility functions
- * for common game development operations.
+ * for common game development operations including quaternion/euler
+ * conversions and matrix decomposition.
*
* @author ESEngine Team
- * @date 2025
+ * @date 2026
*
- * @copyright Copyright (c) 2025 ESEngine Team
+ * @copyright Copyright (c) 2026 ESEngine Team
* Licensed under the MIT License.
*/
#pragma once
@@ -222,7 +223,7 @@ inline glm::mat4 lookAt(const glm::vec3& eye, const glm::vec3& center, const glm
// =============================================================================
/**
- * @brief Decomposes a transformation matrix into components
+ * @brief Decomposes a transformation matrix into components (Euler angles)
* @param matrix The transformation matrix to decompose
* @param position Output: extracted position
* @param rotation Output: extracted Euler angles (radians)
@@ -256,5 +257,126 @@ inline void decompose(const glm::mat4& matrix, glm::vec3& position, glm::vec3& r
rotation.z = std::atan2(rotMatrix[1][0], rotMatrix[0][0]);
}
+/**
+ * @brief Decomposes a transformation matrix into components (quaternion)
+ * @param matrix The transformation matrix to decompose
+ * @param position Output: extracted position
+ * @param rotation Output: extracted rotation as quaternion
+ * @param scale Output: extracted scale factors
+ *
+ * @code
+ * glm::vec3 pos, scl;
+ * glm::quat rot;
+ * math::decompose(transform, pos, rot, scl);
+ * @endcode
+ */
+inline void decompose(const glm::mat4& matrix, glm::vec3& position, glm::quat& rotation, glm::vec3& scale) {
+ // Extract position
+ position = glm::vec3(matrix[3]);
+
+ // Extract scale
+ scale.x = glm::length(glm::vec3(matrix[0]));
+ scale.y = glm::length(glm::vec3(matrix[1]));
+ scale.z = glm::length(glm::vec3(matrix[2]));
+
+ // Build rotation matrix without scale
+ glm::mat3 rotMatrix(
+ glm::vec3(matrix[0]) / scale.x,
+ glm::vec3(matrix[1]) / scale.y,
+ glm::vec3(matrix[2]) / scale.z
+ );
+
+ // Convert rotation matrix to quaternion
+ rotation = glm::quat_cast(rotMatrix);
+}
+
+// =============================================================================
+// Quaternion Utilities
+// =============================================================================
+
+/**
+ * @brief Converts Euler angles (radians) to quaternion
+ * @param euler Euler angles in radians (pitch, yaw, roll / X, Y, Z)
+ * @return Quaternion representing the rotation
+ *
+ * @code
+ * glm::quat rot = math::eulerToQuat(glm::vec3(0, glm::radians(45.0f), 0));
+ * @endcode
+ */
+inline glm::quat eulerToQuat(const glm::vec3& euler) {
+ return glm::quat(euler);
+}
+
+/**
+ * @brief Converts quaternion to Euler angles (radians)
+ * @param quat The quaternion to convert
+ * @return Euler angles in radians (pitch, yaw, roll / X, Y, Z)
+ *
+ * @code
+ * glm::vec3 euler = math::quatToEuler(rotation);
+ * @endcode
+ */
+inline glm::vec3 quatToEuler(const glm::quat& quat) {
+ return glm::eulerAngles(quat);
+}
+
+/**
+ * @brief Converts Euler angles (degrees) to quaternion
+ * @param degrees Euler angles in degrees (pitch, yaw, roll / X, Y, Z)
+ * @return Quaternion representing the rotation
+ */
+inline glm::quat eulerDegreesToQuat(const glm::vec3& degrees) {
+ return glm::quat(toRadians(degrees));
+}
+
+/**
+ * @brief Converts quaternion to Euler angles (degrees)
+ * @param quat The quaternion to convert
+ * @return Euler angles in degrees (pitch, yaw, roll / X, Y, Z)
+ */
+inline glm::vec3 quatToEulerDegrees(const glm::quat& quat) {
+ return toDegrees(glm::eulerAngles(quat));
+}
+
+// =============================================================================
+// Transform Matrix Construction
+// =============================================================================
+
+/**
+ * @brief Constructs a transformation matrix from TRS components
+ * @param position Translation
+ * @param rotation Rotation as quaternion
+ * @param scale Scale factors
+ * @return The combined transformation matrix (T * R * S)
+ *
+ * @code
+ * glm::mat4 model = math::compose(position, rotation, scale);
+ * @endcode
+ */
+inline glm::mat4 compose(const glm::vec3& position, const glm::quat& rotation, const glm::vec3& scale) {
+ glm::mat4 result = glm::mat4(1.0f);
+ result = glm::translate(result, position);
+ result *= glm::mat4_cast(rotation);
+ result = glm::scale(result, scale);
+ return result;
+}
+
+/**
+ * @brief Constructs a transformation matrix from TRS components (Euler angles)
+ * @param position Translation
+ * @param rotation Rotation as Euler angles (radians)
+ * @param scale Scale factors
+ * @return The combined transformation matrix (T * R * S)
+ */
+inline glm::mat4 compose(const glm::vec3& position, const glm::vec3& rotation, const glm::vec3& scale) {
+ glm::mat4 result = glm::mat4(1.0f);
+ result = glm::translate(result, position);
+ result = glm::rotate(result, rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
+ result = glm::rotate(result, rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
+ result = glm::rotate(result, rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
+ result = glm::scale(result, scale);
+ return result;
+}
+
} // namespace math
} // namespace esengine
diff --git a/tests/ecs/test_registry.cpp b/tests/ecs/test_registry.cpp
index dbc2155b2..7e3b15010 100644
--- a/tests/ecs/test_registry.cpp
+++ b/tests/ecs/test_registry.cpp
@@ -2,6 +2,7 @@
// Simple test framework without external dependencies
#include <esengine/ESEngine.hpp>
+#include <esengine/ecs/TransformSystem.hpp>
#include <iostream>
#include <cassert>
@@ -313,6 +314,161 @@ TEST(sparse_set_remove) {
ASSERT_EQ(set.size(), 2u);
}
+// =============================================================================
+// Modern Component Tests
+// =============================================================================
+
+TEST(local_transform_default) {
+ esengine::ecs::Registry registry;
+ esengine::Entity entity = registry.create();
+
+ auto& local = registry.emplace<esengine::ecs::LocalTransform>(entity);
+
+ ASSERT_EQ(local.position.x, 0.0f);
+ ASSERT_EQ(local.position.y, 0.0f);
+ ASSERT_EQ(local.position.z, 0.0f);
+ ASSERT_EQ(local.rotation.w, 1.0f); // Identity quaternion
+ ASSERT_EQ(local.scale.x, 1.0f);
+}
+
+TEST(local_transform_with_position) {
+ esengine::ecs::Registry registry;
+ esengine::Entity entity = registry.create();
+
+ auto& local = registry.emplace<esengine::ecs::LocalTransform>(
+ entity, glm::vec3(10.0f, 20.0f, 30.0f));
+
+ ASSERT_EQ(local.position.x, 10.0f);
+ ASSERT_EQ(local.position.y, 20.0f);
+ ASSERT_EQ(local.position.z, 30.0f);
+}
+
+TEST(local_transform_with_rotation) {
+ esengine::ecs::Registry registry;
+ esengine::Entity entity = registry.create();
+
+ glm::quat rotation = glm::angleAxis(glm::radians(90.0f), glm::vec3(0, 1, 0));
+ auto& local = registry.emplace<esengine::ecs::LocalTransform>(
+ entity, glm::vec3(0.0f), rotation);
+
+ ASSERT_TRUE(esengine::math::approxEqual(local.rotation.y, rotation.y, 0.001f));
+}
+
+TEST(hierarchy_parent_child) {
+ esengine::ecs::Registry registry;
+
+ esengine::Entity parent = registry.create();
+ esengine::Entity child = registry.create();
+
+ registry.emplace<esengine::ecs::LocalTransform>(parent, glm::vec3(10.0f, 0.0f, 0.0f));
+ registry.emplace<esengine::ecs::LocalTransform>(child, glm::vec3(5.0f, 0.0f, 0.0f));
+
+ esengine::ecs::setParent(registry, child, parent);
+
+ ASSERT_TRUE(registry.has<esengine::ecs::Parent>(child));
+ ASSERT_TRUE(registry.has<esengine::ecs::Children>(parent));
+
+ ASSERT_EQ(registry.get<esengine::ecs::Parent>(child).entity, parent);
+ ASSERT_EQ(registry.get<esengine::ecs::Children>(parent).entities.size(), 1u);
+ ASSERT_EQ(registry.get<esengine::ecs::Children>(parent).entities[0], child);
+}
+
+TEST(hierarchy_depth) {
+ esengine::ecs::Registry registry;
+
+ esengine::Entity grandparent = registry.create();
+ esengine::Entity parent = registry.create();
+ esengine::Entity child = registry.create();
+
+ registry.emplace<esengine::ecs::LocalTransform>(grandparent);
+ registry.emplace<esengine::ecs::LocalTransform>(parent);
+ registry.emplace<esengine::ecs::LocalTransform>(child);
+
+ esengine::ecs::setParent(registry, parent, grandparent);
+ esengine::ecs::setParent(registry, child, parent);
+
+ ASSERT_EQ(registry.get<esengine::ecs::HierarchyDepth>(parent).depth, 1u);
+ ASSERT_EQ(registry.get<esengine::ecs::HierarchyDepth>(child).depth, 2u);
+}
+
+TEST(hierarchy_get_root) {
+ esengine::ecs::Registry registry;
+
+ esengine::Entity root = registry.create();
+ esengine::Entity middle = registry.create();
+ esengine::Entity leaf = registry.create();
+
+ registry.emplace<esengine::ecs::LocalTransform>(root);
+ registry.emplace<esengine::ecs::LocalTransform>(middle);
+ registry.emplace<esengine::ecs::LocalTransform>(leaf);
+
+ esengine::ecs::setParent(registry, middle, root);
+ esengine::ecs::setParent(registry, leaf, middle);
+
+ ASSERT_EQ(esengine::ecs::getRoot(registry, leaf), root);
+ ASSERT_EQ(esengine::ecs::getRoot(registry, middle), root);
+ ASSERT_EQ(esengine::ecs::getRoot(registry, root), root);
+}
+
+TEST(hierarchy_is_descendant) {
+ esengine::ecs::Registry registry;
+
+ esengine::Entity root = registry.create();
+ esengine::Entity child = registry.create();
+ esengine::Entity grandchild = registry.create();
+ esengine::Entity unrelated = registry.create();
+
+ registry.emplace<esengine::ecs::LocalTransform>(root);
+ registry.emplace<esengine::ecs::LocalTransform>(child);
+ registry.emplace<esengine::ecs::LocalTransform>(grandchild);
+ registry.emplace<esengine::ecs::LocalTransform>(unrelated);
+
+ esengine::ecs::setParent(registry, child, root);
+ esengine::ecs::setParent(registry, grandchild, child);
+
+ ASSERT_TRUE(esengine::ecs::isDescendantOf(registry, child, root));
+ ASSERT_TRUE(esengine::ecs::isDescendantOf(registry, grandchild, root));
+ ASSERT_TRUE(esengine::ecs::isDescendantOf(registry, grandchild, child));
+ ASSERT_TRUE(!esengine::ecs::isDescendantOf(registry, root, child));
+ ASSERT_TRUE(!esengine::ecs::isDescendantOf(registry, unrelated, root));
+}
+
+TEST(sprite_with_texture_handle) {
+ esengine::ecs::Registry registry;
+ esengine::Entity entity = registry.create();
+
+ esengine::resource::TextureHandle texHandle(42);
+ auto& sprite = registry.emplace<esengine::ecs::Sprite>(entity, texHandle);
+
+ ASSERT_TRUE(sprite.texture.isValid());
+ ASSERT_EQ(sprite.texture.id(), 42u);
+ ASSERT_EQ(sprite.color.r, 1.0f);
+}
+
+TEST(camera_default) {
+ esengine::ecs::Registry registry;
+ esengine::Entity entity = registry.create();
+
+ auto& camera = registry.emplace<esengine::ecs::Camera>(entity);
+
+ ASSERT_EQ(camera.projectionType, esengine::ecs::ProjectionType::Perspective);
+ ASSERT_EQ(camera.fov, 60.0f);
+ ASSERT_EQ(camera.nearPlane, 0.1f);
+ ASSERT_TRUE(!camera.isActive);
+}
+
+TEST(uuid_component) {
+ esengine::ecs::Registry registry;
+ esengine::Entity entity = registry.create();
+
+ auto& uuid = registry.emplace<esengine::ecs::UUID>(entity, 0x12345678ABCDEF00ULL);
+
+ ASSERT_EQ(uuid.value, 0x12345678ABCDEF00ULL);
+
+ esengine::ecs::UUID other(0x12345678ABCDEF00ULL);
+ ASSERT_TRUE(uuid == other);
+}
+
int main() {
std::cout << "ESEngine ECS Unit Tests" << std::endl;
std::cout << "========================" << std::endl;
@@ -333,6 +489,18 @@ int main() {
RUN_TEST(sparse_set_basic);
RUN_TEST(sparse_set_remove);
+ // Modern component tests
+ RUN_TEST(local_transform_default);
+ RUN_TEST(local_transform_with_position);
+ RUN_TEST(local_transform_with_rotation);
+ RUN_TEST(hierarchy_parent_child);
+ RUN_TEST(hierarchy_depth);
+ RUN_TEST(hierarchy_get_root);
+ RUN_TEST(hierarchy_is_descendant);
+ RUN_TEST(sprite_with_texture_handle);
+ RUN_TEST(camera_default);
+ RUN_TEST(uuid_component);
+
std::cout << "========================" << std::endl;
std::cout << "Results: " << passed << " passed, " << failed << " failed" << std::endl;