-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextSinkRenderSystem.cpp
41 lines (35 loc) · 1.45 KB
/
TextSinkRenderSystem.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
#include <Systems/TextSinkRenderSystem.h>
#include <Components/TextSinkComponent.h>
#include <Components/TextSourceComponent.h>
#include <Components/RenderableComponent.h>
#include <Components/SpeedComponent.h>
#include <sstream>
#include <cmath>
TextSinkRenderSystem::TextSinkRenderSystem(ecs::Manager& aManager)
: ecs::ISystem_<TextSinkRenderSystem>(aManager){
if (ids.empty())
{
ids.insert(TextSourceComponent::sGetID());
ids.insert(TextSinkComponent::sGetID());
}
}
void TextSinkRenderSystem::Execute(float time_step)
{
for (auto& entity : manager.getEntities(this->getComponentIDs()))
{
TextSourceComponent& source = manager.getComponent<TextSourceComponent>(entity);
TextSinkComponent& sink = manager.getComponent<TextSinkComponent>(entity);
RenderableComponent& shape = manager.getComponent<RenderableComponent>(source.entity);
RenderableComponent& text = manager.getComponent<RenderableComponent>(sink.entity);
std::stringstream out;
out << "pos| x = " << std::round(shape.shape->getPosition().x);
out << ", y = " << std::round(shape.shape->getPosition().y);
if (manager.hasComponent(source.entity, SpeedComponent::sGetID()))
{
auto& speed = manager.getComponent<SpeedComponent>(source.entity);
out << ", spd| x = " << speed.x;
out << ", y = " << speed.y;
}
text.text->setString(out.str());
}
}