91 lines
3 KiB
C++
91 lines
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 <uint32_t D>
|
|
LayeredViewport<D>::LayeredViewport (Tyler<D>& parTyler) :
|
|
m_tyler(parTyler)
|
|
{
|
|
for (const auto& layer : m_tyler) {
|
|
const TileInfo<D> tinfo(layer);
|
|
auto it_found = m_views.find(tinfo);
|
|
if (m_views.end() == it_found) {
|
|
auto it_new = m_views.insert(it_found, Viewport<D>(m_tyler, nullptr));
|
|
it_new->second.set_tile_info(&it_new->first);
|
|
}
|
|
}
|
|
|
|
m_tyler.register_for_layeradd(this);
|
|
}
|
|
|
|
template <uint32_t D>
|
|
LayeredViewport<D>::~LayeredViewport() noexcept {
|
|
m_tyler.unregister_for_layeradd(this);
|
|
}
|
|
|
|
template <uint32_t D>
|
|
LayeredViewport<D>& LayeredViewport<D>::operator+= (const coords_f& parValue) {
|
|
for (auto& view : m_views) {
|
|
view.second += parValue;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
LayeredViewport<D>& LayeredViewport<D>::operator-= (const coords_f& parValue) {
|
|
for (auto& view : m_views) {
|
|
view.second -= parValue;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
void LayeredViewport<D>::on_layer_added (const LayerBase<D>* parLayer) {
|
|
}
|
|
|
|
template <uint32_t D>
|
|
void LayeredViewport<D>::on_layer_removed (const LayerBase<D>* parLayer) {
|
|
}
|
|
|
|
template <uint32_t D>
|
|
auto LayeredViewport<D>::begin() -> iterator {
|
|
return iterator(m_view.begin(), std::bind(&LayeredViewport<D>::viewport, this, std::placeholders::_1));
|
|
|
|
template <uint32_t D>
|
|
auto LayeredViewport<D>::begin() const -> const_iterator {
|
|
return const_iterator(m_view.begin(), std::bind(&LayeredViewport<D>::viewport, this, std::placeholders::_1));
|
|
}
|
|
|
|
template <uint32_t D>
|
|
auto LayeredViewport<D>::end() -> iterator {
|
|
return iterator(m_view.end(), std::bind(&LayeredViewport<D>::viewport, this, std::placeholders::_1));
|
|
|
|
template <uint32_t D>
|
|
auto LayeredViewport<D>::end() const -> const_iterator {
|
|
return const_iterator(m_view.end(), std::bind(&LayeredViewport<D>::viewport, this, std::placeholders::_1));
|
|
}
|
|
|
|
template <uint32_t D>
|
|
Viewport<D>& LayeredViewport<D>::viewport (const LayerBase<D>& parLayer) {
|
|
return const_cast<Viewport<D>&>(const_cast<const LayeredViewport<D>*>(this)->viewport(parLayer));
|
|
|
|
template <uint32_t D>
|
|
const Viewport<D>& LayeredViewport<D>::viewport (const LayerBase<D>& parLayer) const {
|
|
const TileInfo tinfo { parLayer.tile_size(), parLayer.map_size() };
|
|
return m_views[tinfo];
|
|
}
|
|
} //namespace dk
|