summary refs log tree commit diff stats
path: root/src/systems
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/animating.cpp30
-rw-r--r--src/systems/animating.h3
-rw-r--r--src/systems/rendering.cpp37
-rw-r--r--src/systems/rendering.h22
4 files changed, 33 insertions, 59 deletions
diff --git a/src/systems/animating.cpp b/src/systems/animating.cpp index fcbfca5..91fe925 100644 --- a/src/systems/animating.cpp +++ b/src/systems/animating.cpp
@@ -1,6 +1,7 @@
1#include "animating.h" 1#include "animating.h"
2#include "game.h" 2#include "game.h"
3#include "components/animatable.h" 3#include "components/animatable.h"
4#include "components/transformable.h"
4 5
5void AnimatingSystem::tick(double) 6void AnimatingSystem::tick(double)
6{ 7{
@@ -28,6 +29,35 @@ void AnimatingSystem::tick(double)
28 } 29 }
29} 30}
30 31
32void AnimatingSystem::render(Texture& texture)
33{
34 std::set<id_type> spriteEntities =
35 game_.getEntityManager().getEntitiesWithComponents<
36 AnimatableComponent,
37 TransformableComponent>();
38
39 for (id_type entity : spriteEntities)
40 {
41 auto& sprite = game_.getEntityManager().
42 getComponent<AnimatableComponent>(entity);
43
44 auto& transform = game_.getEntityManager().
45 getComponent<TransformableComponent>(entity);
46
47 Rectangle dstrect {
48 static_cast<int>(transform.getX()),
49 static_cast<int>(transform.getY()),
50 transform.getW(),
51 transform.getH()};
52
53 const AnimationSet& aset = sprite.getAnimationSet();
54 texture.blit(
55 aset.getTexture(),
56 aset.getFrameRect(sprite.getFrame()),
57 dstrect);
58 }
59}
60
31void AnimatingSystem::startAnimation(id_type entity, std::string animation) 61void AnimatingSystem::startAnimation(id_type entity, std::string animation)
32{ 62{
33 auto& sprite = game_.getEntityManager(). 63 auto& sprite = game_.getEntityManager().
diff --git a/src/systems/animating.h b/src/systems/animating.h index 150a74a..d6a89a5 100644 --- a/src/systems/animating.h +++ b/src/systems/animating.h
@@ -3,6 +3,7 @@
3 3
4#include "system.h" 4#include "system.h"
5#include <string> 5#include <string>
6#include "renderer.h"
6 7
7class AnimatingSystem : public System { 8class AnimatingSystem : public System {
8public: 9public:
@@ -13,6 +14,8 @@ public:
13 14
14 void tick(double dt); 15 void tick(double dt);
15 16
17 void render(Texture& texture);
18
16 void startAnimation(id_type entity, std::string animation); 19 void startAnimation(id_type entity, std::string animation);
17 20
18}; 21};
diff --git a/src/systems/rendering.cpp b/src/systems/rendering.cpp deleted file mode 100644 index 8219732..0000000 --- a/src/systems/rendering.cpp +++ /dev/null
@@ -1,37 +0,0 @@
1#include "rendering.h"
2#include "game.h"
3#include "components/animatable.h"
4#include "components/transformable.h"
5
6void RenderingSystem::tick(double)
7{
8 texture_.fill(texture_.entirety(), 0, 0, 0);
9
10 std::set<id_type> spriteEntities =
11 game_.getEntityManager().getEntitiesWithComponents<
12 AnimatableComponent,
13 TransformableComponent>();
14
15 for (id_type entity : spriteEntities)
16 {
17 auto& sprite = game_.getEntityManager().
18 getComponent<AnimatableComponent>(entity);
19
20 auto& transform = game_.getEntityManager().
21 getComponent<TransformableComponent>(entity);
22
23 Rectangle dstrect {
24 static_cast<int>(transform.getX()),
25 static_cast<int>(transform.getY()),
26 transform.getW(),
27 transform.getH()};
28
29 const AnimationSet& aset = sprite.getAnimationSet();
30 texture_.blit(
31 aset.getTexture(),
32 aset.getFrameRect(sprite.getFrame()),
33 dstrect);
34 }
35
36 texture_.renderScreen();
37}
diff --git a/src/systems/rendering.h b/src/systems/rendering.h deleted file mode 100644 index a53ee64..0000000 --- a/src/systems/rendering.h +++ /dev/null
@@ -1,22 +0,0 @@
1#ifndef RENDERING_H_76ABC02A
2#define RENDERING_H_76ABC02A
3
4#include "system.h"
5#include "renderer.h"
6#include "consts.h"
7
8class RenderingSystem : public System {
9public:
10
11 RenderingSystem(Game& game) : System(game)
12 {
13 }
14
15 void tick(double dt);
16
17private:
18
19 Texture texture_ {GAME_WIDTH, GAME_HEIGHT};
20};
21
22#endif /* end of include guard: RENDERING_H_76ABC02A */