Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
EntitySystem.cpp
Go to the documentation of this file.
2 #include "Engine/engine.hpp"
3 
4 namespace Engine
5 {
6  size_t entityCount = 0;
7 
9  {
10  system.clear();
11  }
12 
14  {
15  system.clear();
16  entityCount = 0;
17  }
18 
19  eastl::weak_ptr<Entity> EntitySystem::CreateEntity(eastl::string entityName, int teamId)
20  {
21  AddEntity(eastl::shared_ptr<Entity>(new Entity(entityName)));
22  system.back()->InitializeEntity();
23 
24  return system.back();
25  }
26 
27  eastl::weak_ptr<Entity> EntitySystem::GetEntity(uint64_t Id)
28  {
29  for (size_t i = 0; i < entityCount; i++)
30  {
31  if (system[i]->GetID() == Id)
32  return system[i];
33  }
34 
35  return eastl::weak_ptr<Entity>();
36  }
37 
38  void EntitySystem::Update()
39  {
40  for (size_t i = 0; i < entityCount; ++i)
41  {
42  if (system[i]->GetIsActive())
43  system[i]->Update();
44  }
45  }
46 
47  void EntitySystem::AddEntity(eastl::shared_ptr<Entity> entityToAdd)
48  {
49  if (entityToAdd->GetID() == -1)
50  entityToAdd->SetID(entityCount);
51 
52  system.push_back(eastl::move(entityToAdd));
53  entityCount++;
54  }
55 
56  void EntitySystem::RemoveEntity(eastl::shared_ptr<Entity> entityToRemove)
57  {
58  if (system.size() == 0) return;
59 
60  eastl::shared_ptr<Entity>* it = eastl::find(system.begin(), system.end(), entityToRemove);
61  if (it != system.end())
62  {
63  it->reset();
64  system.erase(it);
65  }
66 
67  system.shrink_to_fit();
68  entityCount--;
69  }
70 
71  eastl::vector<eastl::shared_ptr<Entity>> EntitySystem::GetAllEntities() const
72  {
73  return system;
74  }
75 } // namespace Engine
void AddEntity(eastl::shared_ptr< Entity > entityToAdd)
This method allows you to add a precreated entity to the entity system The entity you want to add to ...
eastl::weak_ptr< Entity > GetEntity(uint64_t Id)
Allows you to get the entity you want based on the id number. NOTE: if you know the team id of the en...
This object is able a holder object for components. NOTE: only the EntitySystem is allowed to create ...
Definition: Entity.hpp:13
void RemoveAllEntities()
This method allows you to clear the entire entity system and all the teams.
size_t entityCount
Definition: EntitySystem.cpp:6
void RemoveEntity(eastl::shared_ptr< Entity > entityToRemove)
This method allows you to remove a specific entity from the entity system The entity you want to remo...
eastl::vector< eastl::shared_ptr< Entity > > GetAllEntities() const
This method will allow you to get all entities availible.
eastl::weak_ptr< Entity > CreateEntity(eastl::string entityName="", int teamId=0)
Allows you to create a new Entity. This method will also add the entity to the given team if that tea...
IMGUI_API ImGuiID GetID(const char *str_id)
Definition: imgui.cpp:6353