From f9e249a972e2ca78293de173fe56b15011e59880 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 2 Sep 2014 16:41:21 +0200 Subject: [PATCH] Buildfix and reorder of files --- include/components/tyler.hpp | 25 +++ include/{ => components}/viewport.hpp | 10 +- include/coords.hpp | 15 -- include/doorkeeper.hpp | 20 +- include/implem/compatibility.h | 58 ++++++ include/implem/coords.hpp | 12 ++ include/implem/vector.hpp | 219 ++++++++++++++++++++++ include/implem/vector.inl | 252 ++++++++++++++++++++++++++ include/itemswithid.hpp | 33 ---- src/doorkeeper.cpp | 4 - 10 files changed, 573 insertions(+), 75 deletions(-) create mode 100644 include/components/tyler.hpp rename include/{ => components}/viewport.hpp (60%) delete mode 100644 include/coords.hpp create mode 100644 include/implem/compatibility.h create mode 100644 include/implem/coords.hpp create mode 100644 include/implem/vector.hpp create mode 100644 include/implem/vector.inl delete mode 100644 include/itemswithid.hpp diff --git a/include/components/tyler.hpp b/include/components/tyler.hpp new file mode 100644 index 0000000..fb683df --- /dev/null +++ b/include/components/tyler.hpp @@ -0,0 +1,25 @@ +#ifndef id6FB3FC97331449038D42AAAB4C01ABA1 +#define id6FB3FC97331449038D42AAAB4C01ABA1 + +#include "implem/coords.hpp" +#include + +namespace dk { + class Viewport; + + template + class Tyler { + public: + Tyler ( const coords& parCoords ); + virtual ~Tyler ( void ) noexcept = default; + + virtual bool batch_load ( const coords& parFrom, const coords& parTo ); + virtual bool single_load ( const coords& parCoords ); + + private: + const coords m_size; + std::vector m_tiles; + }; +} //namespace dk + +#endif diff --git a/include/viewport.hpp b/include/components/viewport.hpp similarity index 60% rename from include/viewport.hpp rename to include/components/viewport.hpp index bc69cb4..2cdf86b 100644 --- a/include/viewport.hpp +++ b/include/components/viewport.hpp @@ -1,20 +1,20 @@ #ifndef id0ADBCC15BA574485BF3267254090D99B #define id0ADBCC15BA574485BF3267254090D99B -#include "coords.hpp" +#include "implem/coords.hpp" namespace dk { class Viewport { public: - explicit Viewport ( const Coords& parSize ); - Viewport ( const Coords& parSize, const Coord; parPos ); + explicit Viewport ( const coords& parSize ); + Viewport ( const coords& parSize, const coords& parPos ); ~Viewport ( void ) noexcept = default; Viewport& operator= ( const Viewport& ) = default; private: - Coords size_; - Coords position_; + coords m_size; + coords m_position; }; } //namespace dk diff --git a/include/coords.hpp b/include/coords.hpp deleted file mode 100644 index c2c47bf..0000000 --- a/include/coords.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef id305A77366E3B4D3C84CC345C93A7C38B -#define id305A77366E3B4D3C84CC345C93A7C38B - -#include - -namespace dk { - typedef std::size_t CoordType; - - struct Coords { - CoordType width; - CoordType height; - }; -} //namespace dk - -#endif diff --git a/include/doorkeeper.hpp b/include/doorkeeper.hpp index b68d866..6d6d13b 100644 --- a/include/doorkeeper.hpp +++ b/include/doorkeeper.hpp @@ -1,23 +1,7 @@ #ifndef id5A4C05FA7D264B65B7B7D14A0792E3A2 #define id5A4C05FA7D264B65B7B7D14A0792E3A2 -#include "coords.hpp" - -namespace dk { - class Viewport; - - class Tyler { - public: - Tyler ( const Coords& parCoords ); - virtual ~Tyler ( void ) noexcept = default; - - virtual bool batch_load ( const Coords& parFrom, const Coords& parTo ); - virtual bool single_load ( const Coords& parCoords ); - - private: - const Coords size_; - - }; -} //namespace dk +#include "components/tyler.hpp" +#include "components/viewport.hpp" #endif diff --git a/include/implem/compatibility.h b/include/implem/compatibility.h new file mode 100644 index 0000000..ad115f0 --- /dev/null +++ b/include/implem/compatibility.h @@ -0,0 +1,58 @@ +/* + 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 id45CDD1DAEF4F42968E3C89F68FDDA9BC +#define id45CDD1DAEF4F42968E3C89F68FDDA9BC + +#if defined(__GNUC__) +# if defined(__clang__) +# if !defined(__has_attribute) + //Fall back to version number comparing +# else +# if __has_attribute(flatten) +# define a_flatten __attribute__((flatten)) +# else +# define a_flatten +# endif +# if __has_attribute(always_inline) +# define a_always_inline __attribute__((always_inline)) +# else +# define a_always_inline +# endif +# if __has_attribute(pure) +# define a_pure __attribute__((pure)) +# else +# define a_pure +# endif +# endif +# else + //Fix here if you get warnings about unsupported attributes on your compiler +# define a_flatten __attribute__((flatten)) +# define a_always_inline __attribute__((always_inline)) +# define a_pure __attribute__((pure)) +# endif +#else +# warning "Unsupported compiler, please fill this section or file a bug" +# define a_flatten +# define a_always_inline +# define a_pure +#endif + +#endif diff --git a/include/implem/coords.hpp b/include/implem/coords.hpp new file mode 100644 index 0000000..7cc057d --- /dev/null +++ b/include/implem/coords.hpp @@ -0,0 +1,12 @@ +#ifndef id305A77366E3B4D3C84CC345C93A7C38B +#define id305A77366E3B4D3C84CC345C93A7C38B + +#include "implem/vector.hpp" + +namespace dk { + typedef int coord_type; + typedef cloonel::Vector coords; + typedef cloonel::Vector int2; +} //namespace dk + +#endif diff --git a/include/implem/vector.hpp b/include/implem/vector.hpp new file mode 100644 index 0000000..af20053 --- /dev/null +++ b/include/implem/vector.hpp @@ -0,0 +1,219 @@ +/* + 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/include/implem/vector.inl b/include/implem/vector.inl new file mode 100644 index 0000000..e79741d --- /dev/null +++ b/include/implem/vector.inl @@ -0,0 +1,252 @@ +/* + 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/include/itemswithid.hpp b/include/itemswithid.hpp deleted file mode 100644 index 19133b5..0000000 --- a/include/itemswithid.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef id9B2FF4B4CA4244EAB93C619479A8E816 -#define id9B2FF4B4CA4244EAB93C619479A8E816 - -#include - -namespace dk { - template - class ItemsWithID { - typedef C container_type; - public: - typedef T value_type; - typedef typename container_type::size_type size_type; - typedef typename container_type::size_type id_type; - typedef value_type& reference_type; - - ItemsWithID ( void ) = default; - ~ItemsWithID ( void ) noexcept = default; - - id_type add ( const value_type& parNewVal ); - void erase ( id_type parID ); - reference_type operator[] ( id_type parID ); - const reference_type operator[] ( id_type parID ) const; - - - private: - container_type items_; - - // see: - // https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md - }; -} //namespace dk - -#endif diff --git a/src/doorkeeper.cpp b/src/doorkeeper.cpp index 848dc67..2be279d 100644 --- a/src/doorkeeper.cpp +++ b/src/doorkeeper.cpp @@ -1,5 +1 @@ #include "doorkeeper.hpp" - - -#include -#include