DoorKeeper/include/doorkeeper/implem/tyler.inl

86 lines
3.3 KiB
C++

/* 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 <http://www.gnu.org/licenses/>.
*/
namespace dk {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename PixConv>
Tyler<PixConv>::Tyler (const coords& parTileSize) :
m_size(0),
m_tilesize(parTileSize)
{
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename PixConv>
typename Tyler<PixConv>::coords::scalar_type Tyler<PixConv>::tiles_count() const {
typename coords::scalar_type retval = 1;
for (uint32_t d = 0; d < dimensions; ++d) {
retval *= m_size[d];
}
return retval;
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename PixConv>
template <typename T>
Layer<T, PixConv>& Tyler<PixConv>::push_layer (BaseMapSource<dimensions>* parTilemap, int parIndex) {
return push_layer<T>(parTilemap, coords(static_cast<CoordinateScalarType>(1)), parIndex);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename PixConv>
template <typename T>
Layer<T, PixConv>& Tyler<PixConv>::push_layer (BaseMapSource<dimensions>* parTilemap, const coords& parSubdiv, int parIndex) {
//TODO: store the index
(void)parIndex;
auto newLayer = new Layer<T, PixConv>(m_tilesize / parSubdiv, m_tilesize, parTilemap);
if (m_size == coords(0)) {
m_size = newLayer->mapSize();
}
else {
DK_ASSERT(newLayer->mapSize() == m_size);
if (newLayer->mapSize() != m_size) {
throw SizeMismatchException();
}
}
DK_ASSERT(newLayer->count() == m_size * parSubdiv);
m_layers.push_back(LayerPtr(newLayer));
return *newLayer;
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename PixConv>
template <typename T>
void Tyler<PixConv>::push_layer_void (BaseMapSource<dimensions>* parTilemap, int parIndex) {
push_layer<T>(parTilemap, parIndex);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename PixConv>
void Tyler<PixConv>::preload (const coords& parFrom, const coords& parTo) {
for (auto& layer : m_layers) {
layer->preload(parFrom, parTo);
}
}
} //namespace dk