Small refactoring in Placeable.

This commit is contained in:
King_DuckZ 2014-02-22 17:06:25 +01:00
parent 85c65b3e68
commit ac85f96907
4 changed files with 26 additions and 16 deletions

View file

@ -6,7 +6,7 @@ namespace cloonel {
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
Character::Character (const std::string& parPath, SDLMain* parMain, ushort2 parSize) :
Placeable(0.0f, 0.0f),
Placeable(float2(0.0f)),
Drawable(parSize),
m_texture(new Texture(parPath, parMain, false))
{
@ -15,7 +15,7 @@ namespace cloonel {
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
Character::Character (const std::string&& parPath, SDLMain* parMain, ushort2 parSize) :
Placeable(0.0f, 0.0f),
Placeable(float2(0.0f)),
Drawable(parSize),
m_texture(new Texture(parPath, parMain, false))
{
@ -44,7 +44,7 @@ namespace cloonel {
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
void Character::Draw() const {
const int2 pos(m_pos + 0.5f);
const int2 pos(GetPos() + 0.5f);
m_texture->Render(pos, m_wh);
}
} //namespace cloonel

View file

@ -5,7 +5,7 @@ namespace cloonel {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void MoverRelative::UpdateSingle (Placeable* parPlaceable) {
const float2 newPos(GetOffset() - parPlaceable->QueryPosition());
const float2 newPos(GetOffset() - parPlaceable->GetPos());
parPlaceable->AddOffset(newPos);
}
} //namespace cloonel

View file

@ -3,17 +3,17 @@
#include <cassert>
namespace cloonel {
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
Placeable::Placeable (float parX, float parY) :
m_pos(parX, parY),
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
Placeable::Placeable (float2 parPos) :
m_pos(parPos),
m_mover(nullptr),
m_idForMover(0)
{
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void Placeable::SwapMover (Mover* parMover) {
if (m_mover) {
assert(0 != m_idForMover);

View file

@ -8,22 +8,32 @@ namespace cloonel {
class Placeable {
public:
const float2& GetPos ( void ) const noexcept { return m_pos; }
const float2& QueryPosition ( void ) const noexcept { return m_pos; }
void AddOffset ( const float2& parOffset ) noexcept { m_pos += parOffset; }
float2 GetPos ( void ) const noexcept;
void AddOffset ( const float2& parOffset ) noexcept;
void SwapMover ( Mover* parMover );
protected:
Placeable ( float parX, float parY );
explicit Placeable ( float2 parPos );
~Placeable ( void ) noexcept = default;
float2 m_pos;
private:
float2 m_pos;
Mover* m_mover;
int m_idForMover;
};
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
inline void Placeable::AddOffset (const float2& parOffset) noexcept {
m_pos += parOffset;
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
inline float2 Placeable::GetPos() const noexcept {
return m_pos;
}
} //namespace cloonel
#endif