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.

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 }

References Configuration::addListener(), and config.

Referenced by calcMemoryLocal().

◆ ~MapLayer()

MapLayer::~MapLayer ( )

Destructor.

Definition at line 81 of file maplayer.cpp.

82 {
83  config.removeListener("highlightAttackRange", this);
85  delete []mTiles;
87  mTempRows.clear();
88 }

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

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 }

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

◆ calcMemoryLocal()

int MapLayer::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 823 of file maplayer.cpp.

824 {
825  return static_cast<int>(sizeof(MapLayer) +
826  sizeof(TileInfo) * mWidth * mHeight +
827  sizeof(MapRowVertexes) * mTempRows.capacity());
828 }

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

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 }

References BLOCK_END, BLOCK_START, CAST_SIZE, TileInfo::count, TileInfo::image, TileInfo::isEnabled, mapTileSize, Image::mBounds, SpecialLayer::mHeight, SpecialLayer::mTiles, SpecialLayer::mWidth, 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 424 of file maplayer.cpp.

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 }

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, Image::mBounds, SpecialLayer::mHeight, SpecialLayer::mTiles, SpecialLayer::mWidth, TileInfo::nextTile, MapType::SPECIAL3, MapType::SPECIAL4, userPalette, TileInfo::width, x, and y.

◆ drawOGL()

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

Definition at line 348 of file maplayer.cpp.

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 }

References BLOCK_END, and BLOCK_START.

◆ drawSDL()

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

Definition at line 178 of file maplayer.cpp.

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 }

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

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,
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,
420  x += mTempLayer->mCache[ptr + x];
421  }
422 }

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

◆ getCounterName()

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

Reimplemented from MemoryCounter.

Definition at line 176 of file maplayer.h.

177  { return mName; }

References mName.

◆ getEmptyTileDrawWidth()

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

Definition at line 741 of file maplayer.cpp.

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 }

References BLOCK_END, BLOCK_START, and x.

◆ getHeight()

int MapLayer::getHeight ( ) const
inline

Definition at line 154 of file maplayer.h.

155  { return mHeight; }

References mHeight.

◆ getTileDrawWidth()

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

Definition at line 698 of file maplayer.cpp.

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 }

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

◆ getWidth()

int MapLayer::getWidth ( ) const
inline

Definition at line 151 of file maplayer.h.

152  { return mWidth; }

References mWidth.

◆ isFringeLayer()

bool MapLayer::isFringeLayer ( ) const
inline

Definition at line 140 of file maplayer.h.

141  { 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 90 of file maplayer.cpp.

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

References config, and Configuration::getBoolValue().

◆ setActorsFix()

void MapLayer::setActorsFix ( const int  y)
inline

Definition at line 169 of file maplayer.h.

170  { 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 143 of file maplayer.h.

145  { mSpecialLayer = val; }

References mSpecialLayer.

◆ setTempLayer()

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

Definition at line 147 of file maplayer.h.

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

89  { 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 77 of file maplayer.h.

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

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

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 }

References TileInfo::count, TileInfo::image, TileInfo::isEnabled, SpecialLayer::mHeight, SpecialLayer::mTiles, SpecialLayer::mWidth, 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 761 of file maplayer.cpp.

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 }

References BlockMask::GROUND, SpecialLayer::mHeight, SpecialLayer::mTiles, SpecialLayer::mWidth, 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 264 of file maplayer.cpp.

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 }

References BLOCK_END, BLOCK_START, CAST_SIZE, delete_all(), FOR_EACH, ImageVertexes::image, MapRowVertexes::images, OpenGLGraphicsVertexes::init(), TileInfo::isEnabled, mapTileSize, Image::mBounds, Image::mGLImage, SpecialLayer::mHeight, SpecialLayer::mTiles, SpecialLayer::mWidth, 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 199 of file maplayer.cpp.

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 }

References BLOCK_END, BLOCK_START, CAST_SIZE, delete_all(), ImageVertexes::image, MapRowVertexes::images, TileInfo::isEnabled, mapTileSize, Image::mBounds, SpecialLayer::mHeight, SpecialLayer::mTiles, SpecialLayer::mWidth, x, and y.

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 setActorsFix().

◆ mDrawLayerFlags

MapTypeT MapLayer::mDrawLayerFlags
private

Definition at line 227 of file maplayer.h.

Referenced by setDrawLayerFlags().

◆ mHeight

const int MapLayer::mHeight
private

Definition at line 225 of file maplayer.h.

Referenced by calcMemoryLocal(), and getHeight().

