Class Registry

Synopsis

#include <src/testing.h>

class Registry

Description

Manages an ECS Registry that allows both C++ components and scripting runtime components. Provides access to all non-runtime ECS operations. Refer to RegistryProxy<ScriptingOBJ> for the api providing both runtime and internal operations.

Methods

create
destroy
emplace
emplace_or_replace
expose_internal_component
get
remove
valid
view

Source

Lines 119-176 in src/testing.h.

class Registry {
    template<class T>
    friend class RegistryProxy;

    entt::registry reg;
    std::vector<RegistryBaseProxy*> proxies;
    std::unordered_map<std::string, const entt::id_type> internal;

public:

    template<class C>
    void expose_internal_component(const std::string& name) {
        const auto id = entt::type_hash<C>::value();
        const auto r = internal.try_emplace(name, id);
        assert(r.second); //Non repeated name and single call per exposed type
    }

    entt::entity create() {
        return reg.create();
    }

    bool valid(const entt::entity entt) const {
        return reg.valid(entt);
    }

    // removing an invalid entt is UB. (same as in EnTT)
    void destroy(const entt::entity entt) {
        for (auto proxy : proxies) {
            proxy->destroy_unchecked(entt);
        }
        reg.destroy(entt);
    }

    template<class C, class... Args>
    C& emplace(const entt::entity entt, Args&&... args) {
        return reg.emplace<C>(entt, args...);
    }

    template<class C, class... Args>
    C& emplace_or_replace(const entt::entity entt, Args&&... args) {
        return reg.emplace_or_replace<C>(entt, args...);
    }

    template<class... C>
    void remove(const entt::entity entt) {
        reg.remove<C...>(entt);
    }

    template<class... C, class... F>
    entt::view<entt::exclude_t<F...>, C...> view(const entt::exclude_t<F...> exclude = {}) {
        return reg.view<C...>(exclude);
    }

    template<class C>
    C& get(const entt::entity entt) {
        return reg.get<C>(entt);
    }
};





Add Discussion as Guest

Log in