ManaPlus
Data Structures | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
Map Class Reference

#include <map.h>

Inheritance diagram for Map:
Properties ConfigListener MemoryCounter

Data Structures

struct  ParticleEffectData
 

Public Member Functions

 Map (const std::string &name, const int width, const int height, const int tileWidth, const int tileHeight)
 
 ~Map ()
 
void initializeAmbientLayers ()
 
void update (const int ticks)
 
void draw (Graphics *const graphics, int scrollX, int scrollY)
 
void drawCollision (Graphics *const graphics, const int scrollX, const int scrollY, const MapTypeT drawFlags) const
 
void addLayer (MapLayer *const layer)
 
void addTileset (Tileset *const tileset)
 
const TilesetgetTilesetWithGid (const int gid) const
 
const MetaTilegetMetaTile (const int x, const int y) const
 
void addBlockMask (const int x, const int y, const BlockTypeT type)
 
void setBlockMask (const int x, const int y, const BlockTypeT type)
 
bool getWalk (const int x, const int y, const unsigned char blockWalkMask) const
 
void setWalk (const int x, const int y)
 
unsigned char getBlockMask (const int x, const int y) const
 
int getWidth () const
 
int getHeight () const
 
int getTileWidth () const
 
int getTileHeight () const
 
const std::string getMusicFile () const
 
void setMusicFile (const std::string &file)
 
const std::string getName () const
 
const std::string getFilename () const
 
const std::string getGatName () const
 
Path findPath (const int startX, const int startY, const int destX, const int destY, const unsigned char blockWalkmask, const int maxCost)
 
void addParticleEffect (const std::string &effectFile, const int x, const int y, const int w, const int h)
 
void initializeParticleEffects () const
 
void addAnimation (const int gid, TileAnimation *const animation)
 
void setDrawLayersFlags (const MapTypeT &n)
 
MapTypeT getDrawLayersFlags () const
 
void addExtraLayer ()
 
void saveExtraLayer () const
 
SpecialLayergetTempLayer () const
 
SpecialLayergetSpecialLayer () const
 
void setHasWarps (const bool n)
 
bool getHasWarps () const
 
std::string getUserMapDirectory () const
 
