2015-08-19 19:06:58 +00:00
|
|
|
/* Copyright 2015, Michele Santullo
|
|
|
|
* This file is part of DoorKeeper.
|
|
|
|
*
|
|
|
|
* DoorKeeper 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.
|
|
|
|
*
|
|
|
|
* DoorKeeper 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 DoorKeeper. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-12-09 22:53:09 +00:00
|
|
|
#ifndef idD3EDC396AA314474B3D909559FFC0247
|
|
|
|
#define idD3EDC396AA314474B3D909559FFC0247
|
|
|
|
|
2015-01-06 15:38:52 +00:00
|
|
|
#include "doorkeeper/primitivetypes.hpp"
|
|
|
|
#include "doorkeeper/components/tileiterator.hpp"
|
2015-05-24 23:37:20 +00:00
|
|
|
#include "doorkeeper/components/basemapsource.hpp"
|
2015-01-06 15:38:52 +00:00
|
|
|
#include "doorkeeper/implem/helpers.hpp"
|
2014-12-09 22:53:09 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2014-12-29 15:17:59 +00:00
|
|
|
#include <memory>
|
2015-01-08 11:20:17 +00:00
|
|
|
#include <cstdint>
|
2015-05-24 15:18:46 +00:00
|
|
|
#if !defined(NDEBUG)
|
|
|
|
#include <iostream>
|
|
|
|
#endif
|
2015-08-25 18:53:35 +00:00
|
|
|
#include <functional>
|
2014-12-09 22:53:09 +00:00
|
|
|
|
|
|
|
namespace dk {
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2014-12-12 19:04:48 +00:00
|
|
|
class Viewport;
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2014-12-09 22:53:09 +00:00
|
|
|
class LayerBase {
|
|
|
|
public:
|
2015-06-06 11:52:48 +00:00
|
|
|
typedef Vector<D> coords;
|
2014-12-09 22:53:09 +00:00
|
|
|
|
2015-08-25 18:53:35 +00:00
|
|
|
LayerBase ( const coords& parCount, const coords& parTileSize );
|
2014-12-09 22:53:09 +00:00
|
|
|
virtual ~LayerBase ( void ) noexcept = default;
|
|
|
|
|
2015-01-05 17:01:28 +00:00
|
|
|
void preload ( const coords& parFrom, const coords& parTo );
|
2014-12-29 15:17:59 +00:00
|
|
|
const coords& mapSize ( void ) const { return m_count; }
|
2014-12-14 12:13:10 +00:00
|
|
|
|
2014-12-09 22:53:09 +00:00
|
|
|
protected:
|
2014-12-12 19:04:48 +00:00
|
|
|
coords m_count;
|
2014-12-11 22:58:52 +00:00
|
|
|
coords m_tilesize;
|
2014-12-29 15:17:59 +00:00
|
|
|
|
|
|
|
private:
|
2015-01-05 17:01:28 +00:00
|
|
|
virtual void onPreload ( const coords& parFrom, const coords& parTo ) = 0;
|
|
|
|
|
|
|
|
coords m_haveFrom;
|
|
|
|
coords m_haveTo;
|
2014-12-09 22:53:09 +00:00
|
|
|
};
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D>
|
2014-12-09 22:53:09 +00:00
|
|
|
class Layer : public LayerBase<D> {
|
2014-12-14 12:13:10 +00:00
|
|
|
friend class Viewport<D>;
|
|
|
|
|
2014-12-09 22:53:09 +00:00
|
|
|
public:
|
|
|
|
typedef typename LayerBase<D>::coords coords;
|
2014-12-12 19:04:48 +00:00
|
|
|
typedef TileIterator<T, D> iterator;
|
2014-12-30 16:53:15 +00:00
|
|
|
typedef TileIterator<const T, D> const_iterator;
|
2014-12-09 22:53:09 +00:00
|
|
|
|
|
|
|
Layer ( const Layer& ) = delete;
|
|
|
|
Layer ( Layer&& ) = default;
|
2015-08-25 18:53:35 +00:00
|
|
|
Layer ( const coords& parTileSize, BaseMapSource<D>* parTilemap );
|
2014-12-09 22:53:09 +00:00
|
|
|
virtual ~Layer ( void ) noexcept = default;
|
|
|
|
|
|
|
|
Layer& operator= ( const Layer& ) = delete;
|
|
|
|
|
2014-12-12 19:04:48 +00:00
|
|
|
iterator begin ( void );
|
2014-12-14 12:13:10 +00:00
|
|
|
iterator end ( void );
|
2014-12-12 19:04:48 +00:00
|
|
|
|
2014-12-09 22:53:09 +00:00
|
|
|
private:
|
2015-01-05 17:01:28 +00:00
|
|
|
virtual void onPreload ( const coords& parFrom, const coords& parTo );
|
|
|
|
|
2014-12-09 22:53:09 +00:00
|
|
|
std::vector<T> m_tiles;
|
2015-06-06 12:14:00 +00:00
|
|
|
BaseMapSource<D>* m_tilemap;
|
2014-12-09 22:53:09 +00:00
|
|
|
};
|
2015-08-25 18:53:35 +00:00
|
|
|
|
|
|
|
namespace implem {
|
|
|
|
template <uint32_t D, typename O>
|
|
|
|
bool at_least_one ( const Vector<D>& parLeft, const Vector<D>& parRight, O parOp ) a_pure;
|
|
|
|
} //namespace implem
|
2014-12-09 22:53:09 +00:00
|
|
|
} //namespace dk
|
|
|
|
|
2015-01-06 15:38:52 +00:00
|
|
|
#include "doorkeeper/implem/layer.inl"
|
2014-12-09 22:53:09 +00:00
|
|
|
|
|
|
|
#endif
|