Skip to content

feat(ecs): add FieldType, FieldDescriptor, ComponentMeta reflection types #648

Description

@JeanPhilippeKernel

Dependency position

THIS ISSUE ──► ComponentReflectionRegistry (#649)
            └──► Register built-in components (#650)
(no dependencies — start immediately, parallel with #647)

This is the start of Track B. No dependencies. Work it in parallel with #647.


Why

These three data structures are the vocabulary of the reflection system. Every other issue in this track depends on them. They are pure type definitions — no logic, no external dependencies beyond <cstdint>.

Work

Create two new header files:

ZEngine/ZEngine/ECS/Reflection/FieldType.h

#pragma once
#include <cstdint>

namespace ZEngine::ECS {

    enum class FieldType : uint8_t {
        Bool,
        Int8, Int16, Int32, Int64,
        UInt8, UInt16, UInt32, UInt64,
        Float, Double,
        Vec2f, Vec3f, Vec4f,
        Quatf,
        Mat4f,
        EntityID,   // display as "Entity #N (gen M)"
        AssetUUID,  // look up asset name via AssetRegistry
        String,     // fixed char[N] buffer
        Enum,       // dropdown; requires EnumValues array
        Struct,     // nested sub-fields
    };

}

ZEngine/ZEngine/ECS/Reflection/ComponentMeta.h

#pragma once
#include <ZEngine/ECS/Reflection/FieldType.h>
#include <ZEngine/ECS/ComponentTypeID.h>
#include <cstdint>

namespace ZEngine::ECS {

    struct EnumValue {
        const char* Name  = nullptr;
        int64_t     Value = 0;
    };

    struct FieldDescriptor {
        const char*            Name        = nullptr;
        FieldType              Type        = FieldType::Float;
        uint32_t               Offset      = 0;        // offsetof(Component, field)
        uint32_t               Size        = 0;        // sizeof(field)
        float                  Min         = -1e9f;
        float                  Max         =  1e9f;
        uint32_t               StringCap   = 0;        // for FieldType::String
        const EnumValue*       EnumValues  = nullptr;
        uint32_t               EnumCount   = 0;
        const FieldDescriptor* SubFields   = nullptr;  // for FieldType::Struct
        uint32_t               SubCount    = 0;
        bool                   Hidden      = false;
        bool                   ReadOnly    = false;
        const char*            Tooltip     = nullptr;
    };

    struct ComponentMeta {
        ComponentTypeID        TypeID      = 0;
        const char*            TypeName    = nullptr;
        uint32_t               Size        = 0;
        uint32_t               Align       = 0;
        const FieldDescriptor* Fields      = nullptr;
        uint32_t               FieldCount  = 0;
        const char*            Category    = "General";
        const char*            Tooltip     = nullptr;
    };

}

Acceptance criteria

  • Both headers compile cleanly with no external dependencies beyond ComponentTypeID.h
  • No .cpp file needed — these are pure data structures
  • FieldDescriptor::Offset and Size are populated using offsetof() and sizeof() at the registration call sites (not here)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1Critical path — blocks other workenhancementNew feature or request

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions