/* 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 Tyler::Tyler() { } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template template Layer& Tyler::push_layer (BaseMapSource* parTilemap, int parIndex) { //TODO: store the index (void)parIndex; auto newLayer = new Layer(parTilemap); m_layers.push_back(LayerPtr(newLayer)); for (auto& callback : m_layerobs_callbacks) { if (nullptr != callback) { callback(*newLayer, true); } } return *newLayer; } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template template void Tyler::push_layer_void (BaseMapSource* parTilemap, int parIndex) { push_layer(parTilemap, parIndex); } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template void Tyler::preload (const coords& parFrom, const coords& parTo) { for (auto& layer : m_layers) { layer->preload(parFrom, parTo); } } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template auto Tyler::begin() -> iterator { return iterator(m_layers.begin()); } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template auto Tyler::begin() const -> const_iterator { return const_iterator(m_layers.begin()); } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template auto Tyler::end() -> iterator { return iterator(m_layers.end()); } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template auto Tyler::end() const -> const_iterator { return const_iterator(m_layers.end()); } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template auto Tyler::register_for_layeradd (layer_callback parCallback) -> LayerObsID { auto retval = m_layerobs_idmanager.allocate(); DK_ASSERT(retval.index() > 0); if (retval.index() > m_layerobs_callbacks.size()) { DK_ASSERT(retval.index() == m_layerobs_callbacks.size() + 1); m_layerobs_callbacks.resize(retval.index()); } else { DK_ASSERT(retval.salt() > 0); } m_layerobs_callbacks[retval.index() - 1] = parCallback; return retval; } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template void Tyler::unregister_for_layeradd (LayerObsID parID) { DK_ASSERT(parID.index() <= m_layerobs_callbacks.size()); DK_ASSERT(nullptr != m_layerobs_callbacks[parID.index() - 1]); m_layerobs_callbacks[parID.index() - 1] = nullptr; m_layerobs_idmanager.free(parID); } } //namespace dk