39 #include "render/graphics.h"
55 const bool fringeLayer,
57 const int tileCondition) :
71 mTileCondition(tileCondition),
73 mIsFringeLayer(fringeLayer),
74 mHighlightAttackRange(
config.getBoolValue(
"highlightAttackRange")),
93 if (value ==
"highlightAttackRange")
95 mHighlightAttackRange =
123 const int dx = mPixelX - scrollX;
124 const int dy = mPixelY - scrollY;
125 for (
int y = startY;
y < endY;
y++)
128 const int yWidth =
y * mWidth;
130 const int py0 = y32 + dy;
136 if (x0 + tilePtr->
nextTile + 1 >= endX)
141 tilePtr = &mTiles[
CAST_SIZE(x0 + yWidth)];
142 if (mTiles[x0 + yWidth].isEnabled ==
false)
147 for (
int x = x0;
x < endX;
x++, tilePtr++)
152 const int px = x32 + dx;
153 const int py = py0 - img->mBounds.h;
157 if (tilePtr->
count == 0)
159 graphics->drawImage(img, px, py);
163 graphics->drawPattern(img,
171 const int nextTile = tilePtr->
nextTile;
182 MapRows::const_iterator rit = mTempRows.begin();
183 const MapRows::const_iterator rit_end = mTempRows.end();
184 while (rit != rit_end)
187 MapRowImages::const_iterator iit = images->begin();
188 const MapRowImages::const_iterator iit_end = images->end();
189 while (iit != iit_end)
191 graphics->drawTileVertexes(*iit);
226 const int dx = mPixelX - scrollX;
227 const int dy = mPixelY - scrollY;
229 for (
int y = startY;
y < endY;
y++)
232 mTempRows.push_back(row);
234 const Image *lastImage =
nullptr;
237 const int yWidth =
y * mWidth;
241 for (
int x = startX;
x < endX;
x++, tilePtr++)
245 Image *
const img = (*tilePtr).image;
247 const int py = py0 - img->mBounds.h;
251 if (lastImage != img)
254 imgVert->
image = img;
255 row->
images.push_back(imgVert);
258 graphics->calcTileSDL(imgVert, px, py);
291 const int dx = mPixelX - scrollX;
292 const int dy = mPixelY - scrollY;
295 mTempRows.push_back(row);
296 Image *lastImage =
nullptr;
298 typedef std::map<int, ImageVertexes*> ImageVertexesMap;
299 ImageVertexesMap imgSet;
301 for (
int y = startY;
y < endY;
y++)
303 const int yWidth =
y * mWidth;
306 for (
int x = startX;
x < endX;
x++, tilePtr++)
310 Image *
const img = (*tilePtr).image;
312 const int py = py0 - img->mBounds.h;
313 const GLuint imgGlImage = img->mGLImage;
317 if ((lastImage ==
nullptr) ||
318 lastImage->mGLImage != imgGlImage)
323 if (imgSet.find(imgGlImage) != imgSet.end())
325 imgVert = imgSet[imgGlImage];
329 if (lastImage !=
nullptr)
330 imgSet[lastImage->mGLImage] = imgVert;
333 imgVert->
image = img;
334 row->
images.push_back(imgVert);
338 graphics->calcTileVertexes(imgVert, lastImage, px, py);
344 graphics->finalize(*it);
352 MapRows::const_iterator rit = mTempRows.begin();
353 const MapRows::const_iterator rit_end = mTempRows.end();
354 while (rit != rit_end)
357 MapRowImages::const_iterator iit = images->begin();
358 const MapRowImages::const_iterator iit_end = images->end();
359 while (iit != iit_end)
361 graphics->drawTileVertexes(*iit);
378 const int py1 = y32 - scrollY;
380 int specialWidth = mSpecialLayer->mWidth;
381 int ptr =
y * specialWidth;
382 if (endX1 > specialWidth)
383 endX1 = specialWidth;
387 const MapItem *item0 = mSpecialLayer->mTiles[ptr + startX];
390 x0 += mSpecialLayer->mCache[ptr + startX] + 1;
392 for (
int x = x0;
x < endX1;
x++)
395 const MapItem *
const item = mSpecialLayer->mTiles[ptr +
x];
398 item->
draw(graphics, px1, py1,
401 x += mSpecialLayer->mCache[ptr +
x];
405 specialWidth = mTempLayer->mWidth;
406 ptr =
y * specialWidth;
408 if (endX1 > specialWidth)
409 endX1 = specialWidth;
410 item0 = mTempLayer->mTiles[ptr + startX];
413 x0 += mTempLayer->mCache[ptr + startX] + 1;
415 for (
int x = x0;
x < endX1;
x++)
418 const MapItem *
const item = mTempLayer->mTiles[ptr +
x];
419 item->
draw(graphics, px1, py1,
421 x += mTempLayer->mCache[ptr +
x];
436 (mSpecialLayer ==
nullptr) ||
437 (mTempLayer ==
nullptr))
460 const int dx = mPixelX - scrollX;
461 const int dy = mPixelY - scrollY;
463 const int specialHeight = mSpecialLayer->mHeight;
469 const int minEndY = std::min(specialHeight, endY);
473 for (
int y = startY;
y < minEndY;
y ++)
480 while (ai != ai_end && (*ai)->getSortPixelY() <= y32s)
482 (*ai)->draw(graphics, -scrollX, -scrollY);
485 BLOCK_END(
"MapLayer::drawFringe drawmobs")
488 if (
y < specialHeight)
490 drawSpecialLayer(graphics,
499 for (
int y = minEndY;
y < endY;
y++)
506 while (ai != ai_end && (*ai)->getSortPixelY() <= y32s)
508 (*ai)->draw(graphics, -scrollX, -scrollY);
511 BLOCK_END(
"MapLayer::drawFringe drawmobs")
516 for (
int y = startY;
y < minEndY;
y ++)
520 const int yWidth =
y * mWidth;
525 while (ai != ai_end &&
526 (*ai)->getSortPixelY() <= y32s)
528 (*ai)->draw(graphics, -scrollX, -scrollY);
531 BLOCK_END(
"MapLayer::drawFringe drawmobs")
533 const int py0 = y32 + dy;
539 drawSpecialLayer(graphics,
542 std::min(x0 + tilePtr->
nextTile + 1, endX),
545 if (x0 + tilePtr->
nextTile + 1 >= endX)
550 tilePtr = &mTiles[
CAST_SIZE(x0 + yWidth)];
551 if (mTiles[x0 + yWidth].isEnabled ==
false)
554 for (
int x = x0;
x < endX;
x++, tilePtr++)
561 const int px = x32 + dx;
562 const int py = py0 - img->mBounds.h;
564 if (tilePtr->
count == 0)
566 graphics->drawImage(img, px, py);
570 graphics->drawPattern(img,
578 const int nextTile = tilePtr->
nextTile;
580 if (
y < specialHeight)
582 drawSpecialLayer(graphics,
585 std::min(
x + nextTile + 1, endX),
594 for (
int y = minEndY;
y < endY;
y++)
598 const int yWidth =
y * mWidth;
603 while (ai != ai_end && (*ai)->getSortPixelY() <= y32s)
605 (*ai)->draw(graphics, -scrollX, -scrollY);
608 BLOCK_END(
"MapLayer::drawFringe drawmobs")
610 const int py0 = y32 + dy;
616 if (x0 + tilePtr->
nextTile + 1 >= endX)
619 tilePtr = &mTiles[
CAST_SIZE(x0 + yWidth)];
620 if (mTiles[x0 + yWidth].isEnabled ==
false)
623 for (
int x = x0;
x < endX;
x++, tilePtr++)
627 const int px = x32 + dx;
628 const int py = py0 - img->mBounds.h;
632 const int c = tilePtr->
count;
636 graphics->drawImage(img, px, py);
640 graphics->drawPattern(img,
647 const int nextTile = tilePtr->
nextTile;
661 (*ai)->draw(graphics, -scrollX, -scrollY);
664 BLOCK_END(
"MapLayer::drawFringe drawmobs")
665 if (mHighlightAttackRange)
673 int x = px - attackRange;
674 int y = py - attackRange;
689 graphics->fillRectangle(
Rect(
x,
y, w, h));
692 graphics->drawRectangle(
Rect(
x,
y, w, h));
705 const Image *
const img1 = tilePtr->image;
707 width = img1->mBounds.w;
708 for (
int x = 1;
x < endX;
x++)
711 const Image *
const img = tilePtr->image;
712 if (img ==
nullptr ||
713 tilePtr->isEnabled ==
false)
724 width += img->mBounds.w;
727 for (
int x2 = c2 + 1; x2 < endX; x2++)
729 if (tilePtr->image !=
nullptr &&
730 tilePtr->isEnabled ==
true)
748 for (
int x = 1;
x < endX;
x++)
751 const Image *
const img = tilePtr->image;
752 if (img !=
nullptr && tilePtr->isEnabled ==
true)
756 BLOCK_END(
"MapLayer::getEmptyTileDrawWidth")
766 const int width1 = width < mWidth ? width : mWidth;
767 const int height1 = height < mHeight ? height : mHeight;
769 for (
int y = mY;
y < height1;
y ++)
771 const MetaTile *metaPtr = metaTiles + (
y - mY) * width;
773 for (
int x = mX;
x < width1;
x ++, metaPtr ++, tilePtr ++)
775 if (tilePtr->image !=
nullptr &&
776 (((metaPtr->
blockmask & mTileCondition) != 0) ||
780 tilePtr->isEnabled =
true;
784 tilePtr->isEnabled =
false;
793 const int width1 = width < mWidth ? width : mWidth;
794 const int height1 = height < mHeight ? height : mHeight;
796 for (
int y = mY;
y < height1;
y ++)
798 for (
int x = mX;
x < width1;
x ++)
805 tilePtr->
count = getEmptyTileDrawWidth(tilePtr,
813 tilePtr->
count = getTileDrawWidth(tilePtr,
817 tilePtr->
width = tileWidth;
826 return static_cast<int>(
sizeof(
MapLayer) +
Actors::const_iterator ActorsCIter
std::list< Actor * > Actors
virtual int getPixelY() const
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
void removeListener(const std::string &key, ConfigListener *const listener)
OpenGLGraphicsVertexes ogl
int getAttackRange() const
void draw(Graphics *const graphics, const int x, const int y, const int dx, const int dy) const
void optionChanged(const std::string &value)
void drawFringe(Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY, const Actors &actors) const
static int getEmptyTileDrawWidth(const TileInfo *img, const int endX, int &nextTile)
void drawSpecialLayer(Graphics *const graphics, const int y, const int startX, const int endX, const int scrollX, const int scrollY) const
void updateOGL(Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY)
void drawSDL(Graphics *const graphics) const
void updateCache(const int width, const int height)
static int getTileDrawWidth(const TileInfo *img, const int endX, int &width, int &nextTile)
int calcMemoryChilds(const int level) const
const SpecialLayer * mTempLayer
int calcMemoryLocal() const
const SpecialLayer * mSpecialLayer
void updateConditionTiles(const MetaTile *const metaTiles, const int width, const int height)
MapLayer(const std::string &name, const int x, const int y, const int width, const int height, const bool isFringeLayer, const int mask, const int tileCondition)
void draw(Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY) const
void drawOGL(Graphics *const graphics) const
void updateSDL(const Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY)
int calcMemory(const int level) const
const Color & getColorWithAlpha(const UserColorIdT type)
static const int mapTileSize
void delete_all(Container &c)
#define FOR_EACH(type, iter, array)
LocalPlayer * localPlayer
std::vector< ImageVertexes * > MapRowImages
#define BLOCK_START(name)
UserPalette * userPalette