Registry

Manage entities and their associated components

class Registry {
    public:
        StorageComponents<Component> &register_component();
        StorageComponents<Component> &get_components();
        StorageComponents<Component> const &get_components() const;
        bool hasComponent(entity_t const &entity);
        Component &getComponent(entity_t const &entity);
        entity_t spawn_entity(std::size_t zIndex = 0, bool state = true);
        void disableEntity(entity_t const &entity);
        void enableEntity(entity_t const &entity);
        bool isEntityEnabled(entity_t const &entity);
        entity_t entity_from_index(std::size_t idx);
        bool isEntityExist(entity_t entity);
        void kill_entity(entity_t const &e);
        typename StorageComponents<Component>::reference_type add_component(entity_t const &to, Component &&component);
        typename StorageComponents<Component>::reference_type emplace_component(entity_t const &to, Params &&...params);
        void modify_component(entity_t const &entity, std::function<void(Component&)> callback);
        void remove_component(entity_t const &from);
        std::multimap<size_t, entity_t> const &get_entity_sprite_order() const;
    private:
        std::multimap<size_t, entity_t> _entity_sprite_order;
        std::unordered_map<std::type_index, std::any> _components_arrays;
        std::map<entity_t, std::pair<bool, size_t>> _entity_to_index;
        entity_t _next_entity_id = 0;
        std::vector<entity_t> _entities;
};

The Registry class is a fundamental component of the ECS (Entity-Component-System) architecture in your program. It serves as the central repository for managing entities and their associated components. You will use this class to create, manipulate, and query entities and their components within your application.

Component Management Methods

  • Registers a component type with the ECS registry, allowing you to attach it to entities later.

  • Returns a reference to the storage container for components of the specified type.

  • Checks if the given entity has the specified component attached.

  • Retrieves the specified component attached to the given entity.

Entity Management Methods

  • Creates and returns a new entity, which can be used to associate components.

  • Retrieves an entity ID from its index.

  • Attaches a component to a specific entity. Create using perfect forwarding for construction for the emplace_component() function.

  • Removes the specified component from an entity.

You will also find a lot of others functions that you may used for handle the entity behavior or things like that, like: void disableEntity(entity_t const &entity); or void enableEntity(entity_t const &entity); for example.

Last updated