Debian Codegraph @

engine/core/view/renderers/instancerenderer.h

raw
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 #ifndef FIFE_INSTANCERENDERER_H
23 #define FIFE_INSTANCERENDERER_H
24
25 // Standard C++ library includes
26 #include <string>
27 #include <list>
28
29 // 3rd party library includes
30
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "view/rendererbase.h"
36 #include "util/time/timer.h"
37
38 namespace FIFE {
39 class Location;
40 class RenderBackend;
41 class InstanceDeleteListener;
42
43 class InstanceRenderer: public RendererBase {
44 public:
45 /** constructor.
46 * @param renderbackend to use
47 * @param position position for this renderer in rendering pipeline
48 */
49 InstanceRenderer(RenderBackend* renderbackend, int32_t position);
50
51 InstanceRenderer(const InstanceRenderer& old);
52
53 RendererBase* clone();
54
55 /** Destructor.
56 */
57 virtual ~InstanceRenderer();
58 void render(Camera* cam, Layer* layer, RenderList& instances);
59 std::string getName() { return "InstanceRenderer"; }
60
61 /** Marks given instance to be outlined with given parameters
62 */
63 void addOutlined(Instance* instance, int32_t r, int32_t g, int32_t b, int32_t width, int32_t threshold = 1);
64
65 /** Marks given instance to be colored with given parameters
66 */
67 void addColored(Instance* instance, int32_t r, int32_t g, int32_t b, int32_t a = 128);
68
69 /** Marks given instance to have a transparent area with given parameters
70 */
71 void addTransparentArea(Instance* instance, const std::list<std::string> &groups, uint32_t w, uint32_t h, uint8_t trans, bool front = true);
72
73 /** Removes instance from outlining list
74 */
75 void removeOutlined(Instance* instance);
76
77 /** Removes instance from coloring list
78 */
79 void removeColored(Instance* instance);
80
81 /** Removes instance form area list
82 */
83 void removeTransparentArea(Instance* instance);
84
85 /** Removes all outlines
86 */
87 void removeAllOutlines();
88
89 /** Removes all coloring
90 */
91 void removeAllColored();
92
93 /** Removes all transparent areas
94 */
95 void removeAllTransparentAreas();
96
97 /** Add groups(Namespaces) into a list. All instances, whose namespace is in the list
98 * will not lighted from the LightRenderer.
99 */
100 void addIgnoreLight(const std::list<std::string> &groups);
101
102 /** Removes groups(Namespaces) from the list
103 */
104 void removeIgnoreLight(const std::list<std::string> &groups);
105
106 /** Removes all groups(Namespaces)
107 */
108 void removeAllIgnoreLight();
109
110 /** Gets instance for interface access
111 */
112 static InstanceRenderer* getInstance(IRendererContainer* cnt);
113
114 /** Provides access point to the RenderBackend
115 */
116 RenderBackend* getRenderBackend() const {return m_renderbackend;}
117
118 /** Removes all stuff
119 */
120 void reset();
121
122 /** Sets the interval in seconds (default is 60).
123 */
124 void setRemoveInterval(uint32_t interval);
125
126 /** Gets the interval in seconds (default is 60).
127 */
128 uint32_t getRemoveInterval() const;
129
130 /** Add properly old ImagePtr into a check list.
131 * If it is still not used after a time(interval) then it is freed.
132 */
133 void addToCheck(const ImagePtr& image);
134
135 /** Timer callback, tried to remove old effect images
136 */
137 void check();
138
139 /** Removes instance from all effects.
140 * Should only be called by delete listener!
141 */
142 void removeInstance(Instance* instance);
143
144 /** Returns true if coloring need binding, otherwise false
145 */
146 bool needColorBinding() { return m_need_bind_coloring; }
147
148 private:
149 bool m_area_layer;
150 uint32_t m_interval;
151 bool m_timer_enabled;
152 std::list<std::string> m_unlit_groups;
153 bool m_need_sorting;
154 bool m_need_bind_coloring;
155
156 enum InstanceRendererEffect {
157 NOTHING = 0x00,
158 OUTLINE = 0x01,
159 COLOR = 0x02,
160 AREA = 0x04
161 };
162 typedef uint8_t Effect;
163
164 // contains per-instance information for outline drawing
165 class OutlineInfo {
166 public:
167 uint8_t r;
168 uint8_t g;
169 uint8_t b;
170 int32_t width;
171 int32_t threshold;
172 bool dirty;
173 ImagePtr outline;
174 Image* curimg;
175 InstanceRenderer* renderer;
176 OutlineInfo(InstanceRenderer* r);
177 ~OutlineInfo();
178 };
179 // contains per-instance information for overlay drawing
180 class ColoringInfo {
181 public:
182 uint8_t r;
183 uint8_t g;
184 uint8_t b;
185 uint8_t a;
186 bool dirty;
187 ImagePtr overlay;
188 Image* curimg;
189 InstanceRenderer* renderer;
190 ColoringInfo(InstanceRenderer* r);
191 ~ColoringInfo();
192 };
193 class AreaInfo {
194 public:
195 Instance* instance;
196 std::list<std::string> groups;
197 uint32_t w;
198 uint32_t h;
199 uint8_t trans;
200 bool front;
201 double z;
202 AreaInfo();
203 ~AreaInfo();
204 };
205 typedef std::map<Instance*, OutlineInfo> InstanceToOutlines_t;
206 typedef std::map<Instance*, ColoringInfo> InstanceToColoring_t;
207 typedef std::map<Instance*, AreaInfo> InstanceToAreas_t;
208
209 InstanceToOutlines_t m_instance_outlines;
210 InstanceToColoring_t m_instance_colorings;
211 InstanceToAreas_t m_instance_areas;
212
213 // struct to hold the ImagePtr with a timestamp
214 typedef struct {
215 ImagePtr image;
216 uint32_t timestamp;
217 } s_image_entry;
218 typedef std::list<s_image_entry> ImagesToCheck_t;
219 // old effect images
220 ImagesToCheck_t m_check_images;
221 // timer
222 Timer m_timer;
223
224 // InstanceDeleteListener to automatically remove Instance effect (outline, coloring, ...)
225 InstanceDeleteListener* m_delete_listener;
226 typedef std::map<Instance*, Effect> InstanceToEffects_t;
227 InstanceToEffects_t m_assigned_instances;
228
229 void renderOverlay(RenderDataType type, RenderItem* item, uint8_t const* coloringColor, bool recoloring);
230
231 /** Binds new outline (if needed) to the instance's OutlineInfo
232 */
233 Image* bindOutline(OutlineInfo& info, RenderItem& vc, Camera* cam);
234 Image* bindMultiOutline(OutlineInfo& info, RenderItem& vc, Camera* cam);
235 Image* bindColoring(ColoringInfo& info, RenderItem& vc, Camera* cam);
236
237 ImagePtr getMultiColorOverlay(const RenderItem& vc, OverlayColors* colors = 0);
238
239 void renderUnsorted(Camera* cam, Layer* layer, RenderList& instances);
240 void renderAlreadySorted(Camera* cam, Layer* layer, RenderList& instances);
241
242 void removeFromCheck(const ImagePtr& image);
243 bool isValidImage(const ImagePtr& image);
244 };
245 }
246
247 #endif