diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-05-11 15:17:30 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-05-11 15:17:30 +0300 |
commit | 788f91b8b779a3b99cf4a7f8f53488f45b2edc09 (patch) | |
tree | 9d9027582877b443bdd872a25de3796b8987cf30 | |
parent | 211aab93fed3462f875b66c3aecf0bfc98c3467a (diff) | |
download | manaverse-788f91b8b779a3b99cf4a7f8f53488f45b2edc09.tar.gz manaverse-788f91b8b779a3b99cf4a7f8f53488f45b2edc09.tar.bz2 manaverse-788f91b8b779a3b99cf4a7f8f53488f45b2edc09.tar.xz manaverse-788f91b8b779a3b99cf4a7f8f53488f45b2edc09.zip |
Move speciallayer into separate file.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 1 | ||||
-rw-r--r-- | src/gui/popups/popupmenu.cpp | 1 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 1 | ||||
-rw-r--r-- | src/gui/windows/socialwindow.cpp | 1 | ||||
-rw-r--r-- | src/resources/map/map.cpp | 1 | ||||
-rw-r--r-- | src/resources/map/maplayer.cpp | 120 | ||||
-rw-r--r-- | src/resources/map/maplayer.h | 32 | ||||
-rw-r--r-- | src/resources/map/speciallayer.cpp | 147 | ||||
-rw-r--r-- | src/resources/map/speciallayer.h | 63 |
11 files changed, 220 insertions, 151 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8721c9036..28f021e56 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -759,6 +759,8 @@ SET(SRCS position.cpp position.h resources/map/properties.h + resources/map/speciallayer.cpp + resources/map/speciallayer.h resources/map/tileanimation.cpp resources/map/tileanimation.h particle/rotationalparticle.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 2289e37ba..b99c2a2e5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -846,6 +846,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ position.cpp \ position.h \ resources/map/properties.h \ + resources/map/speciallayer.cpp \ + resources/map/speciallayer.h \ resources/map/tileanimation.cpp \ resources/map/tileanimation.h \ particle/rotationalparticle.cpp \ diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 697a31069..f1ab7a126 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -69,6 +69,7 @@ #include "resources/db/weaponsdb.h" #include "resources/map/maplayer.h" +#include "resources/map/speciallayer.h" #include "listeners/updatestatuslistener.h" diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index 4b84c47b3..00f22a6e8 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -77,6 +77,7 @@ #include "resources/iteminfo.h" #include "resources/map/maplayer.h" +#include "resources/map/speciallayer.h" #include "utils/copynpaste.h" #include "utils/gettext.h" diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index e2b039fe1..792d64b7e 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -29,6 +29,7 @@ #include "textmanager.h" #include "resources/map/maplayer.h" +#include "resources/map/speciallayer.h" #include "being/localplayer.h" #include "being/playerinfo.h" diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp index dbbb9c75d..61198b736 100644 --- a/src/gui/windows/socialwindow.cpp +++ b/src/gui/windows/socialwindow.cpp @@ -28,6 +28,7 @@ #include "party.h" #include "resources/map/maplayer.h" +#include "resources/map/speciallayer.h" #include "being/localplayer.h" #include "being/playerrelations.h" diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index 7ab41fbef..d1b1bdb47 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -31,6 +31,7 @@ #include "resources/map/mapheights.h" #include "resources/map/maplayer.h" +#include "resources/map/speciallayer.h" #include "resources/map/tileset.h" #include "resources/map/walklayer.h" 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(), diff --git a/src/resources/map/maplayer.h b/src/resources/map/maplayer.h index a631932b6..653009b40 100644 --- a/src/resources/map/maplayer.h +++ b/src/resources/map/maplayer.h @@ -158,38 +158,6 @@ class MapLayer final: public ConfigListener bool mHighlightAttackRange; }; -class SpecialLayer final -{ - public: - friend class Map; - friend class MapLayer; - - SpecialLayer(const int width, const int height); - - A_DELETE_COPY(SpecialLayer) - - ~SpecialLayer(); - - void draw(Graphics *const graphics, int startX, int startY, - int endX, int endY, - const int scrollX, const int scrollY) const; - - MapItem* getTile(const int x, const int y) const A_WARN_UNUSED; - - void setTile(const int x, const int y, MapItem *const item); - - void setTile(const int x, const int y, const int type); - - void addRoad(const Path &road); - - void clean() const; - - private: - int mWidth; - int mHeight; - MapItem **mTiles; -}; - class MapItem final { public: diff --git a/src/resources/map/speciallayer.cpp b/src/resources/map/speciallayer.cpp new file mode 100644 index 000000000..d87a078de --- /dev/null +++ b/src/resources/map/speciallayer.cpp @@ -0,0 +1,147 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "resources/map/speciallayer.h" + +#include "resources/map/map.h" +#include "resources/map/maplayer.h" + +#include "utils/delete2.h" + +#include "debug.h" + +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") +} diff --git a/src/resources/map/speciallayer.h b/src/resources/map/speciallayer.h new file mode 100644 index 000000000..59062bf31 --- /dev/null +++ b/src/resources/map/speciallayer.h @@ -0,0 +1,63 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_MAP_SPECIALLAYER_H +#define RESOURCES_MAP_SPECIALLAYER_H + +#include "position.h" + +#include "localconsts.h" + +class Graphics; +class MapItem; + +class SpecialLayer final +{ + public: + friend class Map; + friend class MapLayer; + + SpecialLayer(const int width, const int height); + + A_DELETE_COPY(SpecialLayer) + + ~SpecialLayer(); + + void draw(Graphics *const graphics, int startX, int startY, + int endX, int endY, + const int scrollX, const int scrollY) const; + + MapItem* getTile(const int x, const int y) const A_WARN_UNUSED; + + void setTile(const int x, const int y, MapItem *const item); + + void setTile(const int x, const int y, const int type); + + void addRoad(const Path &road); + + void clean() const; + + private: + int mWidth; + int mHeight; + MapItem **mTiles; +}; + +#endif // RESOURCES_MAP_SPECIALLAYER_H |