ManaPlus
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Types | Private Attributes | Friends
MapLayer Class Reference

#include <maplayer.h>

Inheritance diagram for MapLayer:
MemoryCounter ConfigListener

Public Member Functions

 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)
 
 ~MapLayer ()
 
void setTile (const int x, const int y, Image *const img)
 
void setTile (const int index, Image *const img)
 
void draw (Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY) const
 
void drawSDL (Graphics *const graphics) const
 
void drawOGL (Graphics *const graphics) const
 
void updateOGL (Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY)
 
void updateSDL (const Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY)
 
void drawFringe (Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY, const Actors &actors) const
 
bool isFringeLayer () const
 
void setSpecialLayer (const SpecialLayer *const val)
 
void setTempLayer (const SpecialLayer *const val)
 
int getWidth () const
 
int getHeight () const
 
void optionChanged (const std::string &value)
 
void setDrawLayerFlags (const MapTypeT &n)
 
void setActorsFix (const int y)
 
int calcMemoryLocal () const
 
int calcMemoryChilds (const int level) const
 
std::string getCounterName () const
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 
- Public Member Functions inherited from ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 

Protected Member Functions

void updateConditionTiles (const MetaTile *const metaTiles, const int width, const int height)
 
void updateCache (const int width, const int height)
 
void drawSpecialLayer (Graphics *const graphics, const int y, const int startX, const int endX, const int scrollX, const int scrollY) const
 

Static Protected Member Functions

static int getTileDrawWidth (const TileInfo *img, const int endX, int &width, int &nextTile)
 
static int getEmptyTileDrawWidth (const TileInfo *img, const int endX, int &nextTile)
 

Private Types

typedef std::vector< MapRowVertexes * > MapRows
 

Private Attributes

const int mX
 
const int mY
 
const int mPixelX
 
const int mPixelY
 
const int mWidth
 
const int mHeight
 
TileInfo *const mTiles
 
MapTypeT mDrawLayerFlags
 
const SpecialLayermSpecialLayer
 
const SpecialLayermTempLayer
 
const std::string mName
 
MapRows mTempRows
 
int mMask
 
int mTileCondition
 
int mActorsFix
 
const bool mIsFringeLayer
 
bool mHighlightAttackRange
 
bool mSpecialFlag
 

Friends

class Map
 

Detailed Description

A map layer. Stores a grid of tiles and their offset, and implements layer rendering.

Definition at line 48 of file maplayer.h.

Member Typedef Documentation

◆ MapRows

typedef std::vector<MapRowVertexes*> MapLayer::MapRows
private

Definition at line 219 of file maplayer.h.

Constructor & Destructor Documentation

◆ MapLayer()

MapLayer::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 
)

Constructor, taking layer origin, size and whether this layer is the fringe layer. The fringe layer is the layer that draws the actors. There can be only one fringe layer per map.

Definition at line 49 of file maplayer.cpp.

References Configuration::addListener(), and config.

Referenced by calcMemoryLocal().

56  :
57  mX(x),
58  mY(y),
61  mWidth(width),
62  mHeight(height),
63  mTiles(new TileInfo[mWidth * mHeight]),
65  mSpecialLayer(nullptr),
66  mTempLayer(nullptr),
67  mName(name),
68  mTempRows(),
69  mMask(mask),
70  mTileCondition(tileCondition),
71  mActorsFix(0),
72  mIsFringeLayer(fringeLayer),
73  mHighlightAttackRange(config.getBoolValue("highlightAttackRange")),
74  mSpecialFlag(true)
75 {
76 // std::fill_n(mTiles, mWidth * mHeight, static_cast<Image*>(nullptr));
77 
78  config.addListener("highlightAttackRange", this);
79 }
const bool mIsFringeLayer
Definition: maplayer.h:224
const int mY
Definition: maplayer.h:209
TileInfo *const mTiles
Definition: maplayer.h:214
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:216
Configuration config
bool mSpecialFlag
Definition: maplayer.h:226
const int mX
Definition: maplayer.h:208
const int mPixelX
Definition: maplayer.h:210
const SpecialLayer * mTempLayer
Definition: maplayer.h:217
void addListener(const std::string &key, ConfigListener *const listener)
bool mHighlightAttackRange
Definition: maplayer.h:225
bool getBoolValue(const std::string &key) const
int mActorsFix
Definition: maplayer.h:223
const std::string mName
Definition: maplayer.h:218
const int mPixelY
Definition: maplayer.h:211
int mTileCondition
Definition: maplayer.h:222
MapTypeT mDrawLayerFlags
Definition: maplayer.h:215
const int mWidth
Definition: maplayer.h:212
static const int mapTileSize
Definition: map.h:26
const int mHeight
Definition: maplayer.h:213
int mMask
Definition: maplayer.h:221
MapRows mTempRows
Definition: maplayer.h:220

◆ ~MapLayer()

MapLayer::~MapLayer ( )

Destructor.

Definition at line 81 of file maplayer.cpp.

References CHECKLISTENERS, config, delete_all(), mTempRows, mTiles, and Configuration::removeListener().

82 {
83  config.removeListener("highlightAttackRange", this);
85  delete []mTiles;
87  mTempRows.clear();
88 }
TileInfo *const mTiles
Definition: maplayer.h:214
Configuration config
void delete_all(Container &c)
Definition: dtor.h:55
#define CHECKLISTENERS
Definition: localconsts.h:305
void removeListener(const std::string &key, ConfigListener *const listener)
MapRows mTempRows
Definition: maplayer.h:220

Member Function Documentation

◆ calcMemoryChilds()

int MapLayer::calcMemoryChilds ( const int  level) const
virtual

Reimplemented from MemoryCounter.

Definition at line 845 of file maplayer.cpp.

References MemoryCounter::calcMemory(), mSpecialLayer, and mTempLayer.

Referenced by setActorsFix().

