Bugfix in MoverRelative.
Old code was "undoing" offsets other than their own, so stacking multiple movers was broken.
This commit is contained in:
parent
383ea0c17b
commit
3e8084c385
3 changed files with 23 additions and 4 deletions
|
@ -14,7 +14,7 @@ namespace cloonel {
|
||||||
Mover ( void ) = default;
|
Mover ( void ) = default;
|
||||||
virtual ~Mover ( void ) noexcept = default;
|
virtual ~Mover ( void ) noexcept = default;
|
||||||
|
|
||||||
void Update ( float parDelta );
|
virtual void Update ( float parDelta );
|
||||||
PlaceableTicketType RegisterPlaceable ( Placeable* parPlaceable ) { return m_placeables.Add(parPlaceable); }
|
PlaceableTicketType RegisterPlaceable ( Placeable* parPlaceable ) { return m_placeables.Add(parPlaceable); }
|
||||||
void UnregisterPlaceable ( PlaceableTicketType parID ) noexcept { m_placeables.Remove(parID); }
|
void UnregisterPlaceable ( PlaceableTicketType parID ) noexcept { m_placeables.Remove(parID); }
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,24 @@
|
||||||
#include "placeable.hpp"
|
#include "placeable.hpp"
|
||||||
|
|
||||||
namespace cloonel {
|
namespace cloonel {
|
||||||
|
///--------------------------------------------------------------------------
|
||||||
|
///--------------------------------------------------------------------------
|
||||||
|
MoverRelative::MoverRelative() :
|
||||||
|
m_prevOffset(0.0f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
void MoverRelative::UpdateSingle (Placeable* parPlaceable) {
|
void MoverRelative::UpdateSingle (Placeable* parPlaceable) {
|
||||||
const float2 newPos(GetOffset() - parPlaceable->GetPos());
|
const float2 offs(GetOffset() - m_prevOffset);
|
||||||
parPlaceable->AddOffset(newPos);
|
parPlaceable->AddOffset(offs);
|
||||||
|
}
|
||||||
|
|
||||||
|
///--------------------------------------------------------------------------
|
||||||
|
///--------------------------------------------------------------------------
|
||||||
|
void MoverRelative::Update (float parDelta) {
|
||||||
|
m_prevOffset = GetOffset();
|
||||||
|
Mover::Update(parDelta);
|
||||||
}
|
}
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
|
@ -6,12 +6,17 @@
|
||||||
namespace cloonel {
|
namespace cloonel {
|
||||||
class MoverRelative : public Mover {
|
class MoverRelative : public Mover {
|
||||||
public:
|
public:
|
||||||
MoverRelative ( void ) = default;
|
MoverRelative ( void );
|
||||||
virtual ~MoverRelative ( void ) noexcept = default;
|
virtual ~MoverRelative ( void ) noexcept = default;
|
||||||
|
|
||||||
|
virtual void Update ( float parDelta );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void UpdateSingle ( Placeable* parPlaceable );
|
virtual void UpdateSingle ( Placeable* parPlaceable );
|
||||||
virtual float2 GetOffset ( void ) const = 0;
|
virtual float2 GetOffset ( void ) const = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
float2 m_prevOffset;
|
||||||
};
|
};
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue