Merge pull request #23 from teamfisk/OrderedSystemPipeline
Ordered system pipeline approved
This commit is contained in:
@@ -14,21 +14,28 @@ public:
|
|||||||
{ }
|
{ }
|
||||||
~SystemPipeline()
|
~SystemPipeline()
|
||||||
{
|
{
|
||||||
for (auto& pair : m_Systems) {
|
for (UnorderedSystems& group : m_OrderedSystemGroups) {
|
||||||
delete pair.second;
|
for (auto& pair : group.Systems) {
|
||||||
|
delete pair.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename... Arguments>
|
template <typename T, typename... Arguments>
|
||||||
void AddSystem(Arguments... args)
|
//All systems with orderlevel 0 will be updated first, then 1, 2, etc.
|
||||||
|
void AddSystem(int updateOrderLevel, Arguments... args)
|
||||||
{
|
{
|
||||||
|
if (updateOrderLevel + 1 > m_OrderedSystemGroups.size()) {
|
||||||
|
m_OrderedSystemGroups.resize(updateOrderLevel + 1);
|
||||||
|
}
|
||||||
|
UnorderedSystems& group = m_OrderedSystemGroups[updateOrderLevel];
|
||||||
System* system = new T(m_EventBroker, args...);
|
System* system = new T(m_EventBroker, args...);
|
||||||
m_Systems[typeid(T).name()] = system;
|
group.Systems[typeid(T).name()] = system;
|
||||||
|
|
||||||
if (std::is_base_of<PureSystem, T>::value) {
|
if (std::is_base_of<PureSystem, T>::value) {
|
||||||
PureSystem* pureSystem = static_cast<PureSystem*>(system);
|
PureSystem* pureSystem = static_cast<PureSystem*>(system);
|
||||||
if (!pureSystem->m_ComponentType.empty()) {
|
if (!pureSystem->m_ComponentType.empty()) {
|
||||||
m_PureSystems[pureSystem->m_ComponentType].push_back(pureSystem);
|
group.PureSystems[pureSystem->m_ComponentType].push_back(pureSystem);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Failed to add pure system \"%s\": Missing component type!", typeid(T).name());
|
LOG_ERROR("Failed to add pure system \"%s\": Missing component type!", typeid(T).name());
|
||||||
}
|
}
|
||||||
@@ -36,41 +43,47 @@ public:
|
|||||||
|
|
||||||
if (std::is_base_of<ImpureSystem, T>::value) {
|
if (std::is_base_of<ImpureSystem, T>::value) {
|
||||||
ImpureSystem* impureSystem = static_cast<ImpureSystem*>(system);
|
ImpureSystem* impureSystem = static_cast<ImpureSystem*>(system);
|
||||||
m_ImpureSystems.push_back(impureSystem);
|
group.ImpureSystems.push_back(impureSystem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update(World* world, double dt)
|
void Update(World* world, double dt)
|
||||||
{
|
{
|
||||||
// Process events
|
for (UnorderedSystems& group : m_OrderedSystemGroups) {
|
||||||
for (auto& pair : m_Systems) {
|
// Process events
|
||||||
m_EventBroker->Process(pair.first);
|
for (auto& pair : group.Systems) {
|
||||||
}
|
m_EventBroker->Process(pair.first);
|
||||||
|
|
||||||
// Update
|
|
||||||
for (auto& pair : m_PureSystems) {
|
|
||||||
const std::string& componentName = pair.first;
|
|
||||||
auto& systems = pair.second;
|
|
||||||
const ComponentPool* pool = world->GetComponents(componentName);
|
|
||||||
if (pool == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
for (auto& component : *pool) {
|
|
||||||
for (auto& system : systems) {
|
// Update
|
||||||
system->UpdateComponent(world, component, dt);
|
for (auto& pair : group.PureSystems) {
|
||||||
|
const std::string& componentName = pair.first;
|
||||||
|
auto& systems = pair.second;
|
||||||
|
const ComponentPool* pool = world->GetComponents(componentName);
|
||||||
|
if (pool == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (auto& component : *pool) {
|
||||||
|
for (auto& system : systems) {
|
||||||
|
system->UpdateComponent(world, component, dt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for (auto& system : group.ImpureSystems) {
|
||||||
for (auto& system : m_ImpureSystems) {
|
system->Update(world, dt);
|
||||||
system->Update(world, dt);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventBroker* m_EventBroker;
|
EventBroker* m_EventBroker;
|
||||||
std::map<std::string, System*> m_Systems;
|
struct UnorderedSystems
|
||||||
std::map<std::string, std::vector<PureSystem*>> m_PureSystems;
|
{
|
||||||
std::vector<ImpureSystem*> m_ImpureSystems;
|
std::map<std::string, System*> Systems;
|
||||||
|
std::map<std::string, std::vector<PureSystem*>> PureSystems;
|
||||||
|
std::vector<ImpureSystem*> ImpureSystems;
|
||||||
|
};
|
||||||
|
std::vector<UnorderedSystems> m_OrderedSystemGroups;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
void CollisionSystem::UpdateComponent(World * world, ComponentWrapper & cAABB, double dt)
|
void CollisionSystem::UpdateComponent(World * world, ComponentWrapper & cAABB, double dt)
|
||||||
{
|
{
|
||||||
//TODO: Update CollisionSystem system after PlayerSystem.
|
|
||||||
|
|
||||||
//Right now, cAABB is a component attached to any entity that should be collideable.
|
//Right now, cAABB is a component attached to any entity that should be collideable.
|
||||||
AABB thisBox;
|
AABB thisBox;
|
||||||
if (!Collision::GetEntityBox(world, cAABB, thisBox)) {
|
if (!Collision::GetEntityBox(world, cAABB, thisBox)) {
|
||||||
|
|||||||
+12
-6
@@ -53,12 +53,18 @@ Game::Game(int argc, char* argv[])
|
|||||||
|
|
||||||
// Create system pipeline
|
// Create system pipeline
|
||||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||||
m_SystemPipeline->AddSystem<RaptorCopterSystem>();
|
|
||||||
m_SystemPipeline->AddSystem<PlayerSystem>();
|
//All systems with orderlevel 0 will be updated first.
|
||||||
m_SystemPipeline->AddSystem<EditorSystem>(m_Renderer);
|
unsigned int updateOrderLevel = 0;
|
||||||
m_SystemPipeline->AddSystem<CollisionSystem>();
|
m_SystemPipeline->AddSystem<RaptorCopterSystem>(updateOrderLevel);
|
||||||
m_SystemPipeline->AddSystem<TriggerSystem>();
|
m_SystemPipeline->AddSystem<PlayerSystem>(updateOrderLevel);
|
||||||
m_SystemPipeline->AddSystem<HealthSystem>();
|
m_SystemPipeline->AddSystem<EditorSystem>(updateOrderLevel, m_Renderer);
|
||||||
|
m_SystemPipeline->AddSystem<HealthSystem>(updateOrderLevel);
|
||||||
|
|
||||||
|
//Collision and TriggerSystem should update after player.
|
||||||
|
++updateOrderLevel;
|
||||||
|
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel);
|
||||||
|
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel);
|
||||||
|
|
||||||
// Invoke network
|
// Invoke network
|
||||||
if (m_Config->Get<bool>("Networking.StartNetwork", false)) {
|
if (m_Config->Get<bool>("Networking.StartNetwork", false)) {
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ GameHealthSystemTest::GameHealthSystemTest()
|
|||||||
|
|
||||||
// Create system pipeline
|
// Create system pipeline
|
||||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||||
m_SystemPipeline->AddSystem<PlayerSystem>();
|
m_SystemPipeline->AddSystem<PlayerSystem>(0);
|
||||||
m_SystemPipeline->AddSystem<HealthSystem>();
|
m_SystemPipeline->AddSystem<HealthSystem>(0);
|
||||||
|
|
||||||
//The Test
|
//The Test
|
||||||
//create entity which has transorm,player,model,health in it. i.e. is a player
|
//create entity which has transorm,player,model,health in it. i.e. is a player
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ Game::Game(int argc, char* argv[]) : someOctTree(AABB(-0.5f*worldSize, 0.5f*worl
|
|||||||
m_World = new HardcodedTestWorld();
|
m_World = new HardcodedTestWorld();
|
||||||
|
|
||||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||||
m_SystemPipeline->AddSystem<PlayerSystem>();
|
m_SystemPipeline->AddSystem<PlayerSystem>(0);
|
||||||
|
|
||||||
m_LastTime = glfwGetTime();
|
m_LastTime = glfwGetTime();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user