846 {
847  int sz = 0;
848  if (mSpecialLayer != nullptr)
849  sz += mSpecialLayer->calcMemory(level + 1);
850  if (mTempLayer != nullptr)
851  sz += mTempLayer->calcMemory(level + 1);
852  return sz;
853 }
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:216
int calcMemory(const int level) const
const SpecialLayer * mTempLayer
Definition: maplayer.h:217

◆ calcMemoryLocal()

int MapLayer::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 838 of file maplayer.cpp.

References MapLayer(), mHeight, mTempRows, and mWidth.

Referenced by setActorsFix().

839 {
840  return static_cast<int>(sizeof(MapLayer) +
841  sizeof(TileInfo) * mWidth * mHeight +
842  sizeof(MapRowVertexes) * mTempRows.capacity());
843 }
const int mWidth
Definition: maplayer.h:212
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)
Definition: maplayer.cpp:49
const int mHeight
Definition: maplayer.h:213
MapRows mTempRows
Definition: maplayer.h:220

◆ draw()

void MapLayer::draw ( Graphics *const  graphics,
int  startX,
int  startY,
int  endX,
int  endY,
const int  scrollX,
const int  scrollY 
) const

Draws this layer to the given graphics context. The coordinates are expected to be in map range and will be translated to local layer coordinates and clipped to the layer's dimensions.

The given actors are only drawn when this layer is the fringe layer.

Definition at line 106 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, CAST_SIZE, TileInfo::count, TileInfo::image, TileInfo::isEnabled, mapTileSize, Image::mBounds, mHeight, mPixelX, mPixelY, mSpecialFlag, mTiles, mWidth, mX, mY, TileInfo::nextTile, TileInfo::width, x, and y.

Referenced by setTile().

113 {
114  BLOCK_START("MapLayer::draw")
115  startX -= mX;
116  startY -= mY;
117  endX -= mX;
118  endY -= mY;
119 
120  if (startX < 0)
121  startX = 0;
122  if (startY < 0)
123  startY = 0;
124  if (endX > mWidth)
125  endX = mWidth;
126  if (endY > mHeight)
127  endY = mHeight;
128 
129  const int dx = mPixelX - scrollX;
130  const int dy = mPixelY - scrollY;
131  for (int y = startY; y < endY; y++)
132  {
133  const int y32 = y * mapTileSize;
134  const int yWidth = y * mWidth;
135 
136  const int py0 = y32 + dy;
137 
138  int x0 = startX;
139  TileInfo *tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
140  if (tilePtr->isEnabled == false)
141  {
142  if (x0 + tilePtr->nextTile + 1 >= endX)
143  {
144  continue;
145  }
146  x0 += tilePtr->nextTile + 1;
147  tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
148  if (mTiles[x0 + yWidth].isEnabled == false)
149  {
150  continue;
151  }
152  }
153  for (int x = x0; x < endX; x++, tilePtr++)
154  {
155  const int x32 = x * mapTileSize;
156 
157  const Image *const img = tilePtr->image;
158  const int px = x32 + dx;
159  const int py = py0 - img->mBounds.h;
160  if (mSpecialFlag ||
161  img->mBounds.h <= mapTileSize)
162  {
163  if (tilePtr->count == 0)
164  {
165  graphics->drawImage(img, px, py);
166  }
167  else
168  {
169  graphics->drawPattern(img,
170  px,
171  py,
172  tilePtr->width,
173  img->mBounds.h);
174  }
175  }
176 
177  const int nextTile = tilePtr->nextTile;
178  x += nextTile;
179  tilePtr += nextTile;
180  }
181  }
182  BLOCK_END("MapLayer::draw")
183 }
const int mY
Definition: maplayer.h:209
Image * image
Definition: tileinfo.h:42
TileInfo *const mTiles
Definition: maplayer.h:214
#define BLOCK_START(name)
Definition: perfomance.h:78
bool mSpecialFlag
Definition: maplayer.h:226
if(!vert) return
const int mX
Definition: maplayer.h:208
#define BLOCK_END(name)
Definition: perfomance.h:79
const int mPixelX
Definition: maplayer.h:210
bool isEnabled
Definition: tileinfo.h:50
const int mPixelY
Definition: maplayer.h:211
int width
Definition: tileinfo.h:44
int count
Definition: tileinfo.h:46
int nextTile
Definition: tileinfo.h:48
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61
const int mWidth
Definition: maplayer.h:212
static const int mapTileSize
Definition: map.h:26
virtual void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)=0
#define CAST_SIZE
Definition: cast.h:33
SDL_Rect mBounds
Definition: image.h:210
const int mHeight
Definition: maplayer.h:213

◆ drawFringe()

void MapLayer::drawFringe ( Graphics *const  graphics,
int  startX,
int  startY,
int  endX,
int  endY,
const int  scrollX,
const int  scrollY,
const Actors actors 
) const

Definition at line 431 of file maplayer.cpp.

References UserColorId::ATTACK_RANGE, UserColorId::ATTACK_RANGE_BORDER, MapType::BLACKWHITE, BLOCK_END, BLOCK_START, CAST_SIZE, TileInfo::count, drawSpecialLayer(), LocalPlayer::getAttackRange(), UserPalette::getColorWithAlpha(), Actor::getPixelX(), Actor::getPixelY(), TileInfo::image, TileInfo::isEnabled, localPlayer, mActorsFix, mapTileSize, Image::mBounds, mDrawLayerFlags, SpecialLayer::mHeight, mHeight, mHighlightAttackRange, mPixelX, mPixelY, mSpecialFlag, mSpecialLayer, mTempLayer, mTiles, mWidth, mX, mY, TileInfo::nextTile, MapType::SPECIAL3, MapType::SPECIAL4, userPalette, TileInfo::width, x, and y.

Referenced by Map::draw(), and setTile().

