summary refs log tree commit diff stats
path: root/src/systems/animating.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-04-28 09:22:44 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-04-28 09:22:44 -0400
commit8016a7146fec3f6f43ca05723441750e5aae3d4d (patch)
tree0d527c1af80cf9ac34a027f9ee6f1acbb95db9f4 /src/systems/animating.cpp
parentf782b81ba10c9b7a1e221b16de0aaa7b6c521729 (diff)
downloadtherapy-8016a7146fec3f6f43ca05723441750e5aae3d4d.tar.gz
therapy-8016a7146fec3f6f43ca05723441750e5aae3d4d.tar.bz2
therapy-8016a7146fec3f6f43ca05723441750e5aae3d4d.zip
Restructured the way the world is loaded
The World class was removed and replaced by the RealizingSystem and RealizableComponent. The realizable entity is intended to be a singleton and to represent the world. The Map class was also removed and integrated into the MappableComponent.

These changes are to facilitate implementation of map objects without needing special intermediary objects (including the Map class). Now, map entities are created as soon as the world is created, and map object entities will be as well. They will simply be deactivated while the map is not active. Multiple players are now slightly better supported, which will be important in the future.

This will likely become inefficient as the world becomes bigger, and some sort of sector-loading process will have to be designed. This also reduces the usefulness of EntityManager's entity-searching capabilities (which are not the most efficiently implemented currently anyway), and will likely in the future require some added functionality to better search subsets of entities.

A lot of the components were also rewritten to use bare member variables instead of accessor methods, as they never had special functionality and just took up space. These components were also documented.
Diffstat (limited to 'src/systems/animating.cpp')
-rw-r--r--src/systems/animating.cpp93
1 files changed, 56 insertions, 37 deletions
diff --git a/src/systems/animating.cpp b/src/systems/animating.cpp index 634af67..8543ba2 100644 --- a/src/systems/animating.cpp +++ b/src/systems/animating.cpp
@@ -13,26 +13,29 @@ void AnimatingSystem::tick(double)
13 auto& sprite = game_.getEntityManager(). 13 auto& sprite = game_.getEntityManager().
14 getComponent<AnimatableComponent>(entity); 14 getComponent<AnimatableComponent>(entity);
15 15
16 if (!sprite.isFrozen()) 16 if (sprite.active)
17 { 17 {
18 sprite.setCountdown(sprite.getCountdown() + 1); 18 if (!sprite.frozen)
19 } 19 {
20 20 sprite.countdown++;
21 const Animation& anim = sprite.getAnimation(); 21 }
22 if (sprite.getCountdown() >= anim.getDelay())
23 {
24 sprite.setFrame(sprite.getFrame() + 1);
25 sprite.setCountdown(0);
26 22
27 if (sprite.getFrame() >= anim.getFirstFrame() + anim.getNumFrames()) 23 const Animation& anim = sprite.getAnimation();
24 if (sprite.countdown >= anim.getDelay())
28 { 25 {
29 sprite.setFrame(anim.getFirstFrame()); 26 sprite.frame++;
27 sprite.countdown = 0;
28
29 if (sprite.frame >= anim.getFirstFrame() + anim.getNumFrames())
30 {
31 sprite.frame = anim.getFirstFrame();
32 }
30 } 33 }
31 }
32 34
33 if (sprite.isFlickering()) 35 if (sprite.flickering)
34 { 36 {
35 sprite.setFlickerTimer((sprite.getFlickerTimer() + 1) % 6); 37 sprite.flickerTimer = (sprite.flickerTimer + 1) % 6;
38 }
36 } 39 }
37 } 40 }
38} 41}
@@ -49,36 +52,52 @@ void AnimatingSystem::render(Texture& texture)
49 auto& sprite = game_.getEntityManager(). 52 auto& sprite = game_.getEntityManager().
50 getComponent<AnimatableComponent>(entity); 53 getComponent<AnimatableComponent>(entity);
51 54
52 auto& transform = game_.getEntityManager(). 55 if (sprite.active)
53 getComponent<TransformableComponent>(entity);
54
55 double alpha = 1.0;
56 if (sprite.isFlickering() && (sprite.getFlickerTimer() < 3))
57 { 56 {
58 alpha = 0.0; 57 auto& transform = game_.getEntityManager().
59 } 58 getComponent<TransformableComponent>(entity);
60 59
61 Rectangle dstrect { 60 double alpha = 1.0;
62 static_cast<int>(transform.getX()), 61 if (sprite.flickering && (sprite.flickerTimer < 3))
63 static_cast<int>(transform.getY()), 62 {
64 transform.getW(), 63 alpha = 0.0;
65 transform.getH()}; 64 }
66 65
67 const AnimationSet& aset = sprite.getAnimationSet(); 66 Rectangle dstrect {
68 game_.getRenderer().blit( 67 static_cast<int>(transform.x),
69 aset.getTexture(), 68 static_cast<int>(transform.y),
70 texture, 69 transform.w,
71 aset.getFrameRect(sprite.getFrame()), 70 transform.h};
72 dstrect, 71
73 alpha); 72 const AnimationSet& aset = sprite.animationSet;
73 game_.getRenderer().blit(
74 aset.getTexture(),
75 texture,
76 aset.getFrameRect(sprite.frame),
77 dstrect,
78 alpha);
79 }
74 } 80 }
75} 81}
76 82
83void AnimatingSystem::initPrototype(id_type entity)
84{
85 auto& sprite = game_.getEntityManager().
86 getComponent<AnimatableComponent>(entity);
87
88 startAnimation(entity, sprite.origAnimation);
89
90 sprite.countdown = 0;
91 sprite.flickering = false;
92 sprite.flickerTimer = 0;
93 sprite.frozen = false;
94}
95
77void AnimatingSystem::startAnimation(id_type entity, std::string animation) 96void AnimatingSystem::startAnimation(id_type entity, std::string animation)
78{ 97{
79 auto& sprite = game_.getEntityManager(). 98 auto& sprite = game_.getEntityManager().
80 getComponent<AnimatableComponent>(entity); 99 getComponent<AnimatableComponent>(entity);
81 100
82 sprite.setAnimation(animation); 101 sprite.animation = std::move(animation);
83 sprite.setFrame(sprite.getAnimation().getFirstFrame()); 102 sprite.frame = sprite.getAnimation().getFirstFrame();
84} 103}