comparison engine/core/view/rendererbase.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_RENDERERBASE_H
23 #define FIFE_RENDERERBASE_H
24
25 // Standard C++ library includes
26 #include <list>
27
28 // 3rd party library includes
29
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
34
35 namespace FIFE {
36 class Camera;
37 class Layer;
38 class Map;
39 class Instance;
40 class RenderBackend;
41
42 class RendererBase;
43 /** RendererListener allows reaction to changes in renderer
44 * Having this implemented via callback mechanism should speed up the rendering a bit
45 * (e.g. no need to sort pipeline order per each frame)
46 */
47 class IRendererListener {
48 public:
49 virtual ~IRendererListener() {}
50
51 /** Renderer's pipeline position has been changed
52 */
53 virtual void onRendererPipelinePositionChanged(RendererBase* renderer) = 0;
54
55 /** Renderer is enabled / disabled
56 */
57 virtual void onRendererEnabledChanged(RendererBase* renderer) = 0;
58 };
59
60 /** Interface to class owning the renderers
61 * Used to get correct subclass of renderer in scripting side (via renderer's static method)
62 */
63 class IRendererContainer {
64 public:
65 virtual ~IRendererContainer() {}
66
67 /** Returns renderer with given name
68 */
69 virtual RendererBase* getRenderer(const std::string& renderername) = 0;
70 };
71
72 /** Base class for all view renderers
73 * View renderer renders one aspect of the view shown on screen
74 */
75 class RendererBase {
76 public:
77 /** Constructor
78 * @param renderbackend to use
79 * @param position position for this renderer in rendering pipeline
80 */
81 RendererBase(RenderBackend* renderbackend, int position);
82
83 /** Copy Constructor
84 */
85 RendererBase(const RendererBase& old);
86
87 /** Makes copy of this renderer
88 */
89 virtual RendererBase* clone() = 0;
90
91 /** Destructor
92 */
93 virtual ~RendererBase() {};
94
95 /** This method is called by the view to ask renderer to draw its rendering aspect based on
96 * given parameters. Renderers receive non-clipped instance stack since there is no
97 * way to know which information is relevant for the renderer. E.g. effect renderer
98 * might need to know offscreen instance locations to be able to draw radiation coming from
99 * some instance not visible on the screen.
100 *
101 * @param cam camera view to draw
102 * @param layer current layer to be rendered
103 * @param instances instances on the current layer
104 * @ see setPipelinePosition
105 */
106 virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) = 0;
107
108 /** Name of the renderer
109 */
110 virtual std::string getName() = 0;
111
112 /** Gets renderer position in the rendering pipeline
113 */
114 int getPipelinePosition() const { return m_pipeline_position; }
115
116 /** Sets renderer position in the rendering pipeline
117 * Pipeline position defines in which order view calls the renderers when update occurs
118 * Note that renderers are called once per rendered layer, thus to update the
119 * whole screen, renderer might receive multiple calls
120 */
121 void setPipelinePosition(int position);
122
123 /** Enables renderer
124 */
125 virtual void setEnabled(bool enabled);
126
127 /** Resets information in the renderer
128 */
129 virtual void reset() {}
130
131 /** Is renderer enabled
132 */
133 bool isEnabled() const { return m_enabled; }
134
135 /** Sets listener for renderer
136 */
137 void setRendererListener(IRendererListener* listener) { m_listener = listener; }
138
139 /** Adds active layer to renderer. Only active layers are rendered
140 */
141 void addActiveLayer(Layer* layer);
142
143 /** Removes active layer from renderer.
144 */
145 void removeActiveLayer(Layer* layer);
146
147 /** Clears all active layers from renderer
148 */
149 void clearActiveLayers();
150
151 /** Activates all layers from given elevation
152 */
153 void activateAllLayers(Map* elevation);
154
155 /** Returns if given layer is currently activated
156 */
157 bool isActivedLayer(Layer* layer);
158
159
160 protected:
161 RendererBase();
162
163 std::list<Layer*> m_active_layers;
164 RenderBackend* m_renderbackend;
165
166 private:
167 bool m_enabled;
168 int m_pipeline_position;
169 IRendererListener* m_listener;
170 };
171 }
172
173 #endif