◆ mHighlightAttackRange

bool MapLayer::mHighlightAttackRange
private

Definition at line 237 of file maplayer.h.

◆ 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.

◆ mPixelY

const int MapLayer::mPixelY
private

Definition at line 223 of file maplayer.h.

◆ mSpecialFlag

bool MapLayer::mSpecialFlag
private

Definition at line 238 of file maplayer.h.

Referenced by setDrawLayerFlags().

◆ mSpecialLayer

const SpecialLayer* MapLayer::mSpecialLayer
private

Definition at line 228 of file maplayer.h.

Referenced by calcMemoryChilds(), and setSpecialLayer().

◆ mTempLayer

const SpecialLayer* MapLayer::mTempLayer
private

Definition at line 229 of file maplayer.h.

Referenced by calcMemoryChilds(), and setTempLayer().

◆ mTempRows

MapRows MapLayer::mTempRows
private

Definition at line 232 of file maplayer.h.

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

◆ mTileCondition

int MapLayer::mTileCondition
private

Definition at line 234 of file maplayer.h.

◆ mTiles

TileInfo* const MapLayer::mTiles
private

Definition at line 226 of file maplayer.h.

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

◆ mWidth

const int MapLayer::mWidth
private

Definition at line 224 of file maplayer.h.

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

◆ mX

const int MapLayer::mX
private

Definition at line 220 of file maplayer.h.

◆ mY

const int MapLayer::mY
private

Definition at line 221 of file maplayer.h.


