Vivid
Loading...
Searching...
No Matches
ECS.h
1#pragma once
2
3#include "editor/camera/Camera.h"
4#include "common/types/Types.h"
5#include "common/types/SmartPointers.h"
6#include "core/ecs/Entity.h"
7#include "core/ecs/Component.h"
8
9namespace Vivid
10{
19 namespace ECS
20 {
21 extern Map<int, Ref<Component>> g_Components;
22 extern Map<int, Ref<Entity>> g_Entities;
23 extern int s_EntityID;
24 extern int s_ComponentID;
25
26 bool AddComponent(int componentID, int entityID);
27 bool RemoveComponent(int componentID, int entityID);
28
29 void Draw(Camera* camera);
30 void ImGuiRender();
31
38 Ref<Component> GetComponent(ComponentType ct, int entityID);
39
49 template <typename T>
50 void GetAllComponents(const ComponentType ct, Vector<T*>& components)
51 {
52 components.reserve(g_Components.size());
53 for (auto& component : g_Components)
54 {
55 if (component.second->GetComponentType() == ct)
56 {
57 components.emplace_back(static_cast<T*>(component.second.get()));
58 }
59 }
60 }
61
67 Ref<Entity> CreateEntity(const String& name);
68
75 template <typename T>
76 typename std::enable_if<std::is_base_of<Component, T>::value, Ref<T>>::type CreateComponent()
77 {
78 Ref<T> component = MakeRef<T>();
79 g_Components[component->GetComponentID()] = component;
80 return component;
81 }
82 };
83}
A class that represents the camera.
Definition: Camera.h:25
Contains functions to create and manage entities and components.