diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-08 13:43:10 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-08 13:43:10 -0500 |
commit | 1400ade977e13e3b535d3c2fddb6e15de3c9b5a5 (patch) | |
tree | 3b44a7e9b60cff2423a7908404a4d6a5e79284f8 /src/systems | |
parent | cefe66cdbb8786dc455657376e36f0ff8785d5bc (diff) | |
download | therapy-1400ade977e13e3b535d3c2fddb6e15de3c9b5a5.tar.gz therapy-1400ade977e13e3b535d3c2fddb6e15de3c9b5a5.tar.bz2 therapy-1400ade977e13e3b535d3c2fddb6e15de3c9b5a5.zip |
Moved sprite rendering into AnimatingSystem
Refactored how systems work slightly. Now, rendering can be done by a number of systems working together. Since the AnimatingSystem handles the animation of sprites, it should also handle the rendering of them. Because of this, the RenderingSystem has been removed.
Diffstat (limited to 'src/systems')
-rw-r--r-- | src/systems/animating.cpp | 30 | ||||
-rw-r--r-- | src/systems/animating.h | 3 | ||||
-rw-r--r-- | src/systems/rendering.cpp | 37 | ||||
-rw-r--r-- | src/systems/rendering.h | 22 |
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 | ||
5 | void AnimatingSystem::tick(double) | 6 | void AnimatingSystem::tick(double) |
6 | { | 7 | { |
@@ -28,6 +29,35 @@ void AnimatingSystem::tick(double) | |||
28 | } | 29 | } |
29 | } | 30 | } |
30 | 31 | ||
32 | void 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 | |||
31 | void AnimatingSystem::startAnimation(id_type entity, std::string animation) | 61 | void 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 | ||
7 | class AnimatingSystem : public System { | 8 | class AnimatingSystem : public System { |
8 | public: | 9 | public: |
@@ -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 | |||
6 | void 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 | |||
8 | class RenderingSystem : public System { | ||
9 | public: | ||
10 | |||
11 | RenderingSystem(Game& game) : System(game) | ||
12 | { | ||
13 | } | ||
14 | |||
15 | void tick(double dt); | ||
16 | |||
17 | private: | ||
18 | |||
19 | Texture texture_ {GAME_WIDTH, GAME_HEIGHT}; | ||
20 | }; | ||
21 | |||
22 | #endif /* end of include guard: RENDERING_H_76ABC02A */ | ||