49 LScene(
const std::string& SceneName,
const bool IsEditorScene =
false);
54 void OnUpdateRuntime(
const float InDeltaTime);
56 void OnUpdateEditor(
const float InDeltaTime);
63 template<
typename T = LEntity>
64 std::vector<T> GetEntities();
66 uint64_t GetEntityCount()
const {
return static_cast<uint64_t
>(EntityMap.size()); }
69 LEntity FindEntity(std::string_view EntityName);
72 FORCEINLINE entt::registry& GetRegistry() {
return Registry; }
73 void DestroyEntity(
const LEntity Entity);
74 bool HasEntity(
const LEntity Entity)
const;
75 bool IsEntityInRegistry(
const LEntity Entity)
const;
77 LEntity CreateEntity(
const std::string& InName =
"");
78 LEntity CreateEntityWithID(
const LUUID UUID,
const std::string& InName =
"");
79 LEntity CreateChildEntity(LEntity Parent,
const std::string& InName =
"");
82 void ParentEntity(LEntity Entity, LEntity Parent);
83 void UnparentEntity(LEntity Entity,
bool bConvertToWorldSpace =
true);
85 glm::mat4 GetWorldSpaceTransform(LEntity Entity);
87 std::string GetName()
const {
return Name; }
88 void SetName(
const std::string& InName) { Name = InName; }
90 void SetActive(
const bool Active);
91 FORCEINLINE
bool IsActive()
const {
return (
this == ActiveScene.Get()); }
94 void Pause(
const bool IsPaused);
96 void CopyTo(TObjectPtr<LScene>& TargetScene);
99 void OnComponentAdded(LEntity Entity, T& TComponent);
102 static void CopyComponent(entt::registry& DestinationRegistry,
103 entt::registry& SourceRegistry,
104 const std::unordered_map<LUUID, entt::entity>& enttMap)
106 auto SourceEntities = SourceRegistry.view<T>();
107 for (
auto SourceEntity : SourceEntities)
109 entt::entity DestEntity = enttMap.at(SourceRegistry.get<LIDComponent>(SourceEntity).ID);
110 auto& SourceComp = SourceRegistry.get<T>(SourceEntity);
111 auto& DestComp = DestinationRegistry.emplace_or_replace<T>(DestEntity, SourceComp);
115 template<
typename TComponent>
116 void CopyComponentIfExists(entt::entity Destination, entt::registry& DestinationRegistry, entt::entity Source)
118 if (Registry.all_of<TComponent>(Source))
120 auto& SourceComp = Registry.get<TComponent>(Source);
121 DestinationRegistry.emplace_or_replace<TComponent>(Destination, SourceComp);
126 #if defined(LK_ENGINE_MSVC)
127 template<
typename TComponent>
128 static void CopyComponentFromScene(LEntity Destination,
129 TObjectPtr<LScene> DestinationScene,
131 TObjectPtr<LScene> SourceScene)
133 SourceScene->CopyComponentIfExists<TComponent>((entt::entity)Destination, DestinationScene->Registry, (entt::entity)Source);
137 template<
typename ...Components>
140 return Registry.view<Components...>();
143 std::unordered_set<LUUID> GetAssetList();
146 static uint8_t GetSceneCount() {
return SceneCounter; }
149 static constexpr const char* FILE_EXTENSION =
"lkscene";
151 inline static TObjectPtr<LScene> ActiveScene =
nullptr;
152 inline static uint8_t SceneCounter = 0;
155 std::string Name =
"";
156 entt::entity SceneEntity;
158 bool bPaused =
false;
159 bool bEditorScene =
false;
161 entt::registry Registry{};
163 std::unordered_map<LUUID, entt::entity> EntityMap{};
165 uint16_t ViewportWidth = 0;
166 uint16_t ViewportHeight = 0;
169 TObjectPtr<LSceneRenderer> Renderer;
171 friend class LEntity;
172 friend class LEditorLayer;
173 friend class LSceneSerializer;
174 friend class LSceneManagerPanel;