Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
WorldContextSet.hpp
1#pragma once
2
3#include <map>
4#include <entt/entt.hpp>
5#include <Common/Memory/SmartPointers/UniquePtr.hpp>
6#include <Common/HashedString.hpp>
7
8#include "WorldContext.hpp"
9
10namespace Grindstone {
11 class WorldContextSet {
12 public:
13
14 WorldContextSet(const std::string& name);
15
16 WorldContextSet(const WorldContextSet&) = delete;
17 WorldContextSet& operator=(const WorldContextSet&) = delete;
18
19 WorldContextSet(WorldContextSet&&) noexcept = default;
20 WorldContextSet& operator=(WorldContextSet&&) noexcept = default;
21
22 virtual ~WorldContextSet();
23
24 void Reset();
25
26 [[nodiscard]] entt::registry& GetEntityRegistry() {
27 return registry;
28 }
29
30 [[nodiscard]] Grindstone::WorldContext* GetContext(Grindstone::HashedString hashedString) {
31 auto it = contexts.find(hashedString);
32 if (it == contexts.end()) {
33 return nullptr;
34 }
35
36 return it->second.Get();
37 }
38
39 [[nodiscard]] const entt::registry& GetEntityRegistry() const {
40 return registry;
41 }
42
43 [[nodiscard]] const Grindstone::WorldContext* GetContext(Grindstone::HashedString hashedString) const {
44 auto it = contexts.find(hashedString);
45 if (it == contexts.end()) {
46 return nullptr;
47 }
48
49 return it->second.Get();
50 }
51
53 contexts.emplace(hashedString, std::move(cxt));
54 }
55
56 void Remove(Grindstone::HashedString hashedString) {
57 contexts.erase(hashedString);
58 }
59
60 protected:
61 std::string name;
62 entt::registry registry;
63 std::map<Grindstone::HashedString, Grindstone::UniquePtr<Grindstone::WorldContext>> contexts;
64 };
65}
Definition HashedString.hpp:9
Definition UniquePtr.hpp:7
Definition WorldContext.hpp:7