26 template<
typename... T>
30 nameComp.m_Name = name;
34 m_UUIDToEntity.insert({ uuidComp.m_UUID, entity });
48 template<
typename... T>
49 [[nodiscard]] std::expected<Entity, Core::CoriError<>>
FindEntity(
const std::string& name) {
52 for (
auto entity : view) {
53 if (name == view.template get<Components::Entity::Name>(entity).m_Name) {
57 return std::unexpected(
Core::CoriError(
"No entity found with the specified name."));
60 template<
typename... T>
66 template<
typename... T,
typename... ExcludeT>
68 auto view =
m_Registry.view<T...>(entt::exclude<ExcludeT...>);
82 template<
typename T,
typename... Args>
84 return m_Registry.ctx().emplace<T>(std::forward<Args>(args)...);
113 template <
typename T,
typename... Args>
requires IsSystem<T>
115 if (m_RegisteredSystems.contains(std::type_index(
typeid(T)))) {
120 std::shared_ptr<T> system = std::make_shared<T>();
121 system->SetOwnerScene(
this);
122 const bool success = system->Create(std::forward<Args>(args)...);
124 auto systemType = std::type_index(
typeid(T));
125 m_SystemPriority.emplace_back(T::Priority, systemType);
127 m_SystemPriority.begin(),
128 m_SystemPriority.end(),
129 [](
const std::pair<SystemPriority, std::type_index>& entry) ->
SystemPriority {
133 m_RegisteredSystems.insert({ systemType, std::move(system) });
143 if (m_RegisteredSystems.contains(std::type_index(
typeid(T)))) {
144 m_RegisteredSystems.erase(std::type_index(
typeid(T)));
151 if (m_RegisteredSystems.contains(std::type_index(
typeid(T)))) {
152 return std::weak_ptr<T>(std::static_pointer_cast<T>(m_RegisteredSystems[std::type_index(
typeid(T))]));
155 return std::unexpected(
Core::CoriError(
"Failed to get system, system is not registered."));
159 return m_ActiveCamera;
163 return m_ActiveCamera;
166 [[nodiscard]] std::string_view
GetName()
const {
182 [[nodiscard]]
bool OnBind();
191 [[nodiscard]]
static std::shared_ptr<Scene>
Create(std::string name);
196 explicit Scene(std::string name);
204 std::unordered_map<std::type_index, std::shared_ptr<System>> m_RegisteredSystems;
205 std::vector<std::pair<SystemPriority, std::type_index>> m_SystemPriority;
207 std::unordered_map<Core::UUID, entt::entity> m_UUIDToEntity;
208 std::unordered_map<Utility::StringHash32, entt::entity> m_EntityCache;
#define CORI_CLEAN_TYPE_NAME(tn)
#define CORI_CORE_DEBUG_TAGGED(...)
#define CORI_CORE_FATAL_TAGGED(...)
#define CORI_CORE_TRACE_TAGGED(...)
#define CORI_CORE_WARN_TAGGED(...)
Custom error class mainly used in std::expected.
A GameTimer is responsible for managing everything that is connected with time, ticks,...
An abstract class that is ment to be used as a template for defining layers.
A class that is used to manipulate Camera of the Scene. Each Scene has one of those.
For InstanceMetrics to work with a type it should derive from this.
A wrapper for an EnTT runtime view that provides an iterator to access Entity instances directly.
Entities are the essential part of WorldSystem.
T & AddComponent(Args &&... args)
Adds a component to the entity.
void RegisterSystem(Args &&... args)
std::expected< void, Core::CoriError<> > AddEntityToCache(const Entity entity, const Utility::StringHash32 key)
T & AddContextComponent(Args &&... args)
static std::shared_ptr< Scene > Create(std::string name)
std::expected< std::weak_ptr< T >, Core::CoriError<> > GetSystem()
friend class SceneManager
std::expected< Entity, Core::CoriError<> > FindEntity(const std::string &name)
auto StaticView(Exclude< ExcludeT... >)
entt::registry m_Registry
void OnTickUpdate(Core::GameTimer &gameTimer)
T & GetContextComponent()
DynamicEntityView DynamicView()
Entity CreateEntity(const std::string &name)
void RemoveEntityFromCache(const Utility::StringHash32 key)
Entity CreateBlankEntity()
std::string_view GetName() const
Graphics::CameraController & GetCameraController()
void RemoveContextComponent()
void DestroyEntity(Entity entity)
void OnUpdate(Core::GameTimer &gameTimer)
const T & GetContextComponent() const
std::expected< Entity, Core::CoriError<> > GetEntityFromCache(const Utility::StringHash32 key)
void OnImGuiRender(Core::GameTimer &gameTimer)
bool HasContextComponent() const
const Graphics::CameraController & GetCameraController() const
uint32_t GetSceneID() const
A wrapper for an EnTT compile-time view that provides an iterator to access Entity instances directly...
Core systems of the engine are here.
entt::hashed_string::hash_type StringHash32
Anything connected to WorldSystem (ECS) is in this namespace.
Every Entity has a hierarchy component by default, it's essential for entity hierarchy system.
Every Entity by default has a name component, it holds a non-unique entity name. Just holds the data,...
Every Entity by default has a UUID component, mostly unused for now.
Helper to exclude certain components from a static view.