DoorKeeper/include/implem/viewport.inl
King_DuckZ c9381a4585 Advancing in the design of Tyler.
Iterating through tiles in viewports now works fine.
You can pass in a custom device as the data source for the tile map.
2014-12-29 16:17:59 +01:00

60 lines
1.8 KiB
C++

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);
}
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);
}
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