Replace vector.hpp with vectorwrapper

This commit is contained in:
King_DuckZ 2016-11-02 18:25:40 +01:00
parent e64b53f8d0
commit 650f8d6de1
25 changed files with 175 additions and 534 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "lib/vectorwrapper"]
path = lib/vectorwrapper
url = https://github.com/KingDuckZ/vectorwrapper.git

View file

@ -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

1
lib/vectorwrapper Submodule

@ -0,0 +1 @@
Subproject commit 00470290fe404e2977882917a4cf4197124256b5

View file

@ -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"

View file

@ -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 <vector>
#include <ciso646>

View file

@ -20,7 +20,7 @@
#ifndef idC5A880D06A03407DB4E9FC21593A47FB
#define idC5A880D06A03407DB4E9FC21593A47FB
#include "vector.hpp"
#include "vectypes.hpp"
namespace cloonel {
class SDLMain;

View file

@ -20,7 +20,7 @@
#ifndef id3E40B29606D048569E18083DB682280F
#define id3E40B29606D048569E18083DB682280F
#include "vector.hpp"
#include "vectypes.hpp"
#include "compatibility.h"
#include <ciso646>
#include <algorithm>

View file

@ -17,7 +17,7 @@
along with CloonelJump. If not, see <http://www.gnu.org/licenses/>.
*/
#include "vector.hpp"
#include "vectypes.hpp"
#include "line.hpp"
#include "geometry.hpp"
#include "compatibility.h"

View file

@ -20,7 +20,7 @@
#ifndef id202E39A912AA43E5A224AC77D676F6CA
#define id202E39A912AA43E5A224AC77D676F6CA
#include "vector.hpp"
#include "vectypes.hpp"
#include "placeable.hpp"
#include "line.hpp"
#include "compatibility.h"

View file

@ -21,8 +21,8 @@
#define id56F112C6551D44039D0C0270F573B35B
#include "compatibility.h"
#include "vector.hpp"
#include "vectormath.hpp"
#include "vectypes.hpp"
#include "vectorwrapper/vectorops.hpp"
#include <ciso646>
#include <cstdint>

View file

@ -20,7 +20,7 @@
#ifndef idDF0B3D1FA4714EF3AB1241C3DA0D4E3D
#define idDF0B3D1FA4714EF3AB1241C3DA0D4E3D
#include "vector.hpp"
#include "vectypes.hpp"
#include "line.hpp"
#include "compatibility.h"
#include <cmath>

View file

@ -21,7 +21,7 @@
#include "sdlmain.hpp"
#include "physicsfswrapper.hpp"
#include "gameplaysceneclassic.hpp"
#include "vector.hpp"
#include "vectypes.hpp"
#include "casts.hpp"
#include <iostream>
#include <stdexcept>

View file

@ -20,7 +20,7 @@
#ifndef id20409B43E62B4247A278B413D1114896
#define id20409B43E62B4247A278B413D1114896
#include "vector.hpp"
#include "vectypes.hpp"
#include "observersmanager.hpp"
#include <unordered_set>

View file

@ -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 {

View file

@ -20,7 +20,7 @@
#ifndef id703E4B8DFFF747DFA97864384B87E9C1
#define id703E4B8DFFF747DFA97864384B87E9C1
#include "vector.hpp"
#include "vectypes.hpp"
#include "mover.hpp"
namespace cloonel {

View file

@ -23,7 +23,7 @@
#include "collisionbarset.hpp"
#include "drawableset.hpp"
#include "vector.hpp"
#include "vectypes.hpp"
#include <list>
#include <boost/circular_buffer.hpp>

View file

@ -20,7 +20,7 @@
#ifndef id8E7A054DAC9040B887F2620EFD229EE8
#define id8E7A054DAC9040B887F2620EFD229EE8
#include "vector.hpp"
#include "vectypes.hpp"
#include <memory>
#include <string>

View file

@ -20,7 +20,7 @@
#ifndef id78906DE4FB0D43219CD3F0D9C620FC06
#define id78906DE4FB0D43219CD3F0D9C620FC06
#include "vector.hpp"
#include "vectypes.hpp"
#include <cstddef>
#include <algorithm>

View file

@ -20,7 +20,7 @@
#ifndef id3098F08C14B84E3C8CE169CBA05C9C86
#define id3098F08C14B84E3C8CE169CBA05C9C86
#include "vector.hpp"
#include "vectypes.hpp"
namespace cloonel {
class SizeRatio {

View file

@ -20,7 +20,7 @@
#ifndef id0F37904CB7274575B7E9419E615DA250
#define id0F37904CB7274575B7E9419E615DA250
#include "vector.hpp"
#include "vectypes.hpp"
#include <string>
struct SDL_Texture;

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef idid0528646832E04CF08E9785B66CFE0BD1
#define idid0528646832E04CF08E9785B66CFE0BD1
#include "compatibility.h"
#include <cstdint>
#include <ciso646>
#include <type_traits>
#include <algorithm>
#include <cassert>
#if !defined(NDEBUG)
#include <iostream>
#endif
#if defined(__INTEL_COMPILER)
# define DONT_GUESS_NOEXCEPT
#endif
namespace cloonel {
template <typename T, uint32_t S>
class Vector {
template <typename U, uint32_t R> friend class Vector;
public:
#if defined(DONT_GUESS_NOEXCEPT)
Vector ( void ) = default;
explicit Vector ( T parValue );
template <typename U> explicit Vector ( const Vector<U, S>& parOther );
#else
Vector ( void ) noexcept(noexcept(T())) = default;
explicit Vector ( T parValue ) noexcept(noexcept(T()) && noexcept(parValue=parValue));
template <typename U> explicit Vector ( const Vector<U, S>& parOther ) noexcept(noexcept(T()) && noexcept(const_cast<U&>(parOther.m_mem[0])=T()));
#endif
template <typename = std::enable_if<S == 2> > Vector ( T parX, T parY ) noexcept : m_mem {parX, parY} {}
template <typename = std::enable_if<S == 3> > Vector ( T parX, T parY, T parZ ) noexcept : m_mem {parX, parY, parZ} {}
template <typename = std::enable_if<S == 4> > Vector ( T parX, T parY, T parZ, T parW ) noexcept : m_mem {parX, parY, parZ, parW} {}
~Vector ( void ) noexcept = default;
enum {
Dimension = S
};
template <typename = std::enable_if< 4 >= S> > T& x ( void ) { return m_mem[0]; }
template <typename = std::enable_if< 4 >= S> > const T& x ( void ) const { return m_mem[0]; }
template <typename = std::enable_if<S >= 2 and 4 >= S> > T& y ( void ) { return m_mem[1]; }
template <typename = std::enable_if<S >= 2 and 4 >= S> > const T& y ( void ) const { return m_mem[1]; }
template <typename = std::enable_if<S >= 3 and 4 >= S> > T& z ( void ) { return m_mem[2]; }
template <typename = std::enable_if<S >= 3 and 4 >= S> > const T& z ( void ) const { return m_mem[2]; }
template <typename = std::enable_if<S >= 4 and 4 >= S> > T& w ( void ) { return m_mem[3]; }
template <typename = std::enable_if<S >= 4 and 4 >= S> > const T& w ( void ) const { return m_mem[3]; }
template <typename U> const Vector& operator+= ( const Vector<U, S>& parOther );
template <typename U> const Vector& operator-= ( const Vector<U, S>& parOther );
template <typename U> const Vector& operator*= ( const Vector<U, S>& parOther );
template <typename U> const Vector& operator/= ( const Vector<U, S>& parOther );
template <typename U> const Vector& operator+= ( U parOther );
template <typename U> const Vector& operator-= ( U parOther );
template <typename U> const Vector& operator*= ( U parOther );
template <typename U> 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 <typename T, typename U, uint32_t S>
Vector<typename std::common_type<T, U>::type, S> operator+ ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
Vector<typename std::common_type<T, U>::type, S> operator- ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
Vector<typename std::common_type<T, U>::type, S> operator* ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
Vector<typename std::common_type<T, U>::type, S> operator/ ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator+ ( U parA, const Vector<T, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator- ( U parA, const Vector<T, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator* ( U parA, const Vector<T, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator/ ( U parA, const Vector<T, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator+ ( const Vector<T, S>& parA, U parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator- ( const Vector<T, S>& parA, U parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator* ( const Vector<T, S>& parA, U parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator/ ( const Vector<T, S>& parA, U parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator< ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator> ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator<= ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator>= ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator== ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator!= ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, uint32_t S>
Vector<T, S> operator- ( Vector<T, S> parOperand ) a_pure;
typedef Vector<float, 2> float2;
typedef Vector<uint16_t, 2> ushort2;
#if !defined(NDEBUG)
typedef Vector<int16_t, 2> short2;
#endif
typedef Vector<int32_t, 2> int2;
#if !defined(NDEBUG)
template <typename T, uint32_t S>
std::ostream& operator<< ( std::ostream& parStream, const Vector<T, S>& parVector ) {
parStream << "<";
for (uint32_t z = 0; z < S - 1; ++z) {
parStream << parVector[z] << ",";
}
parStream << parVector[S - 1] << ">";
return parStream;
}
#endif
namespace implem {
template <typename T, typename U>
struct CategorizeTypes {
typedef typename std::common_type<T, U>::type CommonType;
typedef typename std::conditional<std::is_same<CommonType, T>::value, U, T>::type OtherType;
};
template <typename Cat, uint32_t S, bool Straightforward=std::is_same<typename Cat::CommonType, typename Cat::OtherType>::value>
struct DoOperation {
static Vector<typename Cat::CommonType, S> do_mul ( Vector<typename Cat::CommonType, S> parLho, const Vector<typename Cat::CommonType, S>& parRho ) {
parLho *= parRho;
return parLho;
}
static Vector<typename Cat::CommonType, S> do_div ( Vector<typename Cat::CommonType, S> parLho, const Vector<typename Cat::CommonType, S>& parRho ) {
parLho /= parRho;
return parLho;
}
static Vector<typename Cat::CommonType, S> do_sum ( Vector<typename Cat::CommonType, S> parLho, const Vector<typename Cat::CommonType, S>& parRho ) {
parLho += parRho;
return parLho;
}
static Vector<typename Cat::CommonType, S> do_sub ( Vector<typename Cat::CommonType, S> parLho, const Vector<typename Cat::CommonType, S>& parRho ) {
parLho -= parRho;
return parLho;
}
};
template <typename Cat, uint32_t S>
struct DoOperation<Cat, S, false> {
static Vector<typename Cat::CommonType, S> do_mul ( Vector<typename Cat::CommonType, S> parLho, const Vector<typename Cat::OtherType, S>& parRho ) {
parLho *= parRho;
return parLho;
}
static Vector<typename Cat::CommonType, S> do_mul ( const Vector<typename Cat::OtherType, S>& parLho, const Vector<typename Cat::CommonType, S>& parRho ) {
Vector<typename Cat::CommonType, S> ret(parLho);
ret *= parRho;
return ret;
}
static Vector<typename Cat::CommonType, S> do_div ( Vector<typename Cat::CommonType, S> parLho, const Vector<typename Cat::OtherType, S>& parRho ) {
parLho /= parRho;
return parLho;
}
static Vector<typename Cat::CommonType, S> do_div ( const Vector<typename Cat::OtherType, S>& parLho, const Vector<typename Cat::CommonType, S>& parRho ) {
Vector<typename Cat::CommonType, S> ret(parLho);
ret /= parRho;
return ret;
}
static Vector<typename Cat::CommonType, S> do_sum ( Vector<typename Cat::CommonType, S> parLho, const Vector<typename Cat::OtherType, S>& parRho ) {
parLho += parRho;
return parLho;
}
static Vector<typename Cat::CommonType, S> do_sum ( const Vector<typename Cat::OtherType, S>& parLho, const Vector<typename Cat::CommonType, S>& parRho ) {
Vector<typename Cat::CommonType, S> ret(parLho);
ret += parRho;
return ret;
}
static Vector<typename Cat::CommonType, S> do_sub ( Vector<typename Cat::CommonType, S> parLho, const Vector<typename Cat::OtherType, S>& parRho ) {
parLho -= parRho;
return parLho;
}
static Vector<typename Cat::CommonType, S> do_sub ( const Vector<typename Cat::OtherType, S>& parLho, const Vector<typename Cat::CommonType, S>& parRho ) {
Vector<typename Cat::CommonType, S> ret(parLho);
ret -= parRho;
return ret;
}
};
} //namespace implem
} //namespace cloonel
#include "vector.inl"
#if defined(DONT_GUESS_NOEXCEPT)
#undef DONT_GUESS_NOEXCEPT
#endif
#endif

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
namespace cloonel {
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
template <typename T, uint32_t S>
#if defined(DONT_GUESS_NOEXCEPT)
Vector<T, S>::Vector (T parValue) {
#else
Vector<T, S>::Vector (T parValue) noexcept(noexcept(T()) && noexcept(parValue=parValue)) {
#endif
std::fill(m_mem, m_mem + S, parValue);
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
template <typename T, uint32_t S>
template <typename U>
#if defined(DONT_GUESS_NOEXCEPT)
Vector<T, S>::Vector (const Vector<U, S>& parOther) {
#else
Vector<T, S>::Vector (const Vector<U, S>& parOther) noexcept(noexcept(T()) && noexcept(const_cast<U&>(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 <typename T, uint32_t S>
template <typename U>
const Vector<T, S>& Vector<T, S>::operator+= (const Vector<U, S>& parOther) {
for (uint32_t z = 0; z < S; ++z) {
m_mem[z] += parOther.m_mem[z];
}
return *this;
}
template <typename T, uint32_t S>
template <typename U>
const Vector<T, S>& Vector<T, S>::operator-= (const Vector<U, S>& parOther) {
for (uint32_t z = 0; z < S; ++z) {
m_mem[z] -= parOther.m_mem[z];
}
return *this;
}
template <typename T, uint32_t S>
template <typename U>
const Vector<T, S>& Vector<T, S>::operator*= (const Vector<U, S>& parOther) {
for (uint32_t z = 0; z < S; ++z) {
m_mem[z] *= parOther.m_mem[z];
}
return *this;
}
template <typename T, uint32_t S>
template <typename U>
const Vector<T, S>& Vector<T, S>::operator/= (const Vector<U, S>& 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 <typename T, uint32_t S>
template <typename U>
const Vector<T, S>& Vector<T, S>::operator+= (U parOther) {
for (uint32_t z = 0; z < S; ++z) {
m_mem[z] += parOther;
}
return *this;
}
template <typename T, uint32_t S>
template <typename U>
const Vector<T, S>& Vector<T, S>::operator-= (U parOther) {
for (uint32_t z = 0; z < S; ++z) {
m_mem[z] -= parOther;
}
return *this;
}
template <typename T, uint32_t S>
template <typename U>
const Vector<T, S>& Vector<T, S>::operator*= (U parOther) {
for (uint32_t z = 0; z < S; ++z) {
m_mem[z] *= parOther;
}
return *this;
}
template <typename T, uint32_t S>
template <typename U>
const Vector<T, S>& Vector<T, S>::operator/= (U parOther) {
for (uint32_t z = 0; z < S; ++z) {
m_mem[z] /= parOther;
}
return *this;
}
#pragma GCC diagnostic pop
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
template <typename T, typename U, uint32_t S>
inline
Vector<typename std::common_type<T, U>::type, S> operator+ (const Vector<T, S>& parA, const Vector<U, S>& parB) {
return implem::DoOperation<implem::CategorizeTypes<T, U>, S>::do_sum(parA, parB);
}
template <typename T, typename U, uint32_t S>
inline
Vector<typename std::common_type<T, U>::type, S> operator- (const Vector<T, S>& parA, const Vector<U, S>& parB) {
return implem::DoOperation<implem::CategorizeTypes<T, U>, S>::do_sub(parA, parB);
}
template <typename T, typename U, uint32_t S>
inline
Vector<typename std::common_type<T, U>::type, S> operator* (const Vector<T, S>& parA, const Vector<U, S>& parB) {
return implem::DoOperation<implem::CategorizeTypes<T, U>, S>::do_mul(parA, parB);
}
template <typename T, typename U, uint32_t S>
inline
Vector<typename std::common_type<T, U>::type, S> operator/ (const Vector<T, S>& parA, const Vector<U, S>& parB) {
return implem::DoOperation<implem::CategorizeTypes<T, U>, S>::do_div(parA, parB);
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
template <typename T, typename U, uint32_t S, typename>
Vector<typename std::common_type<T, U>::type, S> operator+ (U parA, const Vector<T, S>& parB) {
return parB + parA;
}
template <typename T, typename U, uint32_t S, typename>
Vector<typename std::common_type<T, U>::type, S> operator- (U parA, const Vector<T, S>& parB) {
return Vector<T, S>(parA) - parB;
}
template <typename T, typename U, uint32_t S, typename>
Vector<typename std::common_type<T, U>::type, S> operator* (U parA, const Vector<T, S>& parB) {
return parB * parA;
}
template <typename T, typename U, uint32_t S, typename>
Vector<typename std::common_type<T, U>::type, S> operator/ (U parA, const Vector<T, S>& parB) {
return Vector<T, S>(parA) / parB;
}
template <typename T, typename U, uint32_t S, typename>
Vector<typename std::common_type<T, U>::type, S> operator+ (const Vector<T, S>& parA, U parB) {
typedef typename std::common_type<T, U>::type RetType;
Vector<RetType, S> retVal;
for (uint32_t z = 0; z < S; ++z) {
retVal[z] = parA[z] + parB;
}
return retVal;
}
template <typename T, typename U, uint32_t S, typename>
Vector<typename std::common_type<T, U>::type, S> operator- (const Vector<T, S>& parA, U parB) {
typedef typename std::common_type<T, U>::type RetType;
Vector<RetType, S> retVal;
for (uint32_t z = 0; z < S; ++z) {
retVal[z] = parA[z] - parB;
}
return retVal;
}
template <typename T, typename U, uint32_t S, typename>
Vector<typename std::common_type<T, U>::type, S> operator* (const Vector<T, S>& parA, U parB) {
typedef typename std::common_type<T, U>::type RetType;
Vector<RetType, S> retVal;
for (uint32_t z = 0; z < S; ++z) {
retVal[z] = parA[z] * parB;
}
return retVal;
}
template <typename T, typename U, uint32_t S, typename>
Vector<typename std::common_type<T, U>::type, S> operator/ (const Vector<T, S>& parA, U parB) {
typedef typename std::common_type<T, U>::type RetType;
Vector<RetType, S> retVal;
for (uint32_t z = 0; z < S; ++z) {
retVal[z] = parA[z] / parB;
}
return retVal;
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename T, typename U, uint32_t S>
inline bool operator< (const Vector<T, S>& parA, const Vector<U, S>& parB) {
bool retVal = true;
for (uint32_t z = 0; z < S; ++z) {
retVal &= static_cast<bool>(parA[z] < parB[z]);
}
return retVal;
}
template <typename T, typename U, uint32_t S>
inline bool operator> (const Vector<T, S>& parA, const Vector<U, S>& parB) {
bool retVal = true;
for (uint32_t z = 0; z < S; ++z) {
retVal &= static_cast<bool>(parA[z] > parB[z]);
}
return retVal;
}
template <typename T, typename U, uint32_t S>
inline bool operator<= (const Vector<T, S>& parA, const Vector<U, S>& parB) {
bool retVal = true;
for (uint32_t z = 0; z < S; ++z) {
retVal &= static_cast<bool>(parA[z] <= parB[z]);
}
return retVal;
}
template <typename T, typename U, uint32_t S>
inline bool operator>= (const Vector<T, S>& parA, const Vector<U, S>& parB) {
bool retVal = true;
for (uint32_t z = 0; z < S; ++z) {
retVal &= static_cast<bool>(parA[z] >= parB[z]);
}
return retVal;
}
template <typename T, typename U, uint32_t S>
inline bool operator== (const Vector<T, S>& parA, const Vector<U, S>& parB) {
bool retVal = true;
for (uint32_t z = 0; z < S; ++z) {
retVal &= static_cast<bool>(parA[z] == parB[z]);
}
return retVal;
}
template <typename T, typename U, uint32_t S>
inline bool operator!= (const Vector<T, S>& parA, const Vector<U, S>& parB) {
return not operator==(parA, parB);
}
template <typename T, uint32_t S>
Vector<T, S> operator- (Vector<T, S> parOperand) {
for (uint32_t z = 0; z < S; ++z) {
parOperand[z] = -parOperand[z];
}
return parOperand;
}
} //namespace cloonel

View file

@ -20,7 +20,7 @@
#ifndef id5DB098DAA5534A0A869DEF23888F96B0
#define id5DB098DAA5534A0A869DEF23888F96B0
#include "vector.hpp"
#include "vectypes.hpp"
#include "compatibility.h"
#include <type_traits>
#include <cstdint>

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef idE31BEAEB229149038D67C6CF370AEEC9
#define idE31BEAEB229149038D67C6CF370AEEC9
#include "vector.hpp"
#if !defined(NDEBUG)
#include <iostream>
#endif
namespace cloonel {
#if !defined(NDEBUG)
template <typename T, uint32_t S>
inline std::ostream& operator<< (std::ostream& parOStream, const Vector<T, S>& parVec) {
parOStream << "<";
for (uint32_t z = 0; z < S - 1; ++z) {
parOStream << parVec[z] << ", ";
}
parOStream << parVec[S - 1] << ">";
return parOStream;
}
#endif
} //namespace cloonel
#endif

145
src/vectypes.hpp Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef id7155F721B70C41B383896327C7D07E30
#define id7155F721B70C41B383896327C7D07E30
#include "vectorwrapper/vectorwrapper.hpp"
#include "vectorwrapper/vector_cast.hpp"
#include "compatibility.h"
#include <array>
#include <cstdint>
#if !defined(NDEBUG)
# include <iostream>
#endif
#include <utility>
#define SPECIALIZE_ARRAY_VECTOR(TYPE, DIM) \
template <> \
struct VectorWrapperInfo<std::array<TYPE, DIM>> { \
enum { dimensions = DIM }; \
typedef TYPE 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 {
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 <typename V>
std::ostream& operator<< (std::ostream& parStream, const Vec<V>& parVec) {
parStream << '<';
for (uint32_t z = 0; z < Vec<V>::dimensions - 1; ++z) {
std::cout << parVec[z] << ", ";
}
std::cout << parVec[Vec<V>::dimensions - 1] << '>';
return parStream;
}
#endif
template <typename V>
Vec<V> operator+ (Vec<V> parLeft, typename VectorWrapperInfo<V>::scalar_type parRight) a_pure;
template <typename V>
Vec<V> operator- (Vec<V> parLeft, typename VectorWrapperInfo<V>::scalar_type parRight) a_pure;
template <typename V>
Vec<V> operator* (Vec<V> parLeft, typename VectorWrapperInfo<V>::scalar_type parRight) a_pure;
template <typename V>
Vec<V> operator/ (Vec<V> parLeft, typename VectorWrapperInfo<V>::scalar_type parRight) a_pure;
template <typename V>
Vec<V> operator+ (typename VectorWrapperInfo<V>::scalar_type parLeft, Vec<V> parRight) a_pure;
template <typename V>
Vec<V> operator* (typename VectorWrapperInfo<V>::scalar_type parLeft, Vec<V> parRight) a_pure;
template <typename V>
inline
Vec<V> operator+ (Vec<V> parLeft, typename VectorWrapperInfo<V>::scalar_type parRight) {
for (uint32_t z = 0; z < Vec<V>::dimensions; ++z) {
parLeft[z] += parRight;
}
return parLeft;
}
template <typename V>
inline
Vec<V> operator- (Vec<V> parLeft, typename VectorWrapperInfo<V>::scalar_type parRight) {
for (uint32_t z = 0; z < Vec<V>::dimensions; ++z) {
parLeft[z] -= parRight;
}
return parLeft;
}
template <typename V>
inline
Vec<V> operator* (Vec<V> parLeft, typename VectorWrapperInfo<V>::scalar_type parRight) {
for (uint32_t z = 0; z < Vec<V>::dimensions; ++z) {
parLeft[z] *= parRight;
}
return parLeft;
}
template <typename V>
inline
Vec<V> operator/ (Vec<V> parLeft, typename VectorWrapperInfo<V>::scalar_type parRight) {
for (uint32_t z = 0; z < Vec<V>::dimensions; ++z) {
parLeft[z] /= parRight;
}
return parLeft;
}
template <typename V>
inline
Vec<V> operator+ (typename VectorWrapperInfo<V>::scalar_type parLeft, Vec<V> parRight) {
for (uint32_t z = 0; z < Vec<V>::dimensions; ++z) {
parRight[z] += parLeft;
}
return parRight;
}
template <typename V>
inline
Vec<V> operator* (typename VectorWrapperInfo<V>::scalar_type parLeft, Vec<V> parRight) {
for (uint32_t z = 0; z < Vec<V>::dimensions; ++z) {
parRight[z] *= parLeft;
}
return parRight;
}
} //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 ushort2 = Vect<uint16_t, 2>;
#if !defined(NDEBUG)
using short2 = Vect<int16_t, 2>;
#endif
using float2 = Vect<float, 2>;
using int2 = Vect<int32_t, 2>;
using vwr::vector_cast;
} //namespace cloonel
#undef SPECIALIZE_ARRAY_VECTOR
#endif