From abee07a8440cbf8507f16b5a04772baaaa2318aa Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Mon, 10 Feb 2014 01:20:16 +0100 Subject: [PATCH] Use the new vector class wherever possible. --- src/game.cpp | 12 +++++------- src/game.hpp | 4 ++-- src/texture.cpp | 11 +++++++---- src/texture.hpp | 6 +++--- src/vector.hpp | 1 + 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index f534be3..83c07a1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -10,8 +10,7 @@ namespace cloonel { Game::Game (SDLMain* parSdlMain) : GameBase(parSdlMain), m_character(nullptr), - m_posx(0.0f), - m_posy(0.0f) + m_pos(0.0f) { } @@ -35,15 +34,14 @@ namespace cloonel { ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ void Game::OnRender() { - const int posx = static_cast(m_posx + 0.5f); - const int posy = static_cast(m_posy + 0.5f); - m_character->Render(posx, posy); + const int2 newPos(static_cast(m_pos + 0.5f)); + m_character->Render(newPos); } ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ void Game::OnUpdate (float parDelta) { - m_posx += parDelta * 15.0f; - m_posy += parDelta * 22.8f; + const float2 increase(parDelta * 15.0f, parDelta * 22.8f); + m_pos += increase; } } //namespace cloonel diff --git a/src/game.hpp b/src/game.hpp index dd8e0f3..bef768f 100644 --- a/src/game.hpp +++ b/src/game.hpp @@ -2,6 +2,7 @@ #define id0E85DAFBFF5D497E8B3699AED806840A #include "gamebase.hpp" +#include "vector.hpp" #include namespace cloonel { @@ -20,8 +21,7 @@ namespace cloonel { virtual void OnUpdate ( float parDelta ); std::unique_ptr m_character; - float m_posx; - float m_posy; + float2 m_pos; }; } //namespace cloonel diff --git a/src/texture.cpp b/src/texture.cpp index b4597f9..776ed88 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -42,15 +42,18 @@ namespace cloonel { m_texture = SDL_CreateTextureFromSurface(m_sdlmain->GetRenderer(), surf); SDL_FreeSurface(surf); - if (m_texture) - SDL_QueryTexture(m_texture, nullptr, nullptr, &m_width, &m_height); + if (m_texture) { + int width, height; + SDL_QueryTexture(m_texture, nullptr, nullptr, &width, &height); + m_size = int2(width, height); + } } ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ - void Texture::Render (int parX, int parY) { + void Texture::Render (const int2& parPos) { assert(IsLoaded()); - const SDL_Rect dest = { parX, parY, m_width, m_height }; + const SDL_Rect dest = { parPos.x(), parPos.y(), m_size.x(), m_size.y() }; SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest); } } //namespace cloonel diff --git a/src/texture.hpp b/src/texture.hpp index a78d5e7..598be44 100644 --- a/src/texture.hpp +++ b/src/texture.hpp @@ -1,6 +1,7 @@ #ifndef id0F37904CB7274575B7E9419E615DA250 #define id0F37904CB7274575B7E9419E615DA250 +#include "vector.hpp" #include struct SDL_Texture; @@ -16,14 +17,13 @@ namespace cloonel { void Reload ( void ); void Destroy ( void ) noexcept; bool IsLoaded ( void ) const { return nullptr != m_texture; } - void Render ( int parX, int parY ); + void Render ( const int2& parPos ); private: const std::string m_path; SDL_Texture* m_texture; SDLMain* const m_sdlmain; - int m_width; - int m_height; + ushort2 m_size; }; } //namespace cloonel diff --git a/src/vector.hpp b/src/vector.hpp index 66c4bdc..4de6da3 100644 --- a/src/vector.hpp +++ b/src/vector.hpp @@ -78,6 +78,7 @@ namespace cloonel { typedef Vector float2; typedef Vector ushort2; + typedef Vector int2; } //namespace cloonel #include "vector.inl" #endif