FIFE  2008.0
instancerenderer.h
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 *
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:
50  InstanceRenderer(RenderBackend* renderbackend, int32_t position);
51 
52  InstanceRenderer(const InstanceRenderer& old);
53 
54  RendererBase* clone();
55 
58  virtual ~InstanceRenderer();
59  void render(Camera* cam, Layer* layer, RenderList& instances);
60  std::string getName() { return "InstanceRenderer"; }
61 
64  void addOutlined(Instance* instance, int32_t r, int32_t g, int32_t b, int32_t width, int32_t threshold = 1);
65 
68  void addColored(Instance* instance, int32_t r, int32_t g, int32_t b);
69 
72  void addTransparentArea(Instance* instance, const std::list<std::string> &groups, uint32_t w, uint32_t h, uint8_t trans, bool front = true);
73 
76  void removeOutlined(Instance* instance);
77 
80  void removeColored(Instance* instance);
81 
84  void removeTransparentArea(Instance* instance);
85 
88  void removeAllOutlines();
89 
92  void removeAllColored();
93 
96  void removeAllTransparentAreas();
97 
101  void addIgnoreLight(const std::list<std::string> &groups);
102 
105  void removeIgnoreLight(const std::list<std::string> &groups);
106 
109  void removeAllIgnoreLight();
110 
113  static InstanceRenderer* getInstance(IRendererContainer* cnt);
114 
117  RenderBackend* getRenderBackend() const {return m_renderbackend;}
118 
121  void reset();
122 
125  void setRemoveInterval(uint32_t interval);
126 
129  uint32_t getRemoveInterval() const;
130 
134  void addToCheck(const ImagePtr& image);
135 
138  void check();
139 
143  void removeInstance(Instance* instance);
144 
147  bool needColorBinding() { return m_need_bind_coloring; }
148 
149  private:
150  bool m_area_layer;
151  uint32_t m_interval;
152  bool m_timer_enabled;
153  std::list<std::string> m_unlit_groups;
154  bool m_need_sorting;
155  bool m_need_bind_coloring;
156 
157  enum InstanceRendererEffect {
158  NOTHING = 0x00,
159  OUTLINE = 0x01,
160  COLOR = 0x02,
161  AREA = 0x04
162  };
163  typedef uint8_t Effect;
164 
165  // contains per-instance information for outline drawing
166  class OutlineInfo {
167  public:
168  uint8_t r;
169  uint8_t g;
170  uint8_t b;
171  int32_t width;
172  int32_t threshold;
173  bool dirty;
174  ImagePtr outline;
175  Image* curimg;
176  InstanceRenderer* renderer;
177  OutlineInfo(InstanceRenderer* r);
178  ~OutlineInfo();
179  };
180  // contains per-instance information for overlay drawing
181  class ColoringInfo {
182  public:
183  uint8_t r;
184  uint8_t g;
185  uint8_t b;
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 
231  Image* bindOutline(OutlineInfo& info, RenderItem& vc, Camera* cam);
232  Image* bindColoring(ColoringInfo& info, RenderItem& vc, Camera* cam);
233 
234  void renderUnsorted(Camera* cam, Layer* layer, RenderList& instances);
235  void renderAlreadySorted(Camera* cam, Layer* layer, RenderList& instances);
236 
237  void removeFromCheck(const ImagePtr& image);
238  bool isValidImage(const ImagePtr& image);
239  };
240 }
241 
242 #endif
RendererBase(RenderBackend *renderbackend, int32_t position)
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39