Hymn to Beauty
C++ 3D Engine
World.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <map>
5#include <typeinfo>
6#include <string>
7
8class Entity;
9namespace Json {
10class Value;
11}
12
14class World {
15 friend class Entity;
16
17 public:
19 World();
20
22 ~World();
23
25
29 Entity* CreateEntity(const std::string& name = "");
30
32
35 const std::vector<Entity*>& GetEntities() const;
36
38 void CreateRoot();
39
41
44 Entity* GetRoot() const;
45
47
50 void RegisterUpdate(Entity* entity);
51
53
56 const std::vector<Entity*>& GetUpdateEntities() const;
57
59 void Clear();
60
62 void ClearKilled();
63
65
68 void Save(const std::string& filename) const;
69
71
74 Json::Value GetSaveJson() const;
75
77
80 void Load(const std::string& filename);
81
83
86 void Load(Json::Value& node);
87
88 private:
89 // Copy constructor.
90 World(World& world) = delete;
91
92 // List of all entities in this world.
93 std::vector<Entity*> entities;
94 Entity* root = nullptr;
95
96 // Entities registered for update event.
97 std::vector<Entity*> updateEntities;
98};
Entity containing various components.
Definition: Entity.hpp:16
std::string name
Name of the entity.
Definition: Entity.hpp:273
The game world containing all entities.
Definition: World.hpp:14
void RegisterUpdate(Entity *entity)
Register an entity to receive update events.
Definition: World.cpp:37
void ClearKilled()
Removes all killed entities and components in the world.
Definition: World.cpp:62
void CreateRoot()
Create root entity.
Definition: World.cpp:29
Entity * GetRoot() const
Get the root entity.
Definition: World.cpp:33
const std::vector< Entity * > & GetUpdateEntities() const
Get all entities that are registered to receive update events.
Definition: World.cpp:41
const std::vector< Entity * > & GetEntities() const
Get all the entities in the world.
Definition: World.cpp:25
void Load(const std::string &filename)
Load the world from file.
Definition: World.cpp:94
void Clear()
Clear the world of all entities.
Definition: World.cpp:45
~World()
Destructor.
Definition: World.cpp:14
Entity * CreateEntity(const std::string &name="")
Create a new entity in the world.
Definition: World.cpp:18
void Save(const std::string &filename) const
Save the world to file.
Definition: World.cpp:79
Json::Value GetSaveJson() const
Get a json file representing the root.
Definition: World.cpp:88
World()
Create a new world.
Definition: World.cpp:12
Definition: Json.cpp:3