25 #include <boost/bind.hpp>
107 renderer->addToCheck(outline);
111 if (renderer->needColorBinding()) {
112 renderer->addToCheck(overlay);
150 m_interval(old.m_interval),
151 m_timer_enabled(false) {
188 FL_WARN(
_log,
"No cellgrid assigned to layer, cannot draw instances");
205 std::multimap<float, RenderItem*> transparentInstances;
215 info.
z = instance_posv.
z;
226 RenderList::iterator instance_it = instances.begin();
227 for (;instance_it != instances.end(); ++instance_it) {
229 Instance* instance = (*instance_it)->instance;
253 std::list<std::string>::iterator group_it = infoa.
groups.begin();
254 for (;group_it != infoa.
groups.end(); ++group_it) {
255 if (str_name.find((*group_it)) != std::string::npos) {
259 rec.
x = p.
x - infoa.
w / 2;
260 rec.
y = p.
y - infoa.
h / 2;
277 transparentInstances.insert(std::pair<float, RenderItem*>(vertexZ, &vc));
281 uint8_t coloringColor[4] = { 0 };
282 Image* outlineImage = 0;
283 bool recoloring =
false;
289 coloringColor[0] = coloring_it->second.r;
290 coloringColor[1] = coloring_it->second.g;
291 coloringColor[2] = coloring_it->second.b;
292 coloringColor[3] = coloring_it->second.a;
302 outlineImage =
bindOutline(outline_it->second, vc, cam);
346 std::multimap<float, RenderItem*>::iterator it = transparentInstances.begin();
347 for( ; it != transparentInstances.end(); ++it) {
351 float vertexZ = it->first;
353 uint8_t coloringColor[4] = { 0 };
354 Image* outlineImage = 0;
355 bool recoloring =
false;
361 coloringColor[0] = coloring_it->second.r;
362 coloringColor[1] = coloring_it->second.g;
363 coloringColor[2] = coloring_it->second.b;
364 coloringColor[3] = coloring_it->second.a;
374 outlineImage =
bindOutline(outline_it->second, vc, cam);
408 info.
z = instance_posv.
z;
419 RenderList::iterator instance_it = instances.begin();
420 for (;instance_it != instances.end(); ++instance_it) {
422 Instance* instance = (*instance_it)->instance;
445 std::list<std::string>::iterator group_it = infoa.
groups.begin();
446 for(;group_it != infoa.
groups.end(); ++group_it) {
447 if(str_name.find((*group_it)) != std::string::npos) {
451 rec.
x = p.
x - infoa.
w / 2;
452 rec.
y = p.
y - infoa.
h / 2;
469 uint8_t coloringColor[4] = { 0 };
470 Image* outlineImage = 0;
471 bool recoloring =
false;
477 coloringColor[0] = coloring_it->second.r;
478 coloringColor[1] = coloring_it->second.g;
479 coloringColor[2] = coloring_it->second.b;
480 coloringColor[3] = coloring_it->second.a;
490 outlineImage =
bindOutline(outline_it->second, vc, cam);
506 std::list<std::string>::iterator unlit_it =
m_unlit_groups.begin();
508 if(lit_name.find(*unlit_it) != std::string::npos) {
553 if (animationOverlay && !animationColorOverlay) {
555 for (std::vector<ImagePtr>::iterator it = animationOverlay->begin(); it != animationOverlay->end(); ++it) {
559 for (std::vector<ImagePtr>::iterator it = animationOverlay->begin(); it != animationOverlay->end(); ++it) {
564 }
else if (animationOverlay && animationColorOverlay) {
565 std::vector<OverlayColors*>::iterator ovit = animationColorOverlay->begin();
566 std::vector<ImagePtr>::iterator it = animationOverlay->begin();
567 for (; it != animationOverlay->end(); ++it, ++ovit) {
577 std::map<Color, Color>::const_iterator cit = oc->
getColors().begin();
578 uint8_t factor[4] = { 0, 0, 0, cit->second.getAlpha() };
584 float alphaFactor1 =
static_cast<float>(coloringColor[3] / 255.0);
585 const std::map<Color, Color>& defaultColors = oc->
getColors();
586 for (std::map<Color, Color>::const_iterator c_it = defaultColors.begin(); c_it != defaultColors.end(); ++c_it) {
587 if (c_it->second.getAlpha() == 0) {
590 float alphaFactor2 =
static_cast<float>(c_it->second.getAlpha() / 255.0);
591 Color c(coloringColor[0]*(1.0-alphaFactor1) + (c_it->second.getR()*alphaFactor2)*alphaFactor1,
592 coloringColor[1]*(1.0-alphaFactor1) + (c_it->second.getG()*alphaFactor2)*alphaFactor1,
593 coloringColor[2]*(1.0-alphaFactor1) + (c_it->second.getB()*alphaFactor2)*alphaFactor1, 255);
597 factor[3] =
static_cast<uint8_t>(255 - factor[3]);
598 factor[3] = std::min(coloringColor[3], factor[3]);
616 std::map<Color, Color>::const_iterator color_it = oc->
getColors().begin();
617 uint8_t rgba[4] = { color_it->second.getR(), color_it->second.getG(), color_it->second.getB(),
static_cast<uint8_t>(255-color_it->second.getAlpha()) };
618 bool noOverlay = rgba[3] == 255;
621 float alphaFactor1 =
static_cast<float>(coloringColor[3] / 255.0);
622 float alphaFactor2 = 1.0-
static_cast<float>(rgba[3] / 255.0);
623 rgba[0] = coloringColor[0]*(1.0-alphaFactor1) + (rgba[0]*alphaFactor2)*alphaFactor1;
624 rgba[1] = coloringColor[1]*(1.0-alphaFactor1) + (rgba[1]*alphaFactor2)*alphaFactor1;
625 rgba[2] = coloringColor[2]*(1.0-alphaFactor1) + (rgba[2]*alphaFactor2)*alphaFactor1;
626 rgba[3] = std::min(coloringColor[3], rgba[3]);
646 if (colorOverlay->
getColors().size() > 1) {
650 std::map<Color, Color>::const_iterator it = colorOverlay->
getColors().begin();
651 uint8_t factor[4] = { 0, 0, 0, it->second.getAlpha() };
655 float alphaFactor1 =
static_cast<float>(coloringColor[3] / 255.0);
656 const std::map<Color, Color>& defaultColors = colorOverlay->
getColors();
657 for (std::map<Color, Color>::const_iterator c_it = defaultColors.begin(); c_it != defaultColors.end(); ++c_it) {
658 if (c_it->second.getAlpha() == 0) {
661 float alphaFactor2 =
static_cast<float>(c_it->second.getAlpha() / 255.0);
662 Color c(coloringColor[0]*(1.0-alphaFactor1) + (c_it->second.getR()*alphaFactor2)*alphaFactor1,
663 coloringColor[1]*(1.0-alphaFactor1) + (c_it->second.getG()*alphaFactor2)*alphaFactor1,
664 coloringColor[2]*(1.0-alphaFactor1) + (c_it->second.getB()*alphaFactor2)*alphaFactor1, 255);
668 factor[3] =
static_cast<uint8_t>(255 - factor[3]);
669 factor[3] = std::min(coloringColor[3], factor[3]);
674 if (!multiColorOverlay) {
687 std::map<Color, Color>::const_iterator color_it = colorOverlay->
getColors().begin();
688 uint8_t rgba[4] = { color_it->second.getR(), color_it->second.getG(), color_it->second.getB(),
static_cast<uint8_t>(255-color_it->second.getAlpha()) };
689 bool noOverlay = rgba[3] == 255;
692 float alphaFactor1 =
static_cast<float>(coloringColor[3] / 255.0);
693 float alphaFactor2 = 1.0-
static_cast<float>(rgba[3] / 255.0);
694 rgba[0] = coloringColor[0]*(1.0-alphaFactor1) + (rgba[0]*alphaFactor2)*alphaFactor1;
695 rgba[1] = coloringColor[1]*(1.0-alphaFactor1) + (rgba[1]*alphaFactor2)*alphaFactor1;
696 rgba[2] = coloringColor[2]*(1.0-alphaFactor1) + (rgba[2]*alphaFactor2)*alphaFactor1;
697 rgba[3] = std::min(coloringColor[3], rgba[3]);
717 inline bool aboveThreshold(int32_t threshold, int32_t alpha, int32_t prev_alpha) {
720 if (((alpha - threshold) >= 0 || (prev_alpha - threshold) >= 0) && (alpha != prev_alpha)) {
727 if((alpha == 0 || prev_alpha == 0) && (alpha != prev_alpha)) {
759 std::stringstream sts;
761 static_cast<uint32_t>(info.
g) <<
"," <<
static_cast<uint32_t>(info.
b) <<
"," << info.
width;
781 SDL_Surface* outline_surface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA,
789 for (int32_t x = 0; x < outline_surface->w; x ++) {
791 for (int32_t y = 0; y < outline_surface->h; y ++) {
795 for (int32_t yy = y; yy < y + info.
width; yy++) {
799 for (int32_t yy = y - info.
width; yy < y; yy++) {
808 for (int32_t y = 0; y < outline_surface->h; y ++) {
810 for (int32_t x = 0; x < outline_surface->w; x ++) {
814 for (int32_t xx = x; xx < x + info.
width; xx++) {
818 for (int32_t xx = x - info.
width; xx < x; xx++) {
854 std::stringstream sts;
858 std::vector<ImagePtr>::iterator it = animationOverlays->begin();
859 for (; it != animationOverlays->end(); ++it) {
862 if ((*it)->isSharedImage()) {
863 (*it)->forceLoadInternal();
865 sts << (*it)->getName() <<
",";
866 mw = std::max(mw, (*it)->getWidth());
867 mh = std::max(mh, (*it)->getHeight());
869 sts << static_cast<uint32_t>(info.
r) <<
"," <<
870 static_cast<uint32_t>(info.
g) <<
"," <<
static_cast<uint32_t>(info.
b) <<
"," << info.
width;
883 SDL_Surface* outline_surface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, mw, mh, 32,
889 it = animationOverlays->begin();
890 for (; it != animationOverlays->end(); ++it) {
892 for (
uint32_t x = 0; x < (*it)->getWidth(); x++) {
894 for (
uint32_t y = 0; y < (*it)->getHeight(); y++) {
895 (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
899 int32_t tx = x + (mw/2 - (*it)->getWidth()/2);
900 int32_t ty = yy + (mh/2 - (*it)->getHeight()/2);
905 int32_t tx = x + (mw/2 - (*it)->getWidth()/2);
906 int32_t ty = yy + (mh/2 - (*it)->getHeight()/2);
916 for (
uint32_t y = 0; y < (*it)->getHeight(); y++) {
918 for (
uint32_t x = 0; x < (*it)->getWidth(); x++) {
919 (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
923 int32_t tx = xx + (mw/2 - (*it)->getWidth()/2);
924 int32_t ty = y + (mh/2 - (*it)->getHeight()/2);
929 int32_t tx = xx + (mw/2 - (*it)->getWidth()/2);
930 int32_t ty = y + (mh/2 - (*it)->getHeight()/2);
977 std::stringstream sts;
979 static_cast<uint32_t>(info.
g) <<
"," <<
static_cast<uint32_t>(info.
b) <<
"," << static_cast<uint32_t>(info.
a);
1000 SDL_Surface* overlay_surface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA,
1005 float alphaFactor =
static_cast<float>(info.
a/255.0);
1006 for (int32_t x = 0; x < overlay_surface->w; x ++) {
1007 for (int32_t y = 0; y < overlay_surface->h; y ++) {
1010 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);
1038 std::map<Color, Color>::const_iterator it = colorMap.begin();
1043 std::stringstream sts;
1045 for (; it != colorMap.end(); ++it) {
1046 sts <<
"," <<
static_cast<uint32_t>(it->second.getR() | (it->second.getG() << 8) | (it->second.getB() << 16) | (it->second.getAlpha()<<24));
1058 if (!exist || !found) {
1066 SDL_Surface* overlay_surface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA,
1071 for (int32_t x = 0; x < overlay_surface->w; x++) {
1072 for (int32_t y = 0; y < overlay_surface->h; y++) {
1074 Color c(r, g, b, a);
1075 it = colorMap.find(c);
1076 if (it != colorMap.end()) {
1077 Image::putPixel(overlay_surface, x, y, it->second.getR(), it->second.getG(), it->second.getB(), it->second.getAlpha());
1100 return colorOverlay;
1109 newinfo.
width = width;
1110 newinfo.
dirty =
true;
1116 std::pair<InstanceToOutlines_t::iterator, bool> insertiter =
m_instance_outlines.insert(std::make_pair(instance, newinfo));
1118 if (insertiter.second ==
false) {
1123 if (info.
r != r || info.
g != g || info.
b != b || info.
width != width) {
1138 Effect& effect = iter.first->second;
1139 if ((effect &
OUTLINE) != OUTLINE) {
1152 newinfo.
dirty =
true;
1158 std::pair<InstanceToColoring_t::iterator, bool> insertiter =
m_instance_colorings.insert(std::make_pair(instance, newinfo));
1160 if (insertiter.second ==
false) {
1165 if (info.
r != r || info.
g != g || info.
b != b || info.
a != a) {
1178 Effect& effect = iter.first->second;
1179 if ((effect &
COLOR) != COLOR) {
1193 newinfo.
trans = trans;
1194 newinfo.
front = front;
1201 std::pair<InstanceToAreas_t::iterator, bool> insertiter =
m_instance_areas.insert(std::make_pair(instance, newinfo));
1203 if (insertiter.second ==
false) {
1206 AreaInfo& info = insertiter.first->second;
1217 Effect& effect = iter.first->second;
1218 if ((effect &
AREA) != AREA) {
1242 if (it->second ==
COLOR) {
1247 it->second -=
COLOR;
1256 if (it->second ==
AREA) {
1260 }
else if ((it->second &
AREA) ==
AREA) {
1291 if (it->second ==
COLOR) {
1295 it->second -=
COLOR;
1309 if (it->second ==
AREA) {
1312 }
else if ((it->second &
AREA) ==
AREA) {
1322 std::list<std::string>::const_iterator group_it = groups.begin();
1323 for(;group_it != groups.end(); ++group_it) {
1331 std::list<std::string>::const_iterator group_it = groups.begin();
1332 for(;group_it != groups.end(); ++group_it) {
1333 std::list<std::string>::iterator unlit_it =
m_unlit_groups.begin();
1335 if((*group_it).find(*unlit_it) != std::string::npos) {
1377 if (it->image.get()->getName() == image.
get()->
getName()) {
1382 entry.
image = image;
1419 if (it->image.get()->getName() == image.
get()->
getName()) {
std::vector< ImagePtr > * getAnimationOverlay() const
Returns pointer to AnimationOverlay vector.
#define FL_WARN(logger, msg)
ImagePtr getMultiColorOverlay(const RenderItem &vc, OverlayColors *colors=0)
Abstract interface for all the renderbackends.
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.
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.
SDL_Surface * detachSurface()
Removes underlying SDL_Surface from the image (if exists) and returns this.
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)
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)
virtual void changeRenderInfos(RenderDataType type, uint16_t elements, int32_t src, int32_t dst, bool light, bool stentest, uint8_t stenref, GLConstants stenop, GLConstants stenfunc, OverlayType otype=OVERLAY_TYPE_NONE)=0
Dirty helper function to change the render infos.
bool isVisible()
Is instance visible or not.
void changeColor(const Color &source, const Color &target)
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...
OverlayColors * getColorOverlay() const
Returns pointer to single ColorOverlay.
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.
virtual void setSurface(SDL_Surface *surface)=0
This frees the current suface and replaces it with the surface passed in the parameter (which can be ...
const std::map< Color, Color > & getColors()
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 void renderZ(const Rect &rect, float vertexZ, uint8_t alpha=255, uint8_t const *rgb=0)
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.
void renderOverlay(RenderDataType type, RenderItem *item, uint8_t const *coloringColor, bool recoloring)
Layer * getFowLayer()
Returns the layer that is used for Fog of War visualization.
ImagePtr getColorOverlayImage()
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 a transparent area with given parameters.
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.
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
bool isDepthBufferEnabled() const
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.
T w
Width of the rectangle.
std::vector< OverlayColors * > * getAnimationColorOverlay() const
Returns pointer to AnimationColorOverlay vector.
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.
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.