summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-03-14 00:23:01 +0300
committerAndrei Karas <akaras@inbox.ru>2016-03-14 01:32:35 +0300
commit14d7b12e9e3be7534d6c3683fd391eb28f95cd77 (patch)
tree1970a9acb175fb6b0020d7915e14ff56bebf3cd1
parent9e77738e7c8a01e343c060a12f0d9d44a96874ed (diff)
downloadmanaverse-14d7b12e9e3be7534d6c3683fd391eb28f95cd77.tar.gz
manaverse-14d7b12e9e3be7534d6c3683fd391eb28f95cd77.tar.bz2
manaverse-14d7b12e9e3be7534d6c3683fd391eb28f95cd77.tar.xz
manaverse-14d7b12e9e3be7534d6c3683fd391eb28f95cd77.zip
Split drawSprites in Being/CompoundSprite into drawSprites and drawPlayerSprites.
-rw-r--r--src/being/being.cpp59
-rw-r--r--src/being/being.h17
-rw-r--r--src/being/compoundsprite.cpp27
-rw-r--r--src/being/compoundsprite.h12
-rw-r--r--src/being/flooritem.cpp2
5 files changed, 60 insertions, 57 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index f31e45447..101b0ef67 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -71,6 +71,7 @@
#include "resources/emoteinfo.h"
#include "resources/emotesprite.h"
#include "resources/horseinfo.h"
+#include "resources/image.h"
#include "resources/iteminfo.h"
#include "resources/db/avatardb.h"
@@ -211,7 +212,7 @@ Being::Being(const BeingId id,
mX(0),
mY(0),
mSortOffsetY(0),
- mOffsetY(0),
+ mPixelOffsetY(0),
mFixedOffsetY(0),
mOldHeight(0),
mDamageTaken(0),
@@ -1736,7 +1737,7 @@ void Being::nextTile() restrict2
mX = pos.x;
mY = pos.y;
const uint8_t height = mMap->getHeightOffset(mX, mY);
- mOffsetY = height - mOldHeight;
+ mPixelOffsetY = height - mOldHeight;
mFixedOffsetY = height;
mNeedPosUpdate = true;
setAction(BeingAction::MOVE, 0);
@@ -1836,12 +1837,12 @@ void Being::logic() restrict2
mNeedPosUpdate = false;
const int halfTile = mapTileSize / 2;
- const float offset2 = static_cast<float>(mOffsetY * abs(offset)) / 2;
-// mSortOffsetY = (mOldHeight - mFixedOffsetY + mOffsetY)
+ const float offset2 = static_cast<float>(mPixelOffsetY * abs(offset)) / 2;
+// mSortOffsetY = (mOldHeight - mFixedOffsetY + mPixelOffsetY)
// * halfTile - offset2;
mSortOffsetY = 0;
const float yOffset3 = (mY + 1) * mapTileSize + yOffset
- - (mOldHeight + mOffsetY) * halfTile + offset2;
+ - (mOldHeight + mPixelOffsetY) * halfTile + offset2;
// Update pixel coordinates
setPixelPositionF(static_cast<float>(mX * mapTileSize
@@ -2978,9 +2979,9 @@ void Being::draw(Graphics *restrict const graphics,
}
}
-void Being::drawSprites(Graphics *restrict const graphics,
- const int posX,
- const int posY) const restrict2
+void Being::drawPlayerSprites(Graphics *restrict const graphics,
+ const int posX,
+ const int posY) const restrict2
{
const int sz = CompoundSprite::getNumberOfLayers();
for (int f = 0; f < sz; f ++)
@@ -3019,14 +3020,44 @@ void Being::drawBasic(Graphics *restrict const graphics,
const int x,
const int y) const restrict2
{
- CompoundSprite::draw(graphics, x, y);
+ drawCompound(graphics, x, y);
+}
+
+void Being::drawCompound(Graphics *const graphics,
+ const int posX,
+ const int posY) const
+{
+ FUNC_BLOCK("CompoundSprite::draw", 1)
+ if (mNeedsRedraw)
+ updateImages();
+
+ if (mSprites.empty()) // Nothing to draw
+ return;
+
+ if (mAlpha == 1.0F && mImage)
+ {
+ graphics->drawImage(mImage,
+ posX + mOffsetX,
+ posY + mOffsetY);
+ }
+ else if (mAlpha && mAlphaImage)
+ {
+ mAlphaImage->setAlpha(mAlpha);
+ graphics->drawImage(mAlphaImage,
+ posX + mOffsetX,
+ posY + mOffsetY);
+ }
+ else
+ {
+ Being::drawPlayerSprites(graphics, posX, posY);
+ }
}
void Being::drawPlayerSpriteAt(Graphics *restrict const graphics,
const int x,
const int y) const restrict2
{
- CompoundSprite::draw(graphics, x, y);
+ drawCompound(graphics, x, y);
if (mShowOwnHP &&
mInfo &&
@@ -4103,8 +4134,8 @@ void Being::setTileCoords(const int x, const int y) restrict2
mY = y;
if (mMap)
{
- mOffsetY = 0;
- mFixedOffsetY = mOffsetY;
+ mPixelOffsetY = 0;
+ mFixedOffsetY = mPixelOffsetY;
mOldHeight = mMap->getHeightOffset(mX, mY);
mNeedPosUpdate = true;
}
@@ -4115,8 +4146,8 @@ void Being::setMap(Map *restrict const map) restrict2
ActorSprite::setMap(map);
if (mMap)
{
- mOffsetY = mMap->getHeightOffset(mX, mY);
- mFixedOffsetY = mOffsetY;
+ mPixelOffsetY = mMap->getHeightOffset(mX, mY);
+ mFixedOffsetY = mPixelOffsetY;
mOldHeight = 0;
mNeedPosUpdate = true;
}
diff --git a/src/being/being.h b/src/being/being.h
index ba392d385..23c7fd7e0 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -521,10 +521,10 @@ class Being notfinal : public ActorSprite,
void setState(const uint8_t state) restrict2;
- virtual void drawSprites(Graphics *restrict const graphics,
- const int posX,
- const int posY) const
- restrict2 override final A_NONNULL(2);
+ void drawPlayerSprites(Graphics *restrict const graphics,
+ const int posX,
+ const int posY) const
+ restrict2 A_NONNULL(2);
virtual void drawSpritesSDL(Graphics *restrict const graphics,
const int posX,
@@ -1019,6 +1019,10 @@ class Being notfinal : public ActorSprite,
const int x,
const int y) const restrict2 A_NONNULL(2);
+ void drawCompound(Graphics *const graphics,
+ const int posX,
+ const int posY) const A_NONNULL(2);
+
/**
* Updates name's location.
*/
@@ -1166,9 +1170,8 @@ class Being notfinal : public ActorSprite,
int mX; // position in tiles
int mY; // position in tiles
- int mSortOffsetY; // caculated offset in pixels based on mOffsetY
- // +++ need change name for fix conflict with CompoundSprite::mOffsetY
- int mOffsetY; // tile height offset in pixels
+ int mSortOffsetY; // caculated offset in pixels based on mPixelOffsetY
+ int mPixelOffsetY; // tile height offset in pixels
// calculated between tiles
int mFixedOffsetY; // fixed tile height offset in pixels for tile
uint8_t mOldHeight;
diff --git a/src/being/compoundsprite.cpp b/src/being/compoundsprite.cpp
index 2af54f247..af2e60d55 100644
--- a/src/being/compoundsprite.cpp
+++ b/src/being/compoundsprite.cpp
@@ -136,33 +136,6 @@ bool CompoundSprite::update(const int time)
return ret;
}
-void CompoundSprite::draw(Graphics *const graphics,
- const int posX,
- const int posY) const
-{
- FUNC_BLOCK("CompoundSprite::draw", 1)
- if (mNeedsRedraw)
- updateImages();
-
- if (mSprites.empty()) // Nothing to draw
- return;
-
- if (mAlpha == 1.0F && mImage)
- {
- graphics->drawImage(mImage, posX + mOffsetX, posY + mOffsetY);
- }
- else if (mAlpha && mAlphaImage)
- {
- mAlphaImage->setAlpha(mAlpha);
- graphics->drawImage(mAlphaImage,
- posX + mOffsetX, posY + mOffsetY);
- }
- else
- {
- drawSprites(graphics, posX, posY);
- }
-}
-
void CompoundSprite::drawSimple(Graphics *const graphics,
const int posX,
const int posY) const
diff --git a/src/being/compoundsprite.h b/src/being/compoundsprite.h
index a1a0e9742..71a77e87e 100644
--- a/src/being/compoundsprite.h
+++ b/src/being/compoundsprite.h
@@ -50,10 +50,6 @@ class CompoundSprite notfinal : public Sprite
bool update(const int time) override final;
- void draw(Graphics *const graphics,
- const int posX,
- const int posY) const override A_NONNULL(2);
-
void drawSimple(Graphics *const graphics,
const int posX,
const int posY) const A_NONNULL(2);
@@ -89,9 +85,9 @@ class CompoundSprite notfinal : public Sprite
void ensureSize(const size_t layerCount);
- virtual void drawSprites(Graphics *const graphics,
- const int posX,
- const int posY) const;
+ void drawSprites(Graphics *const graphics,
+ const int posX,
+ const int posY) const;
virtual void drawSpritesSDL(Graphics *const graphics,
const int posX,
@@ -112,7 +108,7 @@ class CompoundSprite notfinal : public Sprite
std::vector<Sprite*> mSprites;
- private:
+ protected:
void redraw() const;
void updateImages() const;
diff --git a/src/being/flooritem.cpp b/src/being/flooritem.cpp
index 3dd5e3371..72f30998e 100644
--- a/src/being/flooritem.cpp
+++ b/src/being/flooritem.cpp
@@ -193,7 +193,7 @@ void FloorItem::draw(Graphics *const graphics,
const int px = getActorX() + offsetX;
const int py = getActorY() + offsetY;
- CompoundSprite::draw(graphics, px, py);
+ CompoundSprite::drawSimple(graphics, px, py);
if (mHighlight)
{