The documentation for this class was generated from the following files:
Graphics::drawRectangle
virtual void drawRectangle(const Rect &rectangle)=0
CHECKLISTENERS
#define CHECKLISTENERS
Definition: localconsts.h:276
Graphics::drawTileVertexes
virtual void drawTileVertexes(const ImageVertexes *const vert)=0
MapType::SPECIAL4
@ SPECIAL4
Definition: maptype.h:35
MapLayer::mSpecialFlag
bool mSpecialFlag
Definition: maplayer.h:238
MapLayer::mPixelX
const int mPixelX
Definition: maplayer.h:222
CAST_SIZE
#define CAST_SIZE
Definition: cast.h:33
MapLayer::mDrawLayerFlags
MapTypeT mDrawLayerFlags
Definition: maplayer.h:227
MapLayer::mWidth
const int mWidth
Definition: maplayer.h:224
TileInfo
Definition: tileinfo.h:28
MapLayer::mX
const int mX
Definition: maplayer.h:220
MapType
Definition: maptype.h:28
MapLayer::mY
const int mY
Definition: maplayer.h:221
MapType::SPECIAL
@ SPECIAL
Definition: maptype.h:32
UserPalette::getColorWithAlpha
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:199
MapLayer::mTempRows
MapRows mTempRows
Definition: maplayer.h:232
ImageVertexes::ogl
OpenGLGraphicsVertexes ogl
Definition: imagevertexes.h:49
Graphics::finalize
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:464
MapRowImages
std::vector< ImageVertexes * > MapRowImages
Definition: maprowvertexes.h:30
MapItem::mType
int mType
Definition: mapitem.h:87
MapItem
Definition: mapitem.h:31
UserColorId::ATTACK_RANGE
@ ATTACK_RANGE
Definition: usercolorid.h:87
MapLayer::mName
const std::string mName
Definition: maplayer.h:230
MapLayer::mHeight
const int mHeight
Definition: maplayer.h:225
OpenGLGraphicsVertexes::init
void init()
Definition: openglgraphicsvertexes.cpp:109
MapLayer::mHighlightAttackRange
bool mHighlightAttackRange
Definition: maplayer.h:237
Configuration::removeListener
void removeListener(const std::string &key, ConfigListener *const listener)
Definition: configuration.cpp:911
MapLayer::mSpecialLayer
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:228
MapLayer::mMask
int mMask
Definition: maplayer.h:233
MapType::NORMAL
@ NORMAL
Definition: maptype.h:30
Image
Definition: image.h:67
MapLayer::mIsFringeLayer
const bool mIsFringeLayer
Definition: maplayer.h:236
MapType::SPECIAL2
@ SPECIAL2
Definition: maptype.h:33
MapLayer::getTileDrawWidth
static int getTileDrawWidth(const TileInfo *img, const int endX, int &width, int &nextTile)
Definition: maplayer.cpp:698
userPalette
UserPalette * userPalette
Definition: userpalette.cpp:33
Configuration::addListener
void addListener(const std::string &key, ConfigListener *const listener)
Definition: configuration.cpp:905
BlockMask::GROUND
@ GROUND
Definition: blockmask.h:33
ImageVertexes
Definition: imagevertexes.h:38
ActorsCIter
Actors::const_iterator ActorsCIter
Definition: actor.h:38
if
if(!vert) return
TileInfo::nextTile
int nextTile
Definition: tileinfo.h:48
MapLayer::mTileCondition
int mTileCondition
Definition: maplayer.h:234
localPlayer
LocalPlayer * localPlayer
Definition: localplayer.cpp:108
MapType::BLACKWHITE
@ BLACKWHITE
Definition: maptype.h:36
MapLayer::mTiles
TileInfo *const mTiles
Definition: maplayer.h:226
MetaTile
Definition: metatile.h:33
Actor::getPixelY
virtual int getPixelY() const
Definition: actor.h:92
MapType::SPECIAL3
@ SPECIAL3
Definition: maptype.h:34
MemoryCounter::calcMemory
int calcMemory(const int level) const
Definition: memorycounter.cpp:36
MapLayer::mPixelY
const int mPixelY
Definition: maplayer.h:223
TileInfo::image
Image * image
Definition: tileinfo.h:42
MapLayer::MapRows
std::vector< MapRowVertexes * > MapRows
Definition: maplayer.h:231
TileInfo::isEnabled
bool isEnabled
Definition: tileinfo.h:50
x
x
Definition: graphics_calcImageRect.hpp:72
UserColorId::ATTACK_RANGE_BORDER
@ ATTACK_RANGE_BORDER
Definition: usercolorid.h:88
TileInfo::width
int width
Definition: tileinfo.h:44
SpecialLayer::mCache
int * mCache
Definition: speciallayer.h:80
MapLayer::mTempLayer
const SpecialLayer * mTempLayer
Definition: maplayer.h:229
MapRowVertexes
Definition: maprowvertexes.h:32
MapItemType::EMPTY
@ EMPTY
Definition: mapitemtype.h:28
Actor::getPixelX
int getPixelX() const
Definition: actor.h:86
Image::mBounds
SDL_Rect mBounds
Definition: image.h:216
config
Configuration config
Definition: configuration.cpp:51
MapRowVertexes::images
MapRowImages images
Definition: maprowvertexes.h:49
delete_all
void delete_all(Container &c)
Definition: dtor.h:55
Image::mGLImage
GLuint mGLImage
Definition: image.h:188
Graphics::setColor
virtual void setColor(const Color &color)
Definition: graphics.h:319
ImageVertexes::image
const Image * image
Definition: imagevertexes.h:47
LocalPlayer::getAttackRange
int getAttackRange() const
Definition: localplayer.cpp:1004
Graphics::drawPattern
virtual void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)=0
std
Definition: mseprimitives.h:398
Rect
Definition: rect.h:72
MapItem::draw
void draw(Graphics *const graphics, const int x, const int y, const int dx, const int dy) const
Definition: mapitem.cpp:132
MapLayer::getEmptyTileDrawWidth
static int getEmptyTileDrawWidth(const TileInfo *img, const int endX, int &nextTile)
Definition: maplayer.cpp:741
BLOCK_START
#define BLOCK_START(name)
Definition: perfomance.h:78
MapLayer::mActorsFix
int mActorsFix
Definition: maplayer.h:235
BLOCK_END
#define BLOCK_END(name)
Definition: perfomance.h:79
PlayerInfo::clear
void clear()
Definition: playerinfo.cpp:451
Graphics::drawImage
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
new
#define new
Definition: debug_new.h:147
Graphics::fillRectangle
virtual void fillRectangle(const Rect &rectangle)=0
TileInfo::count
int count
Definition: tileinfo.h:46
MapLayer::drawSpecialLayer
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
Graphics::calcTileVertexes
virtual void calcTileVertexes(ImageVertexes *const vert, const Image *const image, int x, int y) const =0
y
y
Definition: graphics_calcImageRect.hpp:72
SpecialLayer::mWidth
int mWidth
Definition: speciallayer.h:81
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)
Definition: maplayer.cpp:49
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
mapTileSize
static const int mapTileSize
Definition: map.h:26
Configuration::getBoolValue
bool getBoolValue(const std::string &key) const
Definition: configuration.cpp:596
Graphics::calcTileSDL
virtual void calcTileSDL(ImageVertexes *const vert, int x, int y) const
Definition: graphics.h:223
SpecialLayer::mTiles
MapItem ** mTiles
Definition: speciallayer.h:79