summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-26 22:09:03 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-26 23:49:56 +0300
commit91998bfc4631cd305062bf9bedd56083a2b2cbde (patch)
tree68b9924a69d4ee27ae41eb0d5f2ec4af2a86fb4e
parentb0167b595a952e1decc48c239c95c52e1bc057d7 (diff)
downloadmanaplus-91998bfc4631cd305062bf9bedd56083a2b2cbde.tar.gz
manaplus-91998bfc4631cd305062bf9bedd56083a2b2cbde.tar.bz2
manaplus-91998bfc4631cd305062bf9bedd56083a2b2cbde.tar.xz
manaplus-91998bfc4631cd305062bf9bedd56083a2b2cbde.zip
allow load and use mask in ambient layers.
default layer mask is 1.
-rw-r--r--src/map.cpp33
-rw-r--r--src/map.h1
-rw-r--r--src/resources/ambientlayer.cpp14
-rw-r--r--src/resources/ambientlayer.h6
4 files changed, 41 insertions, 13 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 3c0c9f4a4..5188da985 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -281,11 +281,15 @@ void Map::initializeAmbientLayers()
Image *const img = resman->getImage(getProperty(name + "image"));
if (img)
{
+ int mask = atoi(getProperty(name + "mask").c_str());
+ if (!mask)
+ mask = 1;
mForegrounds.push_back(new AmbientLayer(img,
getFloatProperty(name + "parallax"),
getFloatProperty(name + "scrollX"),
getFloatProperty(name + "scrollY"),
- getBoolProperty(name + "keepratio")));
+ getBoolProperty(name + "keepratio"),
+ mask));
// The AmbientLayer takes control over the image.
img->decRef();
@@ -301,11 +305,15 @@ void Map::initializeAmbientLayers()
if (img)
{
+ int mask = atoi(getProperty(name + "mask").c_str());
+ if (!mask)
+ mask = 1;
mBackgrounds.push_back(new AmbientLayer(img,
getFloatProperty(name + "parallax"),
getFloatProperty(name + "scrollX"),
getFloatProperty(name + "scrollY"),
- getBoolProperty(name + "keepratio")));
+ getBoolProperty(name + "keepratio"),
+ mask));
// The AmbientLayer takes control over the image.
img->decRef();
@@ -603,11 +611,19 @@ void Map::updateAmbientLayers(const float scrollX, const float scrollY)
// need check mask to update or not to update
- FOR_EACH (AmbientLayerVectorCIter, i, mBackgrounds)
- (*i)->update(timePassed, dx, dy);
+ FOR_EACH (AmbientLayerVectorIter, i, mBackgrounds)
+ {
+ AmbientLayer *const layer = *i;
+ if (layer && (layer->mMask & mMask))
+ layer->update(timePassed, dx, dy);
+ }
- FOR_EACH (AmbientLayerVectorCIter, i, mForegrounds)
- (*i)->update(timePassed, dx, dy);
+ FOR_EACH (AmbientLayerVectorIter, i, mForegrounds)
+ {
+ AmbientLayer *const layer = *i;
+ if (layer && (layer->mMask & mMask))
+ layer->update(timePassed, dx, dy);
+ }
mLastAScrollX = scrollX;
mLastAScrollY = scrollY;
@@ -643,9 +659,10 @@ void Map::drawAmbientLayers(Graphics *const graphics, const LayerType type,
// Draw overlays
FOR_EACHP (AmbientLayerVectorCIter, i, layers)
{
+ const AmbientLayer *const layer = *i;
// need check mask to draw or not to draw
- if (*i)
- (*i)->draw(graphics, graphics->mWidth, graphics->mHeight);
+ if (layer && (layer->mMask & mMask))
+ (layer)->draw(graphics, graphics->mWidth, graphics->mHeight);
// Detail 1: only one overlay, higher: all overlays
if (detail == 1)
diff --git a/src/map.h b/src/map.h
index 49662c919..068a41458 100644
--- a/src/map.h
+++ b/src/map.h
@@ -57,6 +57,7 @@ typedef TilePairVector::const_iterator TilePairVectorCIter;
typedef std::vector<AmbientLayer*> AmbientLayerVector;
typedef AmbientLayerVector::const_iterator AmbientLayerVectorCIter;
+typedef AmbientLayerVector::iterator AmbientLayerVectorIter;
static const int mapTileSize = 32;
diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp
index 6814b0365..cc9ebdaec 100644
--- a/src/resources/ambientlayer.cpp
+++ b/src/resources/ambientlayer.cpp
@@ -21,6 +21,8 @@
#include "resources/ambientlayer.h"
+#include "map.h"
+
#include "render/graphics.h"
#include "resources/image.h"
@@ -31,10 +33,14 @@
AmbientLayer::AmbientLayer(Image *const img, const float parallax,
const float speedX, const float speedY,
- const bool keepRatio) :
- mImage(img), mParallax(parallax),
- mPosX(0), mPosY(0),
- mSpeedX(speedX), mSpeedY(speedY),
+ const bool keepRatio, int mask) :
+ mImage(img),
+ mParallax(parallax),
+ mPosX(0),
+ mPosY(0),
+ mSpeedX(speedX),
+ mSpeedY(speedY),
+ mMask(mask),
mKeepRatio(keepRatio)
{
if (!mImage)
diff --git a/src/resources/ambientlayer.h b/src/resources/ambientlayer.h
index 18bbfb69a..1ab54fd9f 100644
--- a/src/resources/ambientlayer.h
+++ b/src/resources/ambientlayer.h
@@ -26,10 +26,13 @@
class Graphics;
class Image;
+class Map;
class AmbientLayer final
{
public:
+ friend Map;
+
/**
* Constructor.
*
@@ -42,7 +45,7 @@ class AmbientLayer final
*/
AmbientLayer(Image *const img, const float parallax,
const float speedX, const float speedY,
- const bool keepRatio = false);
+ const bool keepRatio, int mask);
A_DELETE_COPY(AmbientLayer)
@@ -59,6 +62,7 @@ class AmbientLayer final
float mPosY; /**< Current layer Y position. */
float mSpeedX; /**< Scrolling speed in X direction. */
float mSpeedY; /**< Scrolling speed in Y direction. */
+ int mMask;
bool mKeepRatio; /**< Keep overlay ratio on every resolution */
};