439 {
440  BLOCK_START("MapLayer::drawFringe")
441  if ((localPlayer == nullptr) ||
442  (mSpecialLayer == nullptr) ||
443  (mTempLayer == nullptr))
444  {
445  BLOCK_END("MapLayer::drawFringe")
446  return;
447  }
448 
449  startX -= mX;
450  startY -= mY;
451  endX -= mX;
452  endY -= mY;
453 
454  if (startX < 0)
455  startX = 0;
456  if (startY < 0)
457  startY = 0;
458  if (endX > mWidth)
459  endX = mWidth;
460  if (endY > mHeight)
461  endY = mHeight;
462 
463  ActorsCIter ai = actors.begin();
464  const ActorsCIter ai_end = actors.end();
465 
466  const int dx = mPixelX - scrollX;
467  const int dy = mPixelY - scrollY;
468 
469  const int specialHeight = mSpecialLayer->mHeight;
470 
471  const bool flag = mDrawLayerFlags == MapType::SPECIAL3 ||
474 
475  const int minEndY = std::min(specialHeight, endY);
476 
477  if (flag)
478  { // flag
479  for (int y = startY; y < minEndY; y ++)
480  {
481  const int y32s = (y + mActorsFix) * mapTileSize;
482 
483  BLOCK_START("MapLayer::drawFringe drawmobs")
484  // If drawing the fringe layer, make sure all actors above this
485  // row of tiles have been drawn
486  while (ai != ai_end && (*ai)->getSortPixelY() <= y32s)
487  {
488  (*ai)->draw(graphics, -scrollX, -scrollY);
489  ++ ai;
490  }
491  BLOCK_END("MapLayer::drawFringe drawmobs")
492 
493  // remove this condition, because it always true
494  if (y < specialHeight)
495  {
496  drawSpecialLayer(graphics,
497  y,
498  startX,
499  endX,
500  scrollX,
501  scrollY);
502  }
503  }
504 
505  for (int y = minEndY; y < endY; y++)
506  {
507  const int y32s = (y + mActorsFix) * mapTileSize;
508 
509  BLOCK_START("MapLayer::drawFringe drawmobs")
510  // If drawing the fringe layer, make sure all actors above this
511  // row of tiles have been drawn
512  while (ai != ai_end && (*ai)->getSortPixelY() <= y32s)
513  {
514  (*ai)->draw(graphics, -scrollX, -scrollY);
515  ++ ai;
516  }
517  BLOCK_END("MapLayer::drawFringe drawmobs")
518  }
519  }
520  else
521  { // !flag
522  for (int y = startY; y < minEndY; y ++)
523  {
524  const int y32 = y * mapTileSize;
525  const int y32s = (y + mActorsFix) * mapTileSize;
526  const int yWidth = y * mWidth;
527 
528  BLOCK_START("MapLayer::drawFringe drawmobs")
529  // If drawing the fringe layer, make sure all actors above this
530  // row of tiles have been drawn
531  while (ai != ai_end &&
532  (*ai)->getSortPixelY() <= y32s)
533  {
534  (*ai)->draw(graphics, -scrollX, -scrollY);
535  ++ ai;
536  }
537  BLOCK_END("MapLayer::drawFringe drawmobs")
538 
539  const int py0 = y32 + dy;
540 
541  int x0 = startX;
542  TileInfo *tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
543  if (tilePtr->isEnabled == false)
544  {
545  drawSpecialLayer(graphics,
546  y,
547  0,
548  std::min(x0 + tilePtr->nextTile + 1, endX),
549  scrollX,
550  scrollY);
551  if (x0 + tilePtr->nextTile + 1 >= endX)
552  {
553  continue;
554  }
555  x0 += tilePtr->nextTile + 1;
556  tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
557  if (mTiles[x0 + yWidth].isEnabled == false)
558  continue;
559  }
560  for (int x = x0; x < endX; x++, tilePtr++)
561  {
562  const int x32 = x * mapTileSize;
563  const Image *const img = tilePtr->image;
564  if (mSpecialFlag ||
565  img->mBounds.h <= mapTileSize)
566  {
567  const int px = x32 + dx;
568  const int py = py0 - img->mBounds.h;
569 
570  if (tilePtr->count == 0)
571  {
572  graphics->drawImage(img, px, py);
573  }
574  else
575  {
576  graphics->drawPattern(img,
577  px,
578  py,
579  tilePtr->width,
580  img->mBounds.h);
581  }
582  }
583 
584  const int nextTile = tilePtr->nextTile;
585  // remove this condition, because it always true
586  if (y < specialHeight)
587  {
588  drawSpecialLayer(graphics,
589  y,
590  x,
591  std::min(x + nextTile + 1, endX),
592  scrollX,
593  scrollY);
594  }
595  x += nextTile;
596  tilePtr += nextTile;
597  }
598  }
599 
600  for (int y = minEndY; y < endY; y++)
601  {
602  const int y32 = y * mapTileSize;
603  const int y32s = (y + mActorsFix) * mapTileSize;
604  const int yWidth = y * mWidth;
605 
606  BLOCK_START("MapLayer::drawFringe drawmobs")
607  // If drawing the fringe layer, make sure all actors above this
608  // row of tiles have been drawn
609  while (ai != ai_end && (*ai)->getSortPixelY() <= y32s)
610  {
611  (*ai)->draw(graphics, -scrollX, -scrollY);
612  ++ ai;
613  }
614  BLOCK_END("MapLayer::drawFringe drawmobs")
615 
616  const int py0 = y32 + dy;
617 
618  int x0 = startX;
619  TileInfo *tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
620  if (tilePtr->isEnabled == false)
621  {
622  if (x0 + tilePtr->nextTile + 1 >= endX)
623  continue;
624  x0 += tilePtr->nextTile + 1;
625  tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
626  if (mTiles[x0 + yWidth].isEnabled == false)
627  continue;
628  }
629  for (int x = x0; x < endX; x++, tilePtr++)
630  {
631  const int x32 = x * mapTileSize;
632  const Image *const img = tilePtr->image;
633  const int px = x32 + dx;
634  const int py = py0 - img->mBounds.h;
635  if (mSpecialFlag ||
636  img->mBounds.h <= mapTileSize)
637  {
638  const int c = tilePtr->count;
639 
640  if (c == 0)
641  {
642  graphics->drawImage(img, px, py);
643  }
644  else
645  {
646  graphics->drawPattern(img,
647  px,
648  py,
649  tilePtr->width,
650  img->mBounds.h);
651  }
652  }
653  const int nextTile = tilePtr->nextTile;
654  x += nextTile;
655  tilePtr += nextTile;
656  }
657  }
658  } // !flag
659 
660  // Draw any remaining actors
663  {
664  BLOCK_START("MapLayer::drawFringe drawmobs")
665  while (ai != ai_end)
666  {
667  (*ai)->draw(graphics, -scrollX, -scrollY);
668  ++ai;
669  }
670  BLOCK_END("MapLayer::drawFringe drawmobs")
672  {
673  const int px = localPlayer->getPixelX()
674  - scrollX - mapTileSize / 2;
675  const int py = localPlayer->getPixelY() - scrollY - mapTileSize;
676  const int attackRange = localPlayer->getAttackRange()
677  * mapTileSize;
678 
679  int x = px - attackRange;
680  int y = py - attackRange;
681  int w = 2 * attackRange + mapTileSize;
682  int h = w;
683  if (attackRange <= mapTileSize)
684  {
685  x -= mapTileSize / 2;
686  y -= mapTileSize / 2;
687  w += mapTileSize;
688  h += mapTileSize;
689  }
690 
691  if (userPalette != nullptr)
692  {
695  graphics->fillRectangle(Rect(x, y, w, h));
698  graphics->drawRectangle(Rect(x, y, w, h));
699  }
700  }
701  }
702  BLOCK_END("MapLayer::drawFringe")
703 }
const int mY
Definition: maplayer.h:209
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:199
TileInfo *const mTiles
Definition: maplayer.h:214
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:216
Definition: rect.h:72
#define BLOCK_START(name)
Definition: perfomance.h:78
bool mSpecialFlag
Definition: maplayer.h:226
if(!vert) return
const int mX
Definition: maplayer.h:208
#define BLOCK_END(name)
Definition: perfomance.h:79
const int mPixelX
Definition: maplayer.h:210
const SpecialLayer * mTempLayer
Definition: maplayer.h:217
virtual void drawRectangle(const Rect &rectangle)=0
UserPalette * userPalette
Definition: userpalette.cpp:33
bool mHighlightAttackRange
Definition: maplayer.h:225
void drawSpecialLayer(Graphics *const graphics, const int y, const int startX, const int endX, const int scrollX, const int scrollY) const
Definition: maplayer.cpp:376
virtual void setColor(const Color &color)
Definition: graphics.h:319
virtual int getPixelY() const
Definition: actor.h:92
LocalPlayer * localPlayer
int mActorsFix
Definition: maplayer.h:223
const int mPixelY
Definition: maplayer.h:211
MapTypeT mDrawLayerFlags
Definition: maplayer.h:215
int getPixelX() const
Definition: actor.h:86
virtual void fillRectangle(const Rect &rectangle)=0
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61
const int mWidth
Definition: maplayer.h:212
static const int mapTileSize
Definition: map.h:26
virtual void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)=0
#define CAST_SIZE
Definition: cast.h:33
SDL_Rect mBounds
Definition: image.h:210
const int mHeight
Definition: maplayer.h:213
Actors::const_iterator ActorsCIter
Definition: actor.h:38
int getAttackRange() const

