DoorKeeper/include/implem/layer.inl

55 lines
2.1 KiB
C++

namespace dk {
namespace implem {
///----------------------------------------------------------------------
///----------------------------------------------------------------------
template <size_t D>
typename LayerBase<D>::coords::value_type area (const typename LayerBase<D>::coords& parVec) {
typename LayerBase<D>::coords::value_type retval(1);
for (size_t d = 0; d < D; ++d) {
retval *= parVec[d];
}
return retval;
}
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <size_t D>
LayerBase<D>::LayerBase (const coords& parCount, const coords& parTileSize, const coords& parMasterTileSize) :
m_count(parCount),
m_tilesize(parTileSize),
m_mastersize(parMasterTileSize)
{
DK_ASSERT((parMasterTileSize / parTileSize) * parTileSize == parMasterTileSize);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename T, size_t D>
Layer<T, D>::Layer (const coords& parCount, const coords& parTileSize, const coords& parMasterTileSize, streamer_type&& parStreamer) :
LayerBase<D>(parCount, parTileSize, parMasterTileSize),
m_streamer(std::move(parStreamer)),
m_activeViewport(*this)
{
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename T, size_t D>
typename Layer<T, D>::iterator Layer<T, D>::begin() {
return iterator(&m_tiles, coords(0), this->m_count);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename T, size_t D>
void Layer<T, D>::setActiveViewport (const coords& parFrom, const coords& parCount) {
m_tiles.clear();
const auto area = implem::area(parCount);
m_tiles.reserve(area);
m_streamer.copy(m_tiles, parFrom, parFrom + parCount);
m_activeViewport.setFrom(parFrom);
m_activeViewport.setSize(parCount);
}
}