File: instancerenderer.h

package info (click to toggle)
fife 0.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,012 kB
  • ctags: 26,660
  • sloc: cpp: 84,903; sh: 10,269; python: 8,753; xml: 1,213; makefile: 265; objc: 245; ansic: 229
file content (242 lines) | stat: -rw-r--r-- 7,432 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/***************************************************************************
 *   Copyright (C) 2005-2013 by the FIFE team                              *
 *   http://www.fifengine.net                                              *
 *   This file is part of FIFE.                                            *
 *                                                                         *
 *   FIFE is free software; you can redistribute it and/or                 *
 *   modify it under the terms of the GNU Lesser General Public            *
 *   License as published by the Free Software Foundation; either          *
 *   version 2.1 of the License, or (at your option) any later version.    *
 *                                                                         *
 *   This library 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     *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU Lesser General Public      *
 *   License along with this library; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

#ifndef FIFE_INSTANCERENDERER_H
#define FIFE_INSTANCERENDERER_H

// Standard C++ library includes
#include <string>
#include <list>

// 3rd party library includes

// FIFE includes
// These includes are split up in two parts, separated by one empty line
// First block: files included from the FIFE root src directory
// Second block: files included from the same folder
#include "view/rendererbase.h"
#include "util/time/timer.h"

namespace FIFE {
	class Location;
	class RenderBackend;
	class InstanceDeleteListener;

	class InstanceRenderer: public RendererBase {
	public:
		/** constructor.
		 * @param renderbackend to use
		 * @param position position for this renderer in rendering pipeline
		 */
		InstanceRenderer(RenderBackend* renderbackend, int32_t position);

		InstanceRenderer(const InstanceRenderer& old);

		RendererBase* clone();

		/** Destructor.
		 */
		virtual ~InstanceRenderer();
		void render(Camera* cam, Layer* layer, RenderList& instances);
		std::string getName() { return "InstanceRenderer"; }

		/** Marks given instance to be outlined with given parameters
		 */
		void addOutlined(Instance* instance, int32_t r, int32_t g, int32_t b, int32_t width, int32_t threshold = 1);

		/** Marks given instance to be colored with given parameters
		 */
		void addColored(Instance* instance, int32_t r, int32_t g, int32_t b, int32_t a = 128);

		/** Marks given instance to have an transparent area with given paramters
		 */
		void addTransparentArea(Instance* instance, const std::list<std::string> &groups, uint32_t w, uint32_t h, uint8_t trans, bool front = true);

		/** Removes instance from outlining list
		 */
		void removeOutlined(Instance* instance);

		/** Removes instance from coloring list
		 */
		void removeColored(Instance* instance);

		/** Removes instance form area list
		 */
		void removeTransparentArea(Instance* instance);

		/** Removes all outlines
		 */
		void removeAllOutlines();

		/** Removes all coloring
		 */
		void removeAllColored();

		/** Removes all transparent areas
		 */
		void removeAllTransparentAreas();

		/** Add groups(Namespaces) into a list. All instances, whose namespace is in the list
		 *  will not lighted from the LightRenderer.
		 */
		void addIgnoreLight(const std::list<std::string> &groups);

		/** Removes groups(Namespaces) from the list
		 */
		void removeIgnoreLight(const std::list<std::string> &groups);

		/** Removes all groups(Namespaces)
		 */
		void removeAllIgnoreLight();

		/** Gets instance for interface access
		 */
		static InstanceRenderer* getInstance(IRendererContainer* cnt);

		/** Provides access point to the RenderBackend
		 */
		RenderBackend* getRenderBackend() const {return m_renderbackend;}

		/** Removes all stuff
		 */
		void reset();

		/** Sets the interval in seconds (default is 60).
		 */
		void setRemoveInterval(uint32_t interval);

		/** Gets the interval in seconds (default is 60).
		 */
		uint32_t getRemoveInterval() const;

		/** Add properly old ImagePtr into a check list.
		  * If it is still not used after a time(interval) then it is freed.
		 */
		void addToCheck(const ImagePtr& image);

		/** Timer callback, tried to remove old effect images
		 */
		void check();

		/** Removes instance from all effects.
		  * Should only be called by delete listener!
		 */
		void removeInstance(Instance* instance);

		/** Returns true if coloring need binding, otherwise false
		 */
		bool needColorBinding() { return m_need_bind_coloring; }

	private:
		bool m_area_layer;
		uint32_t m_interval;
		bool m_timer_enabled;
		std::list<std::string> m_unlit_groups;
		bool m_need_sorting;
		bool m_need_bind_coloring;

		enum InstanceRendererEffect {
			NOTHING = 0x00,
			OUTLINE = 0x01,
			COLOR = 0x02,
			AREA = 0x04
		};
		typedef uint8_t Effect;

		// contains per-instance information for outline drawing
		class OutlineInfo {
		public:
			uint8_t r;
			uint8_t g;
			uint8_t b;
			int32_t width;
			int32_t threshold;
			bool dirty;
			ImagePtr outline;
			Image* curimg;
			InstanceRenderer* renderer;
			OutlineInfo(InstanceRenderer* r);
			~OutlineInfo();
		};
		// contains per-instance information for overlay drawing
		class ColoringInfo {
		public:
			uint8_t r;
			uint8_t g;
			uint8_t b;
			uint8_t a;
			bool dirty;
			ImagePtr overlay;
			Image* curimg;
			InstanceRenderer* renderer;
			ColoringInfo(InstanceRenderer* r);
			~ColoringInfo();
		};
		class AreaInfo {
		public:
			Instance* instance;
			std::list<std::string> groups;
			uint32_t w;
			uint32_t h;
			uint8_t trans;
			bool front;
			double z;
			AreaInfo();
			~AreaInfo();
		};
		typedef std::map<Instance*, OutlineInfo> InstanceToOutlines_t;
		typedef std::map<Instance*, ColoringInfo> InstanceToColoring_t;
		typedef std::map<Instance*, AreaInfo> InstanceToAreas_t;

		InstanceToOutlines_t m_instance_outlines;
		InstanceToColoring_t m_instance_colorings;
		InstanceToAreas_t m_instance_areas;

		// struct to hold the ImagePtr with a timestamp
		typedef struct {
			ImagePtr image;
			uint32_t timestamp;
		} s_image_entry;
		typedef std::list<s_image_entry> ImagesToCheck_t;
		// old effect images
		ImagesToCheck_t m_check_images;
		// timer
		Timer m_timer;

		// InstanceDeleteListener to automatically remove Instance effect (outline, coloring, ...)
		InstanceDeleteListener* m_delete_listener;
		typedef std::map<Instance*, Effect> InstanceToEffects_t;
		InstanceToEffects_t m_assigned_instances;

		/** Binds new outline (if needed) to the instance's OutlineInfo
		 */
		Image* bindOutline(OutlineInfo& info, RenderItem& vc, Camera* cam);
		Image* bindColoring(ColoringInfo& info, RenderItem& vc, Camera* cam);

		void renderUnsorted(Camera* cam, Layer* layer, RenderList& instances);
		void renderAlreadySorted(Camera* cam, Layer* layer, RenderList& instances);

		void removeFromCheck(const ImagePtr& image);
		bool isValidImage(const ImagePtr& image);
	};
}

#endif