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-12 19:04:48 +00:00
|
|
|
namespace dk {
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2014-12-14 12:13:10 +00:00
|
|
|
Viewport<D>::Viewport (Tyler<D>& parTyler) :
|
|
|
|
m_tyler(parTyler)
|
2014-12-12 19:04:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2014-12-14 12:13:10 +00:00
|
|
|
Viewport<D>::Viewport (Tyler<D>& parTyler, const coords& parSize, const coords& parPos) :
|
2015-08-24 22:30:33 +00:00
|
|
|
m_view(parPos, parSize - 1),
|
2014-12-14 12:13:10 +00:00
|
|
|
m_tyler(parTyler)
|
2014-12-12 19:04:48 +00:00
|
|
|
{
|
2015-08-24 22:30:33 +00:00
|
|
|
DK_ASSERT(parPos < parPos + parSize); //parSize > 0
|
2014-12-29 15:17:59 +00:00
|
|
|
DK_ASSERT(parSize + parPos <= parTyler.map_size());
|
2015-08-24 22:30:33 +00:00
|
|
|
m_tyler.preload(m_view.position(), m_view.position() + this->size());
|
2014-12-14 12:13:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2014-12-14 12:13:10 +00:00
|
|
|
template <typename T>
|
|
|
|
typename Layer<T, D>::iterator Viewport<D>::begin (Layer<T, D>& parLayer) const {
|
|
|
|
typedef typename Layer<T, D>::iterator IterType;
|
2015-08-24 22:30:33 +00:00
|
|
|
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_view.position(), m_tyler.map_size() - 1);
|
2014-12-14 12:13:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2014-12-14 12:13:10 +00:00
|
|
|
template <typename T>
|
|
|
|
typename Layer<T, D>::iterator Viewport<D>::end (Layer<T, D>& parLayer) const {
|
|
|
|
typedef typename Layer<T, D>::iterator IterType;
|
2015-08-17 22:03:27 +00:00
|
|
|
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords<D>(m_tyler.map_size() - 1), make_past_end_coords<D>(m_tyler.map_size() - 1));
|
2015-01-05 17:01:28 +00:00
|
|
|
}
|
2014-12-14 12:13:10 +00:00
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2015-01-05 17:01:28 +00:00
|
|
|
template <typename T>
|
|
|
|
typename Layer<T, D>::const_iterator Viewport<D>::begin (const Layer<T, D>& parLayer) const {
|
|
|
|
return this->cbegin(parLayer);
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2015-01-05 17:01:28 +00:00
|
|
|
template <typename T>
|
|
|
|
typename Layer<T, D>::const_iterator Viewport<D>::end (const Layer<T, D>& parLayer) const {
|
|
|
|
return this->cend(parLayer);
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2015-01-05 17:01:28 +00:00
|
|
|
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;
|
2015-08-24 22:30:33 +00:00
|
|
|
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_view.position(), m_tyler.map_size() - 1);
|
2015-01-05 17:01:28 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2015-01-05 17:01:28 +00:00
|
|
|
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;
|
2015-08-17 22:03:27 +00:00
|
|
|
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords<D>(m_tyler.map_size() - 1), make_past_end_coords<D>(m_tyler.map_size() - 1));
|
2014-12-14 12:13:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2014-12-14 12:13:10 +00:00
|
|
|
void Viewport<D>::setFrom (const coords& parFrom) {
|
2015-08-25 12:31:42 +00:00
|
|
|
DK_ASSERT(this->size() + parFrom <= m_tyler.map_size());
|
2015-08-24 22:30:33 +00:00
|
|
|
m_view.set_position(parFrom);
|
|
|
|
m_tyler.preload(m_view.position(), m_view.position() + this->size());
|
2014-12-14 12:13:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2015-08-24 22:30:33 +00:00
|
|
|
typename Viewport<D>::coords Viewport<D>::size() const {
|
|
|
|
return (m_view.upper() + 1);
|
2014-12-12 19:04:48 +00:00
|
|
|
}
|
|
|
|
} //namespace dk
|