libecs-cpp 2.1.0
Entity Component System library in C++
Loading...
Searching...
No Matches
Manager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <unordered_map>
5#include <vector>
6#include <mutex>
7#include <memory>
8#include <atomic>
9#include <condition_variable>
10#include <cstddef>
11#include <libecs-cpp/json.hpp>
12
13namespace ecs
14{
15 class Container;
16
31 class Manager
32 {
33 public:
36
46
55 ecs::Container *Container(const std::string &handle);
56
62
67 std::vector<std::string> ContainersGet();
68
73 bool IsRunning();
74
92 void Shutdown();
93
106 void MessageSubmit(const nlohmann::json &message);
107 private:
108 ecs::Container *containerCreate(const std::string &handle);
109 std::unordered_map<std::string, std::unique_ptr<ecs::Container>> containers;
110 std::mutex mutexContainers;
111 std::size_t sendsInFlight = 0;
112 bool closing = false;
113 std::condition_variable sendsIdle;
114 std::atomic<bool> running = true;
115 };
116}
A container: the entities, components, systems and resources that are updated together.
Definition Container.hpp:70
Creates and owns containers, routes messages between them and shuts them down.
Definition Manager.hpp:32
ecs::Container * Container()
Creates a container with a generated handle.
void Shutdown()
Sets IsRunning() to false and stops every container that has its own thread.
void MessageSubmit(const nlohmann::json &message)
Sends a message to the system named in message["destination"], in the container named there.
Manager()
Creates a running manager with no containers.
~Manager()
Shuts the manager down, then destroys its containers.
std::vector< std::string > ContainersGet()
Returns the handles of all containers, as a snapshot by value.
bool IsRunning()
Says whether the manager is running: true until Shutdown() has been called.
ecs::Container * Container(const std::string &handle)
Returns the container with this handle, creating it if needed.
Definition Clock.hpp:10