FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
instancerenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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 
44  public:
49  InstanceRenderer(RenderBackend* renderbackend, int32_t position);
50 
52 
54 
57  virtual ~InstanceRenderer();
58  void render(Camera* cam, Layer* layer, RenderList& instances);
59  std::string getName() { return "InstanceRenderer"; }
60 
63  void addOutlined(Instance* instance, int32_t r, int32_t g, int32_t b, int32_t width, int32_t threshold = 1);
64 
67  void addColored(Instance* instance, int32_t r, int32_t g, int32_t b, int32_t a = 128);
68 
71  void addTransparentArea(Instance* instance, const std::list<std::string> &groups, uint32_t w, uint32_t h, uint8_t trans, bool front = true);
72 
75  void removeOutlined(Instance* instance);
76 
79  void removeColored(Instance* instance);
80 
83  void removeTransparentArea(Instance* instance);
84 
87  void removeAllOutlines();
88 
91  void removeAllColored();
92 
96 
100  void addIgnoreLight(const std::list<std::string> &groups);
101 
104  void removeIgnoreLight(const std::list<std::string> &groups);
105 
108  void removeAllIgnoreLight();
109 
113 
117 
120  void reset();
121 
124  void setRemoveInterval(uint32_t interval);
125 
128  uint32_t getRemoveInterval() const;
129 
133  void addToCheck(const ImagePtr& image);
134 
137  void check();
138 
142  void removeInstance(Instance* instance);
143 
147 
148  private:
152  std::list<std::string> m_unlit_groups;
155 
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:
170  int32_t width;
171  int32_t threshold;
172  bool dirty;
177  ~OutlineInfo();
178  };
179  // contains per-instance information for overlay drawing
180  class ColoringInfo {
181  public:
186  bool dirty;
191  ~ColoringInfo();
192  };
193  class AreaInfo {
194  public:
196  std::list<std::string> groups;
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 {
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
223 
224  // InstanceDeleteListener to automatically remove Instance effect (outline, coloring, ...)
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 
233  Image* bindOutline(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
std::map< Instance *, AreaInfo > InstanceToAreas_t
ImagePtr getMultiColorOverlay(const RenderItem &vc, OverlayColors *colors=0)
Abstract interface for all the renderbackends.
std::vector< RenderItem * > RenderList
Definition: renderitem.h:130
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 outlined with given parameters.
Base Class for Images.
Definition: image.h:48
std::map< Instance *, OutlineInfo > InstanceToOutlines_t
InstanceToEffects_t m_assigned_instances
uint32_t getRemoveInterval() const
Gets the interval in seconds (default is 60).
Image * bindColoring(ColoringInfo &info, RenderItem &vc, Camera *cam)
void removeInstance(Instance *instance)
Removes instance from all effects.
InstanceRenderer(RenderBackend *renderbackend, int32_t position)
constructor.
Interface to class owning the renderers Used to get correct subclass of renderer in scripting side (v...
Definition: rendererbase.h:66
RenderBackend * getRenderBackend() const
Provides access point to the RenderBackend.
std::list< std::string > m_unlit_groups
InstanceToOutlines_t m_instance_outlines
RendererBase * clone()
Makes copy of this renderer.
void removeAllIgnoreLight()
Removes all groups(Namespaces)
void removeOutlined(Instance *instance)
Removes instance from outlining list.
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Definition: camera.h:59
void check()
Timer callback, tried to remove old effect images.
InstanceDeleteListener * m_delete_listener
void addIgnoreLight(const std::list< std::string > &groups)
Add groups(Namespaces) into a list.
bool needColorBinding()
Returns true if coloring need binding, otherwise false.
RenderBackend * m_renderbackend
Definition: rendererbase.h:171
unsigned char uint8_t
Definition: core.h:38
void removeIgnoreLight(const std::list< std::string > &groups)
Removes groups(Namespaces) from the list.
InstanceToAreas_t m_instance_areas
std::map< Instance *, ColoringInfo > InstanceToColoring_t
Base class for all view renderers View renderer renders one aspect of the view shown on screen...
Definition: rendererbase.h:78
bool isValidImage(const ImagePtr &image)
void renderAlreadySorted(Camera *cam, Layer *layer, RenderList &instances)
virtual ~InstanceRenderer()
Destructor.
A basic layer on a map.
Definition: layer.h:99
void render(Camera *cam, Layer *layer, RenderList &instances)
This method is called by the view to ask renderer to draw its rendering aspect based on given paramet...
void addColored(Instance *instance, int32_t r, int32_t g, int32_t b, int32_t a=128)
Marks given instance to be colored with given parameters.
std::string getName()
Name of the renderer.
void renderOverlay(RenderDataType type, RenderItem *item, uint8_t const *coloringColor, bool recoloring)
void renderUnsorted(Camera *cam, Layer *layer, RenderList &instances)
void removeTransparentArea(Instance *instance)
Removes instance form area list.
void removeAllTransparentAreas()
Removes all transparent areas.
void addTransparentArea(Instance *instance, const std::list< std::string > &groups, uint32_t w, uint32_t h, uint8_t trans, bool front=true)
Marks given instance to have a transparent area with given parameters.
std::map< Instance *, Effect > InstanceToEffects_t
uint32_t timestamp
void reset()
Removes all stuff.
void removeAllOutlines()
Removes all outlines.
Simple Timer class.
Definition: timer.h:61
ImagePtr image
RenderDataType
static InstanceRenderer * getInstance(IRendererContainer *cnt)
Gets instance for interface access.
unsigned int uint32_t
Definition: core.h:40
std::list< std::string > groups
void setRemoveInterval(uint32_t interval)
Sets the interval in seconds (default is 60).
ImagesToCheck_t m_check_images
void removeAllColored()
Removes all coloring.
Image * bindMultiOutline(OutlineInfo &info, RenderItem &vc, Camera *cam)
void addToCheck(const ImagePtr &image)
Add properly old ImagePtr into a check list.
void removeFromCheck(const ImagePtr &image)
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
void removeColored(Instance *instance)
Removes instance from coloring list.
InstanceToColoring_t m_instance_colorings
std::list< s_image_entry > ImagesToCheck_t
Image * bindOutline(OutlineInfo &info, RenderItem &vc, Camera *cam)
Binds new outline (if needed) to the instance&#39;s OutlineInfo.