void addPortal (const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
 
void addRange (const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
 
void addPortalTile (const std::string &name, const int type, const int x, const int y)
 
void updatePortalTile (const std::string &name, const int type, const int x, const int y, const bool addNew)
 
const std::vector< MapItem * > & getPortals () const
 
const TileAnimationgetAnimationForGid (const int gid) const
 
void optionChanged (const std::string &value)
 
MapItemfindPortalXY (const int x, const int y) const
 
int getActorsCount () const
 
void setPvpMode (const int mode)
 
int getPvpMode () const
 
const ObjectsLayergetObjectsLayer () const
 
std::string getObjectData (const unsigned x, const unsigned y, const int type) const
 
void indexTilesets ()
 
void clearIndexedTilesets ()
 
void setActorsFix (const int x, const int y)
 
int getVersion () const
 
void setVersion (const int n)
 
void reduce ()
 
void redrawMap ()
 
bool empty () const
 
void setCustom (const bool b)
 
bool isCustom () const
 
const std::map< int, TileAnimation * > & getTileAnimations () const
 
int getAtlasCount () const
 
void setAtlas (AtlasResource *const atlas)
 
bool haveAtlas () const
 
const MetaTilegetMetaTiles () const
 
const WalkLayergetWalkLayer () const
 
void setWalkLayer (WalkLayer *const layer)
 
void addHeights (const MapHeights *const heights)
 
uint8_t getHeightOffset (const int x, const int y) const
 
void setMask (const int mask)
 
void updateDrawLayersList ()
 
bool isHeightsPresent () const
 
void updateConditionLayers ()
 
void preCacheLayers ()
 
int calcMemoryLocal () const
 
int calcMemoryChilds (const int level) const
 
std::string getCounterName () const
 
void screenResized ()
 
- Public Member Functions inherited from Properties
 Properties ()
 
virtual ~Properties ()
 
const std::string getProperty (const std::string &name, const std::string &def) const
 
float getFloatProperty (const std::string &name, const float def) const
 
bool getBoolProperty (const std::string &name, const bool def) const
 
bool hasProperty (const std::string &name) const
 
void setProperty (const std::string &name, const std::string &value)
 
- Public Member Functions inherited from ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 

Protected Member Functions

Actors::iterator addActor (Actor *const actor)
 
void removeActor (const Actors::iterator &iterator)
 

Private Member Functions

void updateAmbientLayers (const float scrollX, const float scrollY)
 
void drawAmbientLayers (Graphics *const graphics, const MapLayerPositionT type, const int detail) const
 
bool contains (const int x, const int y) const
 

Private Attributes

const int mWidth
 
const int mHeight
 
const int mTileWidth
 
const int mTileHeight
 
int mMaxTileHeight
 
MetaTile *const mMetaTiles
 
WalkLayermWalkLayer
 
Layers mLayers
 
Layers mDrawUnderLayers
 
Layers mDrawOverLayers
 
Tilesets mTilesets
 
Actors mActors
 
bool mHasWarps
 
MapTypeT mDrawLayersFlags
 
unsigned int mOnClosedList
 
unsigned int mOnOpenList
 
AmbientLayerVector mBackgrounds
 
AmbientLayerVector mForegrounds
 
float mLastAScrollX
 
float mLastAScrollY
 
std::vector< ParticleEffectDatamParticleEffects
 
std::vector< MapItem * > mMapPortals
 
std::map< int, TileAnimation * > mTileAnimations
 
std::string mName
 
int mOverlayDetail
 
float mOpacity
 
const RenderType mOpenGL
 
int mPvp
 
bool mTilesetsIndexed
 
Tileset ** mIndexedTilesets
 
int mIndexedTilesetsSize
 
int mActorFixX
 
int mActorFixY
 
int mVersion
 
SpecialLayermSpecialLayer
 
SpecialLayermTempLayer
 
ObjectsLayermObjects
 
MapLayermFringeLayer
 
int mLastX
 
int mLastY
 
int mLastScrollX
 
int mLastScrollY
 
int mDrawX
 
int mDrawY
 
int mDrawScrollX
 
int mDrawScrollY
 
int mMask
 
AtlasResourcemAtlas
 
const MapHeightsmHeights
 
bool mRedrawMap
 
bool mBeingOpacity
 
bool mCachedDraw
 
bool mCustom
 
bool mDrawOnlyFringe
 
bool mClear
 

Friends

class Actor
 
class Minimap
 

Detailed Description

A tile map.

Definition at line 71 of file map.h.

Constructor & Destructor Documentation

◆ Map()

Map::Map ( const std::string &  name,
const int  width,
const int  height,
const int  tileWidth,
const int  tileHeight 
)

Constructor, taking map and tile size as parameters.

Definition at line 96 of file map.cpp.

References Configuration::addListener(), config, Configuration::getBoolValue(), mBeingOpacity, and mOpacity.

Referenced by calcMemoryLocal().

100  :
101  Properties(),
102  mWidth(width), mHeight(height),
103  mTileWidth(tileWidth), mTileHeight(tileHeight),
104  mMaxTileHeight(height),
106  mWalkLayer(nullptr),
107  mLayers(),
109  mDrawOverLayers(),
110  mTilesets(),
111  mActors(),
112  mHasWarps(false),
114  mOnClosedList(1),
115  mOnOpenList(2),
116  mBackgrounds(),
117  mForegrounds(),
118  mLastAScrollX(0.0F),
119  mLastAScrollY(0.0F),
121  mMapPortals(),
122  mTileAnimations(),
123  mName(name),
124  mOverlayDetail(config.getIntValue("OverlayDetail")),
125  mOpacity(config.getFloatValue("guialpha")),
126 #ifdef USE_OPENGL
128 #else // USE_OPENGL
130 #endif // USE_OPENGL
131  mPvp(0),
132  mTilesetsIndexed(false),
133  mIndexedTilesets(nullptr),
135  mActorFixX(0),
136  mActorFixY(0),
137  mVersion(0),
138  mSpecialLayer(new SpecialLayer("special layer", width, height)),
139  mTempLayer(new SpecialLayer("temp layer", width, height)),
140  mObjects(new ObjectsLayer(width, height)),
141  mFringeLayer(nullptr),
142  mLastX(-1),
143  mLastY(-1),
144  mLastScrollX(-1),
145  mLastScrollY(-1),
146  mDrawX(-1),
147  mDrawY(-1),
148  mDrawScrollX(-1),
149  mDrawScrollY(-1),
150  mMask(1),
151 #ifdef USE_OPENGL
152  mAtlas(nullptr),
153 #endif // USE_OPENGL
154  mHeights(nullptr),
155  mRedrawMap(true),
156  mBeingOpacity(false),
157 #ifdef USE_OPENGL
162 #else // USE_OPENGL
163  mCachedDraw(false),
164 #endif // USE_OPENGL
165  mCustom(false),
166  mDrawOnlyFringe(false),
167  mClear(false)
168 {
169  config.addListener("OverlayDetail", this);
170  config.addListener("guialpha", this);
171  config.addListener("beingopacity", this);
172 
173  if (mOpacity != 1.0F)
174  mBeingOpacity = config.getBoolValue("beingopacity");
175  else
176  mBeingOpacity = false;
177 }
int mLastScrollY
Definition: map.h:488
const int mTileHeight
Definition: map.h:414
bool mClear
Definition: map.h:505
bool mDrawOnlyFringe
Definition: map.h:504
AmbientLayerVector mBackgrounds
Definition: map.h:433
int mLastX
Definition: map.h:485
const MapHeights * mHeights
Definition: map.h:499
Tilesets mTilesets
Definition: map.h:421
int mPvp
Definition: map.h:472
WalkLayer * mWalkLayer
Definition: map.h:417
int mDrawScrollY
Definition: map.h:493
Configuration config
int mOverlayDetail
Definition: map.h:469
int mActorFixY
Definition: map.h:477
SpecialLayer * mSpecialLayer
Definition: map.h:480
int mDrawX
Definition: map.h:490
int getIntValue(const std::string &key) const
float getFloatValue(const std::string &key) const
bool mHasWarps
Definition: map.h:423
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:466
ObjectsLayer * mObjects
Definition: map.h:482
bool mTilesetsIndexed
Definition: map.h:473
void addListener(const std::string &key, ConfigListener *const listener)
const int mTileWidth
Definition: map.h:413
std::vector< MapItem * > mMapPortals
Definition: map.h:464
Layers mLayers
Definition: map.h:418
float mLastAScrollX
Definition: map.h:435
int mLastScrollX
Definition: map.h:487
bool getBoolValue(const std::string &key) const
bool mCustom
Definition: map.h:503
MapTypeT mDrawLayersFlags
Definition: map.h:426
int mActorFixX
Definition: map.h:476
std::string mName
Definition: map.h:468
AmbientLayerVector mForegrounds
Definition: map.h:434
bool mRedrawMap
Definition: map.h:500
int mIndexedTilesetsSize
Definition: map.h:475
RenderType intToRenderType(const int mode)
Definition: renderers.cpp:42
bool mCachedDraw
Definition: map.h:502
int mMaxTileHeight
Definition: map.h:415
const int mHeight
Definition: map.h:412
SpecialLayer * mTempLayer
Definition: map.h:481
MetaTile *const mMetaTiles
Definition: map.h:416
const int mWidth
Definition: map.h:411
unsigned int mOnOpenList
Definition: map.h:430
int mDrawY
Definition: map.h:491
int mLastY
Definition: map.h:486
unsigned int mOnClosedList
Definition: map.h:429
MapLayer * mFringeLayer
Definition: map.h:483
float mLastAScrollY
Definition: map.h:436
const RenderType mOpenGL
Definition: map.h:471
float mOpacity
Definition: map.h:470
Layers mDrawUnderLayers
Definition: map.h:419
int mVersion
Definition: map.h:478
bool mBeingOpacity
Definition: map.h:501
int mDrawScrollX
Definition: map.h:492
Layers mDrawOverLayers
Definition: map.h:420
Tileset ** mIndexedTilesets
Definition: map.h:474
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:462
Actors mActors
Definition: map.h:422
AtlasResource * mAtlas
Definition: map.h:496
int mMask
Definition: map.h:494

◆ ~Map()

Map::~Map ( )

Destructor.

Definition at line 179 of file map.cpp.

References CHECKLISTENERS, config, AtlasResource::decRef(), Resource::decRef(), delete2, delete_all(), mAtlas, mBackgrounds, mForegrounds, mFringeLayer, mHeights, mLayers, mMapPortals, mMetaTiles, mObjects, mSpecialLayer, mTempLayer, mTileAnimations, mTilesets, mWalkLayer, and Configuration::removeListeners().

180 {
181  config.removeListeners(this);
183 
184  if (mWalkLayer != nullptr)
185  {
186  mWalkLayer->decRef();
187  mWalkLayer = nullptr;
188  }
189  mFringeLayer = nullptr;
199 #ifdef USE_OPENGL
200  if (mAtlas != nullptr)
201  {
202  mAtlas->decRef();
203  mAtlas = nullptr;
204  }
205 #endif // USE_OPENGL
207  delete [] mMetaTiles;
208 }
AmbientLayerVector mBackgrounds
Definition: map.h:433
virtual void decRef()
Definition: resource.cpp:49
const MapHeights * mHeights
Definition: map.h:499
Tilesets mTilesets
Definition: map.h:421
WalkLayer * mWalkLayer
Definition: map.h:417
Configuration config
SpecialLayer * mSpecialLayer
Definition: map.h:480
#define delete2(var)
Definition: delete2.h:24
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:466
ObjectsLayer * mObjects
Definition: map.h:482
std::vector< MapItem * > mMapPortals
Definition: map.h:464
Layers mLayers
Definition: map.h:418
void delete_all(Container &c)
Definition: dtor.h:55
AmbientLayerVector mForegrounds
Definition: map.h:434
SpecialLayer * mTempLayer
Definition: map.h:481
MetaTile *const mMetaTiles
Definition: map.h:416
void removeListeners(ConfigListener *const listener)
MapLayer * mFringeLayer
Definition: map.h:483
#define CHECKLISTENERS
Definition: localconsts.h:276
AtlasResource * mAtlas
Definition: map.h:496

Member Function Documentation

◆ addActor()

Actors::iterator Map::addActor ( Actor *const  actor)
protected

Adds an actor to the map.

Definition at line 821 of file map.cpp.

References mActors.

Referenced by Actor::setMap().

822 {
823  mActors.push_front(actor);
824 // mSpritesUpdated = true;
825  return mActors.begin();
826 }
Actors mActors
Definition: map.h:422

◆ addAnimation()

void Map::addAnimation ( const int  gid,
TileAnimation *const  animation 
)

Adds a tile animation to the map

Definition at line 1690 of file map.cpp.

References Logger::log(), logger, and mTileAnimations.

Referenced by getTileHeight(), and MapReader::readTileset().

1692 {
1693  std::map<int, TileAnimation*>::iterator it = mTileAnimations.find(gid);
1694  if (it != mTileAnimations.end())
1695  {
1696  logger->log("duplicate map animation with gid = %d", gid);
1697  delete (*it).second;
1698  }
1699  mTileAnimations[gid] = animation;
1700 }
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:466
Logger * logger
Definition: logger.cpp:88
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ addBlockMask()

void Map::addBlockMask ( const int  x,
const int  y,
const BlockTypeT  type 
)

Definition at line 706 of file map.cpp.

References BlockMask::AIR, BlockType::AIR, MetaTile::blockmask, contains(), BlockType::GROUND, BlockMask::GROUND, BlockMask::GROUNDTOP, BlockType::GROUNDTOP, mMetaTiles, BlockMask::MONSTERWALL, BlockType::MONSTERWALL, mWidth, BlockType::NB_BLOCKTYPES, BlockType::NONE, BlockMask::PLAYERWALL, BlockType::PLAYERWALL, BlockMask::WALL, BlockType::WALL, BlockMask::WATER, BlockType::WATER, x, and y.

Referenced by setTile(), and setWalk().

708 {
709  if (type == BlockType::NONE || !contains(x, y))
710  return;
711 
712  const int tileNum = x + y * mWidth;
713 
714  switch (type)
715  {
716  case BlockType::WALL:
718  break;
719  case BlockType::AIR:
720  mMetaTiles[tileNum].blockmask |= BlockMask::AIR;
721  break;
722  case BlockType::WATER:
724  break;
725  case BlockType::GROUND:
727  break;
730  break;
733  break;
736  break;
737  default:
738  case BlockType::NONE:
740  // Do nothing.
741  break;
742  }
743 }
bool contains(const int x, const int y) const
Definition: map.cpp:811
unsigned char blockmask
Definition: metatile.h:51
MetaTile *const mMetaTiles
Definition: map.h:416
const int mWidth
Definition: map.h:411

◆ addExtraLayer()

void Map::addExtraLayer ( )

Definition at line 1141 of file map.cpp.

References addPortalTile(), MapItemType::ARROW_RIGHT, MapItemType::ARROW_UP, BLOCK_END, BLOCK_START, getUserMapDirectory(), MapItemType::HOME, Logger::log(), Logger::log1(), logger, mSpecialLayer, pathJoin(), MapItemType::PORTAL, ServerCommandType::str, updatePortalTile(), x, and y.

Referenced by Game::changeMap(), and getDrawLayersFlags().

1142 {
1143  BLOCK_START("Map::addExtraLayer")
1144  if (mSpecialLayer == nullptr)
1145  {
1146  logger->log1("No special layer");
1147  BLOCK_END("Map::addExtraLayer")
1148  return;
1149  }
1150  const std::string mapFileName = pathJoin(getUserMapDirectory(),
1151  "extralayer.txt");
1152  logger->log("loading extra layer: " + mapFileName);
1153  struct stat statbuf;
1154  if (stat(mapFileName.c_str(), &statbuf) == 0 &&
1155  S_ISREG(statbuf.st_mode))
1156  {
1157  std::ifstream mapFile;
1158  mapFile.open(mapFileName.c_str(), std::ios::in);
1159  if (!mapFile.is_open())
1160  {
1161  mapFile.close();
1162  BLOCK_END("Map::addExtraLayer")
1163  return;
1164  }
1165  char line[201];
1166 
1167  while (mapFile.getline(line, 200))
1168  {
1169  std::string buf;
1170  std::string str = line;
1171  if (!str.empty())
1172  {
1173  std::string x;
1174  std::string y;
1175  std::string type1;
1176  std::string comment;
1177  std::stringstream ss(str);
1178  ss >> x;
1179  ss >> y;
1180  ss >> type1;
1181  ss >> comment;
1182  while (ss >> buf)
1183  comment.append(" ").append(buf);
1184 
1185  const int type = atoi(type1.c_str());
1186 
1187  if (comment.empty())
1188  {
1189  if (type < MapItemType::ARROW_UP
1190  || type > MapItemType::ARROW_RIGHT)
1191  {
1192  comment = "unknown";
1193  }
1194  }
1195  if (type == MapItemType::PORTAL)
1196  {
1197  updatePortalTile(comment,
1198  type,
1199  atoi(x.c_str()),
1200  atoi(y.c_str()),
1201  false);
1202  }
1203  else if (type == MapItemType::HOME)
1204  {
1205  updatePortalTile(comment,
1206  type,
1207  atoi(x.c_str()),
1208  atoi(y.c_str()),
1209  true);
1210  }
1211  else
1212  {
1213  addPortalTile(comment,
1214  type,
1215  atoi(x.c_str()),
1216  atoi(y.c_str()));
1217  }
1218  }
1219  }
1220  mapFile.close();
1221  }
1222  BLOCK_END("Map::addExtraLayer")
1223 }
void updatePortalTile(const std::string &name, const int type, const int x, const int y, const bool addNew)
Definition: map.cpp:1312
void log1(const char *const log_text)
Definition: logger.cpp:233
std::string getUserMapDirectory() const
Definition: map.cpp:1272
std::string pathJoin(std::string str1, const std::string &str2)
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
SpecialLayer * mSpecialLayer
Definition: map.h:480
#define BLOCK_END(name)
Definition: perfomance.h:79
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1299
Logger * logger
Definition: logger.cpp:88

◆ addHeights()

void Map::addHeights ( const MapHeights *const  heights)

Definition at line 1624 of file map.cpp.

References mHeights.

Referenced by MapReader::readLayer(), and setWalkLayer().

1625 {
1626  delete mHeights;
1627  mHeights = heights;
1628 }
const MapHeights * mHeights
Definition: map.h:499

◆ addLayer()

void Map::addLayer ( MapLayer *const  layer)

Adds a layer to this map. The map takes ownership of the layer.

Definition at line 312 of file map.cpp.

References mFringeLayer, and mLayers.

Referenced by MapReader::createEmptyMap(), and MapReader::readLayer().

313 {
314  mLayers.push_back(layer);
315  if (layer->isFringeLayer() && (mFringeLayer == nullptr))
316  mFringeLayer = layer;
317 }
Layers mLayers
Definition: map.h:418
MapLayer * mFringeLayer
Definition: map.h:483
bool isFringeLayer() const
Definition: maplayer.h:140

◆ addParticleEffect()

void Map::addParticleEffect ( const std::string &  effectFile,
const int  x,
const int  y,
const int  w,
const int  h 
)

Adds a particle effect

Definition at line 1100 of file map.cpp.

References mParticleEffects, x, and y.

Referenced by getTileHeight(), and loadReplaceLayer().

1103 {
1104  ParticleEffectData newEffect(effectFile, x, y, w, h);
1105  mParticleEffects.push_back(newEffect);
1106 }
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:462

◆ addPortal()

void Map::addPortal ( const std::string &  name,
const int  type,
const int  x,
const int  y,
const int  dx,
const int  dy 
)

Definition at line 1290 of file map.cpp.

References addPortalTile(), mapTileSize, x, and y.

Referenced by getHasWarps(), and loadReplaceLayer().

1294 {
1295  addPortalTile(name, type, (x / mapTileSize) + (dx / mapTileSize / 2),
1296  (y / mapTileSize) + (dy / mapTileSize / 2));
1297 }
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1299
static const int mapTileSize
Definition: map.h:26

◆ addPortalTile()

void Map::addPortalTile ( const std::string &  name,
const int  type,
const int  x,
const int  y 
)

Definition at line 1299 of file map.cpp.

References mMapPortals, mSpecialLayer, SpecialLayer::setTile(), SpecialLayer::updateCache(), x, and y.

Referenced by addExtraLayer(), addPortal(), getHasWarps(), Ea::BeingRecv::processNameResponse(), EAthena::BeingRecv::processNameResponseTitle(), LocalPlayer::updateNavigateList(), and updatePortalTile().

1302 {
1303  if (mSpecialLayer != nullptr)
1304  {
1305  mSpecialLayer->setTile(x, y, new MapItem(type, name, x, y));
1307  }
1308 
1309  mMapPortals.push_back(new MapItem(type, name, x, y));
1310 }
SpecialLayer * mSpecialLayer
Definition: map.h:480
void setTile(const int x, const int y, MapItem *const item)
std::vector< MapItem * > mMapPortals
Definition: map.h:464
void updateCache()

◆ addRange()

void Map::addRange ( const std::string &  name,
const int  type,
const int  x,
const int  y,
const int  dx,
const int  dy 
)

Definition at line 1278 of file map.cpp.

References ObjectsLayer::addObject(), mapTileSize, mObjects, x, and y.

Referenced by getHasWarps(), and loadReplaceLayer().

1282 {
1283  if (mObjects == nullptr)
1284  return;
1285 
1286  mObjects->addObject(name, type, x / mapTileSize, y / mapTileSize,
1287  dx / mapTileSize, dy / mapTileSize);
1288 }
ObjectsLayer * mObjects
Definition: map.h:482
void addObject(const std::string &name, const int type, const unsigned x, const unsigned y, unsigned dx, unsigned dy)
static const int mapTileSize
Definition: map.h:26

◆ addTileset()

void Map::addTileset ( Tileset *const  tileset)

Adds a tileset to this map. The map takes ownership of the tileset.

Definition at line 319 of file map.cpp.

References mMaxTileHeight, and mTilesets.

Referenced by loadReplaceLayer().

320 {
321  mTilesets.push_back(tileset);
322  const int height = tileset->getHeight();
323  if (height > mMaxTileHeight)
324  mMaxTileHeight = height;
325 }
Tilesets mTilesets
Definition: map.h:421
int mMaxTileHeight
Definition: map.h:415
int getHeight() const
Definition: imageset.h:65

◆ calcMemoryChilds()

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

Reimplemented from MemoryCounter.

Definition at line 1773 of file map.cpp.

References MemoryCounter::calcMemory(), FOR_EACH, mBackgrounds, mForegrounds, mHeights, mLayers, mObjects, mSpecialLayer, mTempLayer, mTilesets, and mWalkLayer.

Referenced by isHeightsPresent().

1774 {
1775  int sz = 0;
1776 
1777  if (mWalkLayer != nullptr)
1778  sz += mWalkLayer->calcMemory(level + 1);
1780  {
1781  sz += (*it)->calcMemory(level + 1);
1782  }
1783  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1784  {
1785  sz += (*it)->calcMemory(level + 1);
1786  }
1788  {
1789  sz += (*it)->calcMemory(level + 1);
1790  }
1792  {
1793  sz += (*it)->calcMemory(level + 1);
1794  }
1795  if (mSpecialLayer != nullptr)
1796  mSpecialLayer->calcMemory(level + 1);
1797  if (mTempLayer != nullptr)
1798  mTempLayer->calcMemory(level + 1);
1799  if (mObjects != nullptr)
1800  mObjects->calcMemory(level + 1);
1801  if (mHeights != nullptr)
1802  mHeights->calcMemory(level + 1);
1803  return sz;
1804 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
AmbientLayerVector mBackgrounds
Definition: map.h:433
const MapHeights * mHeights
Definition: map.h:499
Tilesets mTilesets
Definition: map.h:421
WalkLayer * mWalkLayer
Definition: map.h:417
int calcMemory(const int level) const
SpecialLayer * mSpecialLayer
Definition: map.h:480
ObjectsLayer * mObjects
Definition: map.h:482
Layers mLayers
Definition: map.h:418
Layers::const_iterator LayersCIter
Definition: map.h:62
AmbientLayerVector mForegrounds
Definition: map.h:434
SpecialLayer * mTempLayer
Definition: map.h:481
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:65

◆ calcMemoryLocal()

int Map::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 1755 of file map.cpp.

References mActors, Map(), mBackgrounds, mDrawOverLayers, mDrawUnderLayers, mForegrounds, mHeight, mIndexedTilesetsSize, mLayers, mMapPortals, mName, mParticleEffects, mTileAnimations, mTilesets, and mWidth.

Referenced by isHeightsPresent().

1756 {
1757  return static_cast<int>(sizeof(Map) +
1758  mName.capacity() +
1759  sizeof(MetaTile) * mWidth * mHeight +
1760  sizeof(MapLayer*) * (mLayers.capacity() +
1761  mDrawUnderLayers.capacity() +
1762  mDrawOverLayers.capacity()) +
1763  sizeof(Tileset*) * mTilesets.capacity() +
1764  sizeof(Actor*) * mActors.size() +
1765  sizeof(AmbientLayer*) * (mBackgrounds.capacity()
1766  + mForegrounds.capacity()) +
1767  sizeof(ParticleEffectData) * mParticleEffects.capacity() +
1768  sizeof(MapItem) * mMapPortals.capacity() +
1769  (sizeof(TileAnimation) + sizeof(int)) * mTileAnimations.size() +
1770  sizeof(Tileset*) * mIndexedTilesetsSize);
1771 }
AmbientLayerVector mBackgrounds
Definition: map.h:433
Tilesets mTilesets
Definition: map.h:421
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:466
std::vector< MapItem * > mMapPortals
Definition: map.h:464
Layers mLayers
Definition: map.h:418
std::string mName
Definition: map.h:468
AmbientLayerVector mForegrounds
Definition: map.h:434
int mIndexedTilesetsSize
Definition: map.h:475
const int mHeight
Definition: map.h:412
const int mWidth
Definition: map.h:411
Definition: actor.h:40
Layers mDrawUnderLayers
Definition: map.h:419
Map(const std::string &name, const int width, const int height, const int tileWidth, const int tileHeight)
Definition: map.cpp:96
Layers mDrawOverLayers
Definition: map.h:420
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:462
Actors mActors
Definition: map.h:422

◆ clearIndexedTilesets()

void Map::clearIndexedTilesets ( )

Definition at line 1462 of file map.cpp.

References mIndexedTilesets, mIndexedTilesetsSize, and mTilesetsIndexed.

Referenced by getObjectsLayer(), and loadReplaceLayer().

1463 {
1464  if (!mTilesetsIndexed)
1465  return;
1466 
1467  mTilesetsIndexed = false;
1468  delete [] mIndexedTilesets;
1470 }
bool mTilesetsIndexed
Definition: map.h:473
int mIndexedTilesetsSize
Definition: map.h:475
Tileset ** mIndexedTilesets
Definition: map.h:474

◆ contains()

bool Map::contains ( const int  x,
const int  y 
) const
private

Tells whether the given coordinates fall within the map boundaries.

Definition at line 811 of file map.cpp.

References mHeight, mWidth, x, and y.

Referenced by addBlockMask(), and setBlockMask().

812 {
813  return x >= 0 && y >= 0 && x < mWidth && y < mHeight;
814 }
const int mHeight
Definition: map.h:412
const int mWidth
Definition: map.h:411

◆ draw()

void Map::draw ( Graphics *const  graphics,
int  scrollX,
int  scrollY 
)

Draws the map to the given graphics output. This method draws all layers, actors and overlay effects.

Definition at line 338 of file map.cpp.

References actorCompare, MapLayerPosition::BACKGROUND_LAYERS, MapType::BLACKWHITE, BLOCK_END, BLOCK_START, Graphics::clearScreen(), drawAmbientLayers(), MapLayer::drawFringe(), FOR_EACH, MapLayerPosition::FOREGROUND_LAYERS, UserPalette::getColorWithAlpha(), localPlayer, mActors, mainGraphics, mBeingOpacity, mCachedDraw, mClear, mDrawLayersFlags, mDrawOnlyFringe, mDrawOverLayers, mDrawScrollX, mDrawScrollY, mDrawUnderLayers, mDrawX, mDrawY, mFringeLayer, mLastScrollX, mLastScrollY, mLastX, mLastY, mMaxTileHeight, mOpenGL, mOverlayDetail, mRedrawMap, mSpecialLayer, mTempLayer, mTileHeight, mTileWidth, RENDER_SOFTWARE, restrict, MapLayer::setSpecialLayer(), MapLayer::setTempLayer(), updateAmbientLayers(), userPalette, UserColorId::WALKABLE_HIGHLIGHT, x, and y.

Referenced by drawAmbientLayers().

340 {
341  if (localPlayer == nullptr)
342  return;
343 
344  if (mClear)
346 
347  BLOCK_START("Map::draw")
348  // Calculate range of tiles which are on-screen
349  const int endPixelY = graphics->mHeight + scrollY + mTileHeight - 1
351  const int startX = scrollX / mTileWidth - 2;
352  const int startY = scrollY / mTileHeight;
353  const int endX = (graphics->mWidth + scrollX + mTileWidth - 1)
354  / mTileWidth + 1;
355  const int endY = endPixelY / mTileHeight + 1;
356 
357  // Make sure actors are sorted ascending by Y-coordinate
358  // so that they overlap correctly
359  BLOCK_START("Map::draw sort")
360  mActors.sort(actorCompare);
361  BLOCK_END("Map::draw sort")
362 
363  // update scrolling of all ambient layers
364  updateAmbientLayers(static_cast<float>(scrollX),
365  static_cast<float>(scrollY));
366 
367  // Draw backgrounds
368  drawAmbientLayers(graphics,
371 
372  if (mDrawLayersFlags == MapType::BLACKWHITE && (userPalette != nullptr))
373  {
374  graphics->setColor(userPalette->getColorWithAlpha(
376 
377  graphics->fillRectangle(Rect(0, 0,
378  graphics->mWidth, graphics->mHeight));
379  }
380 
381 #ifdef USE_OPENGL
382  int updateFlag = 0;
383 
384  if (mCachedDraw)
385  {
386  if (mLastX != startX || mLastY != startY || mLastScrollX != scrollX
387  || mLastScrollY != scrollY)
388  { // player moving
389  mLastX = startX;
390  mLastY = startY;
391  mLastScrollX = scrollX;
392  mLastScrollY = scrollY;
393  updateFlag = 2;
394  }
395  else if (mRedrawMap || startX != mDrawX || startY != mDrawY ||
396  scrollX != mDrawScrollX || scrollY != mDrawScrollY)
397  { // player mode to new position
398  mRedrawMap = false;
399  mDrawX = startX;
400  mDrawY = startY;
401  mDrawScrollX = scrollX;
402  mDrawScrollY = scrollY;
403  updateFlag = 1;
404  }
405  }
406 #endif // USE_OPENGL
407 
408  if (mDrawOnlyFringe)
409  {
410  if (mFringeLayer != nullptr)
411  {
414  mFringeLayer->drawFringe(graphics,
415  startX, startY,
416  endX, endY,
417  scrollX, scrollY,
418  mActors);
419  }
420  }
421  else
422  {
423 #ifdef USE_OPENGL
424  if (mCachedDraw)
425  {
426  if (updateFlag != 0)
427  {
428  FOR_EACH (Layers::iterator, it, mDrawUnderLayers)
429  {
430  (*it)->updateOGL(graphics,
431  startX, startY,
432  endX, endY,
433  scrollX, scrollY);
434  }
435  FOR_EACH (Layers::iterator, it, mDrawOverLayers)
436  {
437  (*it)->updateOGL(graphics,
438  startX, startY,
439  endX, endY,
440  scrollX, scrollY);
441  }
442  }
443 
444  FOR_EACH (Layers::iterator, it, mDrawUnderLayers)
445  (*it)->drawOGL(graphics);
446 
447  if (mFringeLayer != nullptr)
448  {
451  mFringeLayer->drawFringe(graphics,
452  startX, startY,
453  endX, endY,
454  scrollX, scrollY,
455  mActors);
456  }
457 
458  FOR_EACH (Layers::iterator, it, mDrawOverLayers)
459  (*it)->drawOGL(graphics);
460  }
461  else
462 #endif // USE_OPENGL
463  {
464  FOR_EACH (Layers::iterator, it, mDrawUnderLayers)
465  {
466  (*it)->draw(graphics,
467  startX, startY,
468  endX, endY,
469  scrollX, scrollY);
470  }
471 
472  if (mFringeLayer != nullptr)
473  {
476  mFringeLayer->drawFringe(graphics,
477  startX, startY,
478  endX, endY,
479  scrollX, scrollY,
480  mActors);
481  }
482 
483  FOR_EACH (Layers::iterator, it, mDrawOverLayers)
484  {
485  (*it)->draw(graphics, startX, startY,
486  endX, endY,
487  scrollX, scrollY);
488  }
489  }
490  }
491 
492  // Don't draw if gui opacity == 1
493  if (mBeingOpacity)
494  {
495  // Draws beings with a lower opacity to make them visible
496  // even when covered by a wall or some other elements...
497  ActorsCIter ai = mActors.begin();
498  const ActorsCIter ai_end = mActors.end();
499 
500  if (mOpenGL == RENDER_SOFTWARE)
501  {
502  while (ai != ai_end)
503  {
504  if (Actor *restrict const actor = *ai)
505  {
506  const int x = actor->getTileX();
507  const int y = actor->getTileY();
508  if (x < startX || x > endX || y < startY || y > endY)
509  {
510  ++ai;
511  continue;
512  }
513  // For now, just draw actors with only one layer.
514  if (actor->getNumberOfLayers() == 1)
515  {
516  actor->setAlpha(0.3F);
517  actor->draw(graphics, -scrollX, -scrollY);
518  actor->setAlpha(1.0F);
519  }
520  }
521  ++ai;
522  }
523  }
524  else
525  {
526  while (ai != ai_end)
527  {
528  if (Actor *const actor = *ai)
529  {
530  actor->setAlpha(0.3F);
531  actor->draw(graphics, -scrollX, -scrollY);
532  actor->setAlpha(1.0F);
533  }
534  ++ai;
535  }
536  }
537  }
538 
539  drawAmbientLayers(graphics,
541  mOverlayDetail);
542  BLOCK_END("Map::draw")
543 }
int mLastScrollY
Definition: map.h:488
const int mTileHeight
Definition: map.h:414
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
bool mClear
Definition: map.h:505
bool mDrawOnlyFringe
Definition: map.h:504
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:199
int mLastX
Definition: map.h:485
Definition: rect.h:72
int mDrawScrollY
Definition: map.h:493
#define BLOCK_START(name)
Definition: perfomance.h:78
int mOverlayDetail
Definition: map.h:469
if(!vert) return
SpecialLayer * mSpecialLayer
Definition: map.h:480
int mDrawX
Definition: map.h:490
#define BLOCK_END(name)
Definition: perfomance.h:79
void updateAmbientLayers(const float scrollX, const float scrollY)
Definition: map.cpp:618
UserPalette * userPalette
Definition: userpalette.cpp:33
const int mTileWidth
Definition: map.h:413
void draw(Graphics *const graphics, int scrollX, int scrollY)
Definition: map.cpp:338
void drawFringe(Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY, const Actors &actors) const
Definition: maplayer.cpp:424
int mLastScrollX
Definition: map.h:487
MapTypeT mDrawLayersFlags
Definition: map.h:426
LocalPlayer * localPlayer
void setTempLayer(const SpecialLayer *const val)
Definition: maplayer.h:147
Graphics * mainGraphics
Definition: graphics.cpp:108
bool mRedrawMap
Definition: map.h:500
virtual void clearScreen() const
Definition: graphics.h:455
bool mCachedDraw
Definition: map.h:502
class ActorFunctuator actorCompare
int mMaxTileHeight
Definition: map.h:415
const int mHeight
Definition: map.h:412
Definition: map.h:71
void setSpecialLayer(const SpecialLayer *const val)
Definition: maplayer.h:143
SpecialLayer * mTempLayer
Definition: map.h:481
const int mWidth
Definition: map.h:411
int mDrawY
Definition: map.h:491
int mLastY
Definition: map.h:486
MapLayer * mFringeLayer
Definition: map.h:483
Definition: actor.h:40
const RenderType mOpenGL
Definition: map.h:471
#define restrict
Definition: localconsts.h:164
Layers mDrawUnderLayers
Definition: map.h:419
Actors::const_iterator ActorsCIter
Definition: actor.h:38
bool mBeingOpacity
Definition: map.h:501
int mDrawScrollX
Definition: map.h:492
Layers mDrawOverLayers
Definition: map.h:420
void drawAmbientLayers(Graphics *const graphics, const MapLayerPositionT type, const int detail) const
Definition: map.cpp:658
Actors mActors
Definition: map.h:422

◆ drawAmbientLayers()

void Map::drawAmbientLayers ( Graphics *const  graphics,
const MapLayerPositionT  type,
const int  detail 
) const
private

Draws the foreground or background layers to the given graphics output.

Definition at line 658 of file map.cpp.

References MapLayerPosition::BACKGROUND_LAYERS, BLOCK_END, BLOCK_START, draw(), FOR_EACHP, MapLayerPosition::FOREGROUND_LAYERS, mBackgrounds, mForegrounds, mMask, and restrict.

Referenced by draw().

661 {
662  BLOCK_START("Map::drawAmbientLayers")
663  // Detail 0 = no ambient effects except background image
664  if (detail <= 0 && type != MapLayerPosition::BACKGROUND_LAYERS)
665  {
666  BLOCK_END("Map::drawAmbientLayers")
667  return;
668  }
669 
670  // find out which layer list to draw
671  const AmbientLayerVector *restrict layers = nullptr;
672  switch (type)
673  {
675  layers = &mForegrounds;
676  break;
678  layers = &mBackgrounds;
679  break;
680  default:
681  return;
682  }
683 
684  // Draw overlays
686  {
687  const AmbientLayer *restrict const layer = *i;
688  // need check mask to draw or not to draw
689  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
690  (layer)->draw(graphics, graphics->mWidth, graphics->mHeight);
691 
692  // Detail 1: only one overlay, higher: all overlays
693  if (detail == 1)
694  break;
695  }
696  BLOCK_END("Map::drawAmbientLayers")
697 }
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:30
AmbientLayerVector mBackgrounds
Definition: map.h:433
int mWidth
Definition: graphics.h:483
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
void draw(Graphics *const graphics, int scrollX, int scrollY)
Definition: map.cpp:338
AmbientLayerVector mForegrounds
Definition: map.h:434
int mHeight
Definition: graphics.h:484
#define restrict
Definition: localconsts.h:164
std::vector< AmbientLayer * > AmbientLayerVector
Definition: map.h:64
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:65
int mMask
Definition: map.h:494

◆ drawCollision()

void Map::drawCollision ( Graphics *const  graphics,
const int  scrollX,
const int  scrollY,
const MapTypeT  drawFlags 
) const

Visualizes collision layer for debugging

Definition at line 568 of file map.cpp.

References BlockMask::AIR, UserColorId::AIR_COLLISION_HIGHLIGHT, UserColorId::COLLISION_HIGHLIGHT, fillCollision, UserPalette::getColorWithAlpha(), BlockMask::GROUNDTOP, UserColorId::GROUNDTOP_COLLISION_HIGHLIGHT, mapTileSize, mHeight, UserColorId::MONSTER_COLLISION_HIGHLIGHT, BlockMask::MONSTERWALL, mTileHeight, mTileWidth, mWidth, UserColorId::NET, BlockMask::PLAYERWALL, MapType::SPECIAL, userPalette, BlockMask::WALL, BlockMask::WATER, UserColorId::WATER_COLLISION_HIGHLIGHT, x, and y.

572 {
573  const int endPixelY = graphics->mHeight + scrollY + mTileHeight - 1;
574  int startX = scrollX / mTileWidth;
575  int startY = scrollY / mTileHeight;
576  int endX = (graphics->mWidth + scrollX + mTileWidth - 1) / mTileWidth;
577  int endY = endPixelY / mTileHeight;
578 
579  if (startX < 0)
580  startX = 0;
581  if (startY < 0)
582  startY = 0;
583  if (endX > mWidth)
584  endX = mWidth;
585  if (endY > mHeight)
586  endY = mHeight;
587 
588  if (drawFlags < MapType::SPECIAL)
589  {
591  graphics->drawNet(
592  startX * mTileWidth - scrollX,
593  startY * mTileHeight - scrollY,
594  endX * mTileWidth - scrollX,
595  endY * mTileHeight - scrollY,
597  }
598 
599  for (int y = startY; y < endY; y++)
600  {
601  const int yWidth = y * mWidth;
602  int tilePtr = startX + yWidth;
603  for (int x = startX; x < endX; x++, tilePtr++)
604  {
605  int width = 0;
606  const int x0 = x;
607 
614  }
615  }
616 }
const int mTileHeight
Definition: map.h:414
#define fillCollision(collision, color)
Definition: map.cpp:545
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:199
int mWidth
Definition: graphics.h:483
UserPalette * userPalette
Definition: userpalette.cpp:33
const int mTileWidth
Definition: map.h:413
virtual void drawNet(const int x1, const int y1, const int x2, const int y2, const int width, const int height)
Definition: graphics.cpp:652
virtual void setColor(const Color &color)
Definition: graphics.h:319
int mHeight
Definition: graphics.h:484
const int mHeight
Definition: map.h:412
const int mWidth
Definition: map.h:411
static const int mapTileSize
Definition: map.h:26

◆ empty()

bool Map::empty ( ) const
inline

Definition at line 320 of file map.h.

References mLayers.

Referenced by SocialNavigationTab::updateList().

321  { return mLayers.empty(); }
Layers mLayers
Definition: map.h:418

◆ findPath()

Path Map::findPath ( const int  startX,
const int  startY,
const int  destX,
const int  destY,
const unsigned char  blockWalkmask,
const int  maxCost 
)

Find a path from one location to the next.

Definition at line 862 of file map.cpp.

References BLOCK_END, BLOCK_START, MetaTile::blockmask, blockWalkMask, CAST_S32, MetaTile::Fcost, MetaTile::Gcost, getWalk(), MetaTile::Hcost, mHeight, mMetaTiles, mOnClosedList, mOnOpenList, mWidth, MetaTile::parentX, MetaTile::parentY, CastType::Position, ServerCommandType::size, Location::tile, BlockMask::WALL, MetaTile::whichList, Location::x, x, Location::y, and y.

Referenced by LocalPlayer::fixAttackTarget(), LocalPlayer::getPathLength(), getTileHeight(), LocalPlayer::isReachable(), LocalPlayer::moveToTarget(), LocalPlayer::navigateTo(), LocalPlayer::pickUp(), and Being::setDestination().

866 {
867  BLOCK_START("Map::findPath")
868  // The basic walking cost of a tile.
869  static const int basicCost = 100;
870  const int basicCost2 = 100 * 362 / 256;
871  const float basicCostF = 100.0 * 362 / 256;
872 
873  // Path to be built up (empty by default)
874  Path path;
875 
876  if (startX >= mWidth || startY >= mHeight || startX < 0 || startY < 0)
877  {
878  BLOCK_END("Map::findPath")
879  return path;
880  }
881 
882  // Return when destination not walkable
883  if (!getWalk(destX, destY, blockWalkMask))
884  {
885  BLOCK_END("Map::findPath")
886  return path;
887  }
888 
889  // Reset starting tile's G cost to 0
890  MetaTile *const startTile = &mMetaTiles[startX + startY * mWidth];
891  if (startTile == nullptr)
892  {
893  BLOCK_END("Map::findPath")
894  return path;
895  }
896 
897  startTile->Gcost = 0;
898 
899  // Declare open list, a list with open tiles sorted on F cost
900  std::priority_queue<Location> openList;
901 
902  // Add the start point to the open list
903  openList.push(Location(startX, startY, startTile));
904 
905  bool foundPath = false;
906 
907  // Keep trying new open tiles until no more tiles to try or target found
908  while (!openList.empty() && !foundPath)
909  {
910  // Take the location with the lowest F cost from the open list.
911  const Location curr = openList.top();
912  openList.pop();
913 
914  const MetaTile *const tile = curr.tile;
915 
916  // If the tile is already on the closed list, this means it has already
917  // been processed with a shorter path to the start point (lower G cost)
918  if (tile->whichList == mOnClosedList)
919  continue;
920 
921  // Put the current tile on the closed list
922  curr.tile->whichList = mOnClosedList;
923 
924  const int curWidth = curr.y * mWidth;
925  const int tileGcost = tile->Gcost;
926 
927  // Check the adjacent tiles
928  for (int dy = -1; dy <= 1; dy++)
929  {
930  const int y = curr.y + dy;
931  if (y < 0 || y >= mHeight)
932  continue;
933 
934  const int yWidth = y * mWidth;
935  const int dy1 = std::abs(y - destY);
936 
937  for (int dx = -1; dx <= 1; dx++)
938  {
939  // Calculate location of tile to check
940  const int x = curr.x + dx;
941 
942  // Skip if if we're checking the same tile we're leaving from,
943  // or if the new location falls outside of the map boundaries
944  if ((dx == 0 && dy == 0) || x < 0 || x >= mWidth)
945  continue;
946 
947  MetaTile *const newTile = &mMetaTiles[x + yWidth];
948 
949  // Skip if the tile is on the closed list or is not walkable
950  // unless its the destination tile
951  // +++ probably here "newTile->blockmask & BlockMask::WALL"
952  // can be removed. It left here only for protect from
953  // walk on wall in any case
954  if (newTile->whichList == mOnClosedList ||
955  (((newTile->blockmask & blockWalkMask) != 0)
956  && !(x == destX && y == destY))
957  || ((newTile->blockmask & BlockMask::WALL) != 0))
958  {
959  continue;
960  }
961 
962  // When taking a diagonal step, verify that we can skip the
963  // corner.
964  if (dx != 0 && dy != 0)
965  {
966  const MetaTile *const t1 = &mMetaTiles[curr.x +
967  (curr.y + dy) * mWidth];
968  const MetaTile *const t2 = &mMetaTiles[curr.x +
969  dx + curWidth];
970 
971  // on player abilities.
972  if (((t1->blockmask | t2->blockmask) & blockWalkMask) != 0)
973  continue;
974  }
975 
976  // Calculate G cost for this route, ~sqrt(2) for moving diagonal
977  int Gcost = tileGcost + (dx == 0 || dy == 0
978  ? basicCost : basicCost2);
979 
980  /* Demote an arbitrary direction to speed pathfinding by
981  adding a defect
982  Important: as long as the total defect along any path is
983  less than the basicCost, the pathfinder will still find one
984  of the shortest paths! */
985  if (dx == 0 || dy == 0)
986  {
987  // Demote horizontal and vertical directions, so that two
988  // consecutive directions cannot have the same Fcost.
989  ++Gcost;
990  }
991 
992 /*
993  // It costs extra to walk through a being (needs to be enough
994  // to make it more attractive to walk around).
995  if (occupied(x, y))
996  {
997  Gcost += 3 * basicCost;
998  }
999 */
1000 
1001  // Skip if Gcost becomes too much
1002  // Warning: probably not entirely accurate
1003  if (maxCost > 0 && Gcost > maxCost * basicCost)
1004  continue;
1005 
1006  if (newTile->whichList != mOnOpenList)
1007  {
1008  // Found a new tile (not on open nor on closed list)
1009 
1010  /* Update Hcost of the new tile. The pathfinder does not
1011  work reliably if the heuristic cost is higher than the
1012  real cost. In particular, using Manhattan distance is
1013  forbidden here. */
1014  const int dx1 = std::abs(x - destX);
1015  newTile->Hcost = std::abs(dx1 - dy1) * basicCost +
1016  CAST_S32(static_cast<float>(std::min(dx1, dy1)) *
1017  (basicCostF));
1018 
1019  // Set the current tile as the parent of the new tile
1020  newTile->parentX = curr.x;
1021  newTile->parentY = curr.y;
1022 
1023  // Update Gcost and Fcost of new tile
1024  newTile->Gcost = Gcost;
1025  newTile->Fcost = Gcost + newTile->Hcost;
1026 
1027  if (x != destX || y != destY)
1028  {
1029  // Add this tile to the open list
1030  newTile->whichList = mOnOpenList;
1031  openList.push(Location(x, y, newTile));
1032  }
1033  else
1034  {
1035  // Target location was found
1036  foundPath = true;
1037  }
1038  }
1039  else if (Gcost < newTile->Gcost)
1040  {
1041  // Found a shorter route.
1042  // Update Gcost and Fcost of the new tile
1043  newTile->Gcost = Gcost;
1044  newTile->Fcost = Gcost + newTile->Hcost;
1045 
1046  // Set the current tile as the parent of the new tile
1047  newTile->parentX = curr.x;
1048  newTile->parentY = curr.y;
1049 
1050  // Add this tile to the open list (it's already
1051  // there, but this instance has a lower F score)
1052  openList.push(Location(x, y, newTile));
1053  }
1054  }
1055  }
1056  }
1057 
1058  // Two new values to indicate whether a tile is on the open or closed list,
1059  // this way we don't have to clear all the values between each pathfinding.
1060  if (mOnOpenList > UINT_MAX - 2)
1061  {
1062  // We reset the list memebers value.
1063  mOnClosedList = 1;
1064  mOnOpenList = 2;
1065 
1066  // Clean up the metaTiles
1067  const int size = mWidth * mHeight;
1068  for (int i = 0; i < size; ++i)
1069  mMetaTiles[i].whichList = 0;
1070  }
1071  else
1072  {
1073  mOnClosedList += 2;
1074  mOnOpenList += 2;
1075  }
1076 
1077  // If a path has been found, iterate backwards using the parent locations
1078  // to extract it.
1079  if (foundPath)
1080  {
1081  int pathX = destX;
1082  int pathY = destY;
1083 
1084  while (pathX != startX || pathY != startY)
1085  {
1086  // Add the new path node to the start of the path list
1087  path.push_front(Position(pathX, pathY));
1088 
1089  // Find out the next parent
1090  const MetaTile *const tile = &mMetaTiles[pathX + pathY * mWidth];
1091  pathX = tile->parentX;
1092  pathY = tile->parentY;
1093  }
1094  }
1095 
1096  BLOCK_END("Map::findPath")
1097  return path;
1098 }
int x
Definition: location.h:57
bool empty() const
Definition: map.h:320
int Gcost
Definition: metatile.h:46
int Fcost
Definition: metatile.h:45
#define BLOCK_START(name)
Definition: perfomance.h:78
MetaTile * tile
Definition: location.h:59
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
int Hcost
Definition: metatile.h:47
unsigned char blockmask
Definition: metatile.h:51
#define CAST_S32
Definition: cast.h:29
bool getWalk(const int x, const int y, const unsigned char blockWalkMask) const
Definition: map.cpp:784
const int mHeight
Definition: map.h:412
int parentX
Definition: metatile.h:49
MetaTile *const mMetaTiles
Definition: map.h:416
const int mWidth
Definition: map.h:411
unsigned int mOnOpenList
Definition: map.h:430
unsigned int mOnClosedList
Definition: map.h:429
int y
Definition: location.h:57
int parentY
Definition: metatile.h:50
std::list< Position > Path
Definition: position.h:48
unsigned whichList
Definition: metatile.h:48

◆ findPortalXY()

MapItem * Map::findPortalXY ( const int  x,
const int  y 
) const

Definition at line 1337 of file map.cpp.

References FOR_EACH, ServerCommandType::item, mMapPortals, restrict, x, and y.

Referenced by RenameListener::action(), SocialNavigationTab::addPortal(), getPortals(), AvatarListBox::mousePressed(), SocialNavigationTab::updateNames(), and updatePortalTile().

1338 {
1339  FOR_EACH (STD_VECTOR<MapItem*>::const_iterator, it, mMapPortals)
1340  {
1341  if (*it == nullptr)
1342  continue;
1343 
1344  MapItem *restrict const item = *it;
1345  if (item->mX == x && item->mY == y)
1346  return item;
1347  }
1348  return nullptr;
1349 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
std::vector< MapItem * > mMapPortals
Definition: map.h:464
#define restrict
Definition: localconsts.h:164

◆ getActorsCount()

int Map::getActorsCount ( ) const
inline

Definition at line 286 of file map.h.

References CAST_S32, mActors, restrict2, and setPvpMode().

Referenced by MapDebugTab::logic().

287  { return CAST_S32(mActors.size()); }
#define CAST_S32
Definition: cast.h:29
Actors mActors
Definition: map.h:422

◆ getAnimationForGid()

const TileAnimation * Map::getAnimationForGid ( const int  gid) const

Gets the tile animation for a specific gid

Definition at line 1351 of file map.cpp.

References mTileAnimations.

Referenced by getPortals().

1352 {
1353  if (mTileAnimations.empty())
1354  return nullptr;
1355 
1356  const TileAnimationMapCIter i = mTileAnimations.find(gid);
1357  return (i == mTileAnimations.end()) ? nullptr : i->second;
1358 }
TileAnimationMap::const_iterator TileAnimationMapCIter
Definition: tileanimation.h:64
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:466

◆ getAtlasCount()

int Map::getAtlasCount ( ) const

Definition at line 1820 of file map.cpp.

References AtlasResource::atlases, CAST_S32, and mAtlas.

Referenced by getTileAnimations(), and MapDebugTab::logic().

1821 {
1822  if (mAtlas == nullptr)
1823  return 0;
1824  return CAST_S32(mAtlas->atlases.size());
1825 }
std::vector< TextureAtlas * > atlases
Definition: atlasresource.h:51
#define CAST_S32
Definition: cast.h:29
AtlasResource * mAtlas
Definition: map.h:496

◆ getBlockMask()

unsigned char Map::getBlockMask ( const int  x,
const int  y 
) const

Definition at line 795 of file map.cpp.

References MetaTile::blockmask, mHeight, mMetaTiles, mWidth, x, and y.

Referenced by Being::getAttackAction(), Being::getCastAction(), Being::getMoveAction(), Being::getSitAction(), Being::getStandAction(), Being::getWeaponAttackAction(), and Being::nextTile().

797 {
798  // You can't walk outside of the map
799  if (x < 0 || y < 0 || x >= mWidth || y >= mHeight)
800  return 0;
801 
802  // Check if the tile is walkable
803  return mMetaTiles[x + y * mWidth].blockmask;
804 }
unsigned char blockmask
Definition: metatile.h:51
const int mHeight
Definition: map.h:412
MetaTile *const mMetaTiles
Definition: map.h:416
const int mWidth
Definition: map.h:411

◆ getCounterName()

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

Reimplemented from MemoryCounter.

Definition at line 372 of file map.h.

References mName, and screenResized().

373  { return mName; }
std::string mName
Definition: map.h:468

◆ getDrawLayersFlags()

MapTypeT Map::getDrawLayersFlags ( ) const
inline

Definition at line 230 of file map.h.

References addExtraLayer(), mDrawLayersFlags, restrict2, and saveExtraLayer().

231  { return mDrawLayersFlags; }
MapTypeT mDrawLayersFlags
Definition: map.h:426

◆ getFilename()

const std::string Map::getFilename ( ) const

Gives the map id based on filepath (ex: 009-1)

Definition at line 847 of file map.cpp.

References fileName, and Properties::getProperty().

Referenced by getTileHeight(), and Minimap::setMap().

848 {
849  const std::string fileName = getProperty("_filename", std::string());
850  const size_t lastSlash = fileName.rfind('/') + 1;
851  return fileName.substr(lastSlash, fileName.rfind('.') - lastSlash);
852 }
std::string fileName
Definition: testmain.cpp:38
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58

◆ getGatName()

const std::string Map::getGatName ( ) const

Definition at line 854 of file map.cpp.

References fileName, Properties::getProperty(), and rfindSepatator().

Referenced by getTileHeight(), and Ea::MapRecv::processSetTilesType().

855 {
856  const std::string fileName = getProperty("_filename", std::string());
857  const size_t lastSlash = rfindSepatator(fileName) + 1;
858  return fileName.substr(lastSlash,
859  fileName.rfind('.') - lastSlash).append(".gat");
860 }
std::string fileName
Definition: testmain.cpp:38
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58
size_t rfindSepatator(const std::string &str1)

◆ getHasWarps()

bool Map::getHasWarps ( ) const
inline

Definition at line 246 of file map.h.

References A_WARN_UNUSED, addPortal(), addPortalTile(), addRange(), getUserMapDirectory(), mHasWarps, restrict, restrict2, and updatePortalTile().

Referenced by Being::drawPortalSpriteAt().

247  { return mHasWarps; }
bool mHasWarps
Definition: map.h:423

◆ getHeight()

int Map::getHeight ( ) const
inline

Returns the height of this map in tiles.

Definition at line 171 of file map.h.

References mHeight.

Referenced by NavigationManager::loadWalkLayer(), Ea::PlayerRecv::processPlayerWarp(), MapReader::readLayer(), Minimap::setMap(), and Viewport::updateMaxVars().

172  { return mHeight; }
const int mHeight
Definition: map.h:412

◆ getHeightOffset()

uint8_t Map::getHeightOffset ( const int  x,
const int  y 
) const

Definition at line 1630 of file map.cpp.

References MapHeights::getHeight(), mHeights, x, and y.

Referenced by Viewport::getMouseTile(), Being::nextTile(), FloorItem::postInit(), Being::setMap(), Being::setTileCoords(), and setWalkLayer().

1631 {
1632  if (mHeights == nullptr)
1633  return 0;
1634  return mHeights->getHeight(x, y);
1635 }
const MapHeights * mHeights
Definition: map.h:499
uint8_t getHeight(const int x, const int y) const
Definition: mapheights.h:43

◆ getMetaTile()

const MetaTile * Map::getMetaTile ( const int  x,
const int  y 
) const

Get tile reference.

Definition at line 816 of file map.cpp.

References mMetaTiles, mWidth, x, and y.

817 {
818  return &mMetaTiles[x + y * mWidth];
819 }
MetaTile *const mMetaTiles
Definition: map.h:416
const int mWidth
Definition: map.h:411

◆ getMetaTiles()

const MetaTile* Map::getMetaTiles ( ) const
inline

Definition at line 343 of file map.h.

References mMetaTiles.

Referenced by NavigationManager::loadWalkLayer().

344  { return mMetaTiles; }
MetaTile *const mMetaTiles
Definition: map.h:416

◆ getMusicFile()

const std::string Map::getMusicFile ( ) const

Definition at line 834 of file map.cpp.

References Properties::getProperty().

Referenced by Setup_Audio::apply(), Game::changeMap(), getTileHeight(), and LocalPlayer::updateMusic().

835 {
836  return getProperty("music", std::string());
837 }
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58

◆ getName()

const std::string Map::getName ( ) const

Definition at line 839 of file map.cpp.

References Properties::getProperty(), and Properties::hasProperty().

Referenced by getTileHeight(), and Minimap::setMap().

840 {
841  if (hasProperty("name"))
842  return getProperty("name", std::string());
843 
844  return getProperty("mapname", std::string());
845 }
bool hasProperty(const std::string &name) const
Definition: properties.h:118
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58

◆ getObjectData()

std::string Map::getObjectData ( const unsigned  x,
const unsigned  y,
const int  type 
) const

Definition at line 1392 of file map.cpp.

References ObjectsLayer::getAt(), mObjects, MapObjectList::objects, restrict, x, and y.

Referenced by getObjectsLayer(), and LocalPlayer::updateMusic().

1394 {
1395  if (mObjects == nullptr)
1396  return "";
1397 
1398  MapObjectList *restrict const list = mObjects->getAt(x, y);
1399  if (list == nullptr)
1400  return "";
1401 
1402  STD_VECTOR<MapObject>::const_iterator it = list->objects.begin();
1403  const STD_VECTOR<MapObject>::const_iterator it_end = list->objects.end();
1404  while (it != it_end)
1405  {
1406  if ((*it).type == type)
1407  return (*it).data;
1408  ++ it;
1409  }
1410 
1411  return "";
1412 }
std::vector< MapObject > objects
Definition: mapobjectlist.h:42
ObjectsLayer * mObjects
Definition: map.h:482
MapObjectList * getAt(const unsigned x, const unsigned y) const
#define restrict
Definition: localconsts.h:164

◆ getObjectsLayer()

const ObjectsLayer* Map::getObjectsLayer ( ) const
inline

Definition at line 294 of file map.h.

References A_WARN_UNUSED, clearIndexedTilesets(), getObjectData(), indexTilesets(), mObjects, restrict2, and setActorsFix().

296  { return mObjects; }
ObjectsLayer * mObjects
Definition: map.h:482

◆ getPortals()

const std::vector<MapItem*>& Map::getPortals ( ) const
inline

Definition at line 270 of file map.h.

References A_WARN_UNUSED, findPortalXY(), getAnimationForGid(), mMapPortals, optionChanged(), and restrict.

Referenced by SocialNavigationTab::updateList().

272  { return mMapPortals; }
std::vector< MapItem * > mMapPortals
Definition: map.h:464

◆ getPvpMode()

int Map::getPvpMode ( ) const
inline

Definition at line 291 of file map.h.

References mPvp.

Referenced by ActorManager::findNearestPvpPlayer().

292  { return mPvp; }
int mPvp
Definition: map.h:472

◆ getSpecialLayer()

SpecialLayer* Map::getSpecialLayer ( ) const
inline

Definition at line 240 of file map.h.

References mSpecialLayer.

Referenced by RenameListener::action(), Viewport::getMouseTile(), PopupMenu::handleLink(), LocalPlayer::setHome(), and SocialNavigationTab::updateList().

241  { return mSpecialLayer; }
SpecialLayer * mSpecialLayer
Definition: map.h:480

◆ getTempLayer()

SpecialLayer* Map::getTempLayer ( ) const
inline

Definition at line 237 of file map.h.

References mTempLayer.

Referenced by LocalPlayer::navigateClean(), LocalPlayer::navigateTo(), LocalPlayer::setRealPos(), and LocalPlayer::updateCoords().

238  { return mTempLayer; }
SpecialLayer * mTempLayer
Definition: map.h:481

◆ getTileAnimations()

const std::map<int, TileAnimation*>& Map::getTileAnimations ( ) const
inline

Definition at line 329 of file map.h.

References A_WARN_UNUSED, getAtlasCount(), and mTileAnimations.

Referenced by MapReader::readBase64Layer(), MapReader::readCsvLayer(), and MapReader::readLayer().

331  { return mTileAnimations; }
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:466

◆ getTileHeight()

int Map::getTileHeight ( ) const
inline

◆ getTilesetWithGid()

const Tileset * Map::getTilesetWithGid ( const int  gid) const

Finds the tile set that a tile with the given global id is part of.

Definition at line 699 of file map.cpp.

References mIndexedTilesets, and mIndexedTilesetsSize.

Referenced by setTile().

700 {
701  if (gid >= 0 && gid < mIndexedTilesetsSize)
702  return mIndexedTilesets[gid];
703  return nullptr;
704 }
int mIndexedTilesetsSize
Definition: map.h:475
Tileset ** mIndexedTilesets
Definition: map.h:474

◆ getTileWidth()

int Map::getTileWidth ( ) const
inline

◆ getUserMapDirectory()

std::string Map::getUserMapDirectory ( ) const

Definition at line 1272 of file map.cpp.

References Properties::getProperty(), pathJoin(), Settings::serverConfigDir, and settings.

Referenced by addExtraLayer(), getHasWarps(), and saveExtraLayer().

1273 {
1275  getProperty("_realfilename", std::string()));
1276 }
std::string pathJoin(std::string str1, const std::string &str2)
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58
Settings settings
Definition: settings.cpp:31
std::string serverConfigDir
Definition: settings.h:116

◆ getVersion()

int Map::getVersion ( ) const
inline

Definition at line 309 of file map.h.

References mVersion.

Referenced by setTile().

310  { return mVersion; }
int mVersion
Definition: map.h:478

◆ getWalk()

bool Map::getWalk ( const int  x,
const int  y,
const unsigned char  blockWalkMask 
) const

Gets walkability for a tile with a blocking bitmask. When called without walkmask, only blocks against colliding tiles.

Definition at line 784 of file map.cpp.

References blockWalkMask, mHeight, mMetaTiles, mWidth, x, and y.

Referenced by Being::botFixOffset(), CrazyMoves::crazyMove8(), findPath(), Viewport::getMouseTile(), Being::moveBotTo(), Being::nextTile(), and LocalPlayer::startWalking().

786 {
787  // You can't walk outside of the map
788  if (x < 0 || y < 0 || x >= mWidth || y >= mHeight)
789  return false;
790 
791  // Check if the tile is walkable
792  return (mMetaTiles[x + y * mWidth].blockmask & blockWalkMask) == 0;
793 }
const int mHeight
Definition: map.h:412
MetaTile *const mMetaTiles
Definition: map.h:416
const int mWidth
Definition: map.h:411

◆ getWalkLayer()

const WalkLayer* Map::getWalkLayer ( ) const
inline

Definition at line 346 of file map.h.

References mWalkLayer.

Referenced by LocalPlayer::isReachable().

347  { return mWalkLayer; }
WalkLayer * mWalkLayer
Definition: map.h:417

◆ getWidth()

int Map::getWidth ( ) const
inline

Returns the width of this map in tiles.

Definition at line 165 of file map.h.

References mWidth.

Referenced by Actions::changeRelation(), NavigationManager::loadWalkLayer(), Ea::PlayerRecv::processPlayerWarp(), MapReader::readLayer(), Minimap::setMap(), and Viewport::updateMaxVars().

166  { return mWidth; }
const int mWidth
Definition: map.h:411

◆ haveAtlas()

bool Map::haveAtlas ( ) const
inline

Definition at line 339 of file map.h.

References mAtlas.

Referenced by MapReader::readTileset().

340  { return mAtlas != nullptr; }
AtlasResource * mAtlas
Definition: map.h:496

◆ indexTilesets()

void Map::indexTilesets ( )

Definition at line 1414 of file map.cpp.

References CAST_S32, CAST_SIZE, FOR_EACH, mIndexedTilesets, mIndexedTilesetsSize, mTilesets, mTilesetsIndexed, restrict, ServerCommandType::size, and anonymous_namespace{stringutils.cpp}::start.

Referenced by getObjectsLayer(), and MapReader::readLayer().

1415 {
1416  if (mTilesetsIndexed)
1417  return;
1418 
1419  mTilesetsIndexed = true;
1420 
1421  const Tileset *restrict s = nullptr;
1422  size_t sSz = 0;
1423  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1424  {
1425  const size_t sz = (*it)->size();
1426  if ((s == nullptr) || CAST_SIZE(s->getFirstGid()) + sSz
1427  < CAST_SIZE((*it)->getFirstGid()) + sz)
1428  {
1429  s = *it;
1430  sSz = sz;
1431  }
1432  }
1433  if (s == nullptr)
1434  {
1436  mIndexedTilesets = nullptr;
1437  return;
1438  }
1439 
1440  const int size = CAST_S32(s->getFirstGid())
1441  + CAST_S32(s->size());
1443  mIndexedTilesets = new Tileset*[CAST_SIZE(size)];
1444  std::fill_n(mIndexedTilesets, size, static_cast<Tileset*>(nullptr));
1445 
1446  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1447  {
1448  Tileset *restrict const s2 = *it;
1449  if (s2 != nullptr)
1450  {
1451  const int start = s2->getFirstGid();
1452  const int end = start + CAST_S32(s2->size());
1453  for (int f = start; f < end; f ++)
1454  {
1455  if (f < size)
1456  mIndexedTilesets[f] = s2;
1457  }
1458  }
1459  }
1460 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Tilesets mTilesets
Definition: map.h:421
bool mTilesetsIndexed
Definition: map.h:473
#define CAST_S32
Definition: cast.h:29
int mIndexedTilesetsSize
Definition: map.h:475
#define restrict
Definition: localconsts.h:164
#define CAST_SIZE
Definition: cast.h:33
Tileset ** mIndexedTilesets
Definition: map.h:474

◆ initializeAmbientLayers()

void Map::initializeAmbientLayers ( )

Initialize ambient layers. Has to be called after all the properties are set.

Definition at line 233 of file map.cpp.

References Properties::getBoolProperty(), Properties::getFloatProperty(), Loader::getImage(), Properties::getProperty(), Properties::hasProperty(), mBackgrounds, mForegrounds, restrict, and Catch::toString().

Referenced by loadReplaceLayer().

234 {
235  // search for "foreground*" or "overlay*" (old term) in map properties
236  for (int i = 0; /* terminated by a break */; i++)
237  {
238  std::string name;
239  if (hasProperty(std::string("foreground").append(
240  toString(i)).append("image")))
241  {
242  name = "foreground" + toString(i);
243  }
244  else if (hasProperty(std::string("overlay").append(
245  toString(i)).append("image")))
246  {
247  name = "overlay" + toString(i);
248  }
249  else
250  {
251  break; // the FOR loop
252  }
253 
254  Image *restrict const img = Loader::getImage(
255  getProperty(name + "image", std::string()));
256  if (img != nullptr)
257  {
258  int mask = atoi(getProperty(name + "mask", std::string()).c_str());
259  if (mask == 0)
260  mask = 1;
261  const float parallax = getFloatProperty(name + "parallax", 0.0F);
262  mForegrounds.push_back(new AmbientLayer(
263  name,
264  img,
265  getFloatProperty(name + "parallaxX", parallax),
266  getFloatProperty(name + "parallaxY", parallax),
267  getFloatProperty(name + "posX", 0.0F),
268  getFloatProperty(name + "posY", 0.0F),
269  getFloatProperty(name + "scrollX", 0.0F),
270  getFloatProperty(name + "scrollY", 0.0F),
271  getBoolProperty(name + "keepratio", false),
272  mask));
273 
274  // The AmbientLayer takes control over the image.
275  img->decRef();
276  }
277  }
278 
279  // search for "background*" in map properties
280  for (int i = 0; hasProperty(std::string("background").append(
281  toString(i)).append("image")); i ++)
282  {
283  const std::string name("background" + toString(i));
284  Image *restrict const img = Loader::getImage(
285  getProperty(name + "image", std::string()));
286 
287  if (img != nullptr)
288  {
289  int mask = atoi(getProperty(name + "mask", std::string()).c_str());
290  if (mask == 0)
291  mask = 1;
292 
293  const float parallax = getFloatProperty(name + "parallax", 0.0F);
294  mBackgrounds.push_back(new AmbientLayer(
295  name,
296  img,
297  getFloatProperty(name + "parallaxX", parallax),
298  getFloatProperty(name + "parallaxY", parallax),
299  getFloatProperty(name + "posX", 0.0F),
300  getFloatProperty(name + "posY", 0.0F),
301  getFloatProperty(name + "scrollX", 0.0F),
302  getFloatProperty(name + "scrollY", 0.0F),
303  getBoolProperty(name + "keepratio", false),
304  mask));
305 
306  // The AmbientLayer takes control over the image.
307  img->decRef();
308  }
309  }
310 }
bool hasProperty(const std::string &name) const
Definition: properties.h:118
AmbientLayerVector mBackgrounds
Definition: map.h:433
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58
float getFloatProperty(const std::string &name, const float def) const
Definition: properties.h:74
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
AmbientLayerVector mForegrounds
Definition: map.h:434
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Definition: image.h:67
#define restrict
Definition: localconsts.h:164
bool getBoolProperty(const std::string &name, const bool def) const
Definition: properties.h:96

◆ initializeParticleEffects()

void Map::initializeParticleEffects ( ) const

Initializes all added particle effects

Definition at line 1108 of file map.cpp.

References ParticleEngine::addEffect(), Particle::adjustEmitterSize(), BLOCK_END, BLOCK_START, config, Configuration::getBoolValue(), mParticleEffects, and particleEngine.

Referenced by Game::changeMap(), and getTileHeight().

1109 {
1110  BLOCK_START("Map::initializeParticleEffects")
1111  if (particleEngine == nullptr)
1112  {
1113  BLOCK_END("Map::initializeParticleEffects")
1114  return;
1115  }
1116 
1117  if (config.getBoolValue("particleeffects"))
1118  {
1119  for (STD_VECTOR<ParticleEffectData>::const_iterator
1120  i = mParticleEffects.begin();
1121  i != mParticleEffects.end();
1122  ++i)
1123  {
1124  // +++ add z for map particle effects?
1125  Particle *const p = particleEngine->addEffect(
1126  i->file,
1127  i->x,
1128  i->y,
1129  0);
1130  if ((p != nullptr) &&
1131  i->w > 0 &&
1132  i->h > 0)
1133  {
1134  p->adjustEmitterSize(i->w, i->h);
1135  }
1136  }
1137  }
1138  BLOCK_END("Map::initializeParticleEffects")
1139 }
Particle * addEffect(const std::string &particleEffectFile, const int pixelX, const int pixelY, const int rotation)
#define BLOCK_START(name)
Definition: perfomance.h:78
ParticleEngine * particleEngine
Configuration config
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:462
void adjustEmitterSize(const int w, const int h)
Definition: particle.cpp:555

◆ isCustom()

bool Map::isCustom ( ) const
inline

Definition at line 326 of file map.h.

References mCustom.

Referenced by LocalPlayer::setRealPos().

327  { return mCustom; }
bool mCustom
Definition: map.h:503

◆ isHeightsPresent()

bool Map::isHeightsPresent ( ) const
inline

Definition at line 361 of file map.h.

References calcMemoryChilds(), calcMemoryLocal(), mHeights, preCacheLayers(), restrict2, and updateConditionLayers().

Referenced by Viewport::getMouseTile().

362  { return mHeights != nullptr; }
const MapHeights * mHeights
Definition: map.h:499

◆ optionChanged()

void Map::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 210 of file map.cpp.

References config, Configuration::getBoolValue(), Configuration::getFloatValue(), Configuration::getIntValue(), mBeingOpacity, mOpacity, and mOverlayDetail.

Referenced by getPortals().

211 {
212  if (value == "OverlayDetail")
213  {
214  mOverlayDetail = config.getIntValue("OverlayDetail");
215  }
216  else if (value == "guialpha")
217  {
218  mOpacity = config.getFloatValue("guialpha");
219  if (mOpacity != 1.0F)
220  mBeingOpacity = config.getBoolValue("beingopacity");
221  else
222  mBeingOpacity = false;
223  }
224  else if (value == "beingopacity")
225  {
226  if (mOpacity != 1.0F)
227  mBeingOpacity = config.getBoolValue("beingopacity");
228  else
229  mBeingOpacity = false;
230  }
231 }
Configuration config
int mOverlayDetail
Definition: map.h:469
int getIntValue(const std::string &key) const
float getFloatValue(const std::string &key) const
bool getBoolValue(const std::string &key) const
float mOpacity
Definition: map.h:470
bool mBeingOpacity
Definition: map.h:501

◆ preCacheLayers()

void Map::preCacheLayers ( )

Definition at line 1745 of file map.cpp.

References FOR_EACH, mHeight, mLayers, mWidth, and restrict.

Referenced by MapReader::addLayerToList(), MapReader::createEmptyMap(), isHeightsPresent(), and Ea::MapRecv::processSetTilesType().

1746 {
1748  {
1749  MapLayer *restrict const layer = *it;
1750  if (layer != nullptr)
1751  layer->updateCache(mWidth, mHeight);
1752  }
1753 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Layers mLayers
Definition: map.h:418
Layers::const_iterator LayersCIter
Definition: map.h:62
const int mHeight
Definition: map.h:412
const int mWidth
Definition: map.h:411
#define restrict
Definition: localconsts.h:164

◆ redrawMap()

void Map::redrawMap ( )
inline

Definition at line 317 of file map.h.

References mRedrawMap.

318  { mRedrawMap = true; }
bool mRedrawMap
Definition: map.h:500

◆ reduce()

void Map::reduce ( )

Definition at line 1472 of file map.cpp.

References CAST_SIZE, config, FOR_EACH, Configuration::getBoolValue(), Logger::log(), logger, mapTileSize, mFringeLayer, mHeight, SubImage::mInternalBounds, mLayers, mOpenGL, mWidth, RENDER_SOFTWARE, restrict, x, and y.

Referenced by loadReplaceLayer(), and setVersion().

1473 {
1474 #ifndef USE_SDL2
1475  if ((mFringeLayer == nullptr) ||
1476  mOpenGL != RENDER_SOFTWARE ||
1477  !config.getBoolValue("enableMapReduce"))
1478  {
1479  return;
1480  }
1481 
1482  int cnt = 0;
1483  for (int x = 0; x < mWidth; x ++)
1484  {
1485  for (int y = 0; y < mHeight; y ++)
1486  {
1487  bool correct(true);
1488  bool dontHaveAlpha(false);
1489 
1490  FOR_EACH (LayersCIter, layeri, mLayers)
1491  {
1492  const MapLayer *restrict const layer = *layeri;
1493  if (x >= layer->mWidth || y >= layer->mHeight)
1494  continue;
1495 
1496  // skip layers with flags
1497  if (layer->mTileCondition != -1 || layer->mMask != 1)
1498  continue;
1499 
1500  Image *restrict const img =
1501  layer->mTiles[x + y * layer->mWidth].image;
1502  if (img != nullptr)
1503  {
1504  if (img->hasAlphaChannel() && img->isAlphaCalculated())
1505  {
1506  if (!img->isAlphaVisible())
1507  {
1508  dontHaveAlpha = true;
1509  img->setAlphaVisible(false);
1510  }
1511  }
1512  else if (img->mBounds.w > mapTileSize
1513  || img->mBounds.h > mapTileSize)
1514  {
1515  correct = false;
1516  img->setAlphaVisible(true);
1517  break;
1518  }
1519  else if (!img->isHasAlphaChannel())
1520  {
1521  dontHaveAlpha = true;
1522  img->setAlphaVisible(false);
1523  }
1524  else if (img->hasAlphaChannel())
1525  {
1526  const uint8_t *restrict const arr =
1527  img->SDLgetAlphaChannel();
1528  if (arr == nullptr)
1529  continue;
1530 
1531  bool bad(false);
1532  bool stop(false);
1533  int width;
1534  const SubImage *restrict const subImg
1535  = dynamic_cast<SubImage*>(img);
1536  if (subImg != nullptr)
1537  width = subImg->mInternalBounds.w;
1538  else
1539  width = img->mBounds.w;
1540 
1541  for (int f = img->mBounds.x;
1542  f < img->mBounds.x + img->mBounds.w; f ++)
1543  {
1544  for (int d = img->mBounds.y;
1545  d < img->mBounds.y + img->mBounds.h; d ++)
1546  {
1547  const uint8_t chan = arr[f + d * width];
1548  if (chan != 255)
1549  {
1550  bad = true;
1551  stop = true;
1552  break;
1553  }
1554  }
1555  if (stop)
1556  break;
1557  }
1558  if (!bad)
1559  {
1560  dontHaveAlpha = true;
1561  img->setAlphaVisible(false);
1562  }
1563  else
1564  {
1565  img->setAlphaVisible(true);
1566  }
1567  }
1568  img->setAlphaCalculated(true);
1569  }
1570  }
1571  if (!correct || !dontHaveAlpha)
1572  continue;
1573 
1574  Layers::reverse_iterator ri = mLayers.rbegin();
1575  while (ri != mLayers.rend())
1576  {
1577  const MapLayer *restrict const layer = *ri;
1578  if (x >= layer->mWidth || y >= layer->mHeight)
1579  {
1580  ++ ri;
1581  continue;
1582  }
1583 
1584  // skip layers with flags
1585  if (layer->mTileCondition != -1 || layer->mMask != 1)
1586  {
1587  ++ ri;
1588  continue;
1589  }
1590 
1591  const Image *restrict img =
1592  layer->mTiles[x + y * layer->mWidth].image;
1593  if ((img != nullptr) && !img->isAlphaVisible())
1594  { // removing all down tiles
1595  ++ ri;
1596  while (ri != mLayers.rend())
1597  {
1598  MapLayer *restrict const layer2 = *ri;
1599  // skip layers with flags
1600  if (layer2->mTileCondition != -1 || layer2->mMask != 1)
1601  {
1602  ++ ri;
1603  continue;
1604  }
1605  const size_t pos = x + y * CAST_SIZE(layer2->mWidth);
1606  img = layer2->mTiles[pos].image;
1607  if (img != nullptr)
1608  {
1609  layer2->mTiles[pos].image = nullptr;
1610  cnt ++;
1611  }
1612  ++ ri;
1613  }
1614  break;
1615  }
1616  ++ ri;
1617  }
1618  }
1619  }
1620  logger->log("tiles reduced: %d", cnt);
1621 #endif // USE_SDL2
1622 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Configuration config
SDL_Rect mInternalBounds
Definition: subimage.h:78
Logger * logger
Definition: logger.cpp:88
Layers mLayers
Definition: map.h:418
bool getBoolValue(const std::string &key) const
Layers::const_iterator LayersCIter
Definition: map.h:62
const int mHeight
Definition: map.h:412
const int mWidth
Definition: map.h:411
MapLayer * mFringeLayer
Definition: map.h:483
Definition: image.h:67
const RenderType mOpenGL
Definition: map.h:471
static const int mapTileSize
Definition: map.h:26
#define restrict
Definition: localconsts.h:164
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ removeActor()

void Map::removeActor ( const Actors::iterator &  iterator)
protected

Removes an actor from the map.

Definition at line 828 of file map.cpp.

References mActors.

Referenced by Actor::setMap(), and Actor::~Actor().

829 {
830  mActors.erase(iterator);
831 // mSpritesUpdated = true;
832 }
Actors mActors
Definition: map.h:422

◆ saveExtraLayer()

void Map::saveExtraLayer ( ) const

Definition at line 1225 of file map.cpp.

References CAST_S32, MapItemType::EMPTY, SpecialLayer::getTile(), getUserMapDirectory(), MapItemType::HOME, ServerCommandType::item, Logger::log(), Logger::log1(), logger, SpecialLayer::mHeight, mkdir_r(), mSpecialLayer, SpecialLayer::mWidth, pathJoin(), reportAlways, restrict, strprintf(), x, and y.

Referenced by QuitDialog::action(), Game::changeMap(), getDrawLayersFlags(), and Game::slowLogic().

1226 {
1227  if (mSpecialLayer == nullptr)
1228  {
1229  logger->log1("No special layer");
1230  return;
1231  }
1232  const std::string mapFileName = pathJoin(getUserMapDirectory(),
1233  "extralayer.txt");
1234  logger->log("saving extra layer: " + mapFileName);
1235 
1236  if (mkdir_r(getUserMapDirectory().c_str()) != 0)
1237  {
1238  logger->log(strprintf("%s doesn't exist and can't be created! "
1239  "Exiting.", getUserMapDirectory().c_str()));
1240  return;
1241  }
1242 
1243  std::ofstream mapFile;
1244  mapFile.open(mapFileName.c_str(), std::ios::binary);
1245  if (!mapFile.is_open())
1246  {
1247  reportAlways("Error opening file for writing: %s",
1248  mapFileName.c_str())
1249  return;
1250  }
1251 
1252  const int width = mSpecialLayer->mWidth;
1253  const int height = mSpecialLayer->mHeight;
1254 
1255  for (int x = 0; x < width; x ++)
1256  {
1257  for (int y = 0; y < height; y ++)
1258  {
1259  const MapItem *restrict const item = mSpecialLayer->getTile(x, y);
1260  if ((item != nullptr) && item->mType != MapItemType::EMPTY
1261  && item->mType != MapItemType::HOME)
1262  {
1263  mapFile << x << " " << y << " "
1264  << CAST_S32(item->mType) << " "
1265  << item->mComment << std::endl;
1266  }
1267  }
1268  }
1269  mapFile.close();
1270 }
void log1(const char *const log_text)
Definition: logger.cpp:233
std::string getUserMapDirectory() const
Definition: map.cpp:1272
std::string pathJoin(std::string str1, const std::string &str2)
int mkdir_r(const char *const pathname)
Create a directory, making leading components first if necessary.
Definition: mkdir.cpp:108
SpecialLayer * mSpecialLayer
Definition: map.h:480
Logger * logger
Definition: logger.cpp:88
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
MapItem * getTile(const int x, const int y) const
#define restrict
Definition: localconsts.h:164
void log(const char *const log_text,...)
Definition: logger.cpp:264
#define reportAlways(...)
Definition: checkutils.h:252

◆ screenResized()

void Map::screenResized ( )

Definition at line 1806 of file map.cpp.

References mClear, mHeight, and mWidth.

Referenced by getCounterName(), loadReplaceLayer(), and Viewport::updateMaxVars().

1807 {
1808  if (mWidth * mapTileSize < mainGraphics->mWidth ||
1809  mHeight * mapTileSize < mainGraphics->mHeight)
1810  {
1811  mClear = true;
1812  }
1813  else
1814  {
1815  mClear = false;
1816  }
1817 }
bool mClear
Definition: map.h:505
const int mHeight
Definition: map.h:412
const int mWidth
Definition: map.h:411

◆ setActorsFix()

void Map::setActorsFix ( const int  x,
const int  y 
)

Definition at line 1723 of file map.cpp.

References mActorFixX, mActorFixY, mFringeLayer, MapLayer::setActorsFix(), x, and y.

Referenced by getObjectsLayer(), and loadReplaceLayer().

1724 {
1725  mActorFixX = x;
1726  mActorFixY = y;
1727  if (mFringeLayer != nullptr)
1729 }
int mActorFixY
Definition: map.h:477
void setActorsFix(const int y)
Definition: maplayer.h:169
int mActorFixX
Definition: map.h:476
MapLayer * mFringeLayer
Definition: map.h:483

◆ setAtlas()

void Map::setAtlas ( AtlasResource *const  atlas)
inline

Definition at line 336 of file map.h.

References mAtlas.

Referenced by loadReplaceLayer().

337  { mAtlas = atlas; }
AtlasResource * mAtlas
Definition: map.h:496

◆ setBlockMask()

void Map::setBlockMask ( const int  x,
const int  y,
const BlockTypeT  type 
)

Definition at line 745 of file map.cpp.

References BlockMask::AIR, BlockType::AIR, MetaTile::blockmask, contains(), BlockType::GROUND, BlockMask::GROUND, BlockMask::GROUNDTOP, BlockType::GROUNDTOP, mMetaTiles, BlockMask::MONSTERWALL, BlockType::MONSTERWALL, mWidth, BlockType::NB_BLOCKTYPES, BlockType::NONE, BlockMask::PLAYERWALL, BlockType::PLAYERWALL, BlockMask::WALL, BlockType::WALL, BlockMask::WATER, BlockType::WATER, x, and y.

Referenced by Ea::MapRecv::processSetTilesType().

747 {
748  if (type == BlockType::NONE || !contains(x, y))
749  return;
750 
751  const int tileNum = x + y * mWidth;
752 
753  switch (type)
754  {
755  case BlockType::WALL:
757  break;
758  case BlockType::AIR:
760  break;
761  case BlockType::WATER:
763  break;
764  case BlockType::GROUND:
766  break;
769  break;
772  break;
775  break;
776  default:
777  case BlockType::NONE:
779  // Do nothing.
780  break;
781  }
782 }
bool contains(const int x, const int y) const
Definition: map.cpp:811
unsigned char blockmask
Definition: metatile.h:51
MetaTile *const mMetaTiles
Definition: map.h:416
const int mWidth
Definition: map.h:411

◆ setCustom()

void Map::setCustom ( const bool  b)
inline

Definition at line 323 of file map.h.

References mCustom.

Referenced by MapReader::createEmptyMap().

324  { mCustom = b; }
bool mCustom
Definition: map.h:503

◆ setDrawLayersFlags()

void Map::setDrawLayersFlags ( const MapTypeT n)

Definition at line 1702 of file map.cpp.

References MapType::BLACKWHITE, FOR_EACH, mDrawLayersFlags, mDrawOnlyFringe, mLayers, restrict, MapType::SPECIAL3, MapType::SPECIAL4, and updateDrawLayersList().

Referenced by Viewport::getMouseTile(), getTileHeight(), and GameModifiers::resetModifiers().

1703 {
1704  mDrawLayersFlags = n;
1708  {
1709  mDrawOnlyFringe = true;
1710  }
1711  else
1712  {
1713  mDrawOnlyFringe = false;
1714  }
1716  FOR_EACH (Layers::iterator, it, mLayers)
1717  {
1718  MapLayer *restrict const layer = *it;
1719  layer->setDrawLayerFlags(mDrawLayersFlags);
1720  }
1721 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
bool mDrawOnlyFringe
Definition: map.h:504
void updateDrawLayersList()
Definition: map.cpp:1637
Layers mLayers
Definition: map.h:418
MapTypeT mDrawLayersFlags
Definition: map.h:426
#define restrict
Definition: localconsts.h:164

◆ setHasWarps()

void Map::setHasWarps ( const bool  n)
inline

Definition at line 243 of file map.h.

References mHasWarps.

244  { mHasWarps = n; }
bool mHasWarps
Definition: map.h:423

◆ setMask()

void Map::setMask ( const int  mask)

Definition at line 1675 of file map.cpp.

References mMask, mRedrawMap, and updateDrawLayersList().

Referenced by Ea::PlayerRecv::processMapMask(), and setWalkLayer().

1676 {
1677  if (mask != mMask)
1678  {
1679  mRedrawMap = true;
1680  mMask = mask;
1682  }
1683 }
void updateDrawLayersList()
Definition: map.cpp:1637
bool mRedrawMap
Definition: map.h:500
int mMask
Definition: map.h:494

◆ setMusicFile()

void Map::setMusicFile ( const std::string &  file)

Definition at line 1685 of file map.cpp.

References Properties::setProperty().

Referenced by getTileHeight(), and Ea::PlayerRecv::processMapMusic().

1686 {
1687  setProperty("music", file);
1688 }
void setProperty(const std::string &name, const std::string &value)
Definition: properties.h:127

◆ setPvpMode()

void Map::setPvpMode ( const int  mode)

Definition at line 1360 of file map.cpp.

References NotifyTypes::GVG_ON, localPlayer, mPvp, NotifyManager::notify(), NotifyTypes::PVP_OFF_GVG_OFF, NotifyTypes::PVP_ON, NotifyTypes::PVP_ON_GVG_ON, and NotifyTypes::PVP_UNKNOWN.

Referenced by getActorsCount(), EAthena::BeingRecv::processMapTypeProperty(), and Ea::BeingRecv::processPvpMapMode().

1361 {
1362  const int oldMode = mPvp;
1363 
1364  if (mode == 0)
1365  mPvp = 0;
1366  else
1367  mPvp |= mode;
1368 
1369  if (mPvp != oldMode && (localPlayer != nullptr))
1370  {
1371  switch (mPvp)
1372  {
1373  case 0:
1375  break;
1376  case 1:
1378  break;
1379  case 2:
1381  break;
1382  case 3:
1384  break;
1385  default:
1387  break;
1388  }
1389  }
1390 }
int mPvp
Definition: map.h:472
void notify(const unsigned int message)
LocalPlayer * localPlayer

◆ setVersion()

void Map::setVersion ( const int  n)
inline

Definition at line 312 of file map.h.

References mVersion, reduce(), and restrict2.

Referenced by loadReplaceLayer().

313  { mVersion = n; }
int mVersion
Definition: map.h:478

◆ setWalk()

void Map::setWalk ( const int  x,
const int  y 
)

Definition at line 806 of file map.cpp.

References addBlockMask(), BlockType::GROUNDTOP, x, and y.

Referenced by LocalPlayer::setRealPos().

807 {
809 }
void addBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:706

◆ setWalkLayer()

void Map::setWalkLayer ( WalkLayer *const  layer)
inline

Definition at line 349 of file map.h.

References A_NONNULL, addHeights(), getHeightOffset(), mWalkLayer, restrict, restrict2, setMask(), and updateDrawLayersList().

Referenced by loadReplaceLayer().

350  { mWalkLayer = layer; }
WalkLayer * mWalkLayer
Definition: map.h:417

◆ update()

void Map::update ( const int  ticks)

Updates animations. Called as needed.

Definition at line 327 of file map.cpp.

References FOR_EACH, mRedrawMap, mTileAnimations, and restrict.

Referenced by Game::logic().

328 {
329  // Update animated tiles
331  {
332  TileAnimation *restrict const tileAni = iAni->second;
333  if ((tileAni != nullptr) && tileAni->update(ticks))
334  mRedrawMap = true;
335  }
336 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
TileAnimationMap::const_iterator TileAnimationMapCIter
Definition: tileanimation.h:64
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:466
bool mRedrawMap
Definition: map.h:500
#define restrict
Definition: localconsts.h:164

◆ updateAmbientLayers()

void Map::updateAmbientLayers ( const float  scrollX,
const float  scrollY 
)
private

Updates scrolling of ambient layers. Has to be called each game tick.

Definition at line 618 of file map.cpp.

References BLOCK_END, BLOCK_START, FOR_EACH, get_elapsed_time(), mBackgrounds, mForegrounds, mLastAScrollX, mLastAScrollY, AmbientLayer::mMask, mMask, tick_time, and AmbientLayer::update().

Referenced by draw().

620 {
621  BLOCK_START("Map::updateAmbientLayers")
622  static int lastTick = tick_time;
623 
624  if (mLastAScrollX == 0.0F && mLastAScrollY == 0.0F)
625  {
626  // First call - initialisation
627  mLastAScrollX = scrollX;
628  mLastAScrollY = scrollY;
629  }
630 
631  // Update Overlays
632  const float dx = scrollX - mLastAScrollX;
633  const float dy = scrollY - mLastAScrollY;
634  const int timePassed = get_elapsed_time(lastTick);
635 
636  // need check mask to update or not to update
637 
639  {
640  AmbientLayer *const layer = *i;
641  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
642  layer->update(timePassed, dx, dy);
643  }
644 
646  {
647  AmbientLayer *const layer = *i;
648  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
649  layer->update(timePassed, dx, dy);
650  }
651 
652  mLastAScrollX = scrollX;
653  mLastAScrollY = scrollY;
654  lastTick = tick_time;
655  BLOCK_END("Map::updateAmbientLayers")
656 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
volatile int tick_time
Definition: timer.cpp:52
AmbientLayerVector mBackgrounds
Definition: map.h:433
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
int get_elapsed_time(const int startTime)
Definition: timer.cpp:93
float mLastAScrollX
Definition: map.h:435
void update(const int timePassed, const float dx, const float dy)
AmbientLayerVector mForegrounds
Definition: map.h:434
float mLastAScrollY
Definition: map.h:436
AmbientLayerVector::iterator AmbientLayerVectorIter
Definition: map.h:66
int mMask
Definition: map.h:494

◆ updateConditionLayers()

void Map::updateConditionLayers ( )

Definition at line 1731 of file map.cpp.

References FOR_EACH, mHeight, mLayers, mMetaTiles, mRedrawMap, mWidth, and restrict.

Referenced by MapReader::addLayerToList(), MapReader::createEmptyMap(), isHeightsPresent(), and Ea::MapRecv::processSetTilesType().

1732 {
1733  mRedrawMap = true;
1734 
1736  {
1737  MapLayer *restrict const layer = *it;
1738  if ((layer == nullptr) || layer->mTileCondition == -1)
1739  continue;
1740  layer->updateConditionTiles(mMetaTiles,
1741  mWidth, mHeight);
1742  }
1743 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Layers mLayers
Definition: map.h:418
Layers::const_iterator LayersCIter
Definition: map.h:62
bool mRedrawMap
Definition: map.h:500
const int mHeight
Definition: map.h:412
MetaTile *const mMetaTiles
Definition: map.h:416
const int mWidth
Definition: map.h:411
#define restrict
Definition: localconsts.h:164

◆ updateDrawLayersList()

void Map::updateDrawLayersList ( )

Definition at line 1637 of file map.cpp.

References MapLayer::isFringeLayer(), mDrawLayersFlags, mDrawOnlyFringe, mDrawOverLayers, mDrawUnderLayers, mLayers, MapLayer::mMask, mMask, and MapType::SPECIAL2.

Referenced by MapReader::createEmptyMap(), loadReplaceLayer(), setDrawLayersFlags(), setMask(), and setWalkLayer().

1638 {
1639  mDrawUnderLayers.clear();
1640  mDrawOverLayers.clear();
1641 
1642  if (mDrawOnlyFringe)
1643  return;
1644 
1645  LayersCIter layers = mLayers.begin();
1646  const LayersCIter layers_end = mLayers.end();
1647  for (; layers != layers_end; ++ layers)
1648  {
1649  MapLayer *const layer = *layers;
1650  if ((layer->mMask & mMask) == 0)
1651  continue;
1652 
1653  if (layer->isFringeLayer())
1654  {
1655  ++ layers;
1656  break;
1657  }
1658 
1659  mDrawUnderLayers.push_back(layer);
1660  }
1661 
1663  return;
1664 
1665  for (; layers != layers_end; ++ layers)
1666  {
1667  MapLayer *const layer = *layers;
1668  if ((layer->mMask & mMask) == 0)
1669  continue;
1670 
1671  mDrawOverLayers.push_back(layer);
1672  }
1673 }
bool mDrawOnlyFringe
Definition: map.h:504
Layers mLayers
Definition: map.h:418
Layers::const_iterator LayersCIter
Definition: map.h:62
MapTypeT mDrawLayersFlags
Definition: map.h:426
Layers mDrawUnderLayers
Definition: map.h:419
Layers mDrawOverLayers
Definition: map.h:420
int mMask
Definition: maplayer.h:233
int mMask
Definition: map.h:494
bool isFringeLayer() const
Definition: maplayer.h:140

◆ updatePortalTile()

void Map::updatePortalTile ( const std::string &  name,
const int  type,
const int  x,
const int  y,
const bool  addNew 
)

Definition at line 1312 of file map.cpp.

References addPortalTile(), findPortalXY(), ServerCommandType::item, mSpecialLayer, restrict, SpecialLayer::setTile(), SpecialLayer::updateCache(), x, and y.

Referenced by addExtraLayer(), getHasWarps(), and LocalPlayer::setHome().

1316 {
1318  if (item != nullptr)
1319  {
1320  item->mComment = name;
1321  item->setType(type);
1322  item->mX = x;
1323  item->mY = y;
1324  if (mSpecialLayer != nullptr)
1325  {
1326  item = new MapItem(type, name, x, y);
1327  mSpecialLayer->setTile(x, y, item);
1329  }
1330  }
1331  else if (addNew)
1332  {
1333  addPortalTile(name, type, x, y);
1334  }
1335 }
SpecialLayer * mSpecialLayer
Definition: map.h:480
void setTile(const int x, const int y, MapItem *const item)
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1299
void updateCache()
MapItem * findPortalXY(const int x, const int y) const
Definition: map.cpp:1337
#define restrict
Definition: localconsts.h:164

Friends And Related Function Documentation

◆ Actor

friend class Actor
friend

Definition at line 378 of file map.h.

◆ Minimap

friend class Minimap
friend

Definition at line 379 of file map.h.

Field Documentation

◆ mActorFixX

int Map::mActorFixX
private

Definition at line 476 of file map.h.

Referenced by setActorsFix().

◆ mActorFixY

int Map::mActorFixY
private

Definition at line 477 of file map.h.

Referenced by setActorsFix().

◆ mActors

Actors Map::mActors
private

Definition at line 422 of file map.h.

Referenced by addActor(), calcMemoryLocal(), draw(), getActorsCount(), and removeActor().

◆ mAtlas

AtlasResource* Map::mAtlas
private

Definition at line 496 of file map.h.

Referenced by getAtlasCount(), haveAtlas(), setAtlas(), and ~Map().

◆ mBackgrounds

AmbientLayerVector Map::mBackgrounds
private

◆ mBeingOpacity

bool Map::mBeingOpacity
private

Definition at line 501 of file map.h.

Referenced by draw(), Map(), and optionChanged().

◆ mCachedDraw

bool Map::mCachedDraw
private

Definition at line 502 of file map.h.

Referenced by draw().

◆ mClear

bool Map::mClear
private

Definition at line 505 of file map.h.

Referenced by draw(), and screenResized().

◆ mCustom

bool Map::mCustom
private

Definition at line 503 of file map.h.

Referenced by isCustom(), and setCustom().

◆ mDrawLayersFlags

MapTypeT Map::mDrawLayersFlags
private

Definition at line 426 of file map.h.

Referenced by draw(), getDrawLayersFlags(), setDrawLayersFlags(), and updateDrawLayersList().

◆ mDrawOnlyFringe

bool Map::mDrawOnlyFringe
private

Definition at line 504 of file map.h.

Referenced by draw(), setDrawLayersFlags(), and updateDrawLayersList().

◆ mDrawOverLayers

Layers Map::mDrawOverLayers
private

Definition at line 420 of file map.h.

Referenced by calcMemoryLocal(), draw(), and updateDrawLayersList().

◆ mDrawScrollX

int Map::mDrawScrollX
private

Definition at line 492 of file map.h.

Referenced by draw().

◆ mDrawScrollY

int Map::mDrawScrollY
private

Definition at line 493 of file map.h.

Referenced by draw().

◆ mDrawUnderLayers

Layers Map::mDrawUnderLayers
private

Definition at line 419 of file map.h.

Referenced by calcMemoryLocal(), draw(), and updateDrawLayersList().

◆ mDrawX

int Map::mDrawX
private

Definition at line 490 of file map.h.

Referenced by draw().

◆ mDrawY

int Map::mDrawY
private

Definition at line 491 of file map.h.

Referenced by draw().

◆ mForegrounds

AmbientLayerVector Map::mForegrounds
private

◆ mFringeLayer

MapLayer* Map::mFringeLayer
private

Definition at line 483 of file map.h.

Referenced by addLayer(), draw(), reduce(), setActorsFix(), and ~Map().

◆ mHasWarps

bool Map::mHasWarps
private

Definition at line 423 of file map.h.

Referenced by getHasWarps(), and setHasWarps().

◆ mHeight

const int Map::mHeight
private

◆ mHeights

const MapHeights* Map::mHeights
private

Definition at line 499 of file map.h.

Referenced by addHeights(), calcMemoryChilds(), getHeightOffset(), isHeightsPresent(), and ~Map().

◆ mIndexedTilesets

Tileset** Map::mIndexedTilesets
private

Definition at line 474 of file map.h.

Referenced by clearIndexedTilesets(), getTilesetWithGid(), and indexTilesets().

◆ mIndexedTilesetsSize

int Map::mIndexedTilesetsSize
private

Definition at line 475 of file map.h.

Referenced by calcMemoryLocal(), clearIndexedTilesets(), getTilesetWithGid(), and indexTilesets().

◆ mLastAScrollX

float Map::mLastAScrollX
private

Definition at line 435 of file map.h.

Referenced by updateAmbientLayers().

◆ mLastAScrollY

float Map::mLastAScrollY
private

Definition at line 436 of file map.h.

Referenced by updateAmbientLayers().

◆ mLastScrollX

int Map::mLastScrollX
private

Definition at line 487 of file map.h.

Referenced by draw().

◆ mLastScrollY

int Map::mLastScrollY
private

Definition at line 488 of file map.h.

Referenced by draw().

◆ mLastX

int Map::mLastX
private

Definition at line 485 of file map.h.

Referenced by draw().

◆ mLastY

int Map::mLastY
private

Definition at line 486 of file map.h.

Referenced by draw().

◆ mLayers

Layers Map::mLayers
private

◆ mMapPortals

std::vector<MapItem*> Map::mMapPortals
private

Definition at line 464 of file map.h.

Referenced by addPortalTile(), calcMemoryLocal(), findPortalXY(), getPortals(), and ~Map().

◆ mMask

int Map::mMask
private

Definition at line 494 of file map.h.

Referenced by drawAmbientLayers(), setMask(), updateAmbientLayers(), and updateDrawLayersList().

◆ mMaxTileHeight

int Map::mMaxTileHeight
private

Definition at line 415 of file map.h.

Referenced by addTileset(), and draw().

◆ mMetaTiles

MetaTile* const Map::mMetaTiles
private

◆ mName

std::string Map::mName
private

Definition at line 468 of file map.h.

Referenced by calcMemoryLocal(), and getCounterName().

◆ mObjects

ObjectsLayer* Map::mObjects
private

Definition at line 482 of file map.h.

Referenced by addRange(), calcMemoryChilds(), getObjectData(), getObjectsLayer(), and ~Map().

◆ mOnClosedList

unsigned int Map::mOnClosedList
private

Definition at line 429 of file map.h.

Referenced by findPath().

◆ mOnOpenList

unsigned int Map::mOnOpenList
private

Definition at line 430 of file map.h.

Referenced by findPath().

◆ mOpacity

float Map::mOpacity
private

Definition at line 470 of file map.h.

Referenced by Map(), and optionChanged().

◆ mOpenGL

const RenderType Map::mOpenGL
private

Definition at line 471 of file map.h.

Referenced by draw(), and reduce().

◆ mOverlayDetail

int Map::mOverlayDetail
private

Definition at line 469 of file map.h.

Referenced by draw(), and optionChanged().

◆ mParticleEffects

std::vector<ParticleEffectData> Map::mParticleEffects
private

Definition at line 462 of file map.h.

Referenced by addParticleEffect(), calcMemoryLocal(), and initializeParticleEffects().

◆ mPvp

int Map::mPvp
private

Definition at line 472 of file map.h.

Referenced by getPvpMode(), and setPvpMode().

◆ mRedrawMap

bool Map::mRedrawMap
private

Definition at line 500 of file map.h.

Referenced by draw(), redrawMap(), setMask(), update(), and updateConditionLayers().

◆ mSpecialLayer

SpecialLayer* Map::mSpecialLayer
private

◆ mTempLayer

SpecialLayer* Map::mTempLayer
private

Definition at line 481 of file map.h.

Referenced by calcMemoryChilds(), draw(), getTempLayer(), and ~Map().

◆ mTileAnimations

std::map<int, TileAnimation*> Map::mTileAnimations
private

◆ mTileHeight

const int Map::mTileHeight
private

Definition at line 414 of file map.h.

Referenced by draw(), drawCollision(), and getTileHeight().

◆ mTilesets

Tilesets Map::mTilesets
private

Definition at line 421 of file map.h.

Referenced by addTileset(), calcMemoryChilds(), calcMemoryLocal(), indexTilesets(), and ~Map().

◆ mTilesetsIndexed

bool Map::mTilesetsIndexed
private

Definition at line 473 of file map.h.

Referenced by clearIndexedTilesets(), and indexTilesets().

◆ mTileWidth

const int Map::mTileWidth
private

Definition at line 413 of file map.h.

Referenced by draw(), drawCollision(), and getTileWidth().

◆ mVersion

int Map::mVersion
private

Definition at line 478 of file map.h.

Referenced by getVersion(), and setVersion().

◆ mWalkLayer

WalkLayer* Map::mWalkLayer
private

Definition at line 417 of file map.h.

Referenced by calcMemoryChilds(), getWalkLayer(), setWalkLayer(), and ~Map().

◆ mWidth

const int Map::mWidth
private

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