aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 37f6e68..70b0b45 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -45,8 +45,9 @@ int Engine::init(void)
systems.add<GameRunSystem>();
systems.add<InputSystem>();
systems.add<PlayerSystem>(entities);
+ systems.add<WorldSystem>();
systems.add<RenderSystem>();
- systems.add<ScriptSystem>(entities);
+ systems.add<ScriptSystem>(entities, *(systems.system<WorldSystem>().get()));
systems.add<PhysicsSystem>();
systems.add<TextSystem>();
systems.configure();
@@ -65,13 +66,19 @@ int Engine::init(void)
"it." << std::endl;
}
+ // Initially update the world to send all systems world data
+ systems.update<WorldSystem>(0);
return 0;
}
void Engine::logicLoop(void)
{
entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */
- double elapsed = 0;
+ double elapsed = 1000; /**< Time elapsed since last logic loop. This
+ should be initialized to something larger
+ than our logic loop period (50ms), so
+ the logic loop is run during our first
+ loop. */
while (shouldRun()) {
auto start = mc::now();
@@ -86,6 +93,8 @@ void Engine::logicLoop(void)
// Update 20 times a second
if (elapsed > 50) {
elapsed = 0;
+
+ systems.update<WorldSystem>(dt);
// All entities with an idle function should be run here
entities.each<Scripted>([](entityx::Entity, Scripted &f){
@@ -155,9 +164,11 @@ void Engine::run(void)
GameState::save("save.json", entities);
// Remove all Lua references from entities
- entities.each<Scripted>([](entityx::Entity, Scripted &f){ f.cleanup(); });
- entities.each<EventListener>([](entityx::Entity, EventListener &f){
+ entities.each<Scripted>([](entityx::Entity, Scripted &f) {
+ f.cleanup(); });
+ entities.each<EventListener>([](entityx::Entity, EventListener &f) {
f.cleanup(); });
+ systems.system<WorldSystem>()->cleanup();
}
bool Engine::shouldRun(void)