Changed System to take World through constructor and store it instead, cause it makes more sense.

This commit is contained in:
2016-01-18 23:59:33 +01:00
parent 3fc44e944c
commit 51979d7f0c
32 changed files with 111 additions and 111 deletions
+11 -7
View File
@@ -9,9 +9,11 @@
class SystemPipeline
{
public:
SystemPipeline(EventBroker* eventBroker)
: m_EventBroker(eventBroker)
SystemPipeline(World* world, EventBroker* eventBroker)
: m_World(world)
, m_EventBroker(eventBroker)
{ }
~SystemPipeline()
{
for (UnorderedSystems& group : m_OrderedSystemGroups) {
@@ -29,7 +31,7 @@ public:
m_OrderedSystemGroups.resize(updateOrderLevel + 1);
}
UnorderedSystems& group = m_OrderedSystemGroups[updateOrderLevel];
System* system = new T(m_EventBroker, args...);
System* system = new T(m_World, m_EventBroker, args...);
group.Systems[typeid(T).name()] = system;
PureSystem* pureSystem = dynamic_cast<PureSystem*>(system);
@@ -47,7 +49,7 @@ public:
}
}
void Update(World* world, double dt)
void Update(double dt)
{
for (UnorderedSystems& group : m_OrderedSystemGroups) {
// Process events
@@ -57,18 +59,18 @@ public:
// Update
for (auto& system : group.ImpureSystems) {
system->Update(world, dt);
system->Update(dt);
}
for (auto& pair : group.PureSystems) {
const std::string& componentName = pair.first;
auto& systems = pair.second;
const ComponentPool* pool = world->GetComponents(componentName);
const ComponentPool* pool = m_World->GetComponents(componentName);
if (pool == nullptr) {
continue;
}
for (auto& component : *pool) {
for (auto& system : systems) {
system->UpdateComponent(world, EntityWrapper(world, component.EntityID), component, dt);
system->UpdateComponent(EntityWrapper(m_World, component.EntityID), component, dt);
}
}
}
@@ -76,7 +78,9 @@ public:
}
private:
World* m_World;
EventBroker* m_EventBroker;
struct UnorderedSystems
{
std::map<std::string, System*> Systems;