summaryrefslogtreecommitdiff
path: root/src/resources/map/maplayer.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-11 15:17:30 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-11 15:17:30 +0300
commit788f91b8b779a3b99cf4a7f8f53488f45b2edc09 (patch)
tree9d9027582877b443bdd872a25de3796b8987cf30 /src/resources/map/maplayer.cpp
parent211aab93fed3462f875b66c3aecf0bfc98c3467a (diff)
downloadmv-788f91b8b779a3b99cf4a7f8f53488f45b2edc09.tar.gz
mv-788f91b8b779a3b99cf4a7f8f53488f45b2edc09.tar.bz2
mv-788f91b8b779a3b99cf4a7f8f53488f45b2edc09.tar.xz
mv-788f91b8b779a3b99cf4a7f8f53488f45b2edc09.zip
Move speciallayer into separate file.
Diffstat (limited to 'src/resources/map/maplayer.cpp')
-rw-r--r--src/resources/map/maplayer.cpp120
1 files changed, 1 insertions, 119 deletions
diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp
index 0bef81273..05013bf71 100644
--- a/src/resources/map/maplayer.cpp
+++ b/src/resources/map/maplayer.cpp
@@ -38,6 +38,7 @@
#include "resources/map/mapobjectlist.h"
#include "resources/map/maprowvertexes.h"
+#include "resources/map/speciallayer.h"
#include "gui/font.h"
#include "gui/gui.h"
@@ -581,125 +582,6 @@ int MapLayer::getTileDrawWidth(const Image *img,
return c;
}
-SpecialLayer::SpecialLayer(const int width, const int height) :
- mWidth(width),
- mHeight(height),
- mTiles(new MapItem*[mWidth * mHeight])
-{
- std::fill_n(mTiles, mWidth * mHeight, static_cast<MapItem*>(nullptr));
-}
-
-SpecialLayer::~SpecialLayer()
-{
- for (int f = 0; f < mWidth * mHeight; f ++)
- delete2(mTiles[f])
- delete [] mTiles;
-}
-
-MapItem* SpecialLayer::getTile(const int x, const int y) const
-{
- if (x < 0 || x >= mWidth ||
- y < 0 || y >= mHeight)
- {
- return nullptr;
- }
- return mTiles[x + y * mWidth];
-}
-
-void SpecialLayer::setTile(const int x, const int y, MapItem *const item)
-{
- if (x < 0 || x >= mWidth ||
- y < 0 || y >= mHeight)
- {
- return;
- }
-
- const int idx = x + y * mWidth;
- delete mTiles[idx];
- if (item)
- item->setPos(x, y);
- mTiles[idx] = item;
-}
-
-void SpecialLayer::setTile(const int x, const int y, const int type)
-{
- if (x < 0 || x >= mWidth ||
- y < 0 || y >= mHeight)
- {
- return;
- }
-
- const int idx = x + y * mWidth;
- MapItem *const tile = mTiles[idx];
- if (tile)
- {
- tile->setType(type);
- tile->setPos(x, y);
- }
- else
- {
- mTiles[idx] = new MapItem(type);
- mTiles[idx]->setPos(x, y);
- }
-}
-
-void SpecialLayer::addRoad(const Path &road)
-{
- FOR_EACH (Path::const_iterator, i, road)
- {
- const Position &pos = (*i);
- MapItem *const item = getTile(pos.x, pos.y);
- if (!item)
- setTile(pos.x, pos.y, new MapItem(MapItem::ROAD));
- else
- item->setType(MapItem::ROAD);
- }
-}
-
-void SpecialLayer::clean() const
-{
- if (!mTiles)
- return;
-
- for (int f = 0; f < mWidth * mHeight; f ++)
- {
- MapItem *const item = mTiles[f];
- if (item)
- item->setType(MapItem::EMPTY);
- }
-}
-
-void SpecialLayer::draw(Graphics *const graphics, int startX, int startY,
- int endX, int endY,
- const int scrollX, const int scrollY) const
-{
- BLOCK_START("SpecialLayer::draw")
- if (startX < 0)
- startX = 0;
- if (startY < 0)
- startY = 0;
- if (endX > mWidth)
- endX = mWidth;
- if (endY > mHeight)
- endY = mHeight;
-
- for (int y = startY; y < endY; y ++)
- {
- const int py = y * mapTileSize - scrollY;
- const int y2 = y * mWidth;
- for (int x = startX; x < endX; x ++)
- {
- const MapItem *const item = mTiles[x + y2];
- if (item)
- {
- item->draw(graphics, x * mapTileSize - scrollX, py,
- mapTileSize, mapTileSize);
- }
- }
- }
- BLOCK_END("SpecialLayer::draw")
-}
-
MapItem::MapItem():
mImage(nullptr),
mComment(),