-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameWorld.cpp
55 lines (45 loc) · 1.14 KB
/
GameWorld.cpp
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
#include <iostream>
#include "GameWorld.hpp"
#include "DescriptionSystem.hpp"
#include "MovementSystem.hpp"
#include "RenderSystem.hpp"
GameWorld::GameWorld () : _window(sf::VideoMode(640, 480), "ECS")
{
initSystems();
}
GameWorld::~GameWorld ()
{}
void GameWorld::update ()
{
_window.clear(sf::Color::White);
for (auto system(_systems.begin()) ; system != _systems.end() ; ++system)
{
(*system)->begin();
for (auto entity(_entities.begin()) ; entity != _entities.end() ; ++entity)
{
if ((*system)->canUpdate(**entity))
{
(*system)->update(**entity);
}
}
(*system)->end();
}
_window.display();
}
GameObject* GameWorld::addObject ()
{
_entities.emplace_back(new GameObject);
return _entities.back().get();
}
void GameWorld::initSystems ()
{
/*
_systems.emplace_back(new MovementSystem);
_systems.back()->registerComponent("Velocity");
_systems.back()->registerComponent("Position");
*/
//_systems.emplace_back(new DescriptionSystem);
_systems.emplace_back(new RenderSystem(&_window));
_systems.back()->registerComponent("Drawable");
_systems.back()->registerComponent("Position");
}