summary refs log tree commit diff stats
path: root/src/systems/animating.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-02-08 13:43:10 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-02-08 13:43:10 -0500
commit1400ade977e13e3b535d3c2fddb6e15de3c9b5a5 (patch)
tree3b44a7e9b60cff2423a7908404a4d6a5e79284f8 /src/systems/animating.cpp
parentcefe66cdbb8786dc455657376e36f0ff8785d5bc (diff)
downloadtherapy-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/animating.cpp')
-rw-r--r--src/systems/animating.cpp30
1 files changed, 30 insertions, 0 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().