DoorKeeper/include/implem/tilemapdata.inl
King_DuckZ 436d738620 Refactoring in map reading code - part 1/2
Fixed a bug when iterating over a view that was smaller than the map size
Added a class to abstract map readers
2015-01-05 18:01:28 +01:00

34 lines
1.3 KiB
C++

namespace dk {
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
template <typename T, std::size_t D>
TileMapData<T, D>::TileMapData (std::unique_ptr<MapStreamBase<D>>&& parStream) :
m_mapstream(std::move(parStream))
{
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
template <typename T, std::size_t D>
void TileMapData<T, D>::fetch (std::vector<T>& parOut, const coords& parFrom, const coords& parTo) {
DK_ASSERT(parFrom >= coords(0));
DK_ASSERT(parFrom < parTo);
DK_ASSERT(parFrom < m_mapstream->mapSize());
DK_ASSERT(parTo <= m_mapstream->mapSize());
const auto tileCount = implem::area(parTo - parFrom);
parOut.resize(tileCount);
m_mapstream->read(
reinterpret_cast<char*>(parOut.data()),
parOut.size() * sizeof(typename std::vector<T>::value_type),
parFrom,
parTo);
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
template <typename T, std::size_t D>
const typename TileMapData<T, D>::coords& TileMapData<T, D>::mapSize() const {
return m_mapstream->mapSize();
}
} //namespace dk