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

Member Typedef Documentation

◆ MapRows

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

Definition at line 232 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 50 of file maplayer.cpp.

57  :
58  mX(x),
59  mY(y),
62  mWidth(width),
63  mHeight(height),
64  mTiles(new TileInfo[mWidth * mHeight]),
66  mSpecialLayer(nullptr),
67  mTempLayer(nullptr),
68  mName(name),
69  mTempRows(),
70  mMask(mask),
71  mTileCondition(tileCondition),
72  mActorsFix(0),
73  mIsFringeLayer(fringeLayer),
74  mHighlightAttackRange(config.getBoolValue("highlightAttackRange")),
75  mSpecialFlag(true)
76 {
77 // std::fill_n(mTiles, mWidth * mHeight, static_cast<Image*>(nullptr));
78 
79  config.addListener("highlightAttackRange", this);
80 }
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
TileInfo *const mTiles
Definition: maplayer.h:227
const int mHeight
Definition: maplayer.h:226
const int mWidth
Definition: maplayer.h:225
int mMask
Definition: maplayer.h:234
const int mPixelX
Definition: maplayer.h:223
bool mHighlightAttackRange
Definition: maplayer.h:238
bool mSpecialFlag
Definition: maplayer.h:239
MapTypeT mDrawLayerFlags
Definition: maplayer.h:228
int mActorsFix
Definition: maplayer.h:236
const std::string mName
Definition: maplayer.h:231
MapRows mTempRows
Definition: maplayer.h:233
const int mX
Definition: maplayer.h:221
const SpecialLayer * mTempLayer
Definition: maplayer.h:230
const int mPixelY
Definition: maplayer.h:224
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:229
const int mY
Definition: maplayer.h:222
const bool mIsFringeLayer
Definition: maplayer.h:237
int mTileCondition
Definition: maplayer.h:235
Configuration config
static const int mapTileSize
Definition: map.h:27
@ NORMAL
Definition: maptype.h:31

References Configuration::addListener(), and config.

Referenced by calcMemoryLocal().

◆ ~MapLayer()

MapLayer::~MapLayer ( )

Destructor.

Definition at line 82 of file maplayer.cpp.

83 {
84  config.removeListener("highlightAttackRange", this);
86  delete []mTiles;
88  mTempRows.clear();
89 }
void removeListener(const std::string &key, ConfigListener *const listener)
void delete_all(Container &c)
Definition: dtor.h:56
#define CHECKLISTENERS
Definition: localconsts.h:277

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

Member Function Documentation

◆ calcMemoryChilds()

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

Reimplemented from MemoryCounter.

Definition at line 831 of file maplayer.cpp.

832 {
833  int sz = 0;
834  if (mSpecialLayer != nullptr)
835  sz += mSpecialLayer->calcMemory(level + 1);
836  if (mTempLayer != nullptr)
837  sz += mTempLayer->calcMemory(level + 1);
838  return sz;
839 }
int calcMemory(const int level) const

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

◆ calcMemoryLocal()

int MapLayer::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 824 of file maplayer.cpp.

825 {
826  return static_cast<int>(sizeof(MapLayer) +
827  sizeof(TileInfo) * mWidth * mHeight +
828  sizeof(MapRowVertexes) * mTempRows.capacity());
829 }
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:50

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

◆ 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 100 of file maplayer.cpp.

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

References BLOCK_END, BLOCK_START, CAST_SIZE, TileInfo::count, TileInfo::image, TileInfo::isEnabled, mapTileSize, TileInfo::nextTile, TileInfo::width, x, and y.

◆ 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 425 of file maplayer.cpp.

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

References UserColorId::ATTACK_RANGE, UserColorId::ATTACK_RANGE_BORDER, MapType::BLACKWHITE, BLOCK_END, BLOCK_START, CAST_SIZE, TileInfo::count, LocalPlayer::getAttackRange(), UserPalette::getColorWithAlpha(), Actor::getPixelX(), Actor::getPixelY(), TileInfo::image, TileInfo::isEnabled, localPlayer, mapTileSize, TileInfo::nextTile, MapType::SPECIAL3, MapType::SPECIAL4, userPalette, TileInfo::width, x, and y.