◆ drawOGL()

void MapLayer::drawOGL ( Graphics *const  graphics) const

Definition at line 355 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, and mTempRows.

Referenced by setTile().

356 {
357  BLOCK_START("MapLayer::drawOGL")
358  MapRows::const_iterator rit = mTempRows.begin();
359  const MapRows::const_iterator rit_end = mTempRows.end();
360  while (rit != rit_end)
361  {
362  const MapRowImages *const images = &(*rit)->images;
363  MapRowImages::const_iterator iit = images->begin();
364  const MapRowImages::const_iterator iit_end = images->end();
365  while (iit != iit_end)
366  {
367  graphics->drawTileVertexes(*iit);
368  ++ iit;
369  }
370  ++ rit;
371  }
372  BLOCK_END("MapLayer::drawOGL")
373 }
std::vector< ImageVertexes * > MapRowImages
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
virtual void drawTileVertexes(const ImageVertexes *const vert)=0
std::vector< MapRowVertexes * > MapRows
Definition: maplayer.h:219
MapRows mTempRows
Definition: maplayer.h:220

◆ drawSDL()

void MapLayer::drawSDL ( Graphics *const  graphics) const

Definition at line 185 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, and mTempRows.

Referenced by setTile().

186 {
187  BLOCK_START("MapLayer::drawSDL")
188  MapRows::const_iterator rit = mTempRows.begin();
189  const MapRows::const_iterator rit_end = mTempRows.end();
190  while (rit != rit_end)
191  {
192  MapRowImages *const images = &(*rit)->images;
193  MapRowImages::const_iterator iit = images->begin();
194  const MapRowImages::const_iterator iit_end = images->end();
195  while (iit != iit_end)
196  {
197  graphics->drawTileVertexes(*iit);
198  ++ iit;
199  }
200  ++ rit;
201  }
202  BLOCK_END("MapLayer::drawSDL")
203 }
std::vector< ImageVertexes * > MapRowImages
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
virtual void drawTileVertexes(const ImageVertexes *const vert)=0
std::vector< MapRowVertexes * > MapRows
Definition: maplayer.h:219
MapRows mTempRows
Definition: maplayer.h:220

◆ drawSpecialLayer()

