mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-04-20 01:52:59 +02:00
refactor engine service id from entt::family to entt::id_hash
This commit is contained in:
parent
4776691b2b
commit
b8a5cd7cf4
@ -127,7 +127,7 @@ void Engine::stop(void) {
|
|||||||
_is_running = false;
|
_is_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Engine::enableService(service_family::family_type s_t) {
|
bool Engine::enableService(entt::id_type s_t) {
|
||||||
if (_services.count(s_t)) {
|
if (_services.count(s_t)) {
|
||||||
auto* ss_entry = _services[s_t].get();
|
auto* ss_entry = _services[s_t].get();
|
||||||
if (ss_entry->first) {
|
if (ss_entry->first) {
|
||||||
@ -148,7 +148,7 @@ bool Engine::enableService(service_family::family_type s_t) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::disableService(service_family::family_type s_t) {
|
void Engine::disableService(entt::id_type s_t) {
|
||||||
if (_services.count(s_t)) {
|
if (_services.count(s_t)) {
|
||||||
auto* s_entry = _services[s_t].get();
|
auto* s_entry = _services[s_t].get();
|
||||||
if (s_entry->first) {
|
if (s_entry->first) {
|
||||||
@ -167,7 +167,7 @@ void Engine::disableService(service_family::family_type s_t) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Engine::provide(service_family::family_type I, service_family::family_type T) {
|
bool Engine::provide(entt::id_type I, entt::id_type T) {
|
||||||
if (!_services.count(T)) {
|
if (!_services.count(T)) {
|
||||||
// TODO: log error
|
// TODO: log error
|
||||||
return false;
|
return false;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "./engine_fwd.hpp"
|
#include "./engine_fwd.hpp"
|
||||||
|
|
||||||
#include <entt/core/family.hpp>
|
#include <entt/core/type_info.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -27,10 +27,10 @@ class Engine {
|
|||||||
friend Services::ImGuiEngineTools;
|
friend Services::ImGuiEngineTools;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using service_family = entt::family<struct internal_service_family>;
|
//using service_family = entt::family<struct internal_service_family>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using service_family_type = service_family::family_type;
|
//using service_family_type = service_family::family_type;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<UpdateStrategies::UpdateStrategy> _update_strategy;
|
std::unique_ptr<UpdateStrategies::UpdateStrategy> _update_strategy;
|
||||||
@ -64,11 +64,11 @@ class Engine {
|
|||||||
void stop(void);
|
void stop(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<service_family::family_type> _service_add_order; // ?
|
std::vector<entt::id_type> _service_add_order; // ?
|
||||||
std::vector<service_family::family_type> _service_enable_order; // ?
|
std::vector<entt::id_type> _service_enable_order; // ?
|
||||||
|
|
||||||
std::unordered_map<
|
std::unordered_map<
|
||||||
service_family::family_type,
|
entt::id_type,
|
||||||
std::shared_ptr<std::pair<
|
std::shared_ptr<std::pair<
|
||||||
bool,
|
bool,
|
||||||
std::unique_ptr<Services::Service>
|
std::unique_ptr<Services::Service>
|
||||||
@ -77,15 +77,16 @@ class Engine {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr auto type(void) {
|
constexpr static auto type(void) {
|
||||||
return service_family::type<T>;
|
//return entt::type_id<T>.hash();
|
||||||
|
return entt::type_hash<T>::value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
T& addService(Args&& ... args) {
|
T& addService(Args&& ... args) {
|
||||||
assert(!tryService<T>());
|
assert(!tryService<T>());
|
||||||
|
|
||||||
auto& ss_entry = _services[service_family::type<T>] =
|
auto& ss_entry = _services[type<T>()] =
|
||||||
std::make_shared<std::pair<bool, std::unique_ptr<Services::Service>>>(
|
std::make_shared<std::pair<bool, std::unique_ptr<Services::Service>>>(
|
||||||
std::make_pair<bool, std::unique_ptr<Services::Service>>(
|
std::make_pair<bool, std::unique_ptr<Services::Service>>(
|
||||||
false,
|
false,
|
||||||
@ -93,11 +94,11 @@ class Engine {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
_service_add_order.emplace_back(service_family::type<T>);
|
_service_add_order.emplace_back(type<T>());
|
||||||
|
|
||||||
// add updates to update strategy
|
// add updates to update strategy
|
||||||
_update_strategy->registerService(
|
_update_strategy->registerService(
|
||||||
service_family::type<T>,
|
type<T>(),
|
||||||
ss_entry.get()->second->registerUpdates()
|
ss_entry.get()->second->registerUpdates()
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -106,8 +107,8 @@ class Engine {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
[[nodiscard]] T* tryService(void) const {
|
[[nodiscard]] T* tryService(void) const {
|
||||||
if (_services.count(service_family::type<T>)) {
|
if (_services.count(type<T>())) {
|
||||||
return static_cast<T*>(_services.at(service_family::type<T>).get()->second.get());
|
return static_cast<T*>(_services.at(type<T>()).get()->second.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -126,22 +127,22 @@ class Engine {
|
|||||||
return *tmp;
|
return *tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool enableService(service_family::family_type s_t);
|
bool enableService(entt::id_type s_t);
|
||||||
void disableService(service_family::family_type s_t);
|
void disableService(entt::id_type s_t);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool enableService(void) {
|
bool enableService(void) {
|
||||||
return enableService(service_family::type<T>);
|
return enableService(type<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void disableService(void) {
|
void disableService(void) {
|
||||||
disableService(service_family::type<T>);
|
disableService(type<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
// provide T as I implementation
|
// provide T as I implementation
|
||||||
// T needs to be an added Service
|
// T needs to be an added Service
|
||||||
bool provide(service_family::family_type I, service_family::family_type T);
|
bool provide(entt::id_type I, entt::id_type T);
|
||||||
|
|
||||||
// provide T as I implementation
|
// provide T as I implementation
|
||||||
// T needs to be an added Service
|
// T needs to be an added Service
|
||||||
@ -150,7 +151,7 @@ class Engine {
|
|||||||
static_assert(std::is_base_of_v<I, T>, "T is not derived from I!");
|
static_assert(std::is_base_of_v<I, T>, "T is not derived from I!");
|
||||||
static_assert(!std::is_same_v<I, T>, "I and T are the same, makes no sense!");
|
static_assert(!std::is_same_v<I, T>, "I and T are the same, makes no sense!");
|
||||||
|
|
||||||
return provide(service_family::type<I>, service_family::type<T>);
|
return provide(type<I>(), type<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: reimplement???
|
// TODO: reimplement???
|
||||||
|
@ -20,20 +20,20 @@ class ScreenDirector : public Service {
|
|||||||
public:
|
public:
|
||||||
struct Screen {
|
struct Screen {
|
||||||
// lists of services relevant for this screen, disable and enable are called when its changed to
|
// lists of services relevant for this screen, disable and enable are called when its changed to
|
||||||
std::vector<Engine::service_family_type> start_disable;
|
std::vector<entt::id_type> start_disable;
|
||||||
std::vector<Engine::service_family_type> start_enable;
|
std::vector<entt::id_type> start_enable;
|
||||||
|
|
||||||
// register provider, when its changed to
|
// register provider, when its changed to
|
||||||
std::vector<
|
std::vector<
|
||||||
std::pair<
|
std::pair<
|
||||||
Engine::service_family_type, // I
|
entt::id_type, // I
|
||||||
Engine::service_family_type // T
|
entt::id_type // T
|
||||||
>
|
>
|
||||||
> start_provide;
|
> start_provide;
|
||||||
|
|
||||||
// lists of services relevant for this screen, disable and enable are called when its changed from
|
// lists of services relevant for this screen, disable and enable are called when its changed from
|
||||||
std::vector<Engine::service_family_type> end_disable;
|
std::vector<entt::id_type> end_disable;
|
||||||
std::vector<Engine::service_family_type> end_enable;
|
std::vector<entt::id_type> end_enable;
|
||||||
|
|
||||||
// called when its changed to, after services disable and enable
|
// called when its changed to, after services disable and enable
|
||||||
std::function<void(MM::Engine&)> start_fn = [](MM::Engine&){};
|
std::function<void(MM::Engine&)> start_fn = [](MM::Engine&){};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user