◆ drawOGL()

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

Definition at line 349 of file maplayer.cpp.

350 {
351  BLOCK_START("MapLayer::drawOGL")
352  MapRows::const_iterator rit = mTempRows.begin();
353  const MapRows::const_iterator rit_end = mTempRows.end();
354  while (rit != rit_end)
355  {
356  const MapRowImages *const images = &(*rit)->images;
357  MapRowImages::const_iterator iit = images->begin();
358  const MapRowImages::const_iterator iit_end = images->end();
359  while (iit != iit_end)
360  {
361  graphics->drawTileVertexes(*iit);
362  ++ iit;
363  }
364  ++ rit;
365  }
366  BLOCK_END("MapLayer::drawOGL")
367 }
virtual void drawTileVertexes(const ImageVertexes *const vert)=0
std::vector< MapRowVertexes * > MapRows
Definition: maplayer.h:232
std::vector< ImageVertexes * > MapRowImages

References BLOCK_END, and BLOCK_START.

◆ drawSDL()

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

Definition at line 179 of file maplayer.cpp.

180 {
181  BLOCK_START("MapLayer::drawSDL")
182  MapRows::const_iterator rit = mTempRows.begin();
183  const MapRows::const_iterator rit_end = mTempRows.end();
184  while (rit != rit_end)
185  {
186  MapRowImages *const images = &(*rit)->images;
187  MapRowImages::const_iterator iit = images->begin();
188  const MapRowImages::const_iterator iit_end = images->end();
189  while (iit != iit_end)
190  {
191  graphics->drawTileVertexes(*iit);
192  ++ iit;
193  }
194  ++ rit;
195  }
196  BLOCK_END("MapLayer::drawSDL")
197 }

References BLOCK_END, and BLOCK_START.

◆ 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 370 of file maplayer.cpp.

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

References MapItem::draw(), MapItemType::EMPTY, mapTileSize, MapItem::mType, x, and y.

◆ getCounterName()

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

Reimplemented from MemoryCounter.

Definition at line 177 of file maplayer.h.

178  { return mName; }

References mName.

◆ getEmptyTileDrawWidth()

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

Definition at line 742 of file maplayer.cpp.

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

References BLOCK_END, BLOCK_START, and x.

◆ getHeight()

int MapLayer::getHeight ( ) const
inline

Definition at line 155 of file maplayer.h.

156  { return mHeight; }

References mHeight.

◆ getTileDrawWidth()

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

Definition at line 699 of file maplayer.cpp.

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

References BLOCK_END, BLOCK_START, and x.

◆ getWidth()

int MapLayer::getWidth ( ) const
inline

Definition at line 152 of file maplayer.h.

153  { return mWidth; }

References mWidth.

◆ isFringeLayer()

bool MapLayer::isFringeLayer ( ) const
inline

Definition at line 141 of file maplayer.h.

142  { return mIsFringeLayer; }

References mIsFringeLayer.

Referenced by Map::updateDrawLayersList().

◆ 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 91 of file maplayer.cpp.

92 {
93  if (value == "highlightAttackRange")
94  {
96  config.getBoolValue("highlightAttackRange");
97  }
98 }

References config, and Configuration::getBoolValue().

◆ setActorsFix()

void MapLayer::setActorsFix ( const int  y)
inline

Definition at line 170 of file maplayer.h.

171  { mActorsFix = y; }

References mActorsFix, and y.

◆ setDrawLayerFlags()

void MapLayer::setDrawLayerFlags ( const MapTypeT n)
inline

◆ setSpecialLayer()

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

Definition at line 144 of file maplayer.h.

146  { mSpecialLayer = val; }

References mSpecialLayer.

◆ setTempLayer()

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

Definition at line 148 of file maplayer.h.

150  { mTempLayer = val; }

References mTempLayer.

◆ setTile() [1/2]

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

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

Definition at line 88 of file maplayer.h.

