summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-12-05 20:20:25 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-12-05 20:20:25 +0000
commitd8539e4ccac014c306329cda2c8bed036a80af39 (patch)
tree2ba911e66c31102173f4df9cbac19049a7f45a4b
parentc65678cd7016d56aa3f8360b7e8d36e275b8c90e (diff)
downloadmana-d8539e4ccac014c306329cda2c8bed036a80af39.tar.gz
mana-d8539e4ccac014c306329cda2c8bed036a80af39.tar.bz2
mana-d8539e4ccac014c306329cda2c8bed036a80af39.tar.xz
mana-d8539e4ccac014c306329cda2c8bed036a80af39.zip
Fix drawing of very high fringe tiles by keeping track of the maximum tile
height.
-rw-r--r--ChangeLog8
-rw-r--r--src/gui/itemshortcutcontainer.cpp1
-rw-r--r--src/gui/itemshortcutcontainer.h4
-rw-r--r--src/gui/itemshortcutwindow.cpp1
-rw-r--r--src/gui/itemshortcutwindow.h1
-rw-r--r--src/itemshortcut.cpp4
-rw-r--r--src/itemshortcut.h23
-rw-r--r--src/map.cpp88
-rw-r--r--src/map.h8
9 files changed, 65 insertions, 73 deletions
diff --git a/ChangeLog b/ChangeLog
index a4cb3a53..289ea334 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-12-05 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * src/map.cpp, src/map.h: Fix drawing of very high fringe tiles by
+ keeping track of the maximum tile height.
+ * src/itemshortcut.h, src/gui/itemshortcutcontainer.h,
+ src/gui/itemshortcutcontainer.cpp, src/gui/itemshortcutwindow.cpp,
+ src/gui/itemshortcutwindow.h, src/itemshortcut.cpp: Random cleanups.
+
2007-12-04 Philipp Sehmisch <tmw@crushnet.org>
* data/graphics/sprites/head-funkywinter.png,
diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp
index 1943ef93..0f7d1332 100644
--- a/src/gui/itemshortcutcontainer.cpp
+++ b/src/gui/itemshortcutcontainer.cpp
@@ -18,6 +18,7 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
+ * $Id$
*/
#include "itemshortcutcontainer.h"
diff --git a/src/gui/itemshortcutcontainer.h b/src/gui/itemshortcutcontainer.h
index 4b154cbb..c69525e0 100644
--- a/src/gui/itemshortcutcontainer.h
+++ b/src/gui/itemshortcutcontainer.h
@@ -18,6 +18,7 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
+ * $Id$
*/
#ifndef _TMW_ITEMSHORTCUTCONTAINER_H__
@@ -26,8 +27,6 @@
#include <guichan/mouselistener.hpp>
#include <guichan/widget.hpp>
-#include <list>
-
class Image;
class Item;
@@ -109,7 +108,6 @@ class ItemShortcutContainer : public gcn::Widget, public gcn::MouseListener
int mGridWidth, mGridHeight;
bool mItemClicked;
Item *mItemMoved;
-
};
#endif
diff --git a/src/gui/itemshortcutwindow.cpp b/src/gui/itemshortcutwindow.cpp
index efac9353..51f9f91e 100644
--- a/src/gui/itemshortcutwindow.cpp
+++ b/src/gui/itemshortcutwindow.cpp
@@ -18,6 +18,7 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
+ * $Id$
*/
#include "itemshortcutwindow.h"
diff --git a/src/gui/itemshortcutwindow.h b/src/gui/itemshortcutwindow.h
index 83bc348d..1dde8686 100644
--- a/src/gui/itemshortcutwindow.h
+++ b/src/gui/itemshortcutwindow.h
@@ -18,6 +18,7 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
+ * $Id$
*/
#ifndef _TMW_ITEMSHORTCUTWINDOW_H
diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp
index c212d506..931ce6f2 100644
--- a/src/itemshortcut.cpp
+++ b/src/itemshortcut.cpp
@@ -18,10 +18,12 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
+ * $Id$
*/
#include "itemshortcut.h"
+#include "item.h"
#include "localplayer.h"
#include "configuration.h"
@@ -51,7 +53,7 @@ void ItemShortcut::load()
if (itemId != -1)
{
- ItemPtr item = player_node->searchForItem(itemId);
+ Item* item = player_node->searchForItem(itemId);
if (item)
{
mItems[i] = item;
diff --git a/src/itemshortcut.h b/src/itemshortcut.h
index d211c7f3..fecb7d86 100644
--- a/src/itemshortcut.h
+++ b/src/itemshortcut.h
@@ -18,20 +18,19 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
+ * $Id$
*/
#ifndef _TMW_ITEMSHORTCUT_H__
#define _TMW_ITEMSHORTCUT_H__
-#include "item.h"
-
#define SHORTCUT_ITEMS 10
+class Item;
+
/**
- * The item pointer
+ * The class which keeps track of the item shortcuts.
*/
-typedef Item* ItemPtr;
-
class ItemShortcut
{
public:
@@ -55,7 +54,7 @@ class ItemShortcut
*
* @param index Index of the shortcut item.
*/
- ItemPtr getItem(int index) const
+ Item* getItem(int index) const
{ return mItems[index]; }
/**
@@ -67,7 +66,7 @@ class ItemShortcut
/**
* Returns the item that is currently selected.
*/
- ItemPtr getItemSelected() const
+ Item* getItemSelected() const
{ return mItemSelected; }
/**
@@ -92,20 +91,20 @@ class ItemShortcut
*
* @param item The item that is to be assigned.
*/
- void setItemSelected(ItemPtr item)
+ void setItemSelected(Item* item)
{ mItemSelected = item; }
/**
* A flag to check if the item is selected.
*/
bool isItemSelected()
- { return (mItemSelected) ? true : false; }
+ { return mItemSelected; }
/**
* Remove a item from the shortcut.
*/
void removeItem(int index)
- { mItems[index] = NULL; }
+ { mItems[index] = 0; }
/**
* Try to use the item specified by the index.
@@ -120,8 +119,8 @@ class ItemShortcut
*/
void save();
- ItemPtr mItems[SHORTCUT_ITEMS]; /**< the items stored */
- ItemPtr mItemSelected; /**< the item held by cursor */
+ Item* mItems[SHORTCUT_ITEMS]; /**< The items stored. */
+ Item* mItemSelected; /**< The item held by cursor. */
};
diff --git a/src/map.cpp b/src/map.cpp
index 1ee2248f..2dbf9cb6 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -65,6 +65,7 @@ struct Location
Map::Map(int width, int height, int tileWidth, int tileHeight):
mWidth(width), mHeight(height),
mTileWidth(tileWidth), mTileHeight(tileHeight),
+ mMaxTileHeight(height),
mOnClosedList(1), mOnOpenList(2),
mLastScrollX(0.0f), mLastScrollY(0.0f)
{
@@ -87,8 +88,7 @@ Map::~Map()
for_each(mOverlays.begin(), mOverlays.end(), make_dtor(mOverlays));
}
-void
-Map::initializeOverlays()
+void Map::initializeOverlays()
{
ResourceManager *resman = ResourceManager::getInstance();
@@ -114,10 +114,12 @@ Map::initializeOverlays()
}
}
-void
-Map::addTileset(Tileset *tileset)
+void Map::addTileset(Tileset *tileset)
{
mTilesets.push_back(tileset);
+
+ if (tileset->getHeight() > mMaxTileHeight)
+ mMaxTileHeight = tileset->getHeight();
}
bool spriteCompare(const Sprite *a, const Sprite *b)
@@ -125,13 +127,9 @@ bool spriteCompare(const Sprite *a, const Sprite *b)
return a->getPixelY() < b->getPixelY();
}
-void
-Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
+void Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
{
- int startX = scrollX / 32;
- int startY = scrollY / 32;
- int endX = (graphics->getWidth() + scrollX + 31) / 32;
- int endY = (graphics->getHeight() + scrollY + 31) / 32;
+ int endPixelY = graphics->getHeight() + scrollY + mTileHeight - 1;
// If drawing the fringe layer, make sure sprites are sorted
SpriteIterator si;
@@ -139,13 +137,14 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
{
mSprites.sort(spriteCompare);
si = mSprites.begin();
-
- // Increase endY to account for high fringe tiles
- // TODO: Improve this hack so that it'll dynamically account for the
- // highest tile.
- endY += 2;
+ endPixelY += mMaxTileHeight - mTileHeight;
}
+ int startX = scrollX / mTileWidth;
+ int startY = scrollY / mTileHeight;
+ int endX = (graphics->getWidth() + scrollX + mTileWidth - 1) / mTileWidth;
+ int endY = endPixelY / mTileHeight;
+
if (startX < 0) startX = 0;
if (startY < 0) startY = 0;
if (endX > mWidth) endX = mWidth;
@@ -169,8 +168,9 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
Image *img = getTile(x, y, layer);
if (img) {
graphics->drawImage(img,
- x * 32 - scrollX,
- y * 32 - scrollY + 32 - img->getHeight());
+ x * mTileWidth - scrollX,
+ y * mTileHeight - scrollY +
+ mTileHeight - img->getHeight());
}
}
}
@@ -186,8 +186,8 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
}
}
-void
-Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail)
+void Map::drawOverlay(Graphics *graphics,
+ float scrollX, float scrollY, int detail)
{
static int lastTick = tick_time;
@@ -226,8 +226,7 @@ Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail)
};
}
-void
-Map::setTileWithGid(int x, int y, int layer, int gid)
+void Map::setTileWithGid(int x, int y, int layer, int gid)
{
if (layer == 3)
{
@@ -251,19 +250,17 @@ class ContainsGidFunctor
int gid;
} containsGid;
-Tileset*
-Map::getTilesetWithGid(int gid)
+Tileset* Map::getTilesetWithGid(int gid) const
{
containsGid.gid = gid;
- TilesetIterator i = find_if(mTilesets.begin(), mTilesets.end(),
+ Tilesets::const_iterator i = find_if(mTilesets.begin(), mTilesets.end(),
containsGid);
return (i == mTilesets.end()) ? NULL : *i;
}
-Image*
-Map::getTileWithGid(int gid)
+Image* Map::getTileWithGid(int gid) const
{
Tileset *set = getTilesetWithGid(gid);
@@ -274,20 +271,17 @@ Map::getTileWithGid(int gid)
return NULL;
}
-void
-Map::setWalk(int x, int y, bool walkable)
+void Map::setWalk(int x, int y, bool walkable)
{
mMetaTiles[x + y * mWidth].walkable = walkable;
}
-bool
-Map::getWalk(int x, int y) const
+bool Map::getWalk(int x, int y) const
{
return !tileCollides(x, y) && !occupied(x, y);
}
-bool
-Map::occupied(int x, int y) const
+bool Map::occupied(int x, int y) const
{
Beings &beings = beingManager->getAll();
for (BeingIterator i = beings.begin(); i != beings.end(); i++)
@@ -302,51 +296,43 @@ Map::occupied(int x, int y) const
return false;
}
-bool
-Map::tileCollides(int x, int y) const
+bool Map::tileCollides(int x, int y) const
{
return !(contains(x, y) && mMetaTiles[x + y * mWidth].walkable);
}
-bool
-Map::contains(int x, int y) const
+bool Map::contains(int x, int y) const
{
return x >= 0 && y >= 0 && x < mWidth && y < mHeight;
}
-void
-Map::setTile(int x, int y, int layer, Image *img)
+void Map::setTile(int x, int y, int layer, Image *img)
{
mTiles[x + y * mWidth + layer * (mWidth * mHeight)] = img;
}
-Image*
-Map::getTile(int x, int y, int layer)
+Image* Map::getTile(int x, int y, int layer)
{
return mTiles[x + y * mWidth + layer * (mWidth * mHeight)];
}
-MetaTile*
-Map::getMetaTile(int x, int y)
+MetaTile* Map::getMetaTile(int x, int y)
{
return &mMetaTiles[x + y * mWidth];
}
-SpriteIterator
-Map::addSprite(Sprite *sprite)
+SpriteIterator Map::addSprite(Sprite *sprite)
{
mSprites.push_front(sprite);
return mSprites.begin();
}
-void
-Map::removeSprite(SpriteIterator iterator)
+void Map::removeSprite(SpriteIterator iterator)
{
mSprites.erase(iterator);
}
-Path
-Map::findPath(int startX, int startY, int destX, int destY)
+Path Map::findPath(int startX, int startY, int destX, int destY)
{
// Path to be built up (empty by default)
Path path;
@@ -510,8 +496,7 @@ Map::findPath(int startX, int startY, int destX, int destY)
return path;
}
-void
-Map::addParticleEffect (std::string effectFile, int x, int y)
+void Map::addParticleEffect (std::string effectFile, int x, int y)
{
ParticleEffectData newEffect;
newEffect.file = effectFile;
@@ -520,8 +505,7 @@ Map::addParticleEffect (std::string effectFile, int x, int y)
particleEffects.push_back(newEffect);
}
-void
-Map::initializeParticleEffects(Particle* particleEngine)
+void Map::initializeParticleEffects(Particle* particleEngine)
{
for (std::list<ParticleEffectData>::iterator i = particleEffects.begin();
i != particleEffects.end();
diff --git a/src/map.h b/src/map.h
index 17772847..5c7fe1e9 100644
--- a/src/map.h
+++ b/src/map.h
@@ -39,7 +39,6 @@ class Tileset;
struct PATH_NODE;
typedef std::vector<Tileset*> Tilesets;
-typedef Tilesets::iterator TilesetIterator;
typedef std::list<Sprite*> Sprites;
typedef Sprites::iterator SpriteIterator;
@@ -202,14 +201,12 @@ class Map : public Properties
* Converts a global tile id to the Image* pointing to the associated
* tile image.
*/
- Image*
- getTileWithGid(int gid);
+ Image* getTileWithGid(int gid) const;
/**
* Finds the tile set that a tile with the given global id is part of.
*/
- Tileset*
- getTilesetWithGid(int gid);
+ Tileset* getTilesetWithGid(int gid) const;
/**
* Tells whether a tile is occupied by a being.
@@ -223,6 +220,7 @@ class Map : public Properties
int mWidth, mHeight;
int mTileWidth, mTileHeight;
+ int mMaxTileHeight;
MetaTile *mMetaTiles;
Image **mTiles;