void MapLayer::drawSpecialLayer ( Graphics *const  graphics,
const int  y,
const int  startX,
const int  endX,
const int  scrollX,
const int  scrollY 
) const
protected

Definition at line 376 of file maplayer.cpp.

References MapItem::draw(), MapItemType::EMPTY, ServerCommandType::item, mapTileSize, SpecialLayer::mCache, mSpecialLayer, mTempLayer, SpecialLayer::mTiles, MapItem::mType, SpecialLayer::mWidth, x, and y.

Referenced by drawFringe(), and getCounterName().

382 {
383  const int y32 = y * mapTileSize;
384  const int py1 = y32 - scrollY;
385  int endX1 = endX;
386  int specialWidth = mSpecialLayer->mWidth;
387  int ptr = y * specialWidth;
388  if (endX1 > specialWidth)
389  endX1 = specialWidth;
390  if (endX1 < 0)
391  endX1 = 0;
392  int x0 = startX;
393  const MapItem *item0 = mSpecialLayer->mTiles[ptr + startX];
394  if ((item0 == nullptr) || item0->mType == MapItemType::EMPTY)
395  {
396  x0 += mSpecialLayer->mCache[ptr + startX] + 1;
397  }
398  for (int x = x0; x < endX1; x++)
399  {
400  const int px1 = x * mapTileSize - scrollX;
401  const MapItem *const item = mSpecialLayer->mTiles[ptr + x];
402  if (item != nullptr)
403  {
404  item->draw(graphics, px1, py1,
405  mapTileSize, mapTileSize);
406  }
407  x += mSpecialLayer->mCache[ptr + x];
408  }
409 
410  x0 = startX;
411  specialWidth = mTempLayer->mWidth;
412  ptr = y * specialWidth;
413  endX1 = endX;
414  if (endX1 > specialWidth)
415  endX1 = specialWidth;
416  item0 = mTempLayer->mTiles[ptr + startX];
417  if ((item0 == nullptr) || item0->mType == MapItemType::EMPTY)
418  {
419  x0 += mTempLayer->mCache[ptr + startX] + 1;
420  }
421  for (int x = x0; x < endX1; x++)
422  {
423  const int px1 = x * mapTileSize - scrollX;
424  const MapItem *const item = mTempLayer->mTiles[ptr + x];
425  item->draw(graphics, px1, py1,
426  mapTileSize, mapTileSize);
427  x += mTempLayer->mCache[ptr + x];
428  }
429 }
int mType
Definition: mapitem.h:87
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:216
const SpecialLayer * mTempLayer
Definition: maplayer.h:217
MapItem ** mTiles
Definition: speciallayer.h:79
static const int mapTileSize
Definition: map.h:26
void draw(Graphics *const graphics, const int x, const int y, const int dx, const int dy) const
Definition: mapitem.cpp:132

◆ getCounterName()

std::string MapLayer::getCounterName ( ) const
inlinevirtual

Reimplemented from MemoryCounter.

Definition at line 164 of file maplayer.h.

References A_NONNULL, A_WARN_UNUSED, drawSpecialLayer(), getEmptyTileDrawWidth(), getTileDrawWidth(), mName, mTileCondition, mTiles, restrict, updateCache(), updateConditionTiles(), and y.

165  { return mName; }
const std::string mName
Definition: maplayer.h:218

◆ getEmptyTileDrawWidth()

int MapLayer::getEmptyTileDrawWidth ( const TileInfo img,
const int  endX,
int &  nextTile 
)
staticprotected

Definition at line 748 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, and x.

Referenced by getCounterName(), and updateCache().

751 {
752  BLOCK_START("MapLayer::getEmptyTileDrawWidth")
753  int c = 0;
754  for (int x = 1; x < endX; x++)
755  {
756  tilePtr ++;
757  const Image *const img = tilePtr->image;
758  if (img != nullptr && tilePtr->isEnabled == true)
759  break;
760  c ++;
761  }
762  BLOCK_END("MapLayer::getEmptyTileDrawWidth")
763 
764  nextTile = c;
765  return c;
766 }
Image * image
Definition: tileinfo.h:42
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
Definition: image.h:61

◆ getHeight()

int MapLayer::getHeight ( ) const
inline

Definition at line 149 of file maplayer.h.

References mHeight, optionChanged(), restrict, and setDrawLayerFlags().

150  { return mHeight; }
const int mHeight
Definition: maplayer.h:213

◆ getTileDrawWidth()

int MapLayer::getTileDrawWidth ( const TileInfo img,
const int  endX,
int &  width,
int &  nextTile 
)
staticprotected

Definition at line 705 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, Image::mBounds, and x.

Referenced by getCounterName(), and updateCache().

709 {
710  BLOCK_START("MapLayer::getTileDrawWidth")
711  const Image *const img1 = tilePtr->image;
712  int c = 0;
713  width = img1->mBounds.w;
714  for (int x = 1; x < endX; x++)
715  {
716  tilePtr ++;
717  const Image *const img = tilePtr->image;
718  if (img == nullptr ||
719  tilePtr->isEnabled == false)
720  {
721  break;
722  }
723  if (img != img1)
724  {
725  nextTile = c;
726  BLOCK_END("MapLayer::getTileDrawWidth")
727  return c;
728  }
729  c ++;
730  width += img->mBounds.w;
731  }
732  int c2 = c;
733  for (int x2 = c2 + 1; x2 < endX; x2++)
734  {
735  if (tilePtr->image != nullptr &&
736  tilePtr->isEnabled == true)
737  {
738  break;
739  }
740  c2 ++;
741  tilePtr ++;
742  }
743  nextTile = c2;
744  BLOCK_END("MapLayer::getTileDrawWidth")
745  return c;
746 }
Image * image
Definition: tileinfo.h:42
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
Definition: image.h:61

◆ getWidth()

int MapLayer::getWidth ( ) const
inline

Definition at line 146 of file maplayer.h.

