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 WorldContextSet() : registry(), contexts() {}
14
15 WorldContextSet(const WorldContextSet&) = delete;
16 WorldContextSet& operator=(const WorldContextSet&) = delete;
17
18 WorldContextSet(WorldContextSet&&) noexcept = default;
19 WorldContextSet& operator=(WorldContextSet&&) noexcept = default;
20
21 virtual ~WorldContextSet();
22
23 [[nodiscard]] entt::registry& Grindstone::WorldContextSet::GetEntityRegistry() {
24 return registry;
25 }
26
27 [[nodiscard]] Grindstone::WorldContext* Grindstone::WorldContextSet::GetContext(Grindstone::HashedString hashedString) {
28 auto it = contexts.find(hashedString);
29 if (it == contexts.end()) {
30 return nullptr;
31 }
32
33 return it->second.Get();
34 }
35
36 [[nodiscard]] const entt::registry& Grindstone::WorldContextSet::GetEntityRegistry() const {
37 return registry;
38 }
39
40 [[nodiscard]] const Grindstone::WorldContext* Grindstone::WorldContextSet::GetContext(Grindstone::HashedString hashedString) const {
41 auto it = contexts.find(hashedString);
42 if (it == contexts.end()) {
43 return nullptr;
44 }
45
46 return it->second.Get();
47 }
48
49 void Grindstone::WorldContextSet::Create(Grindstone::HashedString hashedString, Grindstone::UniquePtr<Grindstone::WorldContext>&& cxt) {
50 contexts.emplace(hashedString, std::move(cxt));
51 }
52
53 void Grindstone::WorldContextSet::Remove(Grindstone::HashedString hashedString) {
54 contexts.erase(hashedString);
55 }
56
57 protected:
58 entt::registry registry;
59 std::map<Grindstone::HashedString, Grindstone::UniquePtr<Grindstone::WorldContext>> contexts;
60 };
61}
Definition HashedString.hpp:9
Definition UniquePtr.hpp:7
Definition WorldContext.hpp:7