2014-12-09 23:53:09 +01:00
|
|
|
#ifndef idD3EDC396AA314474B3D909559FFC0247
|
|
|
|
#define idD3EDC396AA314474B3D909559FFC0247
|
|
|
|
|
|
|
|
#include "primitivetypes.hpp"
|
2014-12-12 20:04:48 +01:00
|
|
|
#include "components/tileiterator.hpp"
|
2014-12-29 16:17:59 +01:00
|
|
|
#include "components/tilemapdata.hpp"
|
|
|
|
#include "implem/helpers.hpp"
|
2014-12-09 23:53:09 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2014-12-29 16:17:59 +01:00
|
|
|
#include <memory>
|
2014-12-09 23:53:09 +01:00
|
|
|
|
|
|
|
namespace dk {
|
2014-12-14 13:13:10 +01:00
|
|
|
template <size_t D>
|
2014-12-12 20:04:48 +01:00
|
|
|
class Viewport;
|
|
|
|
|
2014-12-09 23:53:09 +01:00
|
|
|
template <size_t D>
|
|
|
|
class LayerBase {
|
|
|
|
public:
|
|
|
|
typedef Vector<CoordinateScalarType, D> coords;
|
|
|
|
|
2014-12-12 20:04:48 +01:00
|
|
|
LayerBase ( const coords& parCount, const coords& parTileSize, const coords& parMasterTileSize );
|
2014-12-09 23:53:09 +01:00
|
|
|
virtual ~LayerBase ( void ) noexcept = default;
|
|
|
|
|
2015-01-05 18:01:28 +01:00
|
|
|
void preload ( const coords& parFrom, const coords& parTo );
|
2014-12-14 13:13:10 +01:00
|
|
|
coords count ( void ) const { return m_mastersize / m_tilesize * m_count; }
|
2014-12-29 16:17:59 +01:00
|
|
|
const coords& mapSize ( void ) const { return m_count; }
|
2014-12-14 13:13:10 +01:00
|
|
|
|
2014-12-09 23:53:09 +01:00
|
|
|
protected:
|
2014-12-12 20:04:48 +01:00
|
|
|
coords m_count;
|
2014-12-11 23:58:52 +01:00
|
|
|
coords m_tilesize;
|
|
|
|
coords m_mastersize;
|
2014-12-29 16:17:59 +01:00
|
|
|
|
|
|
|
private:
|
2015-01-05 18:01:28 +01:00
|
|
|
virtual void onPreload ( const coords& parFrom, const coords& parTo ) = 0;
|
|
|
|
|
|
|
|
coords m_haveFrom;
|
|
|
|
coords m_haveTo;
|
2014-12-09 23:53:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, size_t D>
|
|
|
|
class Layer : public LayerBase<D> {
|
2014-12-14 13:13:10 +01:00
|
|
|
friend class Viewport<D>;
|
|
|
|
|
2014-12-09 23:53:09 +01:00
|
|
|
public:
|
|
|
|
typedef typename LayerBase<D>::coords coords;
|
2014-12-12 20:04:48 +01:00
|
|
|
typedef TileIterator<T, D> iterator;
|
2014-12-30 17:53:15 +01:00
|
|
|
typedef TileIterator<const T, D> const_iterator;
|
2014-12-09 23:53:09 +01:00
|
|
|
|
|
|
|
Layer ( const Layer& ) = delete;
|
|
|
|
Layer ( Layer&& ) = default;
|
2014-12-29 16:17:59 +01:00
|
|
|
Layer ( const coords& parTileSize, const coords& parMasterTileSize, TileMapData<T, D>& parTilemap );
|
2014-12-09 23:53:09 +01:00
|
|
|
virtual ~Layer ( void ) noexcept = default;
|
|
|
|
|
|
|
|
Layer& operator= ( const Layer& ) = delete;
|
|
|
|
|
2014-12-12 20:04:48 +01:00
|
|
|
iterator begin ( void );
|
2014-12-14 13:13:10 +01:00
|
|
|
iterator end ( void );
|
2014-12-12 20:04:48 +01:00
|
|
|
|
2014-12-09 23:53:09 +01:00
|
|
|
private:
|
2015-01-05 18:01:28 +01:00
|
|
|
virtual void onPreload ( const coords& parFrom, const coords& parTo );
|
|
|
|
|
2014-12-09 23:53:09 +01:00
|
|
|
std::vector<T> m_tiles;
|
2014-12-29 16:17:59 +01:00
|
|
|
TileMapData<T, D>& m_tilemap;
|
2014-12-09 23:53:09 +01:00
|
|
|
};
|
|
|
|
} //namespace dk
|
|
|
|
|
|
|
|
#include "implem/layer.inl"
|
|
|
|
|
|
|
|
#endif
|