90  { mTiles[index].image = img; }

References TileInfo::image, and mTiles.

◆ setTile() [2/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 78 of file maplayer.h.

81  {
82  mTiles[x + y * mWidth].image = img;
83  }

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

Referenced by setTile().

◆ updateCache()

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

Definition at line 790 of file maplayer.cpp.

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

References TileInfo::count, TileInfo::image, TileInfo::isEnabled, TileInfo::nextTile, TileInfo::width, x, and y.

◆ updateConditionTiles()

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

Definition at line 762 of file maplayer.cpp.

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

References MetaTile::blockmask, BlockMask::GROUND, x, and y.

◆ updateOGL()

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

Definition at line 265 of file maplayer.cpp.

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

References BLOCK_END, BLOCK_START, CAST_SIZE, delete_all(), FOR_EACH, ImageVertexes::image, MapRowVertexes::images, TileInfo::isEnabled, mapTileSize, ImageVertexes::ogl, x, and y.

◆ 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 200 of file maplayer.cpp.

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

References BLOCK_END, BLOCK_START, CAST_SIZE, delete_all(), ImageVertexes::image, MapRowVertexes::images, TileInfo::isEnabled, mapTileSize, x, and y.

Friends And Related Function Documentation

◆ Map

friend class Map
friend

Definition at line 52 of file maplayer.h.

Field Documentation

◆ mActorsFix

int MapLayer::mActorsFix
private

Definition at line 236 of file maplayer.h.

Referenced by setActorsFix().

◆ mDrawLayerFlags

MapTypeT MapLayer::mDrawLayerFlags
private

Definition at line 228 of file maplayer.h.

Referenced by setDrawLayerFlags().

◆ mHeight

const int MapLayer::mHeight
private

Definition at line 226 of file maplayer.h.

Referenced by calcMemoryLocal(), and getHeight().

◆ mHighlightAttackRange

bool MapLayer::mHighlightAttackRange
private

Definition at line 238 of file maplayer.h.

◆ mIsFringeLayer

const bool MapLayer::mIsFringeLayer
private

Whether the actors are drawn.

Definition at line 237 of file maplayer.h.

Referenced by isFringeLayer().

◆ mMask

int MapLayer::mMask
private

Definition at line 234 of file maplayer.h.

Referenced by Map::updateDrawLayersList().

◆ mName

const std::string MapLayer::mName
private

Definition at line 231 of file maplayer.h.

Referenced by getCounterName().

◆ mPixelX

const int MapLayer::mPixelX
private

Definition at line 223 of file maplayer.h.

◆ mPixelY

const int MapLayer::mPixelY
private

Definition at line 224 of file maplayer.h.

◆ mSpecialFlag

bool MapLayer::mSpecialFlag
private

Definition at line 239 of file maplayer.h.

Referenced by setDrawLayerFlags().

◆ mSpecialLayer

const SpecialLayer* MapLayer::mSpecialLayer
private

Definition at line 229 of file maplayer.h.

Referenced by calcMemoryChilds(), and setSpecialLayer().

◆ mTempLayer

const SpecialLayer* MapLayer::mTempLayer
private

Definition at line 230 of file maplayer.h.

Referenced by calcMemoryChilds(), and setTempLayer().

◆ mTempRows

MapRows MapLayer::mTempRows
private

Definition at line 233 of file maplayer.h.

Referenced by calcMemoryLocal(), and ~MapLayer().

◆ mTileCondition

int MapLayer::mTileCondition
private

Definition at line 235 of file maplayer.h.

◆ mTiles

TileInfo* const MapLayer::mTiles
private

Definition at line 227 of file maplayer.h.

Referenced by setTile(), and ~MapLayer().

◆ mWidth

const int MapLayer::mWidth
private

Definition at line 225 of file maplayer.h.

Referenced by calcMemoryLocal(), getWidth(), and setTile().

◆ mX

const int MapLayer::mX
private

Definition at line 221 of file maplayer.h.

◆ mY

const int MapLayer::mY
private

Definition at line 222 of file maplayer.h.


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