References mWidth.

147  { return mWidth; }
const int mWidth
Definition: maplayer.h:212

◆ isFringeLayer()

bool MapLayer::isFringeLayer ( ) const
inline

Definition at line 137 of file maplayer.h.

References mIsFringeLayer.

Referenced by Map::updateDrawLayersList().

138  { return mIsFringeLayer; }
const bool mIsFringeLayer
Definition: maplayer.h:224

◆ optionChanged()

void MapLayer::optionChanged ( const std::string &  name)
virtual

Called when an option changed. The config listener will have to be registered to the option name first.

Implements ConfigListener.

Definition at line 90 of file maplayer.cpp.

References config, Configuration::getBoolValue(), and mHighlightAttackRange.

Referenced by getHeight().

91 {
92  if (value == "highlightAttackRange")
93  {
95  config.getBoolValue("highlightAttackRange");
96  }
97 }
Configuration config
bool mHighlightAttackRange
Definition: maplayer.h:225
bool getBoolValue(const std::string &key) const

◆ setActorsFix()

void MapLayer::setActorsFix ( const int  y)
inline

Definition at line 157 of file maplayer.h.

References calcMemoryChilds(), calcMemoryLocal(), mActorsFix, and y.

Referenced by Map::setActorsFix().

158  { mActorsFix = y; }
int mActorsFix
Definition: maplayer.h:223

◆ setDrawLayerFlags()

void MapLayer::setDrawLayerFlags ( const MapTypeT n)

◆ setSpecialLayer()

void MapLayer::setSpecialLayer ( const SpecialLayer *const  val)
inline

Definition at line 140 of file maplayer.h.

References mSpecialLayer.

Referenced by Map::draw().

141  { mSpecialLayer = val; }
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:216

◆ setTempLayer()

void MapLayer::setTempLayer ( const SpecialLayer *const  val)
inline

Definition at line 143 of file maplayer.h.

References mTempLayer.

Referenced by Map::draw().

144  { mTempLayer = val; }
const SpecialLayer * mTempLayer
Definition: maplayer.h:217

◆ setTile() [1/2]

void MapLayer::setTile ( const int  x,
const int  y,
Image *const  img 
)

Set tile image, with x and y in layer coordinates.

Definition at line 99 of file maplayer.cpp.

References TileInfo::image, mTiles, mWidth, x, and y.

Referenced by setTile().

102 {
103  mTiles[x + y * mWidth].image = img;
104 }
Image * image
Definition: tileinfo.h:42
TileInfo *const mTiles
Definition: maplayer.h:214
const int mWidth
Definition: maplayer.h:212

◆ setTile() [2/2]

void MapLayer::setTile ( const int  index,
Image *const  img 
)
inline

Set tile image with x + y * width already known.

Definition at line 84 of file maplayer.h.

References A_NONNULL, draw(), drawFringe(), drawOGL(), drawSDL(), TileInfo::image, mTiles, restrict, restrict2, updateOGL(), and updateSDL().

86  { mTiles[index].image = img; }
Image * image
Definition: tileinfo.h:42
TileInfo *const mTiles
Definition: maplayer.h:214

◆ updateCache()

void MapLayer::updateCache ( const int  width,
const int  height 
)
protected

Definition at line 804 of file maplayer.cpp.

References TileInfo::count, getEmptyTileDrawWidth(), getTileDrawWidth(), TileInfo::image, TileInfo::isEnabled, mHeight, mTiles, mWidth, mX, mY, TileInfo::nextTile, TileInfo::width, x, and y.

Referenced by getCounterName().

806 {
807  const int width1 = width < mWidth ? width : mWidth;
808  const int height1 = height < mHeight ? height : mHeight;
809 
810  for (int y = mY; y < height1; y ++)
811  {
812  for (int x = mX; x < width1; x ++)
813  {
814  TileInfo *tilePtr = mTiles + y * mWidth + x;
815  int nextTile = 0;
816  if (tilePtr->image == nullptr || tilePtr->isEnabled == false)
817  {
818  tilePtr->isEnabled = false;
819  tilePtr->count = getEmptyTileDrawWidth(tilePtr,
820  width1 - x,
821  nextTile);
822  tilePtr->width = 0;
823  }
824  else
825  {
826  int tileWidth = 0;
827  tilePtr->count = getTileDrawWidth(tilePtr,
828  width1 - x,
829  tileWidth,
830  nextTile);
831  tilePtr->width = tileWidth;
832  }
833  tilePtr->nextTile = nextTile;
834  }
835  }
836 }
static int getEmptyTileDrawWidth(const TileInfo *img, const int endX, int &nextTile)
Definition: maplayer.cpp:748
const int mY
Definition: maplayer.h:209
Image * image
Definition: tileinfo.h:42
TileInfo *const mTiles
Definition: maplayer.h:214
const int mX
Definition: maplayer.h:208
bool isEnabled
Definition: tileinfo.h:50
int width
Definition: tileinfo.h:44
int count
Definition: tileinfo.h:46
static int getTileDrawWidth(const TileInfo *img, const int endX, int &width, int &nextTile)
Definition: maplayer.cpp:705
int nextTile
Definition: tileinfo.h:48
const int mWidth
Definition: maplayer.h:212
const int mHeight
Definition: maplayer.h:213

◆ updateConditionTiles()

void MapLayer::updateConditionTiles ( const MetaTile *const  metaTiles,
const int  width,
const int  height 
)
protected

Definition at line 776 of file maplayer.cpp.

References BlockMask::GROUND, mHeight, mTileCondition, mTiles, mWidth, mX, mY, x, and y.

Referenced by getCounterName().

