From 3e8084c3852cda905e5b726182c38b1c8972e721 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Mon, 24 Feb 2014 21:07:35 +0100 Subject: [PATCH] Bugfix in MoverRelative. Old code was "undoing" offsets other than their own, so stacking multiple movers was broken. --- src/mover.hpp | 2 +- src/moverrelative.cpp | 18 ++++++++++++++++-- src/moverrelative.hpp | 7 ++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/mover.hpp b/src/mover.hpp index 2dd1f1a..ae14cfa 100644 --- a/src/mover.hpp +++ b/src/mover.hpp @@ -14,7 +14,7 @@ namespace cloonel { Mover ( void ) = default; virtual ~Mover ( void ) noexcept = default; - void Update ( float parDelta ); + virtual void Update ( float parDelta ); PlaceableTicketType RegisterPlaceable ( Placeable* parPlaceable ) { return m_placeables.Add(parPlaceable); } void UnregisterPlaceable ( PlaceableTicketType parID ) noexcept { m_placeables.Remove(parID); } diff --git a/src/moverrelative.cpp b/src/moverrelative.cpp index be21b0f..0bcf034 100644 --- a/src/moverrelative.cpp +++ b/src/moverrelative.cpp @@ -2,10 +2,24 @@ #include "placeable.hpp" namespace cloonel { + ///-------------------------------------------------------------------------- + ///-------------------------------------------------------------------------- + MoverRelative::MoverRelative() : + m_prevOffset(0.0f) + { + } + ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- void MoverRelative::UpdateSingle (Placeable* parPlaceable) { - const float2 newPos(GetOffset() - parPlaceable->GetPos()); - parPlaceable->AddOffset(newPos); + const float2 offs(GetOffset() - m_prevOffset); + parPlaceable->AddOffset(offs); + } + + ///-------------------------------------------------------------------------- + ///-------------------------------------------------------------------------- + void MoverRelative::Update (float parDelta) { + m_prevOffset = GetOffset(); + Mover::Update(parDelta); } } //namespace cloonel diff --git a/src/moverrelative.hpp b/src/moverrelative.hpp index cb3642d..8766f87 100644 --- a/src/moverrelative.hpp +++ b/src/moverrelative.hpp @@ -6,12 +6,17 @@ namespace cloonel { class MoverRelative : public Mover { public: - MoverRelative ( void ) = default; + MoverRelative ( void ); virtual ~MoverRelative ( void ) noexcept = default; + virtual void Update ( float parDelta ); + protected: virtual void UpdateSingle ( Placeable* parPlaceable ); virtual float2 GetOffset ( void ) const = 0; + + private: + float2 m_prevOffset; }; } //namespace cloonel