King_DuckZ
436d738620
Fixed a bug when iterating over a view that was smaller than the map size Added a class to abstract map readers
56 lines
2.3 KiB
C++
56 lines
2.3 KiB
C++
namespace dk {
|
|
///--------------------------------------------------------------------------
|
|
///--------------------------------------------------------------------------
|
|
template <size_t D>
|
|
LayerBase<D>::LayerBase (const coords& parCount, const coords& parTileSize, const coords& parMasterTileSize) :
|
|
m_count(parCount / (parMasterTileSize / parTileSize)),
|
|
m_tilesize(parTileSize),
|
|
m_mastersize(parMasterTileSize),
|
|
m_haveFrom(0),
|
|
m_haveTo(0)
|
|
{
|
|
DK_ASSERT((parMasterTileSize / parTileSize) * parTileSize == parMasterTileSize);
|
|
}
|
|
|
|
///--------------------------------------------------------------------------
|
|
///--------------------------------------------------------------------------
|
|
template <size_t D>
|
|
void LayerBase<D>::preload (const coords& parFrom, const coords& parTo) {
|
|
if (parFrom < m_haveFrom or parTo > m_haveTo) {
|
|
this->onPreload(parFrom, parTo);
|
|
m_haveFrom = parFrom;
|
|
m_haveTo = parTo;
|
|
}
|
|
}
|
|
|
|
///--------------------------------------------------------------------------
|
|
///--------------------------------------------------------------------------
|
|
template <typename T, size_t D>
|
|
Layer<T, D>::Layer (const coords& parTileSize, const coords& parMasterTileSize, TileMapData<T, D>& parTilemap) :
|
|
LayerBase<D>(parTilemap.mapSize(), parTileSize, parMasterTileSize),
|
|
m_tilemap(parTilemap)
|
|
{
|
|
}
|
|
|
|
///--------------------------------------------------------------------------
|
|
///--------------------------------------------------------------------------
|
|
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>
|
|
typename Layer<T, D>::iterator Layer<T, D>::end() {
|
|
return iterator(&m_tiles, implem::buildPastEndCoordinate<D>(coords(0), this->m_count), this->m_count);
|
|
}
|
|
|
|
///--------------------------------------------------------------------------
|
|
///--------------------------------------------------------------------------
|
|
template <typename T, size_t D>
|
|
void Layer<T, D>::onPreload (const coords& parFrom, const coords& parTo) {
|
|
m_tiles.clear();
|
|
m_tilemap.fetch(m_tiles, parFrom, parTo);
|
|
}
|
|
}
|