aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine.cpp
blob: 7287f7d086b93c6d5f89623fa1777ed9fc0bb437 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <engine.hpp>

#include <config.hpp>
#include <world.hpp>
#include <window.hpp>
#include <ui.hpp>
#include <inventory.hpp>
#include <components.hpp>
#include <player.hpp>
#include <quest.hpp>

Engine::Engine(void)
    : shouldRun(true), systems(game::entities, game::events)
{
}

void Engine::init(void) {
    game::config::read();
    game::events.subscribe<GameEndEvent>(*this);

    systems.add<WindowSystem>();
    systems.add<RenderSystem>();
	systems.add<InputSystem>();
    //systems.add<InventorySystem>();
    systems.add<WorldSystem>();
    systems.add<PlayerSystem>();
	systems.add<QuestSystem>();

	systems.add<PhysicsSystem>();
	systems.add<MovementSystem>();
	systems.add<DialogSystem>();

    systems.configure();

    ui::initSounds();
	game::config::update();
	getSystem<PlayerSystem>()->create();
}

void Engine::render(entityx::TimeDelta dt)
{
    systems.update<RenderSystem>(dt);
    //systems.update<InventorySystem>(dt); // doesn't do anything...

	ui::fadeUpdate();
}
void Engine::resetRender(entityx::TimeDelta dt)
{
	systems.update<WindowSystem>(dt);
}

void Engine::update(entityx::TimeDelta dt)
{
    systems.update<InputSystem>(dt);
	systems.update<MovementSystem>(dt);
	//systems.update<DialogSystem>(dt); // doesn't do anything
	systems.update<WorldSystem>(dt);
    systems.update<PlayerSystem>(dt);
	//systems.update<QuestSystem>(dt); // doesn't do anything
}


namespace game {
	entityx::EventManager events;
	entityx::EntityManager entities (events);
	SpriteLoader sprite_l;

    Engine engine;
}