/* * Copyright (C) 2022,2024 Riyyi * * SPDX-License-Identifier: MIT */ #pragma once #include // size_t #include // uint32_t #include // std::shared_ptr #include // std::pair #include "entt/entity/registry.hpp" // entt::entity, entt::registry #include "glm/ext/matrix_float4x4.hpp" // glm::mat4 #include "ruc/format/format.h" #include "ruc/json/json.h" #include "inferno/uid.h" namespace Inferno { class Camera; class Texture; class Scene { public: void initialize(); void update(float deltaTime); void render(); void destroy(); uint32_t createEntity(const std::string& name = ""); uint32_t createEntityWithUID(UID id, const std::string& name = ""); uint32_t loadEntity(ruc::Json components, uint32_t parentEntity = entt::null); uint32_t findEntity(std::string_view name); void destroyEntity(uint32_t entity); /** * @brief Return a pair from the camera component: { projection, view } */ std::pair cameraProjectionView(); void validEntity(uint32_t entity) const; template [[nodiscard]] bool hasComponent(uint32_t entity) const { validEntity(entity); return m_registry->has(entt::entity { entity }); } template [[nodiscard]] bool anyComponent(uint32_t entity) const { validEntity(entity); return m_registry->any(entt::entity { entity }); } // TODO: Should replace be allowed? could trigger memory leaks with nativescript // TODO: Replace will make it so an entity cant have multiple scripts template T& addComponent(uint32_t entity, P&&... parameters) const { validEntity(entity); return m_registry->emplace_or_replace(entt::entity { entity }, std::forward

(parameters)...); } template size_t removeComponent(uint32_t entity) const { validEntity(entity); return m_registry->remove_if_exists(entt::entity { entity }); } // TODO: Should replace be allowed? could trigger memory leaks with nativescript template T& getComponent(uint32_t entity, P&&... parameters) const { validEntity(entity); return m_registry->get_or_emplace(entt::entity { entity }, std::forward

(parameters)...); } // const entt::registry& registry() const { return m_registry; } std::shared_ptr registry() const { return m_registry; } private: std::shared_ptr m_texture; std::shared_ptr m_texture2; std::shared_ptr m_registry; }; } // namespace Inferno template<> struct ruc::format::Formatter : Formatter { void format(Builder& builder, entt::entity value) const; }; // @Todo // - Convert registry to stack variable // - Convert registry to scene pointer in systems