25 #include <boost/bind.hpp>
108 renderer->addToCheck(outline);
112 if (renderer->needColorBinding()) {
113 renderer->addToCheck(overlay);
150 m_interval(old.m_interval),
151 m_timer_enabled(false) {
187 FL_WARN(
_log,
"No cellgrid assigned to layer, cannot draw instances");
209 const std::list<Layer*>& layers = parent->
getLayers();
210 std::list<Layer*>::const_iterator iter = layers.begin();
211 for (; iter != layers.end(); ++iter, ++this_layer) {
212 if (*iter == layer) {
218 static const double global_z_max = 100.0;
220 static const double global_z_min = -100.0;
221 static const double depth_range = fabs(global_z_min - global_z_max);
230 double layer_depth_range = depth_range /
static_cast<double>(num_layers);
232 double layer_z_offset = global_z_min +
233 layer_depth_range *
static_cast<double>(this_layer) -
234 layer_depth_range * 0.5;
238 double layer_z_offset = global_z_max - (num_layers - (this_layer - 1)) * 20;
241 std::multimap<float, RenderItem*> transparentInstances;
243 RenderList::iterator instance_it = instances.begin();
244 for (;instance_it != instances.end(); ++instance_it) {
246 Instance* instance = (*instance_it)->instance;
248 float vertexZ =
static_cast<float>(layer_z_offset + vc.
screenpoint.
z);
264 uint8_t rgba[4] = { coloring_it->second.r, coloring_it->second.g, coloring_it->second.b, coloring_it->second.a };
268 if (outline || coloring) {
274 if(lm != 0 && unlit) {
277 std::list<std::string>::iterator unlit_it =
m_unlit_groups.begin();
279 if(lit_name.find(*unlit_it) != std::string::npos) {
291 transparentInstances.insert(std::pair<float, RenderItem*>(vertexZ, &vc));
296 if(!transparentInstances.empty()) {
297 std::multimap<float, RenderItem*>::iterator it = transparentInstances.begin();
298 for( ; it != transparentInstances.end(); ++it) {
301 float vertexZ = it->first;
315 uint8_t rgb[3] = { coloring_it->second.r, coloring_it->second.g, coloring_it->second.b };
319 if (outline || coloring) {
325 if(lm != 0 && unlit) {
328 std::list<std::string>::iterator unlit_it =
m_unlit_groups.begin();
330 if(lit_name.find(*unlit_it) != std::string::npos) {
358 info.
z = instance_posv.
z;
369 RenderList::iterator instance_it = instances.begin();
370 for (;instance_it != instances.end(); ++instance_it) {
372 Instance* instance = (*instance_it)->instance;
395 std::list<std::string>::iterator group_it = infoa.
groups.begin();
396 for(;group_it != infoa.
groups.end(); ++group_it) {
397 if(str_name.find((*group_it)) != std::string::npos) {
401 rec.
x = p.
x - infoa.
w / 2;
402 rec.
y = p.
y - infoa.
h / 2;
442 uint8_t rgba[4] = { coloring_it->second.r, coloring_it->second.g, coloring_it->second.b, coloring_it->second.a };
448 if (outline || coloring) {
456 std::list<std::string>::iterator unlit_it =
m_unlit_groups.begin();
458 if(lit_name.find(*unlit_it) != std::string::npos) {
477 inline bool aboveThreshold(int32_t threshold, int32_t alpha, int32_t prev_alpha) {
480 if (((alpha - threshold) >= 0 || (prev_alpha - threshold) >= 0) && (alpha != prev_alpha)) {
487 if((alpha == 0 || prev_alpha == 0) && (alpha != prev_alpha)) {
516 std::stringstream sts;
518 static_cast<uint32_t>(info.
g) <<
"," <<
static_cast<uint32_t>(info.
b) <<
"," << info.
width;
538 SDL_Surface* outline_surface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA,
546 for (int32_t x = 0; x < outline_surface->w; x ++) {
548 for (int32_t y = 0; y < outline_surface->h; y ++) {
552 for (int32_t yy = y; yy < y + info.
width; yy++) {
556 for (int32_t yy = y - info.
width; yy < y; yy++) {
565 for (int32_t y = 0; y < outline_surface->h; y ++) {
567 for (int32_t x = 0; x < outline_surface->w; x ++) {
571 for (int32_t xx = x; xx < x + info.
width; xx++) {
575 for (int32_t xx = x - info.
width; xx < x; xx++) {
621 std::stringstream sts;
623 static_cast<uint32_t>(info.
g) <<
"," <<
static_cast<uint32_t>(info.
b) <<
"," << static_cast<uint32_t>(info.
a);
644 SDL_Surface* overlay_surface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA,
649 float alphaFactor =
static_cast<float>(info.
a/255.0);
650 for (int32_t x = 0; x < overlay_surface->w; x ++) {
651 for (int32_t y = 0; y < overlay_surface->h; y ++) {
654 Image::putPixel(overlay_surface, x, y, info.
r*(1.0-alphaFactor) + r*alphaFactor, info.
g*(1.0-alphaFactor) + g*alphaFactor, info.
b*(1.0-alphaFactor) + b*alphaFactor, a);
685 newinfo.
width = width;
686 newinfo.
dirty =
true;
692 std::pair<InstanceToOutlines_t::iterator, bool> insertiter =
m_instance_outlines.insert(std::make_pair(instance, newinfo));
694 if (insertiter.second ==
false) {
699 if (info.
r != r || info.
g != g || info.
b != b || info.
width != width) {
714 Effect& effect = iter.first->second;
715 if ((effect &
OUTLINE) != OUTLINE) {
728 newinfo.
dirty =
true;
734 std::pair<InstanceToColoring_t::iterator, bool> insertiter =
m_instance_colorings.insert(std::make_pair(instance, newinfo));
736 if (insertiter.second ==
false) {
741 if (info.
r != r || info.
g != g || info.
b != b || info.
a != a) {
754 Effect& effect = iter.first->second;
755 if ((effect &
COLOR) != COLOR) {
769 newinfo.
trans = trans;
770 newinfo.
front = front;
777 std::pair<InstanceToAreas_t::iterator, bool> insertiter =
m_instance_areas.insert(std::make_pair(instance, newinfo));
779 if (insertiter.second ==
false) {
782 AreaInfo& info = insertiter.first->second;
793 Effect& effect = iter.first->second;
794 if ((effect &
AREA) != AREA) {
818 if (it->second ==
COLOR) {
832 if (it->second ==
AREA) {
836 }
else if ((it->second &
AREA) ==
AREA) {
867 if (it->second ==
COLOR) {
885 if (it->second ==
AREA) {
888 }
else if ((it->second &
AREA) ==
AREA) {
898 std::list<std::string>::const_iterator group_it = groups.begin();
899 for(;group_it != groups.end(); ++group_it) {
907 std::list<std::string>::const_iterator group_it = groups.begin();
908 for(;group_it != groups.end(); ++group_it) {
909 std::list<std::string>::iterator unlit_it =
m_unlit_groups.begin();
911 if((*group_it).find(*unlit_it) != std::string::npos) {
953 if (it->image.get()->getName() == image.
get()->
getName()) {
995 if (it->image.get()->getName() == image.
get()->
getName()) {
#define FL_WARN(logger, msg)
Abstract interface for all the renderbackends.
Map * getMap() const
Get the map this layer is contained in.
T * get() const
allows direct access to underlying pointer
static bool putPixel(SDL_Surface *surface, int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
virtual bool exists(const std::string &name)
Checks to see if an Image exists.
std::vector< RenderItem * > RenderList
virtual ResourceState getState()
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.
virtual void changeRenderInfos(uint16_t elements, int32_t src, int32_t dst, bool light, bool stentest, uint8_t stenref, GLConstants stenop, GLConstants stenfunc)=0
Dirty helper function to change the render infos.
const std::string & getNamespace() const
T h
Height of the rectangle.
void addDeleteListener(InstanceDeleteListener *listener)
Adds new instance delete listener.
Instance visual contains data that is needed to visualize the instance on screen. ...
InstanceToEffects_t m_assigned_instances
OutlineInfo(InstanceRenderer *r)
bool isEnabledFogOfWar()
Gets whether Fog of War visualization is enabled.
uint32_t getRemoveInterval() const
Gets the interval in seconds (default is 60).
virtual const std::string & getName() const =0
The name of the renderbackend.
DoublePoint3D toVirtualScreenCoordinates(const ExactModelCoordinate &map_coords)
Transforms given point from map coordinates to virtual screen coordinates.
Image * bindColoring(ColoringInfo &info, RenderItem &vc, Camera *cam)
void removeInstance(Instance *instance)
Removes instance from all effects.
DoublePoint3D screenpoint
InstanceRenderer(RenderBackend *renderbackend, int32_t position)
constructor.
void getPixelRGBA(int32_t x, int32_t y, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
CellCache * getCellCache()
Returns the CellCache of this layer.
Interface to class owning the renderers Used to get correct subclass of renderer in scripting side (v...
T * getVisual() const
Gets used visualization.
static Logger _log(LM_AUDIO)
void setInterval(int32_t msec)
Set the interval in milliseconds.
std::list< std::string > m_unlit_groups
InstanceToOutlines_t m_instance_outlines
void start()
Start the timer.
virtual void onInstanceDeleted(Instance *instance)
RendererBase * clone()
Makes copy of this renderer.
void removeAllIgnoreLight()
Removes all groups(Namespaces)
void removeOutlined(Instance *instance)
Removes instance from outlining list.
virtual RendererBase * getRenderer(const std::string &renderername)=0
Returns renderer with given name.
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
void check()
Timer callback, tried to remove old effect images.
Layer * getLayer() const
Gets the layer where this location is pointing to.
InstanceDeleteListener * m_delete_listener
static ImageManager * instance()
Location & getLocationRef()
Gets reference of current location of instance.
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
RendererBase * getRenderer(const std::string &name)
Gets renderer with given name.
virtual ImagePtr getPtr(const std::string &name)
uint32_t getLayerCount() const
Get the overall number of layers.
void addIgnoreLight(const std::list< std::string > &groups)
Add groups(Namespaces) into a list.
virtual uint32_t getLightingModel() const =0
Gets the current light model.
void removeDeleteListener(InstanceDeleteListener *listener)
Removes associated instance delete listener.
InstanceRendererDeleteListener(InstanceRenderer *r)
uint32_t getHeight() const
bool m_need_bind_coloring
RenderBackend * m_renderbackend
bool aboveThreshold(int32_t threshold, int32_t alpha, int32_t prev_alpha)
bool isVisible()
Is instance visible or not.
uint32_t getTime() const
Get the time.
InstanceRenderer * m_renderer
void removeIgnoreLight(const std::list< std::string > &groups)
Removes groups(Namespaces) from the list.
virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
Copies given image into this one with respect to given offsets.
InstanceToAreas_t m_instance_areas
void setVisible(bool visible)
Sets visibility value for object to be visualized.
Base class for all view renderers View renderer renders one aspect of the view shown on screen...
Object * getObject()
Gets object where this instance is instantiated from.
Cell * getCell(const ModelCoordinate &mc)
Returns cell on this coordinate.
bool isValidImage(const ImagePtr &image)
void renderAlreadySorted(Camera *cam, Layer *layer, RenderList &instances)
virtual ~InstanceRenderer()
Destructor.
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...
Location getLocation() const
Gets current location of instance.
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.
virtual const std::string & getName()
virtual void setEnabled(bool enabled)
Enables renderer.
uint32_t getWidth() const
A basic cell on a CellCache.
CellGrid * getCellGrid() const
Get the Cellgrid.
Layer * getFowLayer()
Returns the layer that is used for Fog of War visualization.
CellVisualEffect getFoWType()
Returns the cell visual.
void renderUnsorted(Camera *cam, Layer *layer, RenderList &instances)
virtual ~InstanceRendererDeleteListener()
void removeTransparentArea(Instance *instance)
Removes instance form area list.
void removeAllTransparentAreas()
Removes all transparent areas.
virtual void free(const std::string &name)
Frees an Image from memory.
bool intersects(const RectType< T > &rect) const
Check whether two rectangles share some area.
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 an transparent area with given paramters.
bool isSharedImage() const
Returns true if this image shares data with another one.
virtual void setState(const ResourceState &state)
virtual void render(const Rect &rect, uint8_t alpha=255, uint8_t const *rgb=0)=0
Renders itself to the current render target (main screen or attached destination image) at the rectan...
ScreenPoint toScreenCoordinates(const ExactModelCoordinate &map_coords)
Transforms given point from map coordinates to screen coordinates.
void stop()
Stop the timer.
const std::list< Layer * > & getLayers() const
Get the layers on this map.
virtual Image * createImage(IResourceLoader *loader=0)=0
virtual void forceLoadInternal()=0
Forces to load the image into internal memory of GPU.
void reset()
Removes all stuff.
ColoringInfo(InstanceRenderer *r)
void removeAllOutlines()
Removes all outlines.
static InstanceRenderer * getInstance(IRendererContainer *cnt)
Gets instance for interface access.
void setRemoveInterval(uint32_t interval)
Sets the interval in seconds (default is 60).
std::list< std::string > groups
ImagesToCheck_t m_check_images
void removeAllColored()
Removes all coloring.
void addToCheck(const ImagePtr &image)
Add properly old ImagePtr into a check list.
T w
Width of the rectangle.
void removeFromCheck(const ImagePtr &image)
An Instance is an "instantiation" of an Object at a Location.
void setCallback(const type_callback &callback)
Set the callback that will be called.
virtual void renderZ(const Rect &rect, float vertexZ, uint8_t alpha=255, bool forceNewBatch=false, uint8_t const *rgb=0)
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
void removeColored(Instance *instance)
Removes instance from coloring list.
virtual ImagePtr add(Image *res)
Add an Image to the manager.
InstanceToColoring_t m_instance_colorings
Image * bindOutline(OutlineInfo &info, RenderItem &vc, Camera *cam)
Binds new outline (if needed) to the instance's OutlineInfo.