]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fixed coalesce
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 1 Dec 2016 02:37:01 +0000 (21:37 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 1 Dec 2016 02:37:01 +0000 (21:37 -0500)
1  2 
include/common.hpp
src/components.cpp

index 7b98ea928533f9d9cd86122e6ed25ebb1c58ca09,249b9eb1ef7571fcc0fdb986e75e3d1b207c2755..3caa083869842f82d82894c6065bceecffaaa47a
@@@ -58,11 -58,11 +58,7 @@@ typedef unsigned int uint
  
  #define BREAKPOINT __asm__("int $3")
  
--template<typename T>
- inline const T * const& coalesce(const void * &p1, const void * &p2)
 -inline const T * const& coalesce(const T * const &p1, const T * const &p2)
--{
-       return ((p1 == nullptr) ? reinterpret_cast<T*>(p2) : p1);
 -      return ((p1 == nullptr) ? p2 : p1);
--}
++#define coalesce(v1, v2) ((v1 != nullptr) ? v1 : v2)
  
  /**
   * Creates a coordinate of integers.
index a398bece24c3a12fa8b51ef6933b48cb26e3fc16,b74555cabe6c692db21325a29b9168484ea482ab..612e52249c2accecf41acb9814689dc12701d7ac
@@@ -18,7 -18,14 +18,14 @@@ void MovementSystem::update(entityx::En
        en.each<Position, Direction>([dt](entityx::Entity entity, Position &position, Direction &direction) {
                position.x += direction.x * dt;
                position.y += direction.y * dt;
 -              
 +
+               if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
 -                      if (direction.x) {      
++                      if (direction.x) {
+                               entity.component<Sprite>().get()->sprite = entity.component<Animate>().get()->nextFrame();
+                       } else {
+                               entity.component<Sprite>().get()->sprite = entity.component<Animate>().get()->firstFrame();
+                       }
+               }
                if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) {
                        direction.x = 0;
                } else {
@@@ -89,11 -97,7 +97,10 @@@ void RenderSystem::update(entityx::Enti
                                                                0.0, 1.0,
                                                                1.0, 1.0,
                                                                1.0, 0.0};
 -              
 +
-               if (entity.has_component<Animate>()) {
-                       sprite.sprite = entity.component<Animate>().get()->nextFrame();
-               }
++              if (entity.has_component<Animate>())
++                      sprite.sprite = entity.component<Animate>()->nextFrame();
 +
                for (auto &S : sprite.sprite) {
                        float width = HLINES(S.first.size.x);
                        float height = HLINES(S.first.size.y);