summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mana.cbp3
-rw-r--r--mana.files95
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/Makefile.am3
-rw-r--r--src/actor.cpp59
-rw-r--r--src/actor.h131
-rw-r--r--src/being.cpp16
-rw-r--r--src/being.h45
-rw-r--r--src/flooritem.cpp19
-rw-r--r--src/flooritem.h44
-rw-r--r--src/flooritemmanager.cpp2
-rw-r--r--src/localplayer.cpp10
-rw-r--r--src/map.cpp59
-rw-r--r--src/map.h40
-rw-r--r--src/particle.cpp15
-rw-r--r--src/particle.h46
-rw-r--r--src/sprite.h85
17 files changed, 317 insertions, 358 deletions
diff --git a/mana.cbp b/mana.cbp
index 3d3b85e0..021e15cc 100644
--- a/mana.cbp
+++ b/mana.cbp
@@ -94,6 +94,8 @@
</Linker>
<Unit filename="src\SDLMain.h" />
<Unit filename="src\SDLMain.m" />
+ <Unit filename="src\actor.cpp" />
+ <Unit filename="src\actor.h" />
<Unit filename="src\animatedsprite.cpp" />
<Unit filename="src\animatedsprite.h" />
<Unit filename="src\animationparticle.cpp" />
@@ -559,7 +561,6 @@
<Unit filename="src\simpleanimation.h" />
<Unit filename="src\sound.cpp" />
<Unit filename="src\sound.h" />
- <Unit filename="src\sprite.h" />
<Unit filename="src\statuseffect.cpp" />
<Unit filename="src\statuseffect.h" />
<Unit filename="src\text.cpp" />
diff --git a/mana.files b/mana.files
index 552ab8a6..f95cd3a9 100644
--- a/mana.files
+++ b/mana.files
@@ -38,6 +38,8 @@
./Makefile.am
./packaging/windows/readme.txt
./po/CMakeLists.txt
+./src/actor.cpp
+./src/actor.h
./src/animatedsprite.cpp
./src/animatedsprite.h
./src/animationparticle.cpp
@@ -310,52 +312,6 @@
./src/net/chathandler.h
./src/net/download.cpp
./src/net/download.h
-./src/net/tmwa/adminhandler.cpp
-./src/net/tmwa/adminhandler.h
-./src/net/tmwa/beinghandler.cpp
-./src/net/tmwa/beinghandler.h
-./src/net/tmwa/buysellhandler.cpp
-./src/net/tmwa/buysellhandler.h
-./src/net/tmwa/charserverhandler.cpp
-./src/net/tmwa/charserverhandler.h
-./src/net/tmwa/chathandler.cpp
-./src/net/tmwa/chathandler.h
-./src/net/tmwa/gamehandler.cpp
-./src/net/tmwa/gamehandler.h
-./src/net/tmwa/generalhandler.cpp
-./src/net/tmwa/generalhandler.h
-./src/net/tmwa/gui/guildtab.cpp
-./src/net/tmwa/gui/guildtab.h
-./src/net/tmwa/guildhandler.cpp
-./src/net/tmwa/guildhandler.h
-./src/net/tmwa/gui/partytab.cpp
-./src/net/tmwa/gui/partytab.h
-./src/net/tmwa/inventoryhandler.cpp
-./src/net/tmwa/inventoryhandler.h
-./src/net/tmwa/itemhandler.cpp
-./src/net/tmwa/itemhandler.h
-./src/net/tmwa/loginhandler.cpp
-./src/net/tmwa/loginhandler.h
-./src/net/tmwa/messagehandler.cpp
-./src/net/tmwa/messagehandler.h
-./src/net/tmwa/messagein.cpp
-./src/net/tmwa/messagein.h
-./src/net/tmwa/messageout.cpp
-./src/net/tmwa/messageout.h
-./src/net/tmwa/network.cpp
-./src/net/tmwa/network.h
-./src/net/tmwa/npchandler.cpp
-./src/net/tmwa/npchandler.h
-./src/net/tmwa/partyhandler.cpp
-./src/net/tmwa/partyhandler.h
-./src/net/tmwa/playerhandler.cpp
-./src/net/tmwa/playerhandler.h
-./src/net/tmwa/protocol.h
-./src/net/tmwa/specialhandler.cpp
-./src/net/tmwa/specialhandler.h
-./src/net/tmwa/token.h
-./src/net/tmwa/tradehandler.cpp
-./src/net/tmwa/tradehandler.h
./src/net/gamehandler.h
./src/net/generalhandler.h
./src/net/guildhandler.h
@@ -421,6 +377,52 @@
./src/net/playerhandler.h
./src/net/serverinfo.h
./src/net/specialhandler.h
+./src/net/tmwa/adminhandler.cpp
+./src/net/tmwa/adminhandler.h
+./src/net/tmwa/beinghandler.cpp
+./src/net/tmwa/beinghandler.h
+./src/net/tmwa/buysellhandler.cpp
+./src/net/tmwa/buysellhandler.h
+./src/net/tmwa/charserverhandler.cpp
+./src/net/tmwa/charserverhandler.h
+./src/net/tmwa/chathandler.cpp
+./src/net/tmwa/chathandler.h
+./src/net/tmwa/gamehandler.cpp
+./src/net/tmwa/gamehandler.h
+./src/net/tmwa/generalhandler.cpp
+./src/net/tmwa/generalhandler.h
+./src/net/tmwa/gui/guildtab.cpp
+./src/net/tmwa/gui/guildtab.h
+./src/net/tmwa/guildhandler.cpp
+./src/net/tmwa/guildhandler.h
+./src/net/tmwa/gui/partytab.cpp
+./src/net/tmwa/gui/partytab.h
+./src/net/tmwa/inventoryhandler.cpp
+./src/net/tmwa/inventoryhandler.h
+./src/net/tmwa/itemhandler.cpp
+./src/net/tmwa/itemhandler.h
+./src/net/tmwa/loginhandler.cpp
+./src/net/tmwa/loginhandler.h
+./src/net/tmwa/messagehandler.cpp
+./src/net/tmwa/messagehandler.h
+./src/net/tmwa/messagein.cpp
+./src/net/tmwa/messagein.h
+./src/net/tmwa/messageout.cpp
+./src/net/tmwa/messageout.h
+./src/net/tmwa/network.cpp
+./src/net/tmwa/network.h
+./src/net/tmwa/npchandler.cpp
+./src/net/tmwa/npchandler.h
+./src/net/tmwa/partyhandler.cpp
+./src/net/tmwa/partyhandler.h
+./src/net/tmwa/playerhandler.cpp
+./src/net/tmwa/playerhandler.h
+./src/net/tmwa/protocol.h
+./src/net/tmwa/specialhandler.cpp
+./src/net/tmwa/specialhandler.h
+./src/net/tmwa/token.h
+./src/net/tmwa/tradehandler.cpp
+./src/net/tmwa/tradehandler.h
./src/net/tradehandler.h
./src/net/worldinfo.h
./src/npc.cpp
@@ -498,7 +500,6 @@
./src/simpleanimation.h
./src/sound.cpp
./src/sound.h
-./src/sprite.h
./src/statuseffect.cpp
./src/statuseffect.h
./src/text.cpp
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 02a08bfe..3c9e6e82 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -400,6 +400,8 @@ SET(SRCS
utils/mkdir.h
utils/xml.cpp
utils/xml.h
+ actor.cpp
+ actor.h
animatedsprite.cpp
animatedsprite.h
animationparticle.cpp
@@ -487,7 +489,6 @@ SET(SRCS
simpleanimation.h
sound.cpp
sound.h
- sprite.h
statuseffect.cpp
statuseffect.h
text.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 9748dd67..e46be7f5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -301,6 +301,8 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \
utils/mutex.h \
utils/xml.cpp \
utils/xml.h \
+ actor.cpp \
+ actor.h \
animatedsprite.cpp \
animatedsprite.h \
animationparticle.cpp \
@@ -388,7 +390,6 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \
simpleanimation.h \
sound.cpp \
sound.h \
- sprite.h \
statuseffect.cpp \
statuseffect.h \
text.cpp \
diff --git a/src/actor.cpp b/src/actor.cpp
new file mode 100644
index 00000000..4fdce5f1
--- /dev/null
+++ b/src/actor.cpp
@@ -0,0 +1,59 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2010 The Mana Developers
+ *
+ * This file is part of The Mana 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 "actor.h"
+
+#include "map.h"
+
+#include "resources/image.h"
+#include "resources/resourcemanager.h"
+
+Actor::Actor():
+ mMap(NULL),
+ mAlpha(1.0f)
+{}
+
+Actor::~Actor()
+{
+ setMap(NULL);
+}
+
+void Actor::setMap(Map *map)
+{
+ // Remove Actor from potential previous map
+ if (mMap)
+ mMap->removeActor(mMapActor);
+
+ mMap = map;
+
+ // Add Actor to potential new map
+ if (mMap)
+ mMapActor = mMap->addActor(this);
+}
+
+int Actor::getTileX() const
+{
+ return getPixelX() / mMap->getTileWidth();
+}
+
+int Actor::getTileY() const
+{
+ return getPixelY() / mMap->getTileHeight();
+}
diff --git a/src/actor.h b/src/actor.h
new file mode 100644
index 00000000..59e29b88
--- /dev/null
+++ b/src/actor.h
@@ -0,0 +1,131 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2010 The Mana Developers
+ *
+ * This file is part of The Mana 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 ACTOR_H
+#define ACTOR_H
+
+#include "vector.h"
+
+#include <list>
+
+class Actor;
+class Graphics;
+class Image;
+class Map;
+
+typedef std::list<Actor*> Actors;
+
+class Actor
+{
+public:
+ Actor();
+
+ virtual ~Actor();
+
+ /**
+ * Draws the Actor to the given graphics context.
+ *
+ * Note: this function could be simplified if the graphics context
+ * would support setting a translation offset. It already does this
+ * partly with the clipping rectangle support.
+ */
+ virtual void draw(Graphics *graphics, int offsetX, int offsetY) const = 0;
+
+ /**
+ * Returns the horizontal size of the actors graphical representation
+ * in pixels or 0 when it is undefined.
+ */
+ virtual int getWidth() const
+ { return 0; }
+
+ /**
+ * Returns the vertical size of the actors graphical representation
+ * in pixels or 0 when it is undefined.
+ */
+ virtual int getHeight() const
+ { return 0; }
+
+ /**
+ * Returns the pixel position of this actor.
+ */
+ const Vector &getPosition() const
+ { return mPos; }
+
+ /**
+ * Sets the pixel position of this actor.
+ */
+ virtual void setPosition(const Vector &pos)
+ { mPos = pos; }
+
+ /**
+ * Returns the pixels X coordinate of the actor.
+ */
+ int getPixelX() const
+ { return (int) mPos.x; }
+
+ /**
+ * Returns the pixel Y coordinate of the actor.
+ */
+ virtual int getPixelY() const
+ { return (int) mPos.y; }
+
+ /**
+ * Returns the x coordinate in tiles of the actor.
+ */
+ virtual int getTileX() const;
+
+ /**
+ * Returns the y coordinate in tiles of the actor.
+ */
+ virtual int getTileY() const;
+
+ /**
+ * Returns the number of Image layers used to draw the actor.
+ */
+ virtual int getNumberOfLayers() const
+ { return 0; }
+
+ /**
+ * Returns the current alpha value used to draw the actor.
+ */
+ virtual float getAlpha() const
+ { return mAlpha; }
+
+ /**
+ * Sets the alpha value used to draw the actor.
+ */
+ virtual void setAlpha(float alpha)
+ { mAlpha = alpha; }
+
+ void setMap(Map *map);
+
+ Map* getMap() const
+ { return mMap; }
+
+protected:
+ Map *mMap;
+ Vector mPos; /**< Position in pixels relative to map. */
+ float mAlpha;
+
+private:
+ Actors::iterator mMapActor;
+};
+
+#endif // ACTOR_H
diff --git a/src/being.cpp b/src/being.cpp
index 5c737c0c..40a6befd 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -78,13 +78,11 @@ Being::Being(int id, int subtype, Map *map):
mId(id),
mDirection(DOWN),
mSpriteDirection(DIRECTION_DOWN),
- mMap(NULL),
mDispName(0),
mShowName(false),
mEquippedWeapon(NULL),
mText(0),
mStunMode(0),
- mAlpha(1.0f),
mStatusParticleEffects(&mStunParticleEffects, false),
mChildParticleEffects(&mStatusParticleEffects, false),
mMustResetParticles(false),
@@ -109,8 +107,6 @@ Being::~Being()
if (player_node && player_node->getTarget() == this)
player_node->setTarget(NULL);
- setMap(NULL);
-
delete mSpeechBubble;
delete mDispName;
delete mText;
@@ -118,7 +114,7 @@ Being::~Being()
void Being::setPosition(const Vector &pos)
{
- mPos = pos;
+ Actor::setPosition(pos);
updateCoords();
@@ -362,15 +358,7 @@ void Being::setGuildPos(const std::string &pos)
void Being::setMap(Map *map)
{
- // Remove sprite from potential previous map
- if (mMap)
- mMap->removeSprite(mMapSprite);
-
- mMap = map;
-
- // Add sprite to potential new map
- if (mMap)
- mMapSprite = mMap->addSprite(this);
+ Actor::setMap(map);
// Clear particle effect list because child particles became invalid
mChildParticleEffects.clear();
diff --git a/src/being.h b/src/being.h
index 3d3dfa71..6264d56d 100644
--- a/src/being.h
+++ b/src/being.h
@@ -26,7 +26,6 @@
#include "map.h"
#include "particlecontainer.h"
#include "position.h"
-#include "sprite.h"
#include "vector.h"
#include "resources/spritedef.h"
@@ -59,7 +58,7 @@ class Text;
class StatusEffect;
-class Being : public Sprite, public ConfigListener
+class Being : public Actor, public ConfigListener
{
public:
enum Type
@@ -373,7 +372,7 @@ class Being : public Sprite, public ConfigListener
/**
* Draws this being to the given graphics context.
*
- * @see Sprite::draw(Graphics, int, int)
+ * @see Actor::draw(Graphics, int, int)
*
* TODO: The following two functions should be combined.
* at some point draw(), was changed to use mPx and mPy, with arugements
@@ -385,35 +384,6 @@ class Being : public Sprite, public ConfigListener
virtual void drawSpriteAt(Graphics *graphics, int x, int y) const;
- /**
- * Set the alpha opacity used to draw the being.
- */
- virtual void setAlpha(float alpha)
- { mAlpha = alpha; }
-
- /**
- * Returns the current alpha opacity of the Being.
- */
- virtual float getAlpha() const
- { return mAlpha; }
-
- /**
- * Returns the X coordinate in pixels.
- */
- int getPixelX() const
- { return (int) mPos.x; }
-
- /**
- * Returns the Y coordinate in pixels.
- *
- * @see Sprite::getPixelY()
- */
- int getPixelY() const
- { return (int) mPos.y; }
-
- /**
- * Sets the position of this being.
- */
void setPosition(const Vector &pos);
/**
@@ -421,17 +391,12 @@ class Being : public Sprite, public ConfigListener
*
* @see setPosition(const Vector &pos)
*/
- void setPosition(float x, float y, float z = 0.0f)
+ inline void setPosition(float x, float y, float z = 0.0f)
{
setPosition(Vector(x, y, z));
}
/**
- * Returns the position of this being.
- */
- const Vector &getPosition() const { return mPos; }
-
- /**
* Returns the horizontal size of the current base sprite of the being.
*/
virtual int getWidth() const;
@@ -616,10 +581,8 @@ class Being : public Sprite, public ConfigListener
int mId; /**< Unique sprite id */
Uint8 mDirection; /**< Facing direction */
Uint8 mSpriteDirection; /**< Facing direction */
- Map *mMap; /**< Map on which this being resides */
std::string mName; /**< Name of character */
std::string mPartyName;
- MapSprite mMapSprite;
/**
* Holds a text object when the being displays it's name, 0 otherwise
@@ -644,7 +607,6 @@ class Being : public Sprite, public ConfigListener
typedef Sprites::iterator SpriteIterator;
typedef Sprites::const_iterator SpriteConstIterator;
Sprites mSprites;
- float mAlpha; /**< Alpha opacity to draw the sprite */
ParticleList mStunParticleEffects;
ParticleVector mStatusParticleEffects;
@@ -675,7 +637,6 @@ class Being : public Sprite, public ConfigListener
*/
Vector mWalkSpeed;
- Vector mPos; /**< Position coordinates. */
int mX, mY; /**< Position in tile */
int mDamageTaken;
diff --git a/src/flooritem.cpp b/src/flooritem.cpp
index c3442a86..e5a9d215 100644
--- a/src/flooritem.cpp
+++ b/src/flooritem.cpp
@@ -32,24 +32,17 @@ FloorItem::FloorItem(int id,
int x,
int y,
Map *map):
- mId(id),
- mX(x),
- mY(y),
- mMap(map),
- mAlpha(1.0f)
+ mId(id)
{
+ setMap(map);
+ mPos.x = x * map->getTileWidth();
+ mPos.y = y * map->getTileHeight();
// Create a corresponding item instance
mItem = new Item(itemId);
-
- // Add ourselves to the map
- mMapSprite = mMap->addSprite(this);
}
FloorItem::~FloorItem()
{
- // Remove ourselves from the map
- mMap->removeSprite(mMapSprite);
-
delete mItem;
}
@@ -73,7 +66,7 @@ void FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const
if (mAlpha != image->getAlpha())
image->setAlpha(mAlpha);
- graphics->drawImage(image, mX * mMap->getTileWidth() + offsetX,
- mY * mMap->getTileHeight() + offsetY);
+ graphics->drawImage(image, getPixelX() + offsetX,
+ getPixelY() + offsetY);
}
}
diff --git a/src/flooritem.h b/src/flooritem.h
index ec8c37cd..17b7b54d 100644
--- a/src/flooritem.h
+++ b/src/flooritem.h
@@ -23,9 +23,6 @@
#define FLOORITEM_H
#include "map.h"
-#include "sprite.h"
-
-#include <list>
class Graphics;
class Image;
@@ -34,7 +31,7 @@ class Item;
/**
* An item lying on the floor.
*/
-class FloorItem : public Sprite
+class FloorItem : public Actor
{
public:
/**
@@ -57,7 +54,8 @@ class FloorItem : public Sprite
/**
* Returns instance ID of this item.
*/
- int getId() const { return mId; }
+ int getId() const
+ { return mId; }
/**
* Returns the item ID.
@@ -71,53 +69,19 @@ class FloorItem : public Sprite
Item *getItem() const;
/**
- * Returns the x coordinate in tiles.
- */
- int getX() const { return mX; }
-
- /**
- * Returns the y coordinate in tiles.
- */
- int getY() const { return mY; }
-
- /**
- * Returns the pixel y coordinate.
- *
- * @see Sprite::getPixelY()
- */
- int getPixelY() const
- { return mY * mMap->getTileHeight() + mMap->getTileHeight() / 2; }
-
- /**
* Draws this floor item to the given graphics context.
*
- * @see Sprite::draw(Graphics, int, int)
+ * @see Actor::draw(Graphics, int, int)
*/
void draw(Graphics *graphics, int offsetX, int offsetY) const;
- /**
- * Sets the alpha value of the floor item
- */
- void setAlpha(float alpha)
- { mAlpha = alpha; }
-
- /**
- * Returns the current alpha opacity of the floor item.
- */
- virtual float getAlpha() const
- { return mAlpha; }
-
/** We consider flooritems (at least for now) to be one layer-sprites */
virtual int getNumberOfLayers() const
{ return 1; }
private:
int mId;
- int mX, mY;
Item *mItem;
- MapSprite mMapSprite;
- Map *mMap;
- float mAlpha;
};
#endif
diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp
index a190a168..9115b704 100644
--- a/src/flooritemmanager.cpp
+++ b/src/flooritemmanager.cpp
@@ -70,7 +70,7 @@ FloorItem *FloorItemManager::findByCoordinates(int x, int y) const
FloorItems::const_iterator i;
for (i = mFloorItems.begin(); i != mFloorItems.end(); i++)
{
- if ((*i)->getX() == x && (*i)->getY() == y)
+ if ((*i)->getTileX() == x && (*i)->getTileY() == y)
{
return *i;
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 9729f55d..19ddec51 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -704,8 +704,8 @@ void LocalPlayer::setInvItem(int index, int id, int amount)
void LocalPlayer::pickUp(FloorItem *item)
{
- int dx = item->getX() - (int) getPosition().x / 32;
- int dy = item->getY() - (int) getPosition().y / 32;
+ int dx = item->getTileX() - (int) getPosition().x / 32;
+ int dy = item->getTileY() - (int) getPosition().y / 32;
if (dx * dx + dy * dy < 4)
{
@@ -716,12 +716,12 @@ void LocalPlayer::pickUp(FloorItem *item)
{
if (Net::getNetworkType() == ServerInfo::MANASERV)
{
- setDestination(item->getX() * 32 + 16, item->getY() * 32 + 16);
+ setDestination(item->getPixelX() + 16, item->getPixelY() + 16);
mPickUpTarget = item;
}
else
{
- setDestination(item->getX(), item->getY());
+ setDestination(item->getTileX(), item->getTileY());
mPickUpTarget = item;
stopAttack();
}
@@ -1480,4 +1480,4 @@ void AwayListener::action(const gcn::ActionEvent &event)
{
player_node->changeAwayMode();
}
-} \ No newline at end of file
+}
diff --git a/src/map.cpp b/src/map.cpp
index 7ee18450..0c23aeb4 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -27,7 +27,6 @@
#include "graphics.h"
#include "particle.h"
#include "simpleanimation.h"
-#include "sprite.h"
#include "tileset.h"
#include "resources/ambientlayer.h"
@@ -122,7 +121,7 @@ Image* MapLayer::getTile(int x, int y) const
void MapLayer::draw(Graphics *graphics, int startX, int startY,
int endX, int endY, int scrollX, int scrollY,
- const MapSprites &sprites, int debugFlags) const
+ const Actors &actors, int debugFlags) const
{
startX -= mX;
startY -= mY;
@@ -134,19 +133,19 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY,
if (endX > mWidth) endX = mWidth;
if (endY > mHeight) endY = mHeight;
- MapSprites::const_iterator si = sprites.begin();
+ Actors::const_iterator ai = actors.begin();
for (int y = startY; y < endY; y++)
{
- // If drawing the fringe layer, make sure all sprites above this row of
+ // If drawing the fringe layer, make sure all actors above this row of
// tiles have been drawn
if (mIsFringeLayer)
{
- while (si != sprites.end() && (*si)->getPixelY() <= y * 32)
+ while (ai != actors.end() && (*ai)->getPixelY() <= y * 32)
{
- (*si)->setAlpha(1.0f);
- (*si)->draw(graphics, -scrollX, -scrollY);
- si++;
+ (*ai)->setAlpha(1.0f);
+ (*ai)->draw(graphics, -scrollX, -scrollY);
+ ai++;
}
}
@@ -163,14 +162,14 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY,
}
}
- // Draw any remaining sprites
+ // Draw any remaining actors
if (mIsFringeLayer)
{
- while (si != sprites.end())
+ while (ai != actors.end())
{
- (*si)->setAlpha(1.0f);
- (*si)->draw(graphics, -scrollX, -scrollY);
- si++;
+ (*ai)->setAlpha(1.0f);
+ (*ai)->draw(graphics, -scrollX, -scrollY);
+ ai++;
}
}
}
@@ -283,7 +282,7 @@ void Map::addTileset(Tileset *tileset)
mMaxTileHeight = tileset->getHeight();
}
-bool spriteCompare(const Sprite *a, const Sprite *b)
+bool actorCompare(const Actor *a, const Actor *b)
{
return a->getPixelY() < b->getPixelY();
}
@@ -309,9 +308,9 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY)
int endX = (graphics->getWidth() + scrollX + mTileWidth - 1) / mTileWidth;
int endY = endPixelY / mTileHeight;
- // Make sure sprites are sorted ascending by Y-coordinate
+ // Make sure actors are sorted ascending by Y-coordinate
// so that they overlap correctly
- mSprites.sort(spriteCompare);
+ mActors.sort(actorCompare);
// update scrolling of all ambient layers
updateAmbientLayers(scrollX, scrollY);
@@ -327,24 +326,24 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY)
(*layeri)->draw(graphics,
startX, startY, endX, endY,
scrollX, scrollY,
- mSprites, mDebugFlags);
+ mActors, mDebugFlags);
}
// Draws beings with a lower opacity to make them visible
// even when covered by a wall or some other elements...
- MapSprites::const_iterator si = mSprites.begin();
- while (si != mSprites.end())
+ Actors::const_iterator ai = mActors.begin();
+ while (ai != mActors.end())
{
- if (Sprite *sprite = *si)
+ if (Actor *actor = *ai)
{
- // For now, just draw sprites with only one layer.
- if (sprite->getNumberOfLayers() == 1)
+ // For now, just draw actors with only one layer.
+ if (actor->getNumberOfLayers() == 1)
{
- sprite->setAlpha(0.3f);
- sprite->draw(graphics, -scrollX, -scrollY);
+ actor->setAlpha(0.3f);
+ actor->draw(graphics, -scrollX, -scrollY);
}
}
- si++;
+ ai++;
}
drawAmbientLayers(graphics, FOREGROUND_LAYERS, scrollX, scrollY,
@@ -556,15 +555,15 @@ MetaTile *Map::getMetaTile(int x, int y) const
return &mMetaTiles[x + y * mWidth];
}
-MapSprite Map::addSprite(Sprite *sprite)
+Actors::iterator Map::addActor(Actor *actor)
{
- mSprites.push_front(sprite);
- return mSprites.begin();
+ mActors.push_front(actor);
+ return mActors.begin();
}
-void Map::removeSprite(MapSprite iterator)
+void Map::removeActor(Actors::iterator iterator)
{
- mSprites.erase(iterator);
+ mActors.erase(iterator);
}
const std::string Map::getMusicFile() const
diff --git a/src/map.h b/src/map.h
index 0832df93..19d42b02 100644
--- a/src/map.h
+++ b/src/map.h
@@ -22,6 +22,7 @@
#ifndef MAP_H
#define MAP_H
+#include "actor.h"
#include "position.h"
#include "properties.h"
@@ -31,16 +32,12 @@
class Animation;
class AmbientLayer;
class Graphics;
-class Image;
class MapLayer;
class Particle;
class SimpleAnimation;
-class Sprite;
class Tileset;
typedef std::vector<Tileset*> Tilesets;
-typedef std::list<Sprite*> MapSprites;
-typedef MapSprites::iterator MapSprite;
typedef std::vector<MapLayer*> Layers;
/**
@@ -91,7 +88,7 @@ class MapLayer
public:
/**
* Constructor, taking layer origin, size and whether this layer is the
- * fringe layer. The fringe layer is the layer that draws the sprites.
+ * fringe layer. The fringe layer is the layer that draws the actors.
* There can be only one fringe layer per map.
*/
MapLayer(int x, int y, int width, int height, bool isFringeLayer);
@@ -121,20 +118,20 @@ class MapLayer
* expected to be in map range and will be translated to local layer
* coordinates and clipped to the layer's dimensions.
*
- * The given sprites are only drawn when this layer is the fringe
+ * The given actors are only drawn when this layer is the fringe
* layer.
*/
void draw(Graphics *graphics,
int startX, int startY,
int endX, int endY,
int scrollX, int scrollY,
- const MapSprites &sprites,
+ const Actors &actors,
int mDebugFlags) const;
private:
int mX, mY;
int mWidth, mHeight;
- bool mIsFringeLayer; /**< Whether the sprites are drawn. */
+ bool mIsFringeLayer; /**< Whether the actors are drawn. */
Image **mTiles;
};
@@ -190,7 +187,7 @@ class Map : public Properties
/**
* Draws the map to the given graphics output. This method draws all
- * layers, sprites and overlay effects.
+ * layers, actors and overlay effects.
*
* TODO: For efficiency reasons, this method could take into account
* the clipping rectangle set on the Graphics object. However,
@@ -295,16 +292,6 @@ class Map : public Properties
unsigned char walkmask, int maxCost = 20);
/**
- * Adds a sprite to the map.
- */
- MapSprite addSprite(Sprite *sprite);
-
- /**
- * Removes a sprite from the map.
- */
- void removeSprite(MapSprite iterator);
-
- /**
* Adds a particle effect
*/
void addParticleEffect(const std::string &effectFile, int x, int y, int w = 0, int h = 0);
@@ -329,6 +316,19 @@ class Map : public Properties
*/
TileAnimation *getAnimationForGid(int gid) const;
+ protected:
+ friend class Actor;
+
+ /**
+ * Adds an actor to the map.
+ */
+ Actors::iterator addActor(Actor *actor);
+
+ /**
+ * Removes an actor from the map.
+ */
+ void removeActor(Actors::iterator iterator);
+
private:
enum LayerType
@@ -364,7 +364,7 @@ class Map : public Properties
MetaTile *mMetaTiles;
Layers mLayers;
Tilesets mTilesets;
- MapSprites mSprites;
+ Actors mActors;
// debug flags
int mDebugFlags;
diff --git a/src/particle.cpp b/src/particle.cpp
index 84161c9f..398e6a9c 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -61,9 +61,7 @@ Particle::Particle(Map *map):
mLifetimePast(0),
mFadeOut(0),
mFadeIn(0),
- mAlpha(1.0f),
mAutoDelete(true),
- mMap(map),
mAllowSizeAdjust(false),
mGravity(0.0f),
mRandomness(0),
@@ -74,16 +72,12 @@ Particle::Particle(Map *map):
mInvDieDistance(-1.0f),
mMomentum(1.0f)
{
+ setMap(map);
Particle::particleCount++;
- if (mMap)
- setSpriteIterator(mMap->addSprite(this));
}
Particle::~Particle()
{
- // Remove from map sprite list
- if (mMap)
- mMap->removeSprite(mSpriteIterator);
// Delete child emitters and child particles
clear();
Particle::particleCount--;
@@ -393,13 +387,6 @@ void Particle::adjustEmitterSize(int w, int h)
}
}
-void Particle::setMap(Map *map)
-{
- mMap = map;
- if (mMap)
- setSpriteIterator(mMap->addSprite(this));
-}
-
void Particle::clear()
{
delete_all(mChildEmitters);
diff --git a/src/particle.h b/src/particle.h
index 0690e8c4..64221514 100644
--- a/src/particle.h
+++ b/src/particle.h
@@ -22,8 +22,8 @@
#ifndef PARTICLE_H
#define PARTICLE_H
+#include "actor.h"
#include "guichanfwd.h"
-#include "sprite.h"
#include "vector.h"
#include <list>
@@ -41,7 +41,7 @@ typedef Emitters::iterator EmitterIterator;
/**
* A particle spawned by a ParticleEmitter.
*/
-class Particle : public Sprite
+class Particle : public Actor
{
public:
static const float PARTICLE_SKY; /**< Maximum Z position of particles */
@@ -92,12 +92,6 @@ class Particle : public Sprite
{ return (int) (mPos.y + mPos.z) - 64; }
/**
- * Sets the map the particle is on.
- */
- void setMap(Map *map);
-
-
- /**
* Creates a blank particle as a child of the current particle
* Useful for creating target particles
*/
@@ -142,12 +136,6 @@ class Particle : public Sprite
void moveTo(float x, float y);
/**
- * Returns the particle position.
- */
- const Vector& getPosition() const
- { return mPos; }
-
- /**
* Changes the particle position relative
*/
void moveBy (const Vector &change);
@@ -173,32 +161,6 @@ class Particle : public Sprite
{ mFadeIn = fadeIn; }
/**
- * Sets the alpha value of the particle
- */
- void setAlpha(float alpha)
- { mAlpha = alpha; }
-
- /**
- * Returns the current alpha opacity of the particle.
- */
- virtual float getAlpha() const
- { return mAlpha; }
-
- /**
- * Sets the sprite iterator of the particle on the current map to make
- * it easier to remove the particle from the map when it is destroyed.
- */
- void setSpriteIterator(std::list<Sprite*>::iterator spriteIterator)
- { mSpriteIterator = spriteIterator; }
-
- /**
- * Gets the sprite iterator of the particle on the current map.
- */
- std::list<Sprite*>::iterator
- getSpriteIterator() const
- { return mSpriteIterator; }
-
- /**
* Sets the current velocity in 3 dimensional space.
*/
void setVelocity(float x, float y, float z)
@@ -287,17 +249,13 @@ class Particle : public Sprite
protected:
bool mAlive; /**< Is the particle supposed to be drawn and updated?*/
- Vector mPos; /**< Position in pixels relative to map. */
int mLifetimeLeft; /**< Lifetime left in game ticks*/
int mLifetimePast; /**< Age of the particle in game ticks*/
int mFadeOut; /**< Lifetime in game ticks left where fading out begins*/
int mFadeIn; /**< Age in game ticks where fading in is finished*/
- float mAlpha; /**< Opacity of the graphical representation of the particle */
// generic properties
bool mAutoDelete; /**< May the particle request its deletion by the parent particle? */
- Map *mMap; /**< Map the particle is on. */
- std::list<Sprite*>::iterator mSpriteIterator; /**< iterator of the particle on the current map */
Emitters mChildEmitters; /**< List of child emitters. */
Particles mChildParticles; /**< List of particles controlled by this particle */
bool mAllowSizeAdjust; /**< Can the effect size be adjusted by the object props in the map file? */
diff --git a/src/sprite.h b/src/sprite.h
deleted file mode 100644
index 847c01a6..00000000
--- a/src/sprite.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * The Mana Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- *
- * This file is part of The Mana 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 SPRITE_H
-#define SPRITE_H
-
-class Graphics;
-
-/**
- * A sprite is some visible object on a map. This abstract class defines the
- * interface used by the map to sort and display the sprite.
- */
-class Sprite
-{
- public:
- /**
- * Destructor.
- */
- virtual
- ~Sprite() {}
-
- /**
- * Draws the sprite to the given graphics context.
- *
- * Note: this function could be simplified if the graphics context
- * would support setting a translation offset. It already does this
- * partly with the clipping rectangle support.
- */
- virtual void draw(Graphics *graphics, int offsetX, int offsetY) const = 0;
-
- /**
- * Returns the horizontal size of the sprites graphical representation
- * in pixels or 0 when it is undefined.
- */
- virtual int getWidth() const
- { return 0; }
-
- /**
- * Returns the vertical size of the sprites graphical representation
- * in pixels or 0 when it is undefined.
- */
- virtual int getHeight() const
- { return 0; }
-
- /**
- * Returns the pixel Y coordinate of the sprite.
- */
- virtual int getPixelY() const = 0;
-
- /**
- * Returns the number of Image layers used to draw the sprite.
- */
- virtual int getNumberOfLayers() const
- { return 0; }
-
- /**
- * Returns the current alpha value used to draw the sprite.
- */
- virtual float getAlpha() const = 0;
-
- /**
- * Sets the alpha value used to draw the sprite.
- */
- virtual void setAlpha(float alpha) = 0;
-};
-
-#endif