/* 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 .
*/
namespace dk {
template
Viewport::Viewport (Tyler& parTyler) :
m_tyler(parTyler)
{
}
template
Viewport::Viewport (Tyler& parTyler, const coords& parSize, const coords& parPos) :
m_view(parPos, parSize - 1),
m_tyler(parTyler)
{
DK_ASSERT(parPos < parPos + parSize); //parSize > 0
DK_ASSERT(parSize + parPos <= parTyler.map_size());
m_tyler.preload(m_view.position(), m_view.position() + this->size());
}
template
template
typename Layer::iterator Viewport::begin (Layer& parLayer) const {
typedef typename Layer::iterator IterType;
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_view.position(), m_tyler.map_size() - 1);
}
template
template
typename Layer::iterator Viewport::end (Layer& parLayer) const {
typedef typename Layer::iterator IterType;
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords(m_tyler.map_size() - 1), make_past_end_coords(m_tyler.map_size() - 1));
}
template
template
typename Layer::const_iterator Viewport::begin (const Layer& parLayer) const {
return this->cbegin(parLayer);
}
template
template
typename Layer::const_iterator Viewport::end (const Layer& parLayer) const {
return this->cend(parLayer);
}
template
template
typename Layer::const_iterator Viewport::cbegin (const Layer& parLayer) const {
typedef typename Layer::const_iterator IterType;
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_view.position(), m_tyler.map_size() - 1);
}
template
template
typename Layer::const_iterator Viewport::cend (const Layer& parLayer) const {
typedef typename Layer::const_iterator IterType;
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords(m_tyler.map_size() - 1), make_past_end_coords(m_tyler.map_size() - 1));
}
template
void Viewport::setFrom (const coords& parFrom) {
DK_ASSERT(this->size() + parFrom <= m_tyler.map_size());
m_view.set_position(parFrom);
m_tyler.preload(m_view.position(), m_view.position() + this->size());
}
template
typename Viewport::coords Viewport::size() const {
return (m_view.upper() + 1);
}
} //namespace dk