SpiecsEngine
 
Loading...
Searching...
No Matches
World.cpp
Go to the documentation of this file.
1/**
2* @file World.cpp.
3* @brief The World Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
8#include "World.h"
9#include "World/Entity.h"
10
11namespace Spices {
12
13 Entity World::CreateEntity(const std::string& name)
14 {
16
18 }
19
20 Entity World::CreateEntityWithUUID(UUID uuid, const std::string& name)
21 {
23
24 Entity entity = CreateEmptyEntity(uuid);
25 entity.AddComponent<UUIDComponent>(uuid);
26 entity.AddComponent<TransformComponent>();
27 entity.AddComponent<TagComponent>(name);
28 return entity;
29 }
30
31 void World::DestroyEntity(Entity& entity)
32 {
34
35 std::unique_lock<std::shared_mutex> lock(m_Mutex);
36
37 m_Registry.destroy(entity);
38 m_RootEntityMap.erase(entity.GetUUID());
39 }
40
42 {
44
45 return id == -1 ? Entity() : Entity((entt::entity)id, this);
46 }
47
49 {
51
52 if (m_Marker & flags)
53 {
54 m_Marker ^= flags;
55 }
56 }
57
59 {
61
62 std::unique_lock<std::shared_mutex> lock(m_Mutex);
63
64 m_RootEntityMap.erase(entity.GetUUID());
65 }
66
67 void World::AddToRoot(Entity& entity)
68 {
70
71 std::unique_lock<std::shared_mutex> lock(m_Mutex);
72
73 m_RootEntityMap[entity.GetUUID()] = entity;
74 }
75
76 bool World::IsRootEntity(Entity& entity)
77 {
79
80 std::shared_lock<std::shared_mutex> lock(m_Mutex);
81
82 return m_RootEntityMap.find(entity.GetUUID()) != m_RootEntityMap.end();
83 }
84
86 {
88
89 std::unique_lock<std::shared_mutex> lock(m_Mutex);
90
91 Entity entity(m_Registry.create(), this);
92 m_RootEntityMap[uuid] = entity;
93 return entity;
94 }
95}
#define SPICES_PROFILE_ZONE
Entity Class. This class defines the specific behaves of Entity.
Definition Entity.h:20
TagComponent Class. This class defines the specific behaves of TagComponent.
TransformComponent Class. This class defines the specific behaves of TransformComponent.
UUIDComponent Class. This class defines the specific behaves of UUIDComponent.
UUID()
Constructor Function.
Definition UUID.cpp:18
This class helps to generate a uuid for one resource.
Definition UUID.h:16
uint32_t WorldMarkFlags
Definition World.h:53
Entity CreateEntity(const std::string &name="None")
Create a new empty entity in this world.
Definition World.cpp:13
Entity CreateEmptyEntity(UUID uuid)
Definition World.cpp:85
Entity CreateEntityWithUUID(UUID uuid, const std::string &name="None")
Create a new empty entity with a uuid in this world.
Definition World.cpp:20
Entity QueryEntitybyID(uint32_t id)
Get World Entity by id(entt::entity).
Definition World.cpp:41
void DestroyEntity(Entity &entity)
Destroy a entity from this world.
Definition World.cpp:31
WorldMarkFlags m_Marker
World State this frame.
Definition World.h:272
void RemoveFromRoot(Entity &entity)
Remove a entity from this world root.
Definition World.cpp:58
void AddToRoot(Entity &entity)
Add a entity to this world root.
Definition World.cpp:67
bool IsRootEntity(Entity &entity)
Determine if a entity is in root.
Definition World.cpp:76
void ClearMarkerWithBits(WorldMarkFlags flags)
Clear WorldMarkFlags with flags.
Definition World.cpp:48
World Class. This class defines the basic behaves of World. When we create an new world,...
Definition World.h:41