Add tilecoords and unit test.
Disable most projects because the build is broken. A lot.
This commit is contained in:
parent
5b027914d5
commit
6aa4d15381
6 changed files with 165 additions and 4 deletions
|
@ -10,7 +10,7 @@
|
|||
#if !defined(DK_COORD_SCALAR_TYPE)
|
||||
/* this type represent tiles' coordinates, so it should be an integer type */
|
||||
/* so it's not the tile position in your game world */
|
||||
# define DK_COORD_SCALAR_TYPE int
|
||||
# define DK_COORD_SCALAR_TYPE int32_t
|
||||
#endif
|
||||
#if !defined(DK_COORD_DISTANCE_TYPE)
|
||||
# define DK_COORD_DISTANCE_TYPE int64_t
|
||||
|
|
81
include/doorkeeper/implem/tilecoords.inl
Normal file
81
include/doorkeeper/implem/tilecoords.inl
Normal file
|
@ -0,0 +1,81 @@
|
|||
namespace dk {
|
||||
template <uint32_t D>
|
||||
TileCoords<D>::TileCoords (const coords& parSize) :
|
||||
m_pos(CoordinateScalarType(0)),
|
||||
m_size(parSize)
|
||||
{
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
TileCoords<D>::TileCoords (const coords& parValue, const coords& parSize) :
|
||||
m_pos(parValue),
|
||||
m_size(parSize)
|
||||
{
|
||||
assert(parValue < parSize);
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
TileCoords<D>& TileCoords<D>::operator++ () {
|
||||
const coords lower(0);
|
||||
for (CoordinateDistType d = 0; d < D - 1; ++d) {
|
||||
++m_pos[d];
|
||||
if (m_pos[d] >= m_size[d])
|
||||
m_pos[d] = lower[d];
|
||||
else
|
||||
return *this;
|
||||
}
|
||||
++m_pos[D - 1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
TileCoords<D> TileCoords<D>::operator++ (int) {
|
||||
TileCoords<D> retval(*this);
|
||||
++(*this);
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
TileCoords<D>& TileCoords<D>::operator-- () {
|
||||
const coords lower(0);
|
||||
for (CoordinateDistType d = 0; d < D; ++d) {
|
||||
if (m_pos[d] > lower[d]) {
|
||||
--m_pos[d];
|
||||
return;
|
||||
}
|
||||
else {
|
||||
m_pos[d] = m_size[d];
|
||||
}
|
||||
}
|
||||
++m_pos[D - 1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
TileCoords<D> TileCoords<D>::operator-- (int) {
|
||||
TileCoords<D> retval(*this);
|
||||
--(*this);
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
const TileCoords<D>& TileCoords<D>::operator+= (CoordinateScalarType parValue) {
|
||||
CoordinateScalarType acc(parValue);
|
||||
CoordinateScalarType div(1);
|
||||
for (uint32_t z = 0; z < D; ++z) {
|
||||
m_pos[z] = (m_pos[z] + acc / div) % m_size[z];
|
||||
div *= m_size[z];
|
||||
acc += m_pos[z];
|
||||
}
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
bool TileCoords<D>::operator== (const TileCoords& parOther) const {
|
||||
return m_pos == parOther.m_pos and m_size == parOther.m_size;
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
bool TileCoords<D>::operator!= (const TileCoords& parOther) const {
|
||||
return not(*this == parOther);
|
||||
}
|
||||
} //namespace dk
|
Loading…
Add table
Add a link
Reference in a new issue