779 {
780  const int width1 = width < mWidth ? width : mWidth;
781  const int height1 = height < mHeight ? height : mHeight;
782 
783  for (int y = mY; y < height1; y ++)
784  {
785  const MetaTile *metaPtr = metaTiles + (y - mY) * width;
786  TileInfo *tilePtr = mTiles + y * mWidth;
787  for (int x = mX; x < width1; x ++, metaPtr ++, tilePtr ++)
788  {
789  if (tilePtr->image != nullptr &&
790  (((metaPtr->blockmask & mTileCondition) != 0) ||
791  (metaPtr->blockmask == 0 &&
793  {
794  tilePtr->isEnabled = true;
795  }
796  else
797  {
798  tilePtr->isEnabled = false;
799  }
800  }
801  }
802 }
const int mY
Definition: maplayer.h:209
TileInfo *const mTiles
Definition: maplayer.h:214
const int mX
Definition: maplayer.h:208
int mTileCondition
Definition: maplayer.h:222
const int mWidth
Definition: maplayer.h:212
const int mHeight
Definition: maplayer.h:213

◆ updateOGL()

void MapLayer::updateOGL ( Graphics *const  graphics,
int  startX,
int  startY,
int  endX,
int  endY,
const int  scrollX,
const int  scrollY 
)

Definition at line 271 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, CAST_SIZE, delete_all(), FOR_EACH, ImageVertexes::image, MapRowVertexes::images, OpenGLGraphicsVertexes::init(), TileInfo::isEnabled, mapTileSize, Image::mBounds, Image::mGLImage, mHeight, mPixelX, mPixelY, mSpecialFlag, mTempRows, mTiles, mWidth, mX, mY, ImageVertexes::ogl, x, and y.

Referenced by setTile().

278 {
279  BLOCK_START("MapLayer::updateOGL")
281  mTempRows.clear();
282 
283  startX -= mX;
284  startY -= mY;
285  endX -= mX;
286  endY -= mY;
287 
288  if (startX < 0)
289  startX = 0;
290  if (startY < 0)
291  startY = 0;
292  if (endX > mWidth)
293  endX = mWidth;
294  if (endY > mHeight)
295  endY = mHeight;
296 
297  const int dx = mPixelX - scrollX;
298  const int dy = mPixelY - scrollY;
299 
300  MapRowVertexes *const row = new MapRowVertexes;
301  mTempRows.push_back(row);
302  Image *lastImage = nullptr;
303  ImageVertexes *imgVert = nullptr;
304  typedef std::map<int, ImageVertexes*> ImageVertexesMap;
305  ImageVertexesMap imgSet;
306 
307  for (int y = startY; y < endY; y++)
308  {
309  const int yWidth = y * mWidth;
310  const int py0 = y * mapTileSize + dy;
311  TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)];
312  for (int x = startX; x < endX; x++, tilePtr++)
313  {
314  if (!tilePtr->isEnabled)
315  continue;
316  Image *const img = (*tilePtr).image;
317  const int px = x * mapTileSize + dx;
318  const int py = py0 - img->mBounds.h;
319  const GLuint imgGlImage = img->mGLImage;
320  if (mSpecialFlag ||
321  img->mBounds.h <= mapTileSize)
322  {
323  if ((lastImage == nullptr) ||
324  lastImage->mGLImage != imgGlImage)
325  {
326  if (img->mBounds.w > mapTileSize)
327  imgSet.clear();
328 
329  if (imgSet.find(imgGlImage) != imgSet.end())
330  {
331  imgVert = imgSet[imgGlImage];
332  }
333  else
334  {
335  if (lastImage != nullptr)
336  imgSet[lastImage->mGLImage] = imgVert;
337  imgVert = new ImageVertexes;
338  imgVert->ogl.init();
339  imgVert->image = img;
340  row->images.push_back(imgVert);
341  }
342  }
343  lastImage = img;
344  graphics->calcTileVertexes(imgVert, lastImage, px, py);
345  }
346  }
347  }
348  FOR_EACH (MapRowImages::iterator, it, row->images)
349  {
350  graphics->finalize(*it);
351  }
352  BLOCK_END("MapLayer::updateOGL")
353 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
const int mY
Definition: maplayer.h:209
TileInfo *const mTiles
Definition: maplayer.h:214
#define BLOCK_START(name)
Definition: perfomance.h:78
void clear()
Definition: playerinfo.cpp:449
bool mSpecialFlag
Definition: maplayer.h:226
if(!vert) return
const int mX
Definition: maplayer.h:208
#define BLOCK_END(name)
Definition: perfomance.h:79
const int mPixelX
Definition: maplayer.h:210
virtual void calcTileVertexes(ImageVertexes *const vert, const Image *const image, int x, int y) const =0
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:464
#define new
Definition: debug_new.h:147
void delete_all(Container &c)
Definition: dtor.h:55
bool isEnabled
Definition: tileinfo.h:50
const int mPixelY
Definition: maplayer.h:211
GLuint mGLImage
Definition: image.h:182
Definition: image.h:61
const int mWidth
Definition: maplayer.h:212
static const int mapTileSize
Definition: map.h:26
#define CAST_SIZE
Definition: cast.h:33
SDL_Rect mBounds
Definition: image.h:210
const int mHeight
Definition: maplayer.h:213
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49
MapRows mTempRows
Definition: maplayer.h:220

◆ updateSDL()

void MapLayer::updateSDL ( const Graphics *const  graphics,
int  startX,
int  startY,
int  endX,
int  endY,
const int  scrollX,
const int  scrollY 
)

Definition at line 206 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, CAST_SIZE, delete_all(), ImageVertexes::image, MapRowVertexes::images, TileInfo::isEnabled, mapTileSize, Image::mBounds, mHeight, mPixelX, mPixelY, mSpecialFlag, mTempRows, mTiles, mWidth, mX, mY, x, and y.

Referenced by setTile().

213 {
214  BLOCK_START("MapLayer::updateSDL")
216  mTempRows.clear();
217 
218  startX -= mX;
219  startY -= mY;
220  endX -= mX;
221  endY -= mY;
222 
223  if (startX < 0)
224  startX = 0;
225  if (startY < 0)
226  startY = 0;
227  if (endX > mWidth)
228  endX = mWidth;
229  if (endY > mHeight)
230  endY = mHeight;
231 
232  const int dx = mPixelX - scrollX;
233  const int dy = mPixelY - scrollY;
234 
235  for (int y = startY; y < endY; y++)
236  {
237  MapRowVertexes *const row = new MapRowVertexes;
238  mTempRows.push_back(row);
239 
240  const Image *lastImage = nullptr;
241  ImageVertexes *imgVert = nullptr;
242 
243  const int yWidth = y * mWidth;
244  const int py0 = y * mapTileSize + dy;
245  TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)];
246 
247  for (int x = startX; x < endX; x++, tilePtr++)
248  {
249  if (!tilePtr->isEnabled)
250  continue;
251  Image *const img = (*tilePtr).image;
252  const int px = x * mapTileSize + dx;
253  const int py = py0 - img->mBounds.h;
254  if (mSpecialFlag ||
255  img->mBounds.h <= mapTileSize)
256  {
257  if (lastImage != img)
258  {
259  imgVert = new ImageVertexes;
260  imgVert->image = img;
261  row->images.push_back(imgVert);
262  lastImage = img;
263  }
264  graphics->calcTileSDL(imgVert, px, py);
265  }
266  }
267  }
268  BLOCK_END("MapLayer::updateSDL")
269 }
const int mY
Definition: maplayer.h:209
TileInfo *const mTiles
Definition: maplayer.h:214
virtual void calcTileSDL(ImageVertexes *const vert, int x, int y) const
Definition: graphics.h:223
#define BLOCK_START(name)
Definition: perfomance.h:78
const Image * image
Definition: imagevertexes.h:47
void clear()
Definition: playerinfo.cpp:449
bool mSpecialFlag
Definition: maplayer.h:226
if(!vert) return
const int mX
Definition: maplayer.h:208
#define BLOCK_END(name)
Definition: perfomance.h:79
const int mPixelX
Definition: maplayer.h:210
void delete_all(Container &c)
Definition: dtor.h:55
bool isEnabled
Definition: tileinfo.h:50
const int mPixelY
Definition: maplayer.h:211
Definition: image.h:61
const int mWidth
Definition: maplayer.h:212
static const int mapTileSize
Definition: map.h:26
#define CAST_SIZE
Definition: cast.h:33
SDL_Rect mBounds
Definition: image.h:210
const int mHeight
Definition: maplayer.h:213
MapRowImages images
MapRows mTempRows
Definition: maplayer.h:220

