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

View file

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

View file

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

View file

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