Public header files moved into the doorkeeper subdirectory
This commit is contained in:
parent
90d759c696
commit
7a8ffe2060
26 changed files with 35 additions and 35 deletions
69
include/doorkeeper/components/layer.hpp
Normal file
69
include/doorkeeper/components/layer.hpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
#ifndef idD3EDC396AA314474B3D909559FFC0247
|
||||
#define idD3EDC396AA314474B3D909559FFC0247
|
||||
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/components/tileiterator.hpp"
|
||||
#include "doorkeeper/components/tilemapdata.hpp"
|
||||
#include "doorkeeper/implem/helpers.hpp"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace dk {
|
||||
template <size_t D>
|
||||
class Viewport;
|
||||
|
||||
template <size_t D>
|
||||
class LayerBase {
|
||||
public:
|
||||
typedef Vector<CoordinateScalarType, D> coords;
|
||||
|
||||
LayerBase ( const coords& parCount, const coords& parTileSize, const coords& parMasterTileSize );
|
||||
virtual ~LayerBase ( void ) noexcept = default;
|
||||
|
||||
void preload ( const coords& parFrom, const coords& parTo );
|
||||
coords count ( void ) const { return m_mastersize / m_tilesize * m_count; }
|
||||
const coords& mapSize ( void ) const { return m_count; }
|
||||
|
||||
protected:
|
||||
coords m_count;
|
||||
coords m_tilesize;
|
||||
coords m_mastersize;
|
||||
|
||||
private:
|
||||
virtual void onPreload ( const coords& parFrom, const coords& parTo ) = 0;
|
||||
|
||||
coords m_haveFrom;
|
||||
coords m_haveTo;
|
||||
};
|
||||
|
||||
template <typename T, size_t D>
|
||||
class Layer : public LayerBase<D> {
|
||||
friend class Viewport<D>;
|
||||
|
||||
public:
|
||||
typedef typename LayerBase<D>::coords coords;
|
||||
typedef TileIterator<T, D> iterator;
|
||||
typedef TileIterator<const T, D> const_iterator;
|
||||
|
||||
Layer ( const Layer& ) = delete;
|
||||
Layer ( Layer&& ) = default;
|
||||
Layer ( const coords& parTileSize, const coords& parMasterTileSize, TileMapData<T, D>& parTilemap );
|
||||
virtual ~Layer ( void ) noexcept = default;
|
||||
|
||||
Layer& operator= ( const Layer& ) = delete;
|
||||
|
||||
iterator begin ( void );
|
||||
iterator end ( void );
|
||||
|
||||
private:
|
||||
virtual void onPreload ( const coords& parFrom, const coords& parTo );
|
||||
|
||||
std::vector<T> m_tiles;
|
||||
TileMapData<T, D>& m_tilemap;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/layer.inl"
|
||||
|
||||
#endif
|
78
include/doorkeeper/components/tileiterator.hpp
Normal file
78
include/doorkeeper/components/tileiterator.hpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
#ifndef id873715F57B504CCF8227CE03EA28CAFA
|
||||
#define id873715F57B504CCF8227CE03EA28CAFA
|
||||
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/implem/helpers.hpp"
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
namespace dk {
|
||||
namespace implem {
|
||||
template <size_t D>
|
||||
size_t get_index_from_pos ( const Vector<CoordinateScalarType, D>& parPos, const Vector<CoordinateScalarType, D>& parSize ) a_pure;
|
||||
|
||||
template <typename I, typename O>
|
||||
struct TypeWithQualifiers {
|
||||
typedef typename std::conditional<std::is_volatile<I>::value && std::is_const<I>::value,
|
||||
typename std::add_cv<O>::type,
|
||||
typename std::conditional<std::is_volatile<I>::value,
|
||||
typename std::add_volatile<typename std::remove_cv<O>::type>::type,
|
||||
typename std::conditional<std::is_const<I>::value,
|
||||
typename std::add_const<typename std::remove_cv<O>::type>::type,
|
||||
typename std::remove_cv<O>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type result;
|
||||
};
|
||||
|
||||
#if defined(NDEBUG)
|
||||
template <>
|
||||
size_t get_index_from_pos<2> ( const Vector<CoordinateScalarType, 2>& parPos, const Vector<CoordinateScalarType, 2>& parSize ) a_pure;
|
||||
#endif
|
||||
|
||||
template <size_t D>
|
||||
Vector<CoordinateScalarType, D> buildPastEndCoordinate ( const Vector<CoordinateScalarType, D>& parFrom, const Vector<CoordinateScalarType, D>& parTo ) a_pure;
|
||||
} //namespace implem
|
||||
|
||||
template <typename T, size_t D, typename T1=typename std::remove_cv<T>::type>
|
||||
class TileIterator : public boost::iterator_facade<TileIterator<T, D>, T, boost::bidirectional_traversal_tag> {
|
||||
friend class boost::iterator_core_access;
|
||||
typedef std::vector<T1> vector_type;
|
||||
typedef typename implem::TypeWithQualifiers<T, vector_type>::result qualif_vector_type;
|
||||
public:
|
||||
typedef Vector<CoordinateScalarType, D> coords;
|
||||
|
||||
TileIterator ( void );
|
||||
TileIterator ( const TileIterator& parOther ) = default;
|
||||
TileIterator ( TileIterator&& parOther ) = default;
|
||||
TileIterator ( qualif_vector_type* parData, const coords& parFrom, const coords& parTo );
|
||||
TileIterator ( qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo );
|
||||
TileIterator ( qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parSubdiv );
|
||||
~TileIterator ( void ) = default;
|
||||
|
||||
const coords& position ( void ) const { return m_pos; }
|
||||
|
||||
private:
|
||||
void increment ( void );
|
||||
void decrement ( void );
|
||||
void advance ( size_t parAdvance );
|
||||
ptrdiff_t distance_to ( const TileIterator& parOther );
|
||||
bool equal ( const TileIterator& parOther ) const;
|
||||
T& dereference ( void ) const { return (*m_data)[get_current_index()]; }
|
||||
size_t get_current_index ( void ) const { return implem::get_index_from_pos<D>(m_pos, m_subdivareasize) + m_subindex; }
|
||||
|
||||
coords m_pos;
|
||||
coords m_from;
|
||||
coords m_to;
|
||||
coords m_subdivareasize;
|
||||
qualif_vector_type* m_data;
|
||||
CoordinateScalarType m_subindex;
|
||||
CoordinateScalarType m_maxsubindex;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/tileiterator.inl"
|
||||
|
||||
#endif
|
34
include/doorkeeper/components/tilemapdata.hpp
Normal file
34
include/doorkeeper/components/tilemapdata.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef id8F5106DFABC14263ADF235C56E434207
|
||||
#define id8F5106DFABC14263ADF235C56E434207
|
||||
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/implem/compatibility.h"
|
||||
#include "doorkeeper/implem/vector.hpp"
|
||||
#include "doorkeeper/implem/helpers.hpp"
|
||||
#include "doorkeeper/mapreaders/mapstreambase.hpp"
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
|
||||
namespace dk {
|
||||
template <typename T, std::size_t D>
|
||||
class TileMapData {
|
||||
public:
|
||||
typedef Vector<CoordinateScalarType, D> coords;
|
||||
|
||||
TileMapData ( void ) = delete;
|
||||
explicit TileMapData ( std::unique_ptr<MapStreamBase<D>>&& parStream );
|
||||
~TileMapData ( void ) noexcept = default;
|
||||
|
||||
void fetch ( std::vector<T>& parOut, const coords& parFrom, const coords& parTo );
|
||||
const coords& mapSize ( void ) const;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<MapStreamBase<D>> m_mapstream;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/tilemapdata.inl"
|
||||
|
||||
#endif
|
44
include/doorkeeper/components/tyler.hpp
Normal file
44
include/doorkeeper/components/tyler.hpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#ifndef id6FB3FC97331449038D42AAAB4C01ABA1
|
||||
#define id6FB3FC97331449038D42AAAB4C01ABA1
|
||||
|
||||
#include "doorkeeper/components/layer.hpp"
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <ciso646>
|
||||
#include <memory>
|
||||
|
||||
namespace dk {
|
||||
template <typename T, size_t D>
|
||||
class TileMapData;
|
||||
|
||||
template <size_t D>
|
||||
class Tyler {
|
||||
typedef std::unique_ptr<LayerBase<D>> LayerPtr;
|
||||
typedef std::vector<LayerPtr> LayerList;
|
||||
public:
|
||||
typedef typename LayerBase<D>::coords coords;
|
||||
|
||||
Tyler ( void ) = delete;
|
||||
Tyler ( const coords& parSize, const coords& parTileSize );
|
||||
~Tyler ( void ) noexcept = default;
|
||||
|
||||
typename coords::value_type tiles_count ( void ) const;
|
||||
const coords& map_size ( void ) const { return m_size; }
|
||||
|
||||
template <typename T>
|
||||
Layer<T, D>& push_layer ( TileMapData<T, D>& parTilemap );
|
||||
template <typename T>
|
||||
Layer<T, D>& push_layer ( TileMapData<T, D>& parTilemap, const coords& parSubdiv );
|
||||
|
||||
void preload ( const coords& parFrom, const coords& parTo );
|
||||
|
||||
private:
|
||||
const coords m_size;
|
||||
const coords m_tilesize;
|
||||
LayerList m_layers;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/tyler.inl"
|
||||
|
||||
#endif
|
54
include/doorkeeper/components/viewport.hpp
Normal file
54
include/doorkeeper/components/viewport.hpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef id0ADBCC15BA574485BF3267254090D99B
|
||||
#define id0ADBCC15BA574485BF3267254090D99B
|
||||
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/components/tileiterator.hpp"
|
||||
#include "doorkeeper/components/layer.hpp"
|
||||
|
||||
namespace dk {
|
||||
template <size_t D>
|
||||
class Tyler;
|
||||
|
||||
template <typename T, size_t D>
|
||||
class Layer;
|
||||
|
||||
template <size_t D>
|
||||
class Viewport {
|
||||
public:
|
||||
typedef Vector<CoordinateScalarType, D> coords;
|
||||
|
||||
Viewport ( const Viewport& parOther ) = default;
|
||||
explicit Viewport ( Tyler<D>& parTyler );
|
||||
Viewport ( Tyler<D>& parTyler, const coords& parSize, const coords& parPos );
|
||||
~Viewport ( void ) noexcept = default;
|
||||
|
||||
Viewport& operator= ( const Viewport& ) = default;
|
||||
|
||||
void setSize ( const coords& parSize );
|
||||
void setFrom ( const coords& parFrom );
|
||||
void setFromSize ( const coords& parFrom, const coords& parSize );
|
||||
const coords& count ( void ) const { return m_size; }
|
||||
|
||||
template <typename T>
|
||||
typename Layer<T, D>::iterator begin ( Layer<T, D>& parLayer ) const;
|
||||
template <typename T>
|
||||
typename Layer<T, D>::iterator end ( Layer<T, D>& parLayer ) const;
|
||||
template <typename T> inline
|
||||
typename Layer<T, D>::const_iterator begin ( const Layer<T, D>& parLayer ) const a_always_inline;
|
||||
template <typename T> inline
|
||||
typename Layer<T, D>::const_iterator end ( const Layer<T, D>& parLayer ) const a_always_inline;
|
||||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator cbegin ( const Layer<T, D>& parLayer ) const;
|
||||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator cend ( const Layer<T, D>& parLayer ) const;
|
||||
|
||||
private:
|
||||
coords m_size;
|
||||
coords m_position;
|
||||
Tyler<D>& m_tyler;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/viewport.inl"
|
||||
|
||||
#endif
|
10
include/doorkeeper/doorkeeper.hpp
Normal file
10
include/doorkeeper/doorkeeper.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef id5A4C05FA7D264B65B7B7D14A0792E3A2
|
||||
#define id5A4C05FA7D264B65B7B7D14A0792E3A2
|
||||
|
||||
#include "primitivetypes.hpp"
|
||||
#include "components/tyler.hpp"
|
||||
#include "components/viewport.hpp"
|
||||
#include "components/layer.hpp"
|
||||
#include "components/tilemapdata.hpp"
|
||||
|
||||
#endif
|
53
include/doorkeeper/helpers/asciimapsource.hpp
Normal file
53
include/doorkeeper/helpers/asciimapsource.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#ifndef id263B7DAF9A1C40BB8517D5D328DF8A1B
|
||||
#define id263B7DAF9A1C40BB8517D5D328DF8A1B
|
||||
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/implem/vector.hpp"
|
||||
#include <streambuf>
|
||||
#include <vector>
|
||||
#include <boost/iostreams/categories.hpp> // source_tag
|
||||
|
||||
namespace dkh {
|
||||
class AsciiMapSource : public std::streambuf {
|
||||
public:
|
||||
typedef dk::Vector<dk::CoordinateScalarType, 2> coords;
|
||||
typedef int MapTileType;
|
||||
typedef boost::iostreams::source_tag category;
|
||||
enum {
|
||||
MapDimensions = 2
|
||||
};
|
||||
|
||||
AsciiMapSource ( void ) = delete;
|
||||
AsciiMapSource ( const AsciiMapSource& ) = delete;
|
||||
AsciiMapSource ( AsciiMapSource&& parOther ) = default;
|
||||
explicit AsciiMapSource ( const char* parFilename );
|
||||
explicit AsciiMapSource ( const std::string& parFilename );
|
||||
explicit AsciiMapSource ( std::istream& parData );
|
||||
template <typename I>
|
||||
AsciiMapSource ( I parDataFrom, I parDataTo );
|
||||
~AsciiMapSource ( void ) noexcept = default;
|
||||
|
||||
const coords& mapSize ( void ) const noexcept { return m_mapSize; }
|
||||
|
||||
protected:
|
||||
virtual int_type underflow ( void );
|
||||
virtual int_type uflow ( void );
|
||||
virtual int_type pbackfail ( int_type parCh );
|
||||
virtual std::streamsize showmanyc ( void );
|
||||
virtual pos_type seekoff ( off_type parOff, std::ios_base::seekdir parDir, std::ios_base::openmode parWhich );
|
||||
virtual pos_type seekpos( pos_type parPos, std::ios_base::openmode parWhich );
|
||||
|
||||
private:
|
||||
enum {
|
||||
DataSize = sizeof(MapTileType)
|
||||
};
|
||||
|
||||
void parse_map_data ( std::istream& parSrc );
|
||||
|
||||
std::vector<MapTileType> m_wholedata;
|
||||
coords m_mapSize;
|
||||
std::size_t m_bytepos;
|
||||
};
|
||||
} //namespace dkh
|
||||
|
||||
#endif
|
58
include/doorkeeper/implem/compatibility.h
Normal file
58
include/doorkeeper/implem/compatibility.h
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#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
|
37
include/doorkeeper/implem/configuration.h
Normal file
37
include/doorkeeper/implem/configuration.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifndef id2E81C803F1B94170B2C61A63D5020E08
|
||||
#define id2E81C803F1B94170B2C61A63D5020E08
|
||||
|
||||
#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
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
# define MAKE_DK_NAME(a) a
|
||||
namespace dk {
|
||||
#else
|
||||
# define MAKE_DK_NAME(a) dk_ ## a
|
||||
#endif
|
||||
|
||||
typedef DK_COORD_SCALAR_TYPE MAKE_DK_NAME(CoordinateScalarType);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} //namespace dk
|
||||
#endif
|
||||
|
||||
#undef DK_COORD_SCALAR_TYPE
|
||||
#undef MAKE_DK_NAME
|
||||
|
||||
#if !defined(NDEBUG) && !defined(NO_DK_ASSERTIONS)
|
||||
# if !defined(DK_ASSERT)
|
||||
# include <cassert>
|
||||
# define DK_ASSERT(a) assert(a)
|
||||
# endif
|
||||
#else
|
||||
# if !defined(DK_ASSERT)
|
||||
# define DK_ASSERT(a)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif
|
13
include/doorkeeper/implem/helpers.hpp
Normal file
13
include/doorkeeper/implem/helpers.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef id61F9FA08290643D0A947EC0E51060BEA
|
||||
#define id61F9FA08290643D0A947EC0E51060BEA
|
||||
|
||||
namespace dk {
|
||||
namespace implem {
|
||||
template <size_t D>
|
||||
CoordinateScalarType area ( const Vector<CoordinateScalarType, D>& parVec ) a_pure;
|
||||
} //namespace implem
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/helpers.inl"
|
||||
|
||||
#endif
|
15
include/doorkeeper/implem/helpers.inl
Normal file
15
include/doorkeeper/implem/helpers.inl
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace dk {
|
||||
namespace implem {
|
||||
///----------------------------------------------------------------------
|
||||
///----------------------------------------------------------------------
|
||||
template <size_t D>
|
||||
CoordinateScalarType area (const Vector<CoordinateScalarType, D>& parVec) {
|
||||
CoordinateScalarType retval(1);
|
||||
for (size_t d = 0; d < D; ++d) {
|
||||
retval *= parVec[d];
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
} //namespake implem
|
||||
|
||||
} //namespake dk
|
56
include/doorkeeper/implem/layer.inl
Normal file
56
include/doorkeeper/implem/layer.inl
Normal file
|
@ -0,0 +1,56 @@
|
|||
namespace dk {
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <size_t D>
|
||||
LayerBase<D>::LayerBase (const coords& parCount, const coords& parTileSize, const coords& parMasterTileSize) :
|
||||
m_count(parCount / (parMasterTileSize / parTileSize)),
|
||||
m_tilesize(parTileSize),
|
||||
m_mastersize(parMasterTileSize),
|
||||
m_haveFrom(0),
|
||||
m_haveTo(0)
|
||||
{
|
||||
DK_ASSERT((parMasterTileSize / parTileSize) * parTileSize == parMasterTileSize);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <size_t D>
|
||||
void LayerBase<D>::preload (const coords& parFrom, const coords& parTo) {
|
||||
if (parFrom < m_haveFrom or parTo > m_haveTo) {
|
||||
this->onPreload(parFrom, parTo);
|
||||
m_haveFrom = parFrom;
|
||||
m_haveTo = parTo;
|
||||
}
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, size_t D>
|
||||
Layer<T, D>::Layer (const coords& parTileSize, const coords& parMasterTileSize, TileMapData<T, D>& parTilemap) :
|
||||
LayerBase<D>(parTilemap.mapSize(), parTileSize, parMasterTileSize),
|
||||
m_tilemap(parTilemap)
|
||||
{
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, size_t D>
|
||||
typename Layer<T, D>::iterator Layer<T, D>::begin() {
|
||||
return iterator(&m_tiles, coords(0), this->m_count);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, size_t D>
|
||||
typename Layer<T, D>::iterator Layer<T, D>::end() {
|
||||
return iterator(&m_tiles, implem::buildPastEndCoordinate<D>(coords(0), this->m_count), this->m_count);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, size_t D>
|
||||
void Layer<T, D>::onPreload (const coords& parFrom, const coords& parTo) {
|
||||
m_tiles.clear();
|
||||
m_tilemap.fetch(m_tiles, parFrom, parTo);
|
||||
}
|
||||
}
|
21
include/doorkeeper/implem/mapstreambase.inl
Normal file
21
include/doorkeeper/implem/mapstreambase.inl
Normal file
|
@ -0,0 +1,21 @@
|
|||
namespace dk {
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <std::size_t D>
|
||||
MapStreamBase<D>::MapStreamBase (const coords& parMapSize) :
|
||||
m_mapSize(parMapSize)
|
||||
{
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <std::size_t D>
|
||||
void MapStreamBase<D>::read (char* parOut, std::size_t parOutSize, const coords& parFrom, const coords& parTo) {
|
||||
DK_ASSERT(parOut);
|
||||
DK_ASSERT(parOutSize > 0);
|
||||
DK_ASSERT(this->isReadable());
|
||||
DK_ASSERT(parFrom < m_mapSize);
|
||||
DK_ASSERT(parTo <= m_mapSize);
|
||||
this->dataBlockRequested(parOut, parOutSize, parFrom, parTo);
|
||||
}
|
||||
} //namespace dk
|
74
include/doorkeeper/implem/mapstreamraw.inl
Normal file
74
include/doorkeeper/implem/mapstreamraw.inl
Normal file
|
@ -0,0 +1,74 @@
|
|||
namespace dk {
|
||||
namespace implem {
|
||||
///---------------------------------------------------------------------
|
||||
///Only enabled if Device::MapDimensions is defined and is the same
|
||||
///as D. The function's name is set to give a hint to the user as to
|
||||
///why the error has occurred (they are trying to construct a
|
||||
///TileMapData with a set dimension that is different from the one
|
||||
///hardcoded in the device being passed in). The actual name could be
|
||||
///something like get_device_dimensions().
|
||||
///---------------------------------------------------------------------
|
||||
template <std::size_t D, typename Device>
|
||||
inline
|
||||
typename std::enable_if<Device::MapDimensions == D, std::size_t>::type err_mismatching_dimension (const Device*) noexcept {
|
||||
return Device::MapDimensions;
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///Only enabled if Device::MapDimensions is not defined. The function's
|
||||
///name is set to give a hint to the user as to why the error has
|
||||
///occurred (they are trying to construct a TileMapData with a set
|
||||
///dimension that is different from the one hardcoded in the device
|
||||
///being passed in). The actual name could be something like
|
||||
///get_device_dimensions().
|
||||
///---------------------------------------------------------------------
|
||||
template <std::size_t D, typename Device>
|
||||
inline
|
||||
typename std::enable_if<HasMapDimensions<Device>::result == false, std::size_t>::type err_mismatching_dimension (const Device*) noexcept {
|
||||
return 0;
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <std::size_t D, typename Device>
|
||||
inline
|
||||
typename std::enable_if<Device::MapDimensions == D, Vector<CoordinateScalarType, D>>::type retrieve_map_size_from_device (Device* parDevice) {
|
||||
return parDevice->mapSize();
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <std::size_t D, typename Device>
|
||||
inline
|
||||
typename std::enable_if<HasMapDimensions<Device>::result == false, Vector<CoordinateScalarType, D>>::type retrieve_map_size_from_device (Device* parDevice) {
|
||||
return get_map_size_from_device<D>(parDevice);
|
||||
}
|
||||
} //namespace implem
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, std::size_t D>
|
||||
template <typename Device>
|
||||
MapStreamRaw<T, D>::MapStreamRaw (Device& parDevice) :
|
||||
MapStreamBase<D>(implem::retrieve_map_size_from_device<D>(&parDevice)),
|
||||
m_istream(&parDevice),
|
||||
m_deviceHasDim(D == implem::err_mismatching_dimension<D>(&parDevice))
|
||||
{
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, std::size_t D>
|
||||
std::size_t MapStreamRaw<T, D>::dataBlockRequested (char* parOut, std::size_t parOutSize, const coords& parFrom, const coords& parTo) {
|
||||
DK_ASSERT(parOut);
|
||||
|
||||
const std::size_t totalBlocks = implem::area(parTo - parFrom);
|
||||
const std::size_t storableBlocks = parOutSize / sizeof(T);
|
||||
const std::size_t readMem = sizeof(T) * std::min(storableBlocks, totalBlocks);
|
||||
|
||||
const std::streamoff readPos = static_cast<std::streamoff>(implem::area(parFrom));
|
||||
m_istream.seekg(readPos, std::ios_base::beg);
|
||||
m_istream.read(parOut, readMem);
|
||||
return readMem;
|
||||
}
|
||||
} //namespace dk
|
137
include/doorkeeper/implem/tileiterator.inl
Normal file
137
include/doorkeeper/implem/tileiterator.inl
Normal file
|
@ -0,0 +1,137 @@
|
|||
namespace dk {
|
||||
namespace implem {
|
||||
template <size_t D>
|
||||
inline size_t get_index_from_pos (const Vector<CoordinateScalarType, D>& parPos, const Vector<CoordinateScalarType, D>& parSize) {
|
||||
size_t index = 0;
|
||||
for (size_t d = 0; d < D; ++d) {
|
||||
size_t pos = static_cast<size_t>(parPos[D - 1 - d]);
|
||||
for (size_t p = 0; p < D - 1 - d; ++p) {
|
||||
pos *= static_cast<size_t>(parSize[p]);
|
||||
}
|
||||
|
||||
index += pos;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
#if defined(NDEBUG)
|
||||
template <>
|
||||
inline size_t get_index_from_pos<2> (const Vector<CoordinateScalarType, 2>& parPos, const Vector<CoordinateScalarType, 2>& parSize) {
|
||||
return parPos.y() * parSize.x() + parPos.x();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <size_t D>
|
||||
inline Vector<CoordinateScalarType, D> buildPastEndCoordinate (const Vector<CoordinateScalarType, D>& parFrom, const Vector<CoordinateScalarType, D>& parTo) {
|
||||
Vector<CoordinateScalarType, D> retval;
|
||||
for (size_t d = 0; d < D - 1; ++d) {
|
||||
retval[d] = parFrom[d];
|
||||
}
|
||||
retval[D - 1] = parTo[D - 1];
|
||||
return retval;
|
||||
}
|
||||
} //namespace implem
|
||||
|
||||
template <typename T, size_t D, typename T1>
|
||||
TileIterator<T, D, T1>::TileIterator() :
|
||||
m_pos(CoordinateScalarType()),
|
||||
m_from(CoordinateScalarType()),
|
||||
m_to(CoordinateScalarType()),
|
||||
m_subdivareasize(CoordinateScalarType()),
|
||||
m_data(nullptr),
|
||||
m_subindex(0),
|
||||
m_maxsubindex(0)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T, size_t D, typename T1>
|
||||
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const coords& parFrom, const coords& parTo) :
|
||||
m_pos(parFrom),
|
||||
m_from(parFrom),
|
||||
m_to(parTo),
|
||||
m_subdivareasize(parTo - parFrom),
|
||||
m_data(parData),
|
||||
m_subindex(0),
|
||||
m_maxsubindex(0)
|
||||
{
|
||||
DK_ASSERT(parData);
|
||||
}
|
||||
|
||||
template <typename T, size_t D, typename T1>
|
||||
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo) :
|
||||
m_pos(parFrom),
|
||||
m_from(parFrom),
|
||||
m_to(parTo),
|
||||
m_subdivareasize(parAreaTo - parAreaFrom),
|
||||
m_data(parData),
|
||||
m_subindex(0),
|
||||
m_maxsubindex(0)
|
||||
{
|
||||
DK_ASSERT(parData);
|
||||
}
|
||||
|
||||
template <typename T, size_t D, typename T1>
|
||||
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parSubdiv) :
|
||||
m_pos(parFrom),
|
||||
m_from(parFrom),
|
||||
m_to(parTo),
|
||||
m_subdivareasize((parAreaTo - parAreaFrom) * parSubdiv),
|
||||
m_data(parData),
|
||||
m_subindex(0),
|
||||
m_maxsubindex(implem::area(parSubdiv) - 1)
|
||||
{
|
||||
DK_ASSERT(parData);
|
||||
}
|
||||
|
||||
template <typename T, size_t D, typename T1>
|
||||
void TileIterator<T, D, T1>::increment() {
|
||||
if (m_subindex < m_maxsubindex) {
|
||||
++m_subindex;
|
||||
return;
|
||||
}
|
||||
|
||||
m_subindex = 0;
|
||||
for (size_t d = 0; d < D - 1; ++d) {
|
||||
++m_pos[d];
|
||||
if (m_pos[d] >= m_to[d])
|
||||
m_pos[d] = m_from[d];
|
||||
else
|
||||
return;
|
||||
}
|
||||
++m_pos[D - 1];
|
||||
}
|
||||
|
||||
template <typename T, size_t D, typename T1>
|
||||
void TileIterator<T, D, T1>::decrement() {
|
||||
if (m_maxsubindex > 0 and m_subindex == 0) {
|
||||
--m_subindex;
|
||||
}
|
||||
|
||||
m_subindex = m_maxsubindex;
|
||||
for (size_t d = 0; d < D; ++d) {
|
||||
if (m_pos[d] > m_from[d]) {
|
||||
--m_pos[d];
|
||||
return;
|
||||
}
|
||||
else {
|
||||
m_pos[d] = m_to[d];
|
||||
}
|
||||
}
|
||||
++m_pos[D - 1];
|
||||
}
|
||||
|
||||
template <typename T, size_t D, typename T1>
|
||||
void TileIterator<T, D, T1>::advance (size_t parAdvance) {
|
||||
//TODO: implement
|
||||
}
|
||||
|
||||
template <typename T, size_t D, typename T1>
|
||||
ptrdiff_t TileIterator<T, D, T1>::distance_to (const TileIterator& parOther) {
|
||||
return std::distance(this->get_current_index(), parOther.get_current_index());
|
||||
}
|
||||
|
||||
template <typename T, size_t D, typename T1>
|
||||
bool TileIterator<T, D, T1>::equal (const TileIterator& parOther) const {
|
||||
return m_data == parOther.m_data and m_pos == parOther.m_pos;
|
||||
}
|
||||
} //namespace dk
|
34
include/doorkeeper/implem/tilemapdata.inl
Normal file
34
include/doorkeeper/implem/tilemapdata.inl
Normal file
|
@ -0,0 +1,34 @@
|
|||
namespace dk {
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, std::size_t D>
|
||||
TileMapData<T, D>::TileMapData (std::unique_ptr<MapStreamBase<D>>&& parStream) :
|
||||
m_mapstream(std::move(parStream))
|
||||
{
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, std::size_t D>
|
||||
void TileMapData<T, D>::fetch (std::vector<T>& parOut, const coords& parFrom, const coords& parTo) {
|
||||
DK_ASSERT(parFrom >= coords(0));
|
||||
DK_ASSERT(parFrom < parTo);
|
||||
DK_ASSERT(parFrom < m_mapstream->mapSize());
|
||||
DK_ASSERT(parTo <= m_mapstream->mapSize());
|
||||
|
||||
const auto tileCount = implem::area(parTo - parFrom);
|
||||
parOut.resize(tileCount);
|
||||
m_mapstream->read(
|
||||
reinterpret_cast<char*>(parOut.data()),
|
||||
parOut.size() * sizeof(typename std::vector<T>::value_type),
|
||||
parFrom,
|
||||
parTo);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, std::size_t D>
|
||||
const typename TileMapData<T, D>::coords& TileMapData<T, D>::mapSize() const {
|
||||
return m_mapstream->mapSize();
|
||||
}
|
||||
} //namespace dk
|
55
include/doorkeeper/implem/tyler.inl
Normal file
55
include/doorkeeper/implem/tyler.inl
Normal file
|
@ -0,0 +1,55 @@
|
|||
namespace dk {
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <size_t D>
|
||||
Tyler<D>::Tyler (const coords& parSize, const coords& parTileSize) :
|
||||
m_size(parSize),
|
||||
m_tilesize(parTileSize)
|
||||
{
|
||||
assert(m_size.x() > 0 and m_size.y() > 0);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <size_t D>
|
||||
typename Tyler<D>::coords::value_type Tyler<D>::tiles_count() const {
|
||||
typename coords::value_type retval = 1;
|
||||
for (size_t d = 0; d < D; ++d) {
|
||||
retval *= m_size[d];
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <size_t D>
|
||||
template <typename T>
|
||||
Layer<T, D>& Tyler<D>::push_layer (TileMapData<T, D>& parTilemap) {
|
||||
auto newLayer = new Layer<T, D>(m_tilesize, m_tilesize, parTilemap);
|
||||
DK_ASSERT(newLayer->mapSize() == m_size);
|
||||
DK_ASSERT(newLayer->count() == m_size);
|
||||
m_layers.push_back(LayerPtr(newLayer));
|
||||
return *newLayer;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <size_t D>
|
||||
template <typename T>
|
||||
Layer<T, D>& Tyler<D>::push_layer (TileMapData<T, D>& parTilemap, const coords& parSubdiv) {
|
||||
auto newLayer = new Layer<T, D>(m_tilesize / parSubdiv, m_tilesize, parTilemap);
|
||||
DK_ASSERT(newLayer->mapSize() == m_size);
|
||||
DK_ASSERT(newLayer->count() == m_size * parSubdiv);
|
||||
m_layers.push_back(LayerPtr(newLayer));
|
||||
return *newLayer;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <size_t D>
|
||||
void Tyler<D>::preload (const coords& parFrom, const coords& parTo) {
|
||||
for (auto& layer : m_layers) {
|
||||
layer->preload(parFrom, parTo);
|
||||
}
|
||||
}
|
||||
} //namespace dk
|
221
include/doorkeeper/implem/vector.hpp
Normal file
221
include/doorkeeper/implem/vector.hpp
Normal file
|
@ -0,0 +1,221 @@
|
|||
/*
|
||||
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:
|
||||
typedef T value_type;
|
||||
|
||||
#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
|
252
include/doorkeeper/implem/vector.inl
Normal file
252
include/doorkeeper/implem/vector.inl
Normal file
|
@ -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 <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
|
85
include/doorkeeper/implem/viewport.inl
Normal file
85
include/doorkeeper/implem/viewport.inl
Normal file
|
@ -0,0 +1,85 @@
|
|||
namespace dk {
|
||||
template <size_t D>
|
||||
Viewport<D>::Viewport (Tyler<D>& parTyler) :
|
||||
m_tyler(parTyler)
|
||||
{
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
Viewport<D>::Viewport (Tyler<D>& parTyler, const coords& parSize, const coords& parPos) :
|
||||
m_size(parSize),
|
||||
m_position(parPos),
|
||||
m_tyler(parTyler)
|
||||
{
|
||||
DK_ASSERT(parPos <= parPos + parSize);
|
||||
DK_ASSERT(parSize + parPos <= parTyler.map_size());
|
||||
m_tyler.preload(m_position, m_position + m_size);
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::iterator Viewport<D>::begin (Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::iterator IterType;
|
||||
return IterType(&parLayer.m_tiles, m_position, m_position + m_size, coords(0), m_tyler.map_size());
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::iterator Viewport<D>::end (Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::iterator IterType;
|
||||
const auto to(m_position + m_size);
|
||||
return IterType(&parLayer.m_tiles, implem::buildPastEndCoordinate(m_position, to), to, coords(0), m_tyler.map_size());
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator Viewport<D>::begin (const Layer<T, D>& parLayer) const {
|
||||
return this->cbegin(parLayer);
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator Viewport<D>::end (const Layer<T, D>& parLayer) const {
|
||||
return this->cend(parLayer);
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator Viewport<D>::cbegin (const Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::const_iterator IterType;
|
||||
return IterType(&parLayer.m_tiles, m_position, m_position + m_size, coords(0), m_tyler.map_size());
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator Viewport<D>::cend (const Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::const_iterator IterType;
|
||||
const auto to(m_position + m_size);
|
||||
return IterType(&parLayer.m_tiles, implem::buildPastEndCoordinate(m_position, to), to, coords(0), m_tyler.map_size());
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
void Viewport<D>::setSize (const coords& parSize) {
|
||||
DK_ASSERT(m_position <= m_position + parSize);
|
||||
DK_ASSERT(parSize + m_position <= m_tyler.map_size());
|
||||
m_size = parSize;
|
||||
m_tyler.preload(m_position, m_position + m_size);
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
void Viewport<D>::setFrom (const coords& parFrom) {
|
||||
DK_ASSERT(parFrom <= parFrom + m_size);
|
||||
DK_ASSERT(m_size + parFrom <= m_tyler.map_size());
|
||||
m_position = parFrom;
|
||||
m_tyler.preload(m_position, m_position + m_size);
|
||||
}
|
||||
|
||||
template <size_t D>
|
||||
void Viewport<D>::setFromSize (const coords& parFrom, const coords& parSize) {
|
||||
DK_ASSERT(parFrom <= parFrom + parSize);
|
||||
DK_ASSERT(parSize + parFrom <= m_tyler.map_size());
|
||||
m_position = parFrom;
|
||||
m_size = parSize;
|
||||
m_tyler.preload(m_position, m_position + m_size);
|
||||
}
|
||||
} //namespace dk
|
32
include/doorkeeper/mapreaders/mapstreambase.hpp
Normal file
32
include/doorkeeper/mapreaders/mapstreambase.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef id3CAE7A32F0C3428EA125F91D261C0029
|
||||
#define id3CAE7A32F0C3428EA125F91D261C0029
|
||||
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/implem/vector.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
namespace dk {
|
||||
template <std::size_t D>
|
||||
class MapStreamBase {
|
||||
public:
|
||||
typedef Vector<CoordinateScalarType, D> coords;
|
||||
|
||||
MapStreamBase ( void ) = delete;
|
||||
explicit MapStreamBase ( const coords& parMapSize );
|
||||
virtual ~MapStreamBase ( void ) noexcept = default;
|
||||
|
||||
virtual bool isReadable ( void ) const = 0;
|
||||
virtual bool isWriteable ( void ) const = 0;
|
||||
|
||||
const coords& mapSize ( void ) const noexcept { return m_mapSize; }
|
||||
void read ( char* parOut, std::size_t parOutSize, const coords& parFrom, const coords& parTo );
|
||||
|
||||
private:
|
||||
virtual std::size_t dataBlockRequested ( char* parOut, std::size_t parOutSize, const coords& parFrom, const coords& parTo ) = 0;
|
||||
const coords m_mapSize;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/mapstreambase.inl"
|
||||
|
||||
#endif
|
65
include/doorkeeper/mapreaders/mapstreamraw.hpp
Normal file
65
include/doorkeeper/mapreaders/mapstreamraw.hpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#ifndef id56E2396E102B4E10B20466D6B57A4C66
|
||||
#define id56E2396E102B4E10B20466D6B57A4C66
|
||||
|
||||
#include "doorkeeper/mapreaders/mapstreambase.hpp"
|
||||
#include "doorkeeper/implem/helpers.hpp"
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
#include <istream>
|
||||
|
||||
namespace dk {
|
||||
namespace implem {
|
||||
template <typename T>
|
||||
class HasMapDimensions {
|
||||
class yes { char m; };
|
||||
class nope { yes m[2]; };
|
||||
static yes deduce ( int a, int b = T::MapDimensions );
|
||||
static nope deduce ( ... );
|
||||
public:
|
||||
enum {
|
||||
result = (sizeof(yes) == sizeof(deduce(1)))
|
||||
};
|
||||
};
|
||||
|
||||
template <std::size_t D, typename Device>
|
||||
typename std::enable_if<Device::MapDimensions == D, std::size_t>::type err_mismatching_dimension ( const Device* ) noexcept a_pure;
|
||||
|
||||
template <std::size_t D, typename Device>
|
||||
typename std::enable_if<HasMapDimensions<Device>::result == false, std::size_t>::type err_mismatching_dimension ( const Device* ) noexcept a_pure;
|
||||
|
||||
template <std::size_t D, typename Device>
|
||||
typename std::enable_if<Device::MapDimensions == D, Vector<CoordinateScalarType, D>>::type retrieve_map_size_from_device ( Device* parDevice );
|
||||
|
||||
template <std::size_t D, typename Device>
|
||||
typename std::enable_if<HasMapDimensions<Device>::result == false, Vector<CoordinateScalarType, D>>::type retrieve_map_size_from_device ( Device* parDevice );
|
||||
} //namespace implem
|
||||
|
||||
//Customization point - specialize to enable map size retrieval for Device
|
||||
template <std::size_t D, typename Device>
|
||||
typename Device::coords get_map_size_from_device ( const Device* parDevice );
|
||||
|
||||
template <typename T, std::size_t D>
|
||||
class MapStreamRaw : public MapStreamBase<D> {
|
||||
public:
|
||||
typedef typename MapStreamBase<D>::coords coords;
|
||||
|
||||
MapStreamRaw ( void ) = delete;
|
||||
template <typename Device>
|
||||
explicit MapStreamRaw ( Device& parDevice );
|
||||
virtual ~MapStreamRaw ( void ) noexcept = default;
|
||||
|
||||
virtual bool isReadable ( void ) const { return true; }
|
||||
virtual bool isWriteable ( void ) const { return false; }
|
||||
|
||||
private:
|
||||
virtual std::size_t dataBlockRequested ( char* parOut, std::size_t parOutSize, const coords& parFrom, const coords& parTo );
|
||||
|
||||
std::istream m_istream;
|
||||
const bool m_deviceHasDim;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/mapstreamraw.inl"
|
||||
|
||||
#endif
|
13
include/doorkeeper/primitivetypes.hpp
Normal file
13
include/doorkeeper/primitivetypes.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef id583F11FE0934446E9135B4ADCFA1E4F9
|
||||
#define id583F11FE0934446E9135B4ADCFA1E4F9
|
||||
|
||||
#include <ciso646>
|
||||
#include "implem/compatibility.h"
|
||||
#include "implem/configuration.h"
|
||||
#include "implem/vector.hpp"
|
||||
|
||||
namespace dk {
|
||||
using cloonel::Vector;
|
||||
} //namespace dk
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue