diff --git a/src/character.cpp b/src/character.cpp index cdc1839..8536ee3 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -47,7 +47,7 @@ namespace cloonel { m_bounceCallback(&DoNothing), m_texture(new Texture(parPath, parMain, false)) #if defined(WITH_DEBUG_VISUALS) - , m_bottomBarDrawable(parMain, Colour(250, 5, 1), static_cast(m_bottomBar.From()), static_cast(m_bottomBar.To())) + , m_bottomBarDrawable(parMain, Colour(250, 5, 1), vector_cast(m_bottomBar.From()), vector_cast(m_bottomBar.To())) #endif { assert(parMain); @@ -68,7 +68,7 @@ namespace cloonel { ///------------------------------------------------------------------------- void Character::Prepare() { const SDLMain* const sdlmain = m_texture->SDLObject(); - const int2 screensize(sdlmain->WidthHeight()); + const int2 screensize(vector_cast(sdlmain->WidthHeight())); m_texture->Reload(); } diff --git a/src/drawableline.cpp b/src/drawableline.cpp index fd96569..5bc61a0 100644 --- a/src/drawableline.cpp +++ b/src/drawableline.cpp @@ -34,7 +34,7 @@ namespace cloonel { ///---------------------------------------------------------------------- ///---------------------------------------------------------------------- void ClipLine (const SDL_Rect& parArea, Line& parLine) { - Line line(static_cast(parLine[0]), static_cast(parLine[1])); + Line line(vector_cast(parLine[0]), vector_cast(parLine[1])); const float al = static_cast(parArea.x); const float at = static_cast(parArea.y); const float ar = static_cast(parArea.x + parArea.w); @@ -110,9 +110,9 @@ namespace cloonel { SDL_SetRenderDrawColor(m_sdlmain->GetRenderer(), m_colour.r, m_colour.g, m_colour.b, m_colour.a); LineBase scaledLine(*this); - scaledLine += static_cast(parPos); + scaledLine += vector_cast(parPos); scaledLine *= parScaling; - const short2 wh(static_cast(m_sdlmain->WidthHeight())); + const short2 wh(vector_cast(m_sdlmain->WidthHeight())); { SDL_Rect screen; screen.x = screen.y = 0; diff --git a/src/line.hpp b/src/line.hpp index ffe5922..d1dfce3 100644 --- a/src/line.hpp +++ b/src/line.hpp @@ -26,6 +26,18 @@ #include #include +namespace vwr { + template + struct VectorWrapperInfo, 2>> { + enum { dimensions = 2 }; + typedef cloonel::Vector scalar_type; + typedef std::array vector_type; + static scalar_type& get_at (uint32_t parIndex, vector_type& parVector) { + return parVector[parIndex]; + } + }; +} //namespace vwr + namespace cloonel { template class Line { diff --git a/src/line.inl b/src/line.inl index 5c35a6e..6016ae8 100644 --- a/src/line.inl +++ b/src/line.inl @@ -54,8 +54,11 @@ namespace cloonel { template template Line& Line::operator*= (const Vector& parRhs) { - m_points.x() = static_cast(m_points.x() * parRhs); - m_points.y() = static_cast(m_points.y() * parRhs); + typedef typename std::common_type::type CommonType; + typedef Vector CommVecType; + + m_points.x() = vector_cast(vector_cast(m_points.x()) * vector_cast(parRhs)); + m_points.y() = vector_cast(vector_cast(m_points.y()) * vector_cast(parRhs)); return *this; } diff --git a/src/platform.cpp b/src/platform.cpp index 7f69fc9..5f0df7d 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -33,7 +33,7 @@ namespace cloonel { m_collisionTop(new HorzCollisionBar(parPos, parSize.x())), m_surface(parTexture) #if defined(WITH_DEBUG_VISUALS) - , m_collisionTopDrawable(parSdlMain, Colour(215, 181, 3), static_cast(parPos), static_cast(parPos + float2(parSize.x(), 0.0f))) + , m_collisionTopDrawable(parSdlMain, Colour(215, 181, 3), vector_cast(parPos), vector_cast(parPos + float2(parSize.x(), 0.0f))) #endif { assert(m_surface); diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp index 2d0d9df..2e00bd1 100644 --- a/src/sdlmain.cpp +++ b/src/sdlmain.cpp @@ -89,7 +89,7 @@ namespace cloonel { m_gameName(parGameName), m_localData(new LocalData) { - m_localData->sizeratio.SetOriginal(static_cast(parReferenceRes), static_cast(parRes)); + m_localData->sizeratio.SetOriginal(vector_cast(parReferenceRes), vector_cast(parRes)); m_localData->initialized = false; #if defined(RASPBERRY_PI) m_localData->bcmInitialized = false; @@ -178,7 +178,7 @@ namespace cloonel { ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ void SDLMain::SetResolution (ushort2 parRes) { - m_localData->sizeratio.UpdateResolution(static_cast(parRes)); + m_localData->sizeratio.UpdateResolution(vector_cast(parRes)); { SDL_Renderer* const renderer = GetRenderer(); assert(renderer); @@ -225,7 +225,7 @@ namespace cloonel { ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ ushort2 SDLMain::WidthHeight() const noexcept { - return static_cast(m_localData->sizeratio.Resolution()); + return vector_cast(m_localData->sizeratio.Resolution()); } ///------------------------------------------------------------------------ diff --git a/src/texture.cpp b/src/texture.cpp index 1ecb5e2..aa0ba7a 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -354,7 +354,7 @@ namespace cloonel { if (m_texture) { int2 wh; SDL_QueryTexture(m_texture, nullptr, nullptr, &wh.x(), &wh.y()); - m_size = static_cast(wh); + m_size = vector_cast(wh); } } @@ -369,14 +369,14 @@ namespace cloonel { RectFloat src(float2(0.0f), m_size); if (parClip) { - const RectFloat clip(float2(0.0f), static_cast(m_sdlmain->WidthHeight())); + const RectFloat clip(float2(0.0f), vector_cast(m_sdlmain->WidthHeight())); const bool visible = ClipRect(src, dest, clip); if (not visible) return; } #if !defined(NDEBUG) else { - const RectFloat clip(float2(0.0f), static_cast(m_sdlmain->WidthHeight())); + const RectFloat clip(float2(0.0f), vector_cast(m_sdlmain->WidthHeight())); assert(IsRectCompletelyInsideRect(dest, clip)); } #endif diff --git a/src/tiledwallpaper.cpp b/src/tiledwallpaper.cpp index 5cf693d..f730baf 100644 --- a/src/tiledwallpaper.cpp +++ b/src/tiledwallpaper.cpp @@ -33,7 +33,7 @@ namespace cloonel { ///---------------------------------------------------------------------- float2 CountTilesInScreen (const ushort2& parScreenSize, const ushort2& parTileSize) { assert(ushort2(0) != parTileSize); - return static_cast((parTileSize - 1 + parScreenSize) / parTileSize); + return vector_cast((parTileSize - 1 + parScreenSize) / parTileSize); } } //unnamed namespace @@ -73,7 +73,7 @@ namespace cloonel { ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- void TiledWallpaper::Draw() const { - const ushort2 grid(static_cast(m_tileCount.tileCount())); + const ushort2 grid(vector_cast(m_tileCount.tileCount())); const float2& sz = m_tileCount.tileSize(); //TODO: add code to tell the renderer if the current tile will need clipping or not @@ -100,7 +100,7 @@ namespace cloonel { TiledWallpaper::TileCountNotifiable::TileCountNotifiable (SDLMain* parMain, const ushort2& parTileSize) : BaseClass(parMain), m_tileCount(CountTilesInScreen(parMain->WidthHeight(), parTileSize)), - m_tileSize(static_cast(parTileSize)) + m_tileSize(vector_cast(parTileSize)) #if defined(WITH_DEBUG_VISUALS) , m_screenRes(1.0f) #endif @@ -114,16 +114,16 @@ namespace cloonel { void TiledWallpaper::TileCountNotifiable::NotifyResChanged (const SizeRatio& parSize) { std::cout << "Autoregistering" << std::endl; BaseClass::NotifyResChanged(parSize); - m_tileCount = CountTilesInScreen(static_cast(parSize.Resolution()), static_cast(m_tileSize)); + m_tileCount = CountTilesInScreen(vector_cast(parSize.Resolution()), vector_cast(m_tileSize)); #if defined(WITH_DEBUG_VISUALS) m_screenRes = parSize.Resolution(); #endif #if !defined(NDEBUG) { m_screenRes = parSize.Resolution(); - const ushort2 tileSize(static_cast(m_tileSize)); - const ushort2 screenRes(static_cast(parSize.Resolution())); - const ushort2 tileCount(static_cast(m_tileCount)); + const ushort2 tileSize(vector_cast(m_tileSize)); + const ushort2 screenRes(vector_cast(parSize.Resolution())); + const ushort2 tileCount(vector_cast(m_tileCount)); assert(tileCount * tileSize < screenRes + tileSize); } #endif diff --git a/src/vectormath.hpp b/src/vectormath.hpp index 5f1a123..790e009 100644 --- a/src/vectormath.hpp +++ b/src/vectormath.hpp @@ -28,8 +28,6 @@ #include namespace cloonel { - template - typename std::common_type::type dot ( const Vector& parA, const Vector& parB ) a_pure; template Vector::type, 3> cross ( const Vector& parA, const Vector& parB ) a_pure; template diff --git a/src/vectormath.inl b/src/vectormath.inl index e82e37f..9716da0 100644 --- a/src/vectormath.inl +++ b/src/vectormath.inl @@ -18,17 +18,6 @@ */ namespace cloonel { - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - template - typename std::common_type::type dot (const Vector& parA, const Vector& parB) { - typename std::common_type::type retVal(0); - for (uint32_t z = 0; z < S; ++z) { - retVal += parA[z] * parB[z]; - } - return retVal; - } - ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template diff --git a/src/vectypes.hpp b/src/vectypes.hpp index 1b9f568..9ff09b3 100644 --- a/src/vectypes.hpp +++ b/src/vectypes.hpp @@ -128,14 +128,14 @@ namespace vwr { //make stuff from CloonelJump compile happily namespace cloonel { template - using Vect = ::vwr::Vec, S>; + using Vector = ::vwr::Vec, S>; - using ushort2 = Vect; + using ushort2 = Vector; #if !defined(NDEBUG) - using short2 = Vect; + using short2 = Vector; #endif - using float2 = Vect; - using int2 = Vect; + using float2 = Vector; + using int2 = Vector; using vwr::vector_cast; } //namespace cloonel