DoorKeeper/include/implem/layer.inl

57 lines
2.2 KiB
Text
Raw Normal View History

namespace dk {
2014-12-12 19:04:48 +00:00
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>
2014-12-12 19:04:48 +00:00
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>
2014-12-12 19:04:48 +00:00
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)
{
2014-12-13 03:50:23 +00:00
DK_ASSERT(m_streamer.tilesCount() == this->m_count);
setActiveViewport(coords(0), parCount);
}
2014-12-12 19:04:48 +00:00
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
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();
2014-12-13 03:50:23 +00:00
const auto area = implem::area<D>(parCount);
2014-12-12 19:04:48 +00:00
m_tiles.reserve(area);
m_streamer.copy(m_tiles, parFrom, parFrom + parCount);
m_activeViewport.setFrom(parFrom);
m_activeViewport.setSize(parCount);
}
}