Created
May 22, 2016 10:21
-
-
Save mhaemmerle/851273780b3af155d801302458e24b16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2016 Juan Delgado (JuDelCo) | |
// License: MIT License | |
// MIT License web page: https://opensource.org/licenses/MIT | |
#include "EntitasPP/SystemContainer.hpp" | |
#include "EntitasPP/Matcher.hpp" | |
#include "EntitasPP/Pool.hpp" | |
#include <iostream> | |
#include <string> | |
using namespace EntitasPP; | |
class DemoComponent : public IComponent { | |
public: | |
void Reset(const std::string& name1, const std::string& name2) { | |
std::cout << "Created new entity: " << name1 << "," << name2 << std::endl; | |
} | |
}; | |
class DemoSystem : public IInitializeSystem, public IExecuteSystem, public ISetPoolSystem { | |
public: | |
void SetPool(Pool* pool) { | |
mPool = pool; | |
} | |
void Initialize() { | |
mPool->CreateEntity()->Add<DemoComponent>("foo", "bar"); | |
std::cout << "DemoSystem initialized" << std::endl; | |
} | |
void Execute() { | |
mPool->CreateEntity()->Add<DemoComponent>("foo", "bar"); | |
auto entitiesCount = mPool->GetGroup(Matcher_AllOf(DemoComponent))->Count(); | |
std::cout << "There are " << entitiesCount << " entities with the component 'DemoComponent'" << std::endl; | |
std::cout << "DemoSystem executed" << std::endl; | |
} | |
private: | |
Pool* mPool; | |
}; | |
class FooSystem : public IReactiveSystem { | |
//TriggerOnEvent trigger; | |
public: | |
FooSystem() { | |
//auto m = Matcher_AllOf(DemoComponent); | |
//trigger = m.OnEntityAdded(); | |
} | |
void Execute(std::vector<EntityPtr> entities) { | |
for (auto &e : entities) { | |
} | |
} | |
}; | |
int main(const int argc, const char* argv[]) { | |
auto systems = std::make_shared<SystemContainer>(); | |
auto pool = std::make_shared<Pool>(); | |
systems->Add(pool->CreateSystem<DemoSystem>()); | |
systems->Add(pool->CreateSystem<FooSystem>()); | |
systems->Initialize(); | |
for (unsigned int i = 0; i < 2; ++i) { | |
systems->Execute(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment