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 231 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:236
const int mY
Definition: maplayer.h:221
TileInfo *const mTiles
Definition: maplayer.h:226
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:228
Configuration config
bool mSpecialFlag
Definition: maplayer.h:238
const int mX
Definition: maplayer.h:220
const int mPixelX
Definition: maplayer.h:222
const SpecialLayer * mTempLayer
Definition: maplayer.h:229
void addListener(const std::string &key, ConfigListener *const listener)
bool mHighlightAttackRange
Definition: maplayer.h:237
bool getBoolValue(const std::string &key) const
int mActorsFix
Definition: maplayer.h:235
const std::string mName
Definition: maplayer.h:230
const int mPixelY
Definition: maplayer.h:223
int mTileCondition
Definition: maplayer.h:234
MapTypeT mDrawLayerFlags
Definition: maplayer.h:227
const int mWidth
Definition: maplayer.h:224
static const int mapTileSize
Definition: map.h:26
const int mHeight
Definition: maplayer.h:225
int mMask
Definition: maplayer.h:233
MapRows mTempRows
Definition: maplayer.h:232

◆ ~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:226
Configuration config
void delete_all(Container &c)
Definition: dtor.h:55
#define CHECKLISTENERS
Definition: localconsts.h:276
void removeListener(const std::string &key, ConfigListener *const listener)
MapRows mTempRows
Definition: maplayer.h:232

Member Function Documentation

◆ calcMemoryChilds()

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

Reimplemented from MemoryCounter.

Definition at line 830 of file maplayer.cpp.

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

Referenced by setActorsFix().

831 {
832  int sz = 0;
833  if (mSpecialLayer != nullptr)
834  sz += mSpecialLayer->calcMemory(level + 1);
835  if (mTempLayer != nullptr)
836  sz += mTempLayer->calcMemory(level + 1);
837  return sz;
838 }
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:228
int calcMemory(const int level) const
const SpecialLayer * mTempLayer
Definition: maplayer.h:229

◆ calcMemoryLocal()

int MapLayer::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 823 of file maplayer.cpp.

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

Referenced by setActorsFix().

824 {
825  return static_cast<int>(sizeof(MapLayer) +
826  sizeof(TileInfo) * mWidth * mHeight +
827  sizeof(MapRowVertexes) * mTempRows.capacity());
828 }
const int mWidth
Definition: maplayer.h:224
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:225
MapRows mTempRows
Definition: maplayer.h:232

◆ 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 99 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().

106 {
107  BLOCK_START("MapLayer::draw")
108  startX -= mX;
109  startY -= mY;
110  endX -= mX;
111  endY -= mY;
112 
113  if (startX < 0)
114  startX = 0;
115  if (startY < 0)
116  startY = 0;
117  if (endX > mWidth)
118  endX = mWidth;
119  if (endY > mHeight)
120  endY = mHeight;
121 
122  const int dx = mPixelX - scrollX;
123  const int dy = mPixelY - scrollY;
124  for (int y = startY; y < endY; y++)
125  {
126  const int y32 = y * mapTileSize;
127  const int yWidth = y * mWidth;
128 
129  const int py0 = y32 + dy;
130 
131  int x0 = startX;
132  TileInfo *tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
133  if (tilePtr->isEnabled == false)
134  {
135  if (x0 + tilePtr->nextTile + 1 >= endX)
136  {
137  continue;
138  }
139  x0 += tilePtr->nextTile + 1;
140  tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
141  if (mTiles[x0 + yWidth].isEnabled == false)
142  {
143  continue;
144  }
145  }
146  for (int x = x0; x < endX; x++, tilePtr++)
147  {
148  const int x32 = x * mapTileSize;
149 
150  const Image *const img = tilePtr->image;
151  const int px = x32 + dx;
152  const int py = py0 - img->mBounds.h;
153  if (mSpecialFlag ||
154  img->mBounds.h <= mapTileSize)
155  {
156  if (tilePtr->count == 0)
157  {
158  graphics->drawImage(img, px, py);
159  }
160  else
161  {
162  graphics->drawPattern(img,
163  px,
164  py,
165  tilePtr->width,
166  img->mBounds.h);
167  }
168  }
169 
170  const int nextTile = tilePtr->nextTile;
171  x += nextTile;
172  tilePtr += nextTile;
173  }
174  }
175  BLOCK_END("MapLayer::draw")
176 }
const int mY
Definition: maplayer.h:221
Image * image
Definition: tileinfo.h:42
TileInfo *const mTiles
Definition: maplayer.h:226
#define BLOCK_START(name)
Definition: perfomance.h:78
bool mSpecialFlag
Definition: maplayer.h:238
if(!vert) return
const int mX
Definition: maplayer.h:220
#define BLOCK_END(name)
Definition: perfomance.h:79
const int mPixelX
Definition: maplayer.h:222
bool isEnabled
Definition: tileinfo.h:50
const int mPixelY
Definition: maplayer.h:223
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:224
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:225

◆ 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 424 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().

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

◆ drawOGL()

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

Definition at line 348 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, and mTempRows.

Referenced by setTile().

349 {
350  BLOCK_START("MapLayer::drawOGL")
351  MapRows::const_iterator rit = mTempRows.begin();
352  const MapRows::const_iterator rit_end = mTempRows.end();
353  while (rit != rit_end)
354  {
355  const MapRowImages *const images = &(*rit)->images;
356  MapRowImages::const_iterator iit = images->begin();
357  const MapRowImages::const_iterator iit_end = images->end();
358  while (iit != iit_end)
359  {
360  graphics->drawTileVertexes(*iit);
361  ++ iit;
362  }
363  ++ rit;
364  }
365  BLOCK_END("MapLayer::drawOGL")
366 }
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:231
MapRows mTempRows
Definition: maplayer.h:232

◆ drawSDL()

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

Definition at line 178 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, and mTempRows.

Referenced by setTile().

179 {
180  BLOCK_START("MapLayer::drawSDL")
181  MapRows::const_iterator rit = mTempRows.begin();
182  const MapRows::const_iterator rit_end = mTempRows.end();
183  while (rit != rit_end)
184  {
185  MapRowImages *const images = &(*rit)->images;
186  MapRowImages::const_iterator iit = images->begin();
187  const MapRowImages::const_iterator iit_end = images->end();
188  while (iit != iit_end)
189  {
190  graphics->drawTileVertexes(*iit);
191  ++ iit;
192  }
193  ++ rit;
194  }
195  BLOCK_END("MapLayer::drawSDL")
196 }
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:231
MapRows mTempRows
Definition: maplayer.h:232

◆ 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 369 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().

375 {
376  const int y32 = y * mapTileSize;
377  const int py1 = y32 - scrollY;
378  int endX1 = endX;
379  int specialWidth = mSpecialLayer->mWidth;
380  int ptr = y * specialWidth;
381  if (endX1 > specialWidth)
382  endX1 = specialWidth;
383  if (endX1 < 0)
384  endX1 = 0;
385  int x0 = startX;
386  const MapItem *item0 = mSpecialLayer->mTiles[ptr + startX];
387  if ((item0 == nullptr) || item0->mType == MapItemType::EMPTY)
388  {
389  x0 += mSpecialLayer->mCache[ptr + startX] + 1;
390  }
391  for (int x = x0; x < endX1; x++)
392  {
393  const int px1 = x * mapTileSize - scrollX;
394  const MapItem *const item = mSpecialLayer->mTiles[ptr + x];
395  if (item != nullptr)
396  {
397  item->draw(graphics, px1, py1,
398  mapTileSize, mapTileSize);
399  }
400  x += mSpecialLayer->mCache[ptr + x];
401  }
402 
403  x0 = startX;
404  specialWidth = mTempLayer->mWidth;
405  ptr = y * specialWidth;
406  endX1 = endX;
407  if (endX1 > specialWidth)
408  endX1 = specialWidth;
409  item0 = mTempLayer->mTiles[ptr + startX];
410  if ((item0 == nullptr) || item0->mType == MapItemType::EMPTY)
411  {
412  x0 += mTempLayer->mCache[ptr + startX] + 1;
413  }
414  for (int x = x0; x < endX1; x++)
415  {
416  const int px1 = x * mapTileSize - scrollX;
417  const MapItem *const item = mTempLayer->mTiles[ptr + x];
418  item->draw(graphics, px1, py1,
419  mapTileSize, mapTileSize);
420  x += mTempLayer->mCache[ptr + x];
421  }
422 }
int mType
Definition: mapitem.h:87
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:228
const SpecialLayer * mTempLayer
Definition: maplayer.h:229
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

◆ getEmptyTileDrawWidth()

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

Definition at line 741 of file maplayer.cpp.

References BLOCK_END, BLOCK_START, and x.

Referenced by getCounterName(), and updateCache().

744 {
745  BLOCK_START("MapLayer::getEmptyTileDrawWidth")
746  int c = 0;
747  for (int x = 1; x < endX; x++)
748  {
749  tilePtr ++;
750  const Image *const img = tilePtr->image;
751  if (img != nullptr && tilePtr->isEnabled == true)
752  break;
753  c ++;
754  }
755  BLOCK_END("MapLayer::getEmptyTileDrawWidth")
756 
757  nextTile = c;
758  return c;
759 }
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 154 of file maplayer.h.

References mHeight, optionChanged(), and restrict.

155  { return mHeight; }
const int mHeight
Definition: maplayer.h:225

◆ getTileDrawWidth()

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

Definition at line 698 of file maplayer.cpp.

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

Referenced by getCounterName(), and updateCache().

702 {
703  BLOCK_START("MapLayer::getTileDrawWidth")
704  const Image *const img1 = tilePtr->image;
705  int c = 0;
706  width = img1->mBounds.w;
707  for (int x = 1; x < endX; x++)
708  {
709  tilePtr ++;
710  const Image *const img = tilePtr->image;
711  if (img == nullptr ||
712  tilePtr->isEnabled == false)
713  {
714  break;
715  }
716  if (img != img1)
717  {
718  nextTile = c;
719  BLOCK_END("MapLayer::getTileDrawWidth")
720  return c;
721  }
722  c ++;
723  width += img->mBounds.w;
724  }
725  int c2 = c;
726  for (int x2 = c2 + 1; x2 < endX; x2++)
727  {
728  if (tilePtr->image != nullptr &&
729  tilePtr->isEnabled == true)
730  {
731  break;
732  }
733  c2 ++;
734  tilePtr ++;
735  }
736  nextTile = c2;
737  BLOCK_END("MapLayer::getTileDrawWidth")
738  return c;
739 }
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 151 of file maplayer.h.

References mWidth.

152  { return mWidth; }
const int mWidth
Definition: maplayer.h:224

◆ isFringeLayer()

bool MapLayer::isFringeLayer ( ) const
inline

Definition at line 140 of file maplayer.h.

References mIsFringeLayer.

Referenced by Map::updateDrawLayersList().

141  { return mIsFringeLayer; }
const bool mIsFringeLayer
Definition: maplayer.h:236

◆ 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:237
bool getBoolValue(const std::string &key) const

◆ setActorsFix()

void MapLayer::setActorsFix ( const int  y)
inline

Definition at line 169 of file maplayer.h.

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

Referenced by Map::setActorsFix().

170  { mActorsFix = y; }
int mActorsFix
Definition: maplayer.h:235

◆ setDrawLayerFlags()

void MapLayer::setDrawLayerFlags ( const MapTypeT n)
inline

◆ setSpecialLayer()

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

Definition at line 143 of file maplayer.h.

References mSpecialLayer.

Referenced by Map::draw().

145  { mSpecialLayer = val; }
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:228

◆ setTempLayer()

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

Definition at line 147 of file maplayer.h.

References mTempLayer.

Referenced by Map::draw().

149  { mTempLayer = val; }
const SpecialLayer * mTempLayer
Definition: maplayer.h:229

◆ setTile() [1/2]

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

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

Definition at line 77 of file maplayer.h.

References TileInfo::image, mTiles, and mWidth.

Referenced by setTile().

80  {
81  mTiles[x + y * mWidth].image = img;
82  }
Image * image
Definition: tileinfo.h:42
TileInfo *const mTiles
Definition: maplayer.h:226
const int mWidth
Definition: maplayer.h:224

◆ 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 87 of file maplayer.h.

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

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

◆ updateCache()

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

Definition at line 789 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().

791 {
792  const int width1 = width < mWidth ? width : mWidth;
793  const int height1 = height < mHeight ? height : mHeight;
794 
795  for (int y = mY; y < height1; y ++)
796  {
797  for (int x = mX; x < width1; x ++)
798  {
799  TileInfo *tilePtr = mTiles + y * mWidth + x;
800  int nextTile = 0;
801  if (tilePtr->image == nullptr || tilePtr->isEnabled == false)
802  {
803  tilePtr->isEnabled = false;
804  tilePtr->count = getEmptyTileDrawWidth(tilePtr,
805  width1 - x,
806  nextTile);
807  tilePtr->width = 0;
808  }
809  else
810  {
811  int tileWidth = 0;
812  tilePtr->count = getTileDrawWidth(tilePtr,
813  width1 - x,
814  tileWidth,
815  nextTile);
816  tilePtr->width = tileWidth;
817  }
818  tilePtr->nextTile = nextTile;
819  }
820  }
821 }
static int getEmptyTileDrawWidth(const TileInfo *img, const int endX, int &nextTile)
Definition: maplayer.cpp:741
const int mY
Definition: maplayer.h:221
Image * image
Definition: tileinfo.h:42
TileInfo *const mTiles
Definition: maplayer.h:226
const int mX
Definition: maplayer.h:220
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:698
int nextTile
Definition: tileinfo.h:48
const int mWidth
Definition: maplayer.h:224
const int mHeight
Definition: maplayer.h:225

◆ updateConditionTiles()

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

Definition at line 761 of file maplayer.cpp.

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

Referenced by getCounterName().

764 {
765  const int width1 = width < mWidth ? width : mWidth;
766  const int height1 = height < mHeight ? height : mHeight;
767 
768  for (int y = mY; y < height1; y ++)
769  {
770  const MetaTile *metaPtr = metaTiles + (y - mY) * width;
771  TileInfo *tilePtr = mTiles + y * mWidth;
772  for (int x = mX; x < width1; x ++, metaPtr ++, tilePtr ++)
773  {
774  if (tilePtr->image != nullptr &&
775  (((metaPtr->blockmask & mTileCondition) != 0) ||
776  (metaPtr->blockmask == 0 &&
778  {
779  tilePtr->isEnabled = true;
780  }
781  else
782  {
783  tilePtr->isEnabled = false;
784  }
785  }
786  }
787 }
const int mY
Definition: maplayer.h:221
TileInfo *const mTiles
Definition: maplayer.h:226
const int mX
Definition: maplayer.h:220
int mTileCondition
Definition: maplayer.h:234
const int mWidth
Definition: maplayer.h:224
const int mHeight
Definition: maplayer.h:225

◆ updateOGL()

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

Definition at line 264 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().

271 {
272  BLOCK_START("MapLayer::updateOGL")
274  mTempRows.clear();
275 
276  startX -= mX;
277  startY -= mY;
278  endX -= mX;
279  endY -= mY;
280 
281  if (startX < 0)
282  startX = 0;
283  if (startY < 0)
284  startY = 0;
285  if (endX > mWidth)
286  endX = mWidth;
287  if (endY > mHeight)
288  endY = mHeight;
289 
290  const int dx = mPixelX - scrollX;
291  const int dy = mPixelY - scrollY;
292 
293  MapRowVertexes *const row = new MapRowVertexes;
294  mTempRows.push_back(row);
295  Image *lastImage = nullptr;
296  ImageVertexes *imgVert = nullptr;
297  typedef std::map<int, ImageVertexes*> ImageVertexesMap;
298  ImageVertexesMap imgSet;
299 
300  for (int y = startY; y < endY; y++)
301  {
302  const int yWidth = y * mWidth;
303  const int py0 = y * mapTileSize + dy;
304  TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)];
305  for (int x = startX; x < endX; x++, tilePtr++)
306  {
307  if (!tilePtr->isEnabled)
308  continue;
309  Image *const img = (*tilePtr).image;
310  const int px = x * mapTileSize + dx;
311  const int py = py0 - img->mBounds.h;
312  const GLuint imgGlImage = img->mGLImage;
313  if (mSpecialFlag ||
314  img->mBounds.h <= mapTileSize)
315  {
316  if ((lastImage == nullptr) ||
317  lastImage->mGLImage != imgGlImage)
318  {
319  if (img->mBounds.w > mapTileSize)
320  imgSet.clear();
321 
322  if (imgSet.find(imgGlImage) != imgSet.end())
323  {
324  imgVert = imgSet[imgGlImage];
325  }
326  else
327  {
328  if (lastImage != nullptr)
329  imgSet[lastImage->mGLImage] = imgVert;
330  imgVert = new ImageVertexes;
331  imgVert->ogl.init();
332  imgVert->image = img;
333  row->images.push_back(imgVert);
334  }
335  }
336  lastImage = img;
337  graphics->calcTileVertexes(imgVert, lastImage, px, py);
338  }
339  }
340  }
341  FOR_EACH (MapRowImages::iterator, it, row->images)
342  {
343  graphics->finalize(*it);
344  }
345  BLOCK_END("MapLayer::updateOGL")
346 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
const int mY
Definition: maplayer.h:221
TileInfo *const mTiles
Definition: maplayer.h:226
#define BLOCK_START(name)
Definition: perfomance.h:78
void clear()
Definition: playerinfo.cpp:450
bool mSpecialFlag
Definition: maplayer.h:238
if(!vert) return
const int mX
Definition: maplayer.h:220
#define BLOCK_END(name)
Definition: perfomance.h:79
const int mPixelX
Definition: maplayer.h:222
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:223
GLuint mGLImage
Definition: image.h:182
Definition: image.h:61
const int mWidth
Definition: maplayer.h:224
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:225
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49
MapRows mTempRows
Definition: maplayer.h:232

◆ 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 199 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().

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

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 235 of file maplayer.h.

Referenced by drawFringe(), and setActorsFix().

◆ mDrawLayerFlags

MapTypeT MapLayer::mDrawLayerFlags
private

Definition at line 227 of file maplayer.h.

Referenced by drawFringe(), and setDrawLayerFlags().

◆ mHeight

const int MapLayer::mHeight
private

◆ mHighlightAttackRange

bool MapLayer::mHighlightAttackRange
private

Definition at line 237 of file maplayer.h.

Referenced by drawFringe(), and optionChanged().

◆ mIsFringeLayer

const bool MapLayer::mIsFringeLayer
private

Whether the actors are drawn.

Definition at line 236 of file maplayer.h.

Referenced by isFringeLayer().

◆ mMask

int MapLayer::mMask
private

Definition at line 233 of file maplayer.h.

Referenced by Map::updateDrawLayersList().

◆ mName

const std::string MapLayer::mName
private

Definition at line 230 of file maplayer.h.

Referenced by getCounterName().

◆ mPixelX

const int MapLayer::mPixelX
private

Definition at line 222 of file maplayer.h.

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

◆ mPixelY

const int MapLayer::mPixelY
private

Definition at line 223 of file maplayer.h.

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

◆ mSpecialFlag

bool MapLayer::mSpecialFlag
private

Definition at line 238 of file maplayer.h.

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

◆ mSpecialLayer

const SpecialLayer* MapLayer::mSpecialLayer
private

Definition at line 228 of file maplayer.h.

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

◆ mTempLayer

const SpecialLayer* MapLayer::mTempLayer
private

Definition at line 229 of file maplayer.h.

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

◆ mTempRows

MapRows MapLayer::mTempRows
private

Definition at line 232 of file maplayer.h.

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

◆ mTileCondition

int MapLayer::mTileCondition
private

Definition at line 234 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 220 of file maplayer.h.

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

◆ mY

const int MapLayer::mY
private

Definition at line 221 of file maplayer.h.

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


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