Friends And Related Function Documentation

◆ Map

friend class Map
friend

Definition at line 51 of file maplayer.h.

Field Documentation

◆ mActorsFix

int MapLayer::mActorsFix
private

Definition at line 223 of file maplayer.h.

Referenced by drawFringe(), and setActorsFix().

◆ mDrawLayerFlags

MapTypeT MapLayer::mDrawLayerFlags
private

Definition at line 215 of file maplayer.h.

Referenced by drawFringe(), and setDrawLayerFlags().

◆ mHeight

const int MapLayer::mHeight
private

◆ mHighlightAttackRange

bool MapLayer::mHighlightAttackRange
private

Definition at line 225 of file maplayer.h.

Referenced by drawFringe(), and optionChanged().

◆ mIsFringeLayer

const bool MapLayer::mIsFringeLayer
private

Whether the actors are drawn.

Definition at line 224 of file maplayer.h.

Referenced by isFringeLayer().

◆ mMask

int MapLayer::mMask
private

Definition at line 221 of file maplayer.h.

Referenced by Map::updateDrawLayersList().

◆ mName

const std::string MapLayer::mName
private

Definition at line 218 of file maplayer.h.

Referenced by getCounterName().

◆ mPixelX

const int MapLayer::mPixelX
private

Definition at line 210 of file maplayer.h.

Referenced by draw(), drawFringe(), updateOGL(), and updateSDL().

◆ mPixelY

const int MapLayer::mPixelY
private

Definition at line 211 of file maplayer.h.

Referenced by draw(), drawFringe(), updateOGL(), and updateSDL().

◆ mSpecialFlag

bool MapLayer::mSpecialFlag
private

Definition at line 226 of file maplayer.h.

Referenced by draw(), drawFringe(), setDrawLayerFlags(), updateOGL(), and updateSDL().

◆ mSpecialLayer

const SpecialLayer* MapLayer::mSpecialLayer
private

Definition at line 216 of file maplayer.h.

Referenced by calcMemoryChilds(), drawFringe(), drawSpecialLayer(), and setSpecialLayer().

◆ mTempLayer

const SpecialLayer* MapLayer::mTempLayer
private

Definition at line 217 of file maplayer.h.

Referenced by calcMemoryChilds(), drawFringe(), drawSpecialLayer(), and setTempLayer().

◆ mTempRows

MapRows MapLayer::mTempRows
private

Definition at line 220 of file maplayer.h.

Referenced by calcMemoryLocal(), drawOGL(), drawSDL(), updateOGL(), updateSDL(), and ~MapLayer().

◆ mTileCondition

int MapLayer::mTileCondition
private

Definition at line 222 of file maplayer.h.

Referenced by getCounterName(), and updateConditionTiles().

◆ mTiles

TileInfo* const MapLayer::mTiles
private

◆ mWidth

const int MapLayer::mWidth
private

◆ mX

const int MapLayer::mX
private

Definition at line 208 of file maplayer.h.

Referenced by draw(), drawFringe(), updateCache(), updateConditionTiles(), updateOGL(), and updateSDL().

◆ mY

const int MapLayer::mY
private

Definition at line 209 of file maplayer.h.

Referenced by draw(), drawFringe(), updateCache(), updateConditionTiles(), updateOGL(), and updateSDL().


The documentation for this class was generated from the following files: