/* Copyright 2015, Michele Santullo
* This file is part of DoorKeeper.
*
* DoorKeeper is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DoorKeeper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DoorKeeper. If not, see .
*/
namespace dk {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template
LayerBase::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
void LayerBase::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
Layer::Layer (const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource* parTilemap) :
LayerBase(parTilemap->mapSize(), parTileSize, parMasterTileSize),
m_tilemap(parTilemap)
{
DK_ASSERT(m_tilemap);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template
typename Layer::iterator Layer::begin() {
return iterator(&m_tiles, m_tilemap->pixel_conv(), coords(0), this->m_count);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template
typename Layer::iterator Layer::end() {
return iterator(&m_tiles, m_tilemap->pixel_conv(), make_past_end_coords(this->m_count - 1), make_past_end_coords(this->m_count - 1));
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template
void Layer::onPreload (const coords& parFrom, const coords& parTo) {
m_tiles.clear();
m_tilemap->fetch(m_tiles, parFrom, parTo);
#if !defined(NDEBUG)
std::cout << "Preloading layer from " << parFrom << " to " << parTo << '\n';
#endif
}
}