1 /*************************************************************************** 2 * Copyright (C) 2005-2019 by the FIFE team * 3 * http://www.fifengine.net * 4 * This file is part of FIFE. * 5 * * 6 * FIFE is free software; you can redistribute it and/or * 7 * modify it under the terms of the GNU Lesser General Public * 8 * License as published by the Free Software Foundation; either * 9 * version 2.1 of the License, or (at your option) any later version. * 10 * * 11 * This library is distributed in the hope that it will be useful, * 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 14 * Lesser General Public License for more details. * 15 * * 16 * You should have received a copy of the GNU Lesser General Public * 17 * License along with this library; if not, write to the * 18 * Free Software Foundation, Inc., * 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 20 ***************************************************************************/ 21 22 // Standard C++ library includes 23 24 // 3rd party library includes 25 26 // FIFE includes 27 // These includes are split up in two parts, separated by one empty line 28 // First block: files included from the FIFE root src directory 29 // Second block: files included from the same folder 30 #include "model/structures/layer.h" 31 #include "model/structures/map.h" 32 #include "util/log/logger.h" 33 #include "rendererbase.h" 34 35 namespace FIFE { 36 static Logger _log(LM_VIEW); 37 38 // use some big value, so that non-positioned renderers show on top 39 const int32_t DEFAULT_RENDERER_POSITION = 1000; 40 RendererBase(RenderBackend * renderbackend,int32_t position)41 RendererBase::RendererBase(RenderBackend* renderbackend, int32_t position): 42 m_renderbackend(renderbackend), 43 m_enabled(false), 44 m_pipeline_position(DEFAULT_RENDERER_POSITION), 45 m_listener(NULL) { 46 setPipelinePosition(position); 47 } 48 RendererBase(const RendererBase & old)49 RendererBase::RendererBase(const RendererBase& old): 50 m_renderbackend(old.m_renderbackend), 51 m_enabled(old.m_enabled), 52 m_pipeline_position(old.m_pipeline_position), 53 m_listener(NULL) { 54 setPipelinePosition(old.m_pipeline_position); 55 } 56 RendererBase()57 RendererBase::RendererBase(): 58 m_renderbackend(NULL), 59 m_enabled(false), 60 m_pipeline_position(DEFAULT_RENDERER_POSITION), 61 m_listener(NULL) { 62 } 63 setPipelinePosition(int32_t position)64 void RendererBase::setPipelinePosition(int32_t position) { 65 if (position !=m_pipeline_position) { 66 m_pipeline_position = position; 67 if (m_listener) { 68 m_listener->onRendererPipelinePositionChanged(this); 69 } 70 } 71 } 72 setEnabled(bool enabled)73 void RendererBase::setEnabled(bool enabled) { 74 if (m_enabled != enabled) { 75 m_enabled = enabled; 76 if (m_listener) { 77 m_listener->onRendererEnabledChanged(this); 78 } 79 } 80 } 81 addActiveLayer(Layer * layer)82 void RendererBase::addActiveLayer(Layer* layer) { 83 if (std::find(m_active_layers.begin(), m_active_layers.end(), layer) == m_active_layers.end()) { 84 m_active_layers.push_back(layer); 85 } 86 } 87 removeActiveLayer(Layer * layer)88 void RendererBase::removeActiveLayer(Layer* layer) { 89 m_active_layers.remove(layer); 90 } 91 clearActiveLayers()92 void RendererBase::clearActiveLayers() { 93 m_active_layers.clear(); 94 } 95 isActivedLayer(Layer * layer)96 bool RendererBase::isActivedLayer(Layer* layer) { 97 return std::find(m_active_layers.begin(), m_active_layers.end(), layer) != m_active_layers.end(); 98 } 99 activateAllLayers(Map * map)100 void RendererBase::activateAllLayers(Map* map) { 101 clearActiveLayers(); 102 103 const std::list<Layer*>& tmp = map->getLayers(); 104 std::list<Layer*>::const_iterator it = tmp.begin(); 105 for (; it != tmp.end(); ++it) { 106 addActiveLayer(*it); 107 } 108 } 109 110 } 111