From 650f8d6de1ccdc9dd09351d2771aafdcd993ba59 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 2 Nov 2016 18:25:40 +0100 Subject: [PATCH] Replace vector.hpp with vectorwrapper --- .gitmodules | 3 + CMakeLists.txt | 6 + lib/vectorwrapper | 1 + src/character.hpp | 2 +- src/collider.cpp | 3 +- src/drawable.hpp | 2 +- src/geometry.hpp | 2 +- src/geometry_2d.hpp | 2 +- src/horzcollisionbar.hpp | 2 +- src/line.hpp | 4 +- src/line_helpers.hpp | 2 +- src/main.cpp | 2 +- src/movers/mover.hpp | 2 +- src/movers/moveroneshot.hpp | 2 +- src/placeable.hpp | 2 +- src/platformset.hpp | 2 +- src/sdlmain.hpp | 2 +- src/sizenotifiable.hpp | 2 +- src/sizeratio.hpp | 2 +- src/texture.hpp | 2 +- src/vector.hpp | 219 ------------------------------- src/vector.inl | 252 ------------------------------------ src/vectormath.hpp | 2 +- src/vectorprettyprint.hpp | 44 ------- src/vectypes.hpp | 145 +++++++++++++++++++++ 25 files changed, 175 insertions(+), 534 deletions(-) create mode 100644 .gitmodules create mode 160000 lib/vectorwrapper delete mode 100644 src/vector.hpp delete mode 100644 src/vector.inl delete mode 100644 src/vectorprettyprint.hpp create mode 100644 src/vectypes.hpp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a65741a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/vectorwrapper"] + path = lib/vectorwrapper + url = https://github.com/KingDuckZ/vectorwrapper.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c4311d4..de6899d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ include_directories( include "${PROJECT_BINARY_DIR}" ${PHYSFS_INCLUDE_DIR} + lib/vectorwrapper/include ) configure_file( @@ -128,6 +129,11 @@ target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES} ) +target_compile_definitions(${PROJECT_NAME} + PRIVATE VWR_STATIC_CAST_RESULTS + PRIVATE VWR_SIZE_TYPE=uint32_t +) + if (RASPBERRY_PI) target_link_libraries(${PROJECT_NAME} bcm_host diff --git a/lib/vectorwrapper b/lib/vectorwrapper new file mode 160000 index 0000000..0047029 --- /dev/null +++ b/lib/vectorwrapper @@ -0,0 +1 @@ +Subproject commit 00470290fe404e2977882917a4cf4197124256b5 diff --git a/src/character.hpp b/src/character.hpp index e2c5143..c2958c3 100644 --- a/src/character.hpp +++ b/src/character.hpp @@ -23,7 +23,7 @@ #include "placeable.hpp" #include "drawable.hpp" #include "drawableset.hpp" -#include "vector.hpp" +#include "vectypes.hpp" #include "sizenotifiable.hpp" #include "horzcollisionbar.hpp" #include "collidertypedef.hpp" diff --git a/src/collider.cpp b/src/collider.cpp index 326de75..120d46f 100644 --- a/src/collider.cpp +++ b/src/collider.cpp @@ -20,8 +20,9 @@ #include "collider.hpp" #include "horzcollisionbar.hpp" #include "line.hpp" -#include "vector.hpp" +#include "vectypes.hpp" #include "collisionbarset.hpp" +#include "vectorwrapper/vectorops.hpp" #include "vectormath.hpp" #include #include diff --git a/src/drawable.hpp b/src/drawable.hpp index 12b1bda..ae32aeb 100644 --- a/src/drawable.hpp +++ b/src/drawable.hpp @@ -20,7 +20,7 @@ #ifndef idC5A880D06A03407DB4E9FC21593A47FB #define idC5A880D06A03407DB4E9FC21593A47FB -#include "vector.hpp" +#include "vectypes.hpp" namespace cloonel { class SDLMain; diff --git a/src/geometry.hpp b/src/geometry.hpp index 2260951..731f123 100644 --- a/src/geometry.hpp +++ b/src/geometry.hpp @@ -20,7 +20,7 @@ #ifndef id3E40B29606D048569E18083DB682280F #define id3E40B29606D048569E18083DB682280F -#include "vector.hpp" +#include "vectypes.hpp" #include "compatibility.h" #include #include diff --git a/src/geometry_2d.hpp b/src/geometry_2d.hpp index 0c5b807..e327aa9 100644 --- a/src/geometry_2d.hpp +++ b/src/geometry_2d.hpp @@ -17,7 +17,7 @@ along with CloonelJump. If not, see . */ -#include "vector.hpp" +#include "vectypes.hpp" #include "line.hpp" #include "geometry.hpp" #include "compatibility.h" diff --git a/src/horzcollisionbar.hpp b/src/horzcollisionbar.hpp index 8087b5f..81ead6c 100644 --- a/src/horzcollisionbar.hpp +++ b/src/horzcollisionbar.hpp @@ -20,7 +20,7 @@ #ifndef id202E39A912AA43E5A224AC77D676F6CA #define id202E39A912AA43E5A224AC77D676F6CA -#include "vector.hpp" +#include "vectypes.hpp" #include "placeable.hpp" #include "line.hpp" #include "compatibility.h" diff --git a/src/line.hpp b/src/line.hpp index 440d1bc..ffe5922 100644 --- a/src/line.hpp +++ b/src/line.hpp @@ -21,8 +21,8 @@ #define id56F112C6551D44039D0C0270F573B35B #include "compatibility.h" -#include "vector.hpp" -#include "vectormath.hpp" +#include "vectypes.hpp" +#include "vectorwrapper/vectorops.hpp" #include #include diff --git a/src/line_helpers.hpp b/src/line_helpers.hpp index 9d45043..a64fd30 100644 --- a/src/line_helpers.hpp +++ b/src/line_helpers.hpp @@ -20,7 +20,7 @@ #ifndef idDF0B3D1FA4714EF3AB1241C3DA0D4E3D #define idDF0B3D1FA4714EF3AB1241C3DA0D4E3D -#include "vector.hpp" +#include "vectypes.hpp" #include "line.hpp" #include "compatibility.h" #include diff --git a/src/main.cpp b/src/main.cpp index 5fe901e..efc08f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ #include "sdlmain.hpp" #include "physicsfswrapper.hpp" #include "gameplaysceneclassic.hpp" -#include "vector.hpp" +#include "vectypes.hpp" #include "casts.hpp" #include #include diff --git a/src/movers/mover.hpp b/src/movers/mover.hpp index 5e3e7d8..012be08 100644 --- a/src/movers/mover.hpp +++ b/src/movers/mover.hpp @@ -20,7 +20,7 @@ #ifndef id20409B43E62B4247A278B413D1114896 #define id20409B43E62B4247A278B413D1114896 -#include "vector.hpp" +#include "vectypes.hpp" #include "observersmanager.hpp" #include diff --git a/src/movers/moveroneshot.hpp b/src/movers/moveroneshot.hpp index 888472a..cb1c444 100644 --- a/src/movers/moveroneshot.hpp +++ b/src/movers/moveroneshot.hpp @@ -26,7 +26,7 @@ //For example issuing 1, then 2 will put your Placeable in position 3, //assuming it started at 0. -#include "vector.hpp" +#include "vectypes.hpp" #include "mover.hpp" namespace cloonel { diff --git a/src/placeable.hpp b/src/placeable.hpp index 3a870a2..6f0e028 100644 --- a/src/placeable.hpp +++ b/src/placeable.hpp @@ -20,7 +20,7 @@ #ifndef id703E4B8DFFF747DFA97864384B87E9C1 #define id703E4B8DFFF747DFA97864384B87E9C1 -#include "vector.hpp" +#include "vectypes.hpp" #include "mover.hpp" namespace cloonel { diff --git a/src/platformset.hpp b/src/platformset.hpp index e2838bb..709488f 100644 --- a/src/platformset.hpp +++ b/src/platformset.hpp @@ -23,7 +23,7 @@ #include "collisionbarset.hpp" #include "drawableset.hpp" -#include "vector.hpp" +#include "vectypes.hpp" #include #include diff --git a/src/sdlmain.hpp b/src/sdlmain.hpp index dc05b8c..4cd56ee 100644 --- a/src/sdlmain.hpp +++ b/src/sdlmain.hpp @@ -20,7 +20,7 @@ #ifndef id8E7A054DAC9040B887F2620EFD229EE8 #define id8E7A054DAC9040B887F2620EFD229EE8 -#include "vector.hpp" +#include "vectypes.hpp" #include #include diff --git a/src/sizenotifiable.hpp b/src/sizenotifiable.hpp index 132cf34..7ef2d86 100644 --- a/src/sizenotifiable.hpp +++ b/src/sizenotifiable.hpp @@ -20,7 +20,7 @@ #ifndef id78906DE4FB0D43219CD3F0D9C620FC06 #define id78906DE4FB0D43219CD3F0D9C620FC06 -#include "vector.hpp" +#include "vectypes.hpp" #include #include diff --git a/src/sizeratio.hpp b/src/sizeratio.hpp index 6e0cc4f..6135f95 100644 --- a/src/sizeratio.hpp +++ b/src/sizeratio.hpp @@ -20,7 +20,7 @@ #ifndef id3098F08C14B84E3C8CE169CBA05C9C86 #define id3098F08C14B84E3C8CE169CBA05C9C86 -#include "vector.hpp" +#include "vectypes.hpp" namespace cloonel { class SizeRatio { diff --git a/src/texture.hpp b/src/texture.hpp index 73534b5..a9837eb 100644 --- a/src/texture.hpp +++ b/src/texture.hpp @@ -20,7 +20,7 @@ #ifndef id0F37904CB7274575B7E9419E615DA250 #define id0F37904CB7274575B7E9419E615DA250 -#include "vector.hpp" +#include "vectypes.hpp" #include struct SDL_Texture; diff --git a/src/vector.hpp b/src/vector.hpp deleted file mode 100644 index af20053..0000000 --- a/src/vector.hpp +++ /dev/null @@ -1,219 +0,0 @@ -/* - Copyright 2014 Michele "King_DuckZ" Santullo - - This file is part of CloonelJump. - - CloonelJump is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - CloonelJump is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with CloonelJump. If not, see . -*/ - -#ifndef idid0528646832E04CF08E9785B66CFE0BD1 -#define idid0528646832E04CF08E9785B66CFE0BD1 - -#include "compatibility.h" -#include -#include -#include -#include -#include - -#if !defined(NDEBUG) -#include -#endif - -#if defined(__INTEL_COMPILER) -# define DONT_GUESS_NOEXCEPT -#endif - -namespace cloonel { - template - class Vector { - template friend class Vector; - public: -#if defined(DONT_GUESS_NOEXCEPT) - Vector ( void ) = default; - explicit Vector ( T parValue ); - template explicit Vector ( const Vector& parOther ); -#else - Vector ( void ) noexcept(noexcept(T())) = default; - explicit Vector ( T parValue ) noexcept(noexcept(T()) && noexcept(parValue=parValue)); - template explicit Vector ( const Vector& parOther ) noexcept(noexcept(T()) && noexcept(const_cast(parOther.m_mem[0])=T())); -#endif - template > Vector ( T parX, T parY ) noexcept : m_mem {parX, parY} {} - template > Vector ( T parX, T parY, T parZ ) noexcept : m_mem {parX, parY, parZ} {} - template > Vector ( T parX, T parY, T parZ, T parW ) noexcept : m_mem {parX, parY, parZ, parW} {} - - ~Vector ( void ) noexcept = default; - - enum { - Dimension = S - }; - - template = S> > T& x ( void ) { return m_mem[0]; } - template = S> > const T& x ( void ) const { return m_mem[0]; } - template = 2 and 4 >= S> > T& y ( void ) { return m_mem[1]; } - template = 2 and 4 >= S> > const T& y ( void ) const { return m_mem[1]; } - template = 3 and 4 >= S> > T& z ( void ) { return m_mem[2]; } - template = 3 and 4 >= S> > const T& z ( void ) const { return m_mem[2]; } - template = 4 and 4 >= S> > T& w ( void ) { return m_mem[3]; } - template = 4 and 4 >= S> > const T& w ( void ) const { return m_mem[3]; } - - template const Vector& operator+= ( const Vector& parOther ); - template const Vector& operator-= ( const Vector& parOther ); - template const Vector& operator*= ( const Vector& parOther ); - template const Vector& operator/= ( const Vector& parOther ); - template const Vector& operator+= ( U parOther ); - template const Vector& operator-= ( U parOther ); - template const Vector& operator*= ( U parOther ); - template const Vector& operator/= ( U parOther ); - - T& operator[] ( uint32_t parIndex ) { assert(parIndex < S); return m_mem[parIndex]; } - const T& operator[] ( uint32_t parIndex ) const { assert(parIndex < S); return m_mem[parIndex]; } - - private: - T m_mem[S]; - }; - - template - Vector::type, S> operator+ ( const Vector& parA, const Vector& parB ) a_pure; - template - Vector::type, S> operator- ( const Vector& parA, const Vector& parB ) a_pure; - template - Vector::type, S> operator* ( const Vector& parA, const Vector& parB ) a_pure; - template - Vector::type, S> operator/ ( const Vector& parA, const Vector& parB ) a_pure; - template ::value>::type> - Vector::type, S> operator+ ( U parA, const Vector& parB ) a_pure; - template ::value>::type> - Vector::type, S> operator- ( U parA, const Vector& parB ) a_pure; - template ::value>::type> - Vector::type, S> operator* ( U parA, const Vector& parB ) a_pure; - template ::value>::type> - Vector::type, S> operator/ ( U parA, const Vector& parB ) a_pure; - template ::value>::type> - Vector::type, S> operator+ ( const Vector& parA, U parB ) a_pure; - template ::value>::type> - Vector::type, S> operator- ( const Vector& parA, U parB ) a_pure; - template ::value>::type> - Vector::type, S> operator* ( const Vector& parA, U parB ) a_pure; - template ::value>::type> - Vector::type, S> operator/ ( const Vector& parA, U parB ) a_pure; - - template - bool operator< ( const Vector& parA, const Vector& parB ) a_pure; - template - bool operator> ( const Vector& parA, const Vector& parB ) a_pure; - template - bool operator<= ( const Vector& parA, const Vector& parB ) a_pure; - template - bool operator>= ( const Vector& parA, const Vector& parB ) a_pure; - template - bool operator== ( const Vector& parA, const Vector& parB ) a_pure; - template - bool operator!= ( const Vector& parA, const Vector& parB ) a_pure; - - template - Vector operator- ( Vector parOperand ) a_pure; - - typedef Vector float2; - typedef Vector ushort2; -#if !defined(NDEBUG) - typedef Vector short2; -#endif - typedef Vector int2; - -#if !defined(NDEBUG) - template - std::ostream& operator<< ( std::ostream& parStream, const Vector& parVector ) { - parStream << "<"; - for (uint32_t z = 0; z < S - 1; ++z) { - parStream << parVector[z] << ","; - } - parStream << parVector[S - 1] << ">"; - return parStream; - } -#endif - - namespace implem { - template - struct CategorizeTypes { - typedef typename std::common_type::type CommonType; - typedef typename std::conditional::value, U, T>::type OtherType; - }; - template ::value> - struct DoOperation { - static Vector do_mul ( Vector parLho, const Vector& parRho ) { - parLho *= parRho; - return parLho; - } - static Vector do_div ( Vector parLho, const Vector& parRho ) { - parLho /= parRho; - return parLho; - } - static Vector do_sum ( Vector parLho, const Vector& parRho ) { - parLho += parRho; - return parLho; - } - static Vector do_sub ( Vector parLho, const Vector& parRho ) { - parLho -= parRho; - return parLho; - } - }; - template - struct DoOperation { - static Vector do_mul ( Vector parLho, const Vector& parRho ) { - parLho *= parRho; - return parLho; - } - static Vector do_mul ( const Vector& parLho, const Vector& parRho ) { - Vector ret(parLho); - ret *= parRho; - return ret; - } - static Vector do_div ( Vector parLho, const Vector& parRho ) { - parLho /= parRho; - return parLho; - } - static Vector do_div ( const Vector& parLho, const Vector& parRho ) { - Vector ret(parLho); - ret /= parRho; - return ret; - } - static Vector do_sum ( Vector parLho, const Vector& parRho ) { - parLho += parRho; - return parLho; - } - static Vector do_sum ( const Vector& parLho, const Vector& parRho ) { - Vector ret(parLho); - ret += parRho; - return ret; - } - static Vector do_sub ( Vector parLho, const Vector& parRho ) { - parLho -= parRho; - return parLho; - } - static Vector do_sub ( const Vector& parLho, const Vector& parRho ) { - Vector ret(parLho); - ret -= parRho; - return ret; - } - }; - } //namespace implem -} //namespace cloonel -#include "vector.inl" - -#if defined(DONT_GUESS_NOEXCEPT) -#undef DONT_GUESS_NOEXCEPT -#endif - -#endif diff --git a/src/vector.inl b/src/vector.inl deleted file mode 100644 index e79741d..0000000 --- a/src/vector.inl +++ /dev/null @@ -1,252 +0,0 @@ -/* - Copyright 2014 Michele "King_DuckZ" Santullo - - This file is part of CloonelJump. - - CloonelJump is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - CloonelJump is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with CloonelJump. If not, see . -*/ - -namespace cloonel { - ///------------------------------------------------------------------------- - ///------------------------------------------------------------------------- - template -#if defined(DONT_GUESS_NOEXCEPT) - Vector::Vector (T parValue) { -#else - Vector::Vector (T parValue) noexcept(noexcept(T()) && noexcept(parValue=parValue)) { -#endif - std::fill(m_mem, m_mem + S, parValue); - } - - ///------------------------------------------------------------------------- - ///------------------------------------------------------------------------- - template - template -#if defined(DONT_GUESS_NOEXCEPT) - Vector::Vector (const Vector& parOther) { -#else - Vector::Vector (const Vector& parOther) noexcept(noexcept(T()) && noexcept(const_cast(parOther.m_mem[0])=T())) { -#endif - std::copy(parOther.m_mem, parOther.m_mem + S, m_mem); - } - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" - ///------------------------------------------------------------------------- - ///------------------------------------------------------------------------- - template - template - const Vector& Vector::operator+= (const Vector& parOther) { - for (uint32_t z = 0; z < S; ++z) { - m_mem[z] += parOther.m_mem[z]; - } - return *this; - } - template - template - const Vector& Vector::operator-= (const Vector& parOther) { - for (uint32_t z = 0; z < S; ++z) { - m_mem[z] -= parOther.m_mem[z]; - } - return *this; - } - template - template - const Vector& Vector::operator*= (const Vector& parOther) { - for (uint32_t z = 0; z < S; ++z) { - m_mem[z] *= parOther.m_mem[z]; - } - return *this; - } - template - template - const Vector& Vector::operator/= (const Vector& parOther) { - for (uint32_t z = 0; z < S; ++z) { - m_mem[z] /= parOther.m_mem[z]; - } - return *this; - } -#pragma GCC diagnostic pop - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" - ///------------------------------------------------------------------------- - ///------------------------------------------------------------------------- - template - template - const Vector& Vector::operator+= (U parOther) { - for (uint32_t z = 0; z < S; ++z) { - m_mem[z] += parOther; - } - return *this; - } - template - template - const Vector& Vector::operator-= (U parOther) { - for (uint32_t z = 0; z < S; ++z) { - m_mem[z] -= parOther; - } - return *this; - } - template - template - const Vector& Vector::operator*= (U parOther) { - for (uint32_t z = 0; z < S; ++z) { - m_mem[z] *= parOther; - } - return *this; - } - template - template - const Vector& Vector::operator/= (U parOther) { - for (uint32_t z = 0; z < S; ++z) { - m_mem[z] /= parOther; - } - return *this; - } -#pragma GCC diagnostic pop - - ///------------------------------------------------------------------------- - ///------------------------------------------------------------------------- - template - inline - Vector::type, S> operator+ (const Vector& parA, const Vector& parB) { - return implem::DoOperation, S>::do_sum(parA, parB); - } - template - inline - Vector::type, S> operator- (const Vector& parA, const Vector& parB) { - return implem::DoOperation, S>::do_sub(parA, parB); - } - template - inline - Vector::type, S> operator* (const Vector& parA, const Vector& parB) { - return implem::DoOperation, S>::do_mul(parA, parB); - } - template - inline - Vector::type, S> operator/ (const Vector& parA, const Vector& parB) { - return implem::DoOperation, S>::do_div(parA, parB); - } - - ///------------------------------------------------------------------------- - ///------------------------------------------------------------------------- - template - Vector::type, S> operator+ (U parA, const Vector& parB) { - return parB + parA; - } - template - Vector::type, S> operator- (U parA, const Vector& parB) { - return Vector(parA) - parB; - } - template - Vector::type, S> operator* (U parA, const Vector& parB) { - return parB * parA; - } - template - Vector::type, S> operator/ (U parA, const Vector& parB) { - return Vector(parA) / parB; - } - template - Vector::type, S> operator+ (const Vector& parA, U parB) { - typedef typename std::common_type::type RetType; - Vector retVal; - for (uint32_t z = 0; z < S; ++z) { - retVal[z] = parA[z] + parB; - } - return retVal; - } - template - Vector::type, S> operator- (const Vector& parA, U parB) { - typedef typename std::common_type::type RetType; - Vector retVal; - for (uint32_t z = 0; z < S; ++z) { - retVal[z] = parA[z] - parB; - } - return retVal; - } - template - Vector::type, S> operator* (const Vector& parA, U parB) { - typedef typename std::common_type::type RetType; - Vector retVal; - for (uint32_t z = 0; z < S; ++z) { - retVal[z] = parA[z] * parB; - } - return retVal; - } - template - Vector::type, S> operator/ (const Vector& parA, U parB) { - typedef typename std::common_type::type RetType; - Vector retVal; - for (uint32_t z = 0; z < S; ++z) { - retVal[z] = parA[z] / parB; - } - return retVal; - } - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - template - inline bool operator< (const Vector& parA, const Vector& parB) { - bool retVal = true; - for (uint32_t z = 0; z < S; ++z) { - retVal &= static_cast(parA[z] < parB[z]); - } - return retVal; - } - template - inline bool operator> (const Vector& parA, const Vector& parB) { - bool retVal = true; - for (uint32_t z = 0; z < S; ++z) { - retVal &= static_cast(parA[z] > parB[z]); - } - return retVal; - } - template - inline bool operator<= (const Vector& parA, const Vector& parB) { - bool retVal = true; - for (uint32_t z = 0; z < S; ++z) { - retVal &= static_cast(parA[z] <= parB[z]); - } - return retVal; - } - template - inline bool operator>= (const Vector& parA, const Vector& parB) { - bool retVal = true; - for (uint32_t z = 0; z < S; ++z) { - retVal &= static_cast(parA[z] >= parB[z]); - } - return retVal; - } - template - inline bool operator== (const Vector& parA, const Vector& parB) { - bool retVal = true; - for (uint32_t z = 0; z < S; ++z) { - retVal &= static_cast(parA[z] == parB[z]); - } - return retVal; - } - template - inline bool operator!= (const Vector& parA, const Vector& parB) { - return not operator==(parA, parB); - } - - template - Vector operator- (Vector parOperand) { - for (uint32_t z = 0; z < S; ++z) { - parOperand[z] = -parOperand[z]; - } - return parOperand; - } -} //namespace cloonel diff --git a/src/vectormath.hpp b/src/vectormath.hpp index c79d2ca..5f1a123 100644 --- a/src/vectormath.hpp +++ b/src/vectormath.hpp @@ -20,7 +20,7 @@ #ifndef id5DB098DAA5534A0A869DEF23888F96B0 #define id5DB098DAA5534A0A869DEF23888F96B0 -#include "vector.hpp" +#include "vectypes.hpp" #include "compatibility.h" #include #include diff --git a/src/vectorprettyprint.hpp b/src/vectorprettyprint.hpp deleted file mode 100644 index ee193db..0000000 --- a/src/vectorprettyprint.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright 2014 Michele "King_DuckZ" Santullo - - This file is part of CloonelJump. - - CloonelJump is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - CloonelJump is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with CloonelJump. If not, see . -*/ - -#ifndef idE31BEAEB229149038D67C6CF370AEEC9 -#define idE31BEAEB229149038D67C6CF370AEEC9 - -#include "vector.hpp" - -#if !defined(NDEBUG) -#include -#endif - -namespace cloonel { -#if !defined(NDEBUG) - template - inline std::ostream& operator<< (std::ostream& parOStream, const Vector& parVec) { - parOStream << "<"; - for (uint32_t z = 0; z < S - 1; ++z) { - parOStream << parVec[z] << ", "; - } - parOStream << parVec[S - 1] << ">"; - return parOStream; - } - -#endif -} //namespace cloonel - -#endif diff --git a/src/vectypes.hpp b/src/vectypes.hpp new file mode 100644 index 0000000..1b9f568 --- /dev/null +++ b/src/vectypes.hpp @@ -0,0 +1,145 @@ +/* + Copyright 2016 Michele "King_DuckZ" Santullo + + This file is part of CloonelJump. + + CloonelJump is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + CloonelJump is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with CloonelJump. If not, see . +*/ + +#ifndef id7155F721B70C41B383896327C7D07E30 +#define id7155F721B70C41B383896327C7D07E30 + +#include "vectorwrapper/vectorwrapper.hpp" +#include "vectorwrapper/vector_cast.hpp" +#include "compatibility.h" +#include +#include +#if !defined(NDEBUG) +# include +#endif +#include + +#define SPECIALIZE_ARRAY_VECTOR(TYPE, DIM) \ + template <> \ + struct VectorWrapperInfo> { \ + enum { dimensions = DIM }; \ + typedef TYPE scalar_type; \ + typedef std::array vector_type; \ + static scalar_type& get_at (uint32_t parIndex, vector_type& parVector) { \ + return parVector[parIndex]; \ + } \ + } + +namespace vwr { + SPECIALIZE_ARRAY_VECTOR(float, 2); + SPECIALIZE_ARRAY_VECTOR(uint16_t, 2); +#if !defined(NDEBUG) + SPECIALIZE_ARRAY_VECTOR(int16_t, 2); +#endif + SPECIALIZE_ARRAY_VECTOR(int32_t, 2); + +#if !defined(NDEBUG) + template + std::ostream& operator<< (std::ostream& parStream, const Vec& parVec) { + parStream << '<'; + for (uint32_t z = 0; z < Vec::dimensions - 1; ++z) { + std::cout << parVec[z] << ", "; + } + std::cout << parVec[Vec::dimensions - 1] << '>'; + return parStream; + } +#endif + + template + Vec operator+ (Vec parLeft, typename VectorWrapperInfo::scalar_type parRight) a_pure; + template + Vec operator- (Vec parLeft, typename VectorWrapperInfo::scalar_type parRight) a_pure; + template + Vec operator* (Vec parLeft, typename VectorWrapperInfo::scalar_type parRight) a_pure; + template + Vec operator/ (Vec parLeft, typename VectorWrapperInfo::scalar_type parRight) a_pure; + template + Vec operator+ (typename VectorWrapperInfo::scalar_type parLeft, Vec parRight) a_pure; + template + Vec operator* (typename VectorWrapperInfo::scalar_type parLeft, Vec parRight) a_pure; + + template + inline + Vec operator+ (Vec parLeft, typename VectorWrapperInfo::scalar_type parRight) { + for (uint32_t z = 0; z < Vec::dimensions; ++z) { + parLeft[z] += parRight; + } + return parLeft; + } + template + inline + Vec operator- (Vec parLeft, typename VectorWrapperInfo::scalar_type parRight) { + for (uint32_t z = 0; z < Vec::dimensions; ++z) { + parLeft[z] -= parRight; + } + return parLeft; + } + template + inline + Vec operator* (Vec parLeft, typename VectorWrapperInfo::scalar_type parRight) { + for (uint32_t z = 0; z < Vec::dimensions; ++z) { + parLeft[z] *= parRight; + } + return parLeft; + } + template + inline + Vec operator/ (Vec parLeft, typename VectorWrapperInfo::scalar_type parRight) { + for (uint32_t z = 0; z < Vec::dimensions; ++z) { + parLeft[z] /= parRight; + } + return parLeft; + } + + template + inline + Vec operator+ (typename VectorWrapperInfo::scalar_type parLeft, Vec parRight) { + for (uint32_t z = 0; z < Vec::dimensions; ++z) { + parRight[z] += parLeft; + } + return parRight; + } + template + inline + Vec operator* (typename VectorWrapperInfo::scalar_type parLeft, Vec parRight) { + for (uint32_t z = 0; z < Vec::dimensions; ++z) { + parRight[z] *= parLeft; + } + return parRight; + } +} //namespace vwr + +//make stuff from CloonelJump compile happily +namespace cloonel { + template + using Vect = ::vwr::Vec, S>; + + using ushort2 = Vect; +#if !defined(NDEBUG) + using short2 = Vect; +#endif + using float2 = Vect; + using int2 = Vect; + + using vwr::vector_cast; +} //namespace cloonel + +#undef SPECIALIZE_ARRAY_VECTOR + +#endif