Cast vectors explicitly using vector_cast.

This commit is contained in:
King_DuckZ 2016-11-02 18:31:59 +01:00
parent 650f8d6de1
commit 68d179975e
11 changed files with 41 additions and 39 deletions

View file

@ -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<short2>(m_bottomBar.From()), static_cast<short2>(m_bottomBar.To()))
, m_bottomBarDrawable(parMain, Colour(250, 5, 1), vector_cast<short2>(m_bottomBar.From()), vector_cast<short2>(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<int2>(sdlmain->WidthHeight()));
m_texture->Reload();
}

View file

@ -34,7 +34,7 @@ namespace cloonel {
///----------------------------------------------------------------------
///----------------------------------------------------------------------
void ClipLine (const SDL_Rect& parArea, Line<int16_t, 2>& parLine) {
Line<float, 2> line(static_cast<float2>(parLine[0]), static_cast<float2>(parLine[1]));
Line<float, 2> line(vector_cast<float2>(parLine[0]), vector_cast<float2>(parLine[1]));
const float al = static_cast<float>(parArea.x);
const float at = static_cast<float>(parArea.y);
const float ar = static_cast<float>(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<short2>(parPos);
scaledLine += vector_cast<short2>(parPos);
scaledLine *= parScaling;
const short2 wh(static_cast<short2>(m_sdlmain->WidthHeight()));
const short2 wh(vector_cast<short2>(m_sdlmain->WidthHeight()));
{
SDL_Rect screen;
screen.x = screen.y = 0;

View file

@ -26,6 +26,18 @@
#include <ciso646>
#include <cstdint>
namespace vwr {
template <typename T>
struct VectorWrapperInfo<std::array<cloonel::Vector<T, 2>, 2>> {
enum { dimensions = 2 };
typedef cloonel::Vector<T, 2> scalar_type;
typedef std::array<scalar_type, dimensions> vector_type;
static scalar_type& get_at (uint32_t parIndex, vector_type& parVector) {
return parVector[parIndex];
}
};
} //namespace vwr
namespace cloonel {
template <typename T, uint32_t S>
class Line {

View file

@ -54,8 +54,11 @@ namespace cloonel {
template <typename T, uint32_t S>
template <typename U>
Line<T, S>& Line<T, S>::operator*= (const Vector<U, S>& parRhs) {
m_points.x() = static_cast<Point>(m_points.x() * parRhs);
m_points.y() = static_cast<Point>(m_points.y() * parRhs);
typedef typename std::common_type<U, T>::type CommonType;
typedef Vector<CommonType, S> CommVecType;
m_points.x() = vector_cast<Point>(vector_cast<CommVecType>(m_points.x()) * vector_cast<CommVecType>(parRhs));
m_points.y() = vector_cast<Point>(vector_cast<CommVecType>(m_points.y()) * vector_cast<CommVecType>(parRhs));
return *this;
}

View file

@ -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<short2>(parPos), static_cast<short2>(parPos + float2(parSize.x(), 0.0f)))
, m_collisionTopDrawable(parSdlMain, Colour(215, 181, 3), vector_cast<short2>(parPos), vector_cast<short2>(parPos + float2(parSize.x(), 0.0f)))
#endif
{
assert(m_surface);

View file

@ -89,7 +89,7 @@ namespace cloonel {
m_gameName(parGameName),
m_localData(new LocalData)
{
m_localData->sizeratio.SetOriginal(static_cast<float2>(parReferenceRes), static_cast<float2>(parRes));
m_localData->sizeratio.SetOriginal(vector_cast<float2>(parReferenceRes), vector_cast<float2>(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<float2>(parRes));
m_localData->sizeratio.UpdateResolution(vector_cast<float2>(parRes));
{
SDL_Renderer* const renderer = GetRenderer();
assert(renderer);
@ -225,7 +225,7 @@ namespace cloonel {
///------------------------------------------------------------------------
///------------------------------------------------------------------------
ushort2 SDLMain::WidthHeight() const noexcept {
return static_cast<ushort2>(m_localData->sizeratio.Resolution());
return vector_cast<ushort2>(m_localData->sizeratio.Resolution());
}
///------------------------------------------------------------------------

View file

@ -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<float2>(wh);
m_size = vector_cast<float2>(wh);
}
}
@ -369,14 +369,14 @@ namespace cloonel {
RectFloat src(float2(0.0f), m_size);
if (parClip) {
const RectFloat clip(float2(0.0f), static_cast<float2>(m_sdlmain->WidthHeight()));
const RectFloat clip(float2(0.0f), vector_cast<float2>(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<float2>(m_sdlmain->WidthHeight()));
const RectFloat clip(float2(0.0f), vector_cast<float2>(m_sdlmain->WidthHeight()));
assert(IsRectCompletelyInsideRect(dest, clip));
}
#endif

View file

@ -33,7 +33,7 @@ namespace cloonel {
///----------------------------------------------------------------------
float2 CountTilesInScreen (const ushort2& parScreenSize, const ushort2& parTileSize) {
assert(ushort2(0) != parTileSize);
return static_cast<float2>((parTileSize - 1 + parScreenSize) / parTileSize);
return vector_cast<float2>((parTileSize - 1 + parScreenSize) / parTileSize);
}
} //unnamed namespace
@ -73,7 +73,7 @@ namespace cloonel {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void TiledWallpaper::Draw() const {
const ushort2 grid(static_cast<ushort2>(m_tileCount.tileCount()));
const ushort2 grid(vector_cast<ushort2>(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<float2>(parTileSize))
m_tileSize(vector_cast<float2>(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<ushort2>(parSize.Resolution()), static_cast<ushort2>(m_tileSize));
m_tileCount = CountTilesInScreen(vector_cast<ushort2>(parSize.Resolution()), vector_cast<ushort2>(m_tileSize));
#if defined(WITH_DEBUG_VISUALS)
m_screenRes = parSize.Resolution();
#endif
#if !defined(NDEBUG)
{
m_screenRes = parSize.Resolution();
const ushort2 tileSize(static_cast<ushort2>(m_tileSize));
const ushort2 screenRes(static_cast<ushort2>(parSize.Resolution()));
const ushort2 tileCount(static_cast<ushort2>(m_tileCount));
const ushort2 tileSize(vector_cast<ushort2>(m_tileSize));
const ushort2 screenRes(vector_cast<ushort2>(parSize.Resolution()));
const ushort2 tileCount(vector_cast<ushort2>(m_tileCount));
assert(tileCount * tileSize < screenRes + tileSize);
}
#endif

View file

@ -28,8 +28,6 @@
#include <cassert>
namespace cloonel {
template <typename T, typename U, uint32_t S>
typename std::common_type<T, U>::type dot ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U>
Vector<typename std::common_type<T, U>::type, 3> cross ( const Vector<T, 3>& parA, const Vector<U, 3>& parB ) a_pure;
template <typename T, uint32_t S>

View file

@ -18,17 +18,6 @@
*/
namespace cloonel {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename T, typename U, uint32_t S>
typename std::common_type<T, U>::type dot (const Vector<T, S>& parA, const Vector<U, S>& parB) {
typename std::common_type<T, U>::type retVal(0);
for (uint32_t z = 0; z < S; ++z) {
retVal += parA[z] * parB[z];
}
return retVal;
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename T, typename U>

View file

@ -128,14 +128,14 @@ namespace vwr {
//make stuff from CloonelJump compile happily
namespace cloonel {
template <typename T, uint32_t S>
using Vect = ::vwr::Vec<std::array<T, std::size_t(S)>, S>;
using Vector = ::vwr::Vec<std::array<T, std::size_t(S)>, S>;
using ushort2 = Vect<uint16_t, 2>;
using ushort2 = Vector<uint16_t, 2>;
#if !defined(NDEBUG)
using short2 = Vect<int16_t, 2>;
using short2 = Vector<int16_t, 2>;
#endif
using float2 = Vect<float, 2>;
using int2 = Vect<int32_t, 2>;
using float2 = Vector<float, 2>;
using int2 = Vector<int32_t, 2>;
using vwr::vector_cast;
} //namespace cloonel