Files
Seele/src/Engine/System/SystemBase.h
T

64 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
#include <entt/entt.hpp>
#include <thread_pool/thread_pool.h>
2022-11-17 16:47:42 +01:00
#include "Component/Component.h"
namespace Seele
{
namespace System
{
template<typename... Components>
class SystemBase
{
public:
SystemBase(entt::registry& registry) : registry(registry) {}
virtual ~SystemBase() {}
2022-11-29 16:34:42 +01:00
template<is_component Comp>
auto getDependencies()
{
return Comp::dependencies;
}
2022-11-29 16:34:42 +01:00
template<typename Comp>
Dependencies<> getDependencies()
{
return Dependencies<>();
}
template<typename... Dep>
auto mergeDependencies(Dep... deps)
{
return (deps | ...);
}
template<typename... Deps>
void setupView(Dependencies<Deps...>, dp::thread_pool<>&)
{
registry.view<Components..., Deps...>().each([&](Components&... comp, Deps&... deps){
//pool.enqueue_detach([&](){
2022-11-29 16:34:42 +01:00
(accessComponent(deps) + ...);
update((comp,...));
//});
});
}
2022-11-29 16:34:42 +01:00
template<>
void setupView(Dependencies<>, dp::thread_pool<>&)
{
2022-11-29 16:34:42 +01:00
registry.view<Components...>().each([&](Components&... comp){
//pool.enqueue_detach([&](){
update(comp...);
//});
});
}
void run(dp::thread_pool<>& pool, double delta)
{
deltaTime = delta;
setupView(mergeDependencies((getDependencies<Components>(),...)), pool);
}
virtual void update(Components&... components) = 0;
2022-11-29 16:34:42 +01:00
protected:
double deltaTime;
private:
entt::registry& registry;
};
} // namespace System
} // namespace Seele