-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenderSystem.cpp
34 lines (30 loc) · 1021 Bytes
/
RenderSystem.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
#include <Systems/RenderSystem.h>
#include <Components/RenderableComponent.h>
#include <Components/PositionComponent.h>
RenderSystem::RenderSystem(ecs::Manager& aManager, sf::RenderWindow* target)
: ecs::ISystem_<RenderSystem>(aManager),
rTarget(target){
if (ids.empty())
{
ids.insert(RenderableComponent::sGetID());
ids.insert(PositionComponent::sGetID());
}
}
void RenderSystem::Execute(float time_step)
{
rTarget->clear();
for (auto& entity : manager.getEntities(this->getComponentIDs()))
{
RenderableComponent& target = manager.getComponent<RenderableComponent>(entity);
PositionComponent& pos = manager.getComponent<PositionComponent>(entity);
if (target.shape){
target.shape->setPosition(pos.x, pos.y);
rTarget->draw(*(target.shape));
}
else if (target.text){
target.text->setPosition(pos.x, pos.y);
rTarget->draw(*(target.text));
}
}
rTarget->display();
}