summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-16 15:07:13 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-16 15:31:05 +0300
commit0bfeccc16c5606cec5979b49c5d6b3bd298912fb (patch)
tree6294d19e429c3c6e9386f0e70260607bdfb7f315 /src/resources
parent407a4233221c2280ef2a92914c8d23e463aa665c (diff)
downloadmanaplus-0bfeccc16c5606cec5979b49c5d6b3bd298912fb.tar.gz
manaplus-0bfeccc16c5606cec5979b49c5d6b3bd298912fb.tar.bz2
manaplus-0bfeccc16c5606cec5979b49c5d6b3bd298912fb.tar.xz
manaplus-0bfeccc16c5606cec5979b49c5d6b3bd298912fb.zip
Improve a bit map layers draw.
Also fix issue with some map draw modes.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/map/map.cpp48
-rw-r--r--src/resources/map/maplayer.cpp55
-rw-r--r--src/resources/map/maplayer.h17
3 files changed, 71 insertions, 49 deletions
diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp
index aa7248c8d..49006a5b2 100644
--- a/src/resources/map/map.cpp
+++ b/src/resources/map/map.cpp
@@ -394,7 +394,7 @@ void Map::draw(Graphics *const graphics, int scrollX, int scrollY)
mFringeLayer->setSpecialLayer(mSpecialLayer);
mFringeLayer->setTempLayer(mTempLayer);
mFringeLayer->drawFringe(graphics, startX, startY, endX, endY,
- scrollX, scrollY, &mActors, mDrawLayersFlags, mActorFixY);
+ scrollX, scrollY, &mActors, mActorFixY);
}
}
else
@@ -406,8 +406,10 @@ void Map::draw(Graphics *const graphics, int scrollX, int scrollY)
MapLayer *const layer = *it;
if (updateFlag)
{
- layer->updateOGL(graphics, startX, startY,
- endX, endY, scrollX, scrollY, mDrawLayersFlags);
+ layer->updateOGL(graphics,
+ startX, startY,
+ endX, endY,
+ scrollX, scrollY);
}
layer->drawOGL(graphics);
@@ -417,8 +419,12 @@ void Map::draw(Graphics *const graphics, int scrollX, int scrollY)
{
mFringeLayer->setSpecialLayer(mSpecialLayer);
mFringeLayer->setTempLayer(mTempLayer);
- mFringeLayer->drawFringe(graphics, startX, startY, endX, endY,
- scrollX, scrollY, &mActors, mDrawLayersFlags, mActorFixY);
+ mFringeLayer->drawFringe(graphics,
+ startX, startY,
+ endX, endY,
+ scrollX, scrollY,
+ &mActors,
+ mActorFixY);
}
FOR_EACH (Layers::iterator, it, mDrawOverLayers)
@@ -426,8 +432,10 @@ void Map::draw(Graphics *const graphics, int scrollX, int scrollY)
MapLayer *const layer = *it;
if (updateFlag)
{
- layer->updateOGL(graphics, startX, startY,
- endX, endY, scrollX, scrollY, mDrawLayersFlags);
+ layer->updateOGL(graphics,
+ startX, startY,
+ endX, endY,
+ scrollX, scrollY);
}
layer->drawOGL(graphics);
@@ -437,22 +445,28 @@ void Map::draw(Graphics *const graphics, int scrollX, int scrollY)
{
FOR_EACH (Layers::iterator, it, mDrawUnderLayers)
{
- (*it)->draw(graphics, startX, startY, endX, endY,
- scrollX, scrollY, mDrawLayersFlags);
+ (*it)->draw(graphics,
+ startX, startY,
+ endX, endY,
+ scrollX, scrollY);
}
if (mFringeLayer)
{
mFringeLayer->setSpecialLayer(mSpecialLayer);
mFringeLayer->setTempLayer(mTempLayer);
- mFringeLayer->drawFringe(graphics, startX, startY, endX, endY,
- scrollX, scrollY, &mActors, mDrawLayersFlags, mActorFixY);
+ mFringeLayer->drawFringe(graphics,
+ startX, startY,
+ endX, endY,
+ scrollX, scrollY,
+ &mActors, mActorFixY);
}
FOR_EACH (Layers::iterator, it, mDrawOverLayers)
{
- (*it)->draw(graphics, startX, startY, endX, endY,
- scrollX, scrollY, mDrawLayersFlags);
+ (*it)->draw(graphics, startX, startY,
+ endX, endY,
+ scrollX, scrollY);
}
}
}
@@ -1538,6 +1552,9 @@ void Map::updateDrawLayersList()
mDrawUnderLayers.push_back(layer);
}
+ if (mDrawLayersFlags == MapType::SPECIAL2)
+ return;
+
for (; layers != layers_end; ++ layers)
{
MapLayer *const layer = *layers;
@@ -1588,4 +1605,9 @@ void Map::setDrawLayersFlags(const MapType::MapType &n)
mDrawOnlyFringe = false;
}
updateDrawLayersList();
+ FOR_EACH (Layers::iterator, it, mLayers)
+ {
+ MapLayer *const layer = *it;
+ layer->setDrawLayerFlags(mDrawLayersFlags);
+ }
}
diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp
index 83df5d580..3fad0aee9 100644
--- a/src/resources/map/maplayer.cpp
+++ b/src/resources/map/maplayer.cpp
@@ -51,12 +51,14 @@ MapLayer::MapLayer(const int x, const int y,
mWidth(width),
mHeight(height),
mTiles(new Image*[mWidth * mHeight]),
+ mDrawLayerFlags(MapType::NORMAL),
mSpecialLayer(nullptr),
mTempLayer(nullptr),
mTempRows(),
mMask(mask),
mIsFringeLayer(fringeLayer),
- mHighlightAttackRange(config.getBoolValue("highlightAttackRange"))
+ mHighlightAttackRange(config.getBoolValue("highlightAttackRange")),
+ mSpecialFlag(true)
{
std::fill_n(mTiles, mWidth * mHeight, static_cast<Image*>(nullptr));
@@ -88,8 +90,7 @@ void MapLayer::setTile(const int x, const int y, Image *const img)
void MapLayer::draw(Graphics *const graphics,
int startX, int startY, int endX, int endY,
- const int scrollX, const int scrollY,
- const int layerDrawFlags) const
+ const int scrollX, const int scrollY) const
{
if (!localPlayer)
return;
@@ -111,9 +112,6 @@ void MapLayer::draw(Graphics *const graphics,
const int dx = (mX * mapTileSize) - scrollX;
const int dy = (mY * mapTileSize) - scrollY + mapTileSize;
- const bool flag = (layerDrawFlags != MapType::SPECIAL
- && layerDrawFlags != MapType::SPECIAL2
- && layerDrawFlags != MapType::SPECIAL4);
for (int y = startY; y < endY; y++)
{
@@ -134,7 +132,7 @@ void MapLayer::draw(Graphics *const graphics,
{
const int px = x32 + dx;
const int py = py0 - img->mBounds.h;
- if (flag || img->mBounds.h <= mapTileSize)
+ if (mSpecialFlag || img->mBounds.h <= mapTileSize)
{
int width = 0;
// here need not draw over player position
@@ -182,8 +180,7 @@ void MapLayer::drawSDL(Graphics *const graphics) const
void MapLayer::updateSDL(const Graphics *const graphics,
int startX, int startY,
int endX, int endY,
- const int scrollX, const int scrollY,
- const int layerDrawFlags)
+ const int scrollX, const int scrollY)
{
BLOCK_START("MapLayer::updateSDL")
delete_all(mTempRows);
@@ -205,9 +202,6 @@ void MapLayer::updateSDL(const Graphics *const graphics,
const int dx = (mX * mapTileSize) - scrollX;
const int dy = (mY * mapTileSize) - scrollY + mapTileSize;
- const bool flag = (layerDrawFlags != MapType::SPECIAL
- && layerDrawFlags != MapType::SPECIAL2
- && layerDrawFlags != MapType::SPECIAL4);
for (int y = startY; y < endY; y++)
{
@@ -228,7 +222,7 @@ void MapLayer::updateSDL(const Graphics *const graphics,
{
const int px = x * mapTileSize + dx;
const int py = py0 - img->mBounds.h;
- if (flag || img->mBounds.h <= mapTileSize)
+ if (mSpecialFlag || img->mBounds.h <= mapTileSize)
{
if (lastImage != img)
{
@@ -248,8 +242,7 @@ void MapLayer::updateSDL(const Graphics *const graphics,
void MapLayer::updateOGL(Graphics *const graphics,
int startX, int startY,
int endX, int endY,
- const int scrollX, const int scrollY,
- const int layerDrawFlags)
+ const int scrollX, const int scrollY)
{
BLOCK_START("MapLayer::updateOGL")
delete_all(mTempRows);
@@ -271,9 +264,6 @@ void MapLayer::updateOGL(Graphics *const graphics,
const int dx = (mX * mapTileSize) - scrollX;
const int dy = (mY * mapTileSize) - scrollY + mapTileSize;
- const bool flag = (layerDrawFlags != MapType::SPECIAL
- && layerDrawFlags != MapType::SPECIAL2
- && layerDrawFlags != MapType::SPECIAL4);
MapRowVertexes *const row = new MapRowVertexes();
mTempRows.push_back(row);
@@ -295,7 +285,7 @@ void MapLayer::updateOGL(Graphics *const graphics,
const int px = x * mapTileSize + dx;
const int py = py0 - img->mBounds.h;
const GLuint imgGlImage = img->mGLImage;
- if (flag || img->mBounds.h <= mapTileSize)
+ if (mSpecialFlag || img->mBounds.h <= mapTileSize)
{
if (!lastImage || lastImage->mGLImage != imgGlImage)
{
@@ -365,7 +355,7 @@ void MapLayer::drawFringe(Graphics *const graphics, int startX, int startY,
int endX, int endY,
const int scrollX, const int scrollY,
const Actors *const actors,
- const int layerDrawFlags, const int yFix) const
+ const int yFix) const
{
BLOCK_START("MapLayer::drawFringe")
if (!localPlayer || !mSpecialLayer || !mTempLayer)
@@ -397,6 +387,10 @@ void MapLayer::drawFringe(Graphics *const graphics, int startX, int startY,
const int specialWidth = mSpecialLayer->mWidth;
const int specialHeight = mSpecialLayer->mHeight;
+ const bool flag = mDrawLayerFlags == MapType::SPECIAL3
+ || mDrawLayerFlags == MapType::SPECIAL4
+ || mDrawLayerFlags == MapType::BLACKWHITE;
+
for (int y = startY; y < endY; y++)
{
const int y32 = y * mapTileSize;
@@ -413,9 +407,7 @@ void MapLayer::drawFringe(Graphics *const graphics, int startX, int startY,
}
BLOCK_END("MapLayer::drawFringe drawmobs")
- if (layerDrawFlags == MapType::SPECIAL3
- || layerDrawFlags == MapType::SPECIAL4
- || layerDrawFlags == MapType::BLACKWHITE)
+ if (flag)
{
if (y < specialHeight)
{
@@ -464,10 +456,7 @@ void MapLayer::drawFringe(Graphics *const graphics, int startX, int startY,
{
const int px = x32 + dx;
const int py = py0 - img->mBounds.h;
- if ((layerDrawFlags != MapType::SPECIAL
- && layerDrawFlags != MapType::SPECIAL2
- && layerDrawFlags != MapType::SPECIAL4)
- || img->mBounds.h <= mapTileSize)
+ if (mSpecialFlag || img->mBounds.h <= mapTileSize)
{
int width = 0;
// here need not draw over player position
@@ -524,8 +513,8 @@ void MapLayer::drawFringe(Graphics *const graphics, int startX, int startY,
}
// Draw any remaining actors
- if (layerDrawFlags != MapType::SPECIAL3
- && layerDrawFlags != MapType::SPECIAL4)
+ if (mDrawLayerFlags != MapType::SPECIAL3
+ && mDrawLayerFlags != MapType::SPECIAL4)
{
BLOCK_START("MapLayer::drawFringe drawmobs")
while (ai != ai_end)
@@ -594,3 +583,11 @@ int MapLayer::getTileDrawWidth(const Image *img,
BLOCK_END("MapLayer::getTileDrawWidth")
return c;
}
+
+void MapLayer::setDrawLayerFlags(const MapType::MapType &n)
+{
+ mDrawLayerFlags = n;
+ mSpecialFlag = (mDrawLayerFlags != MapType::SPECIAL
+ && mDrawLayerFlags != MapType::SPECIAL2
+ && mDrawLayerFlags != MapType::SPECIAL4);
+}
diff --git a/src/resources/map/maplayer.h b/src/resources/map/maplayer.h
index 6eebe5713..d02f4f7b1 100644
--- a/src/resources/map/maplayer.h
+++ b/src/resources/map/maplayer.h
@@ -27,6 +27,8 @@
#include "being/actor.h"
+#include "resources/map/maptype.h"
+
#include <vector>
class Image;
@@ -86,8 +88,7 @@ class MapLayer final: public ConfigListener
*/
void draw(Graphics *const graphics,
int startX, int startY, int endX, int endY,
- const int scrollX, const int scrollY,
- const int layerDrawFlags) const;
+ const int scrollX, const int scrollY) const;
void drawSDL(Graphics *const graphics) const;
@@ -97,22 +98,20 @@ class MapLayer final: public ConfigListener
void updateOGL(Graphics *const graphics,
int startX, int startY,
int endX, int endY,
- const int scrollX, const int scrollY,
- const int layerDrawFlags);
+ const int scrollX, const int scrollY);
#endif
void updateSDL(const Graphics *const graphics,
int startX, int startY,
int endX, int endY,
- const int scrollX, const int scrollY,
- const int layerDrawFlags);
+ const int scrollX, const int scrollY);
void drawFringe(Graphics *const graphics,
int startX, int startY,
int endX, int endY,
const int scrollX, const int scrollY,
const Actors *const actors,
- const int layerDrawFlags, const int yFix) const;
+ const int yFix) const;
bool isFringeLayer() const A_WARN_UNUSED
{ return mIsFringeLayer; }
@@ -131,6 +130,8 @@ class MapLayer final: public ConfigListener
void optionChanged(const std::string &value) override final;
+ void setDrawLayerFlags(const MapType::MapType &n);
+
protected:
static int getTileDrawWidth(const Image *img,
const int endX,
@@ -142,6 +143,7 @@ class MapLayer final: public ConfigListener
const int mWidth;
const int mHeight;
Image **const mTiles;
+ MapType::MapType mDrawLayerFlags;
const SpecialLayer *mSpecialLayer;
const SpecialLayer *mTempLayer;
typedef std::vector<MapRowVertexes*> MapRows;
@@ -149,6 +151,7 @@ class MapLayer final: public ConfigListener
int mMask;
const bool mIsFringeLayer; /**< Whether the actors are drawn. */
bool mHighlightAttackRange;
+ bool mSpecialFlag;
};
#endif // RESOURCES_MAP_MAPLAYER_H