summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-02 21:26:57 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-02 21:26:57 +0000
commit19e15c87a1fc74f71fd6f9a743201a24ac582997 (patch)
treea615525476ef6bad8a2af4d8b90c8aea935f9109 /src
parent29f07d2f98b82674708f1185f26ed3c482992b04 (diff)
downloadmana-client-19e15c87a1fc74f71fd6f9a743201a24ac582997.tar.gz
mana-client-19e15c87a1fc74f71fd6f9a743201a24ac582997.tar.bz2
mana-client-19e15c87a1fc74f71fd6f9a743201a24ac582997.tar.xz
mana-client-19e15c87a1fc74f71fd6f9a743201a24ac582997.zip
Merged trunk changes from revision 2716 to 2756 into the 0.1.0 branch.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/game.cpp29
-rw-r--r--src/gui/buy.cpp11
-rw-r--r--src/gui/buysell.cpp2
-rw-r--r--src/gui/inventorywindow.cpp1
-rw-r--r--src/gui/trade.cpp10
-rw-r--r--src/map.cpp137
-rw-r--r--src/map.h32
-rw-r--r--src/net/network.h2
-rw-r--r--src/properties.h29
-rw-r--r--src/resources/ambientoverlay.cpp73
-rw-r--r--src/resources/ambientoverlay.h57
-rw-r--r--src/resources/mapreader.cpp128
14 files changed, 315 insertions, 200 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9d1be555..6a46aba4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -211,6 +211,8 @@ SET(SRCS
net/gameserver/internal.h
net/gameserver/player.cpp
net/gameserver/player.h
+ resources/ambientoverlay.cpp
+ resources/ambientoverlay.h
resources/buddylist.cpp
resources/buddylist.h
resources/image.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index fc59329d..8ab16e32 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -174,6 +174,8 @@ tmw_SOURCES = graphic/imagerect.h \
net/gameserver/internal.h \
net/gameserver/player.cpp \
net/gameserver/player.h \
+ resources/ambientoverlay.cpp \
+ resources/ambientoverlay.h \
resources/image.cpp \
resources/image.h \
resources/imagewriter.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 2abd9e26..5052f2ce 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -195,9 +195,7 @@ void createGuiWindows()
chargeDialog->setPosition(
screenW - 5 - chargeDialog->getWidth(),
screenH - chargeDialog->getHeight() - 15);
- tradeWindow->setPosition(screenW - statusWindow->getWidth() -
- tradeWindow->getWidth() - 10,
- inventoryWindow->getY() + inventoryWindow->getHeight());
+
/*buddyWindow->setPosition(10,
minimap->getHeight() + 30);*/
@@ -488,21 +486,18 @@ void Game::handleInput()
}
break;
- // Attempt to hide all windows
+ // Hide certain windows
case SDLK_h:
- statusWindow->setVisible(false);
- buyDialog->setVisible(false);
- sellDialog->setVisible(false);
- buySellDialog->setVisible(false);
- inventoryWindow->setVisible(false);
- npcTextDialog->setVisible(false);
- npcListDialog->setVisible(false);
- skillDialog->setVisible(false);
- setupWindow->setVisible(false);
- equipmentWindow->setVisible(false);
- chargeDialog->setVisible(false);
- helpWindow->setVisible(false);
- debugWindow->setVisible(false);
+ if (!chatWindow->isFocused())
+ {
+ statusWindow->setVisible(false);
+ inventoryWindow->setVisible(false);
+ skillDialog->setVisible(false);
+ setupWindow->setVisible(false);
+ equipmentWindow->setVisible(false);
+ helpWindow->setVisible(false);
+ debugWindow->setVisible(false);
+ }
break;
// Picking up items on the floor
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 41bdd67e..73f696b7 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -49,7 +49,7 @@ BuyDialog::BuyDialog():
mScrollArea = new ScrollArea(mItemList);
mSlider = new Slider(1.0);
mQuantityLabel = new gcn::Label("0");
- mMoneyLabel = new gcn::Label("Price: 0 GP");
+ mMoneyLabel = new gcn::Label("Price : 0 GP / 0 GP");
mIncreaseButton = new Button("+", "+", this);
mDecreaseButton = new Button("-", "-", this);
mBuyButton = new Button("Buy", "buy", this);
@@ -113,6 +113,8 @@ BuyDialog::~BuyDialog()
void BuyDialog::setMoney(int amount)
{
mMoney = amount;
+ mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP");
+ mMoneyLabel->adjustSize();
}
void BuyDialog::reset()
@@ -128,7 +130,7 @@ void BuyDialog::reset()
mDecreaseButton->setEnabled(false);
mQuantityLabel->setCaption("0");
mQuantityLabel->adjustSize();
- mMoneyLabel->setCaption("Price: 0");
+ mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP");
mMoneyLabel->adjustSize();
mItemDescLabel->setCaption("");
mItemEffectLabel->setCaption("");
@@ -158,7 +160,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
mSlider->setValue(0);
mQuantityLabel->setCaption("0");
mQuantityLabel->adjustSize();
- mMoneyLabel->setCaption("Price : 0 GP");
+ mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP");
mMoneyLabel->adjustSize();
// Disable buttons for buying and decreasing
@@ -259,7 +261,8 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
mQuantityLabel->adjustSize();
int price = mAmountItems * mShopItems->at(selectedItem).price;
- mMoneyLabel->setCaption("Price : " + toString(price) + " GP");
+ mMoneyLabel->setCaption("Price : " + toString(price) + " GP / "
+ + toString(mMoney) + " GP" );
mMoneyLabel->adjustSize();
}
}
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index ac0dcc84..4bbbb2ff 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -48,6 +48,8 @@ BuySellDialog::BuySellDialog():
setContentSize(x, 2 * y + buyButton->getHeight());
setLocationRelativeTo(getParent());
+
+ requestFocus();
}
void BuySellDialog::action(const std::string &eventId, gcn::Widget *widget)
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index ea0fd8c0..452b7c16 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -49,6 +49,7 @@ InventoryWindow::InventoryWindow():
setResizable(true);
setMinWidth(240);
setMinHeight(172);
+ // If you adjust these defaults, don't forget to adjust the trade window's.
setDefaultSize(115, 25, 322, 172);
mUseButton = new Button("Use", "use", this);
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 630881ea..2ac56ae5 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -47,7 +47,8 @@ TradeWindow::TradeWindow():
mMyInventory(new Inventory()),
mPartnerInventory(new Inventory())
{
- setContentSize(322, 150);
+ setWindowName("Trade");
+ setDefaultSize(115, 197, 322, 150);
mAddButton = new Button("Add", "add", this);
mOkButton = new Button("Ok", "ok", this);
@@ -100,12 +101,12 @@ TradeWindow::TradeWindow():
mMoneyLabel->setPosition(8 + 60 + 50 + 6, getHeight() - 20);
mMoneyLabel2->setPosition(8, getHeight() - 20);
- mCancelButton->setPosition(getWidth() - 48, getHeight() - 49);
- mTradeButton->setPosition(mCancelButton->getX() - 40
+ mCancelButton->setPosition(getWidth() - 54, getHeight() - 49);
+ mTradeButton->setPosition(mCancelButton->getX() - 41
, getHeight() - 49);
mOkButton->setPosition(mTradeButton->getX() - 24,
getHeight() - 49);
- mAddButton->setPosition(mOkButton->getX() - 32,
+ mAddButton->setPosition(mOkButton->getX() - 31,
getHeight() - 49);
mMyItemContainer->setSize(getWidth() - 24 - 12 - 1,
@@ -121,7 +122,6 @@ TradeWindow::TradeWindow():
mItemDescriptionLabel->setPosition(8,
mItemNameLabel->getY() + mItemNameLabel->getHeight() + 4);
- setContentSize(getWidth(), getHeight());
}
TradeWindow::~TradeWindow()
diff --git a/src/map.cpp b/src/map.cpp
index 3ccaafc0..1cdc1077 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -27,13 +27,17 @@
#include <queue>
#include "beingmanager.h"
+#include "game.h"
#include "graphics.h"
#include "sprite.h"
#include "tileset.h"
+#include "resources/resourcemanager.h"
+#include "resources/ambientoverlay.h"
#include "resources/image.h"
#include "utils/dtor.h"
+#include "utils/tostring.h"
/**
* A location on a tile map. Used for pathfinding, open list.
@@ -79,27 +83,34 @@ Map::~Map()
for_each(mTilesets.begin(), mTilesets.end(), make_dtor(mTilesets));
mTilesets.clear();
// clean up overlays
- std::list<AmbientOverlay>::iterator i;
- for (i = mOverlays.begin(); i != mOverlays.end(); i++)
- {
- (*i).image->decRef();
- }
+ for_each(mOverlays.begin(), mOverlays.end(), make_dtor(mOverlays));
}
void
-Map::setSize(int width, int height)
+Map::initializeOverlays()
{
- delete[] mMetaTiles;
- delete[] mTiles;
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ for (int i = 0;
+ hasProperty("overlay" + toString(i) + "image");
+ i++)
+ {
+ const std::string name = "overlay" + toString(i);
- mWidth = width;
- mHeight = height;
+ Image *img = resman->getImage(getProperty(name + "image"));
+ float speedX = getFloatProperty(name + "scrollX");
+ float speedY = getFloatProperty(name + "scrollY");
+ float parallax = getFloatProperty(name + "parallax");
- int size = width * height;
+ if (img)
+ {
+ mOverlays.push_back(
+ new AmbientOverlay(img, parallax, speedX, speedY));
- mMetaTiles = new MetaTile[size];
- mTiles = new Image*[size * 3];
- std::fill_n(mTiles, size * 3, (Image*)0);
+ // The AmbientOverlay takes control over the image.
+ img->decRef();
+ }
+ }
}
void
@@ -179,99 +190,39 @@ Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail)
{
static int lastTick = tick_time;
- // detail 0: no overlays
+ // Detail 0: no overlays
if (detail <= 0) return;
- std::list<AmbientOverlay>::iterator i;
-
- // Avoid freaking out when tick_time overflows
- if (tick_time < lastTick)
- {
- lastTick = tick_time;
- }
-
if (mLastScrollX == 0.0f && mLastScrollY == 0.0f)
{
- // first call - initialisation
+ // First call - initialisation
mLastScrollX = scrollX;
mLastScrollY = scrollY;
}
- //update Overlays
- while (lastTick < tick_time)
- {
- for (i = mOverlays.begin(); i != mOverlays.end(); i++)
- {
- if ((*i).image != NULL)
- {
- //apply self scrolling
- (*i).scrollX -= (*i).scrollSpeedX;
- (*i).scrollY -= (*i).scrollSpeedY;
-
- //apply parallaxing
- (*i).scrollX += (scrollX - mLastScrollX) * (*i).parallax;
- (*i).scrollY += (scrollY - mLastScrollY) * (*i).parallax;
-
- //keep the image pattern on the screen
- while ((*i).scrollX > (*i).image->getWidth())
- {
- (*i).scrollX -= (*i).image->getWidth();
- }
- while ((*i).scrollY > (*i).image->getHeight())
- {
- (*i).scrollY -= (*i).image->getHeight();
- }
- while ((*i).scrollX < 0)
- {
- (*i).scrollX += (*i).image->getWidth();
- }
- while ((*i).scrollY < 0)
- {
- (*i).scrollY += (*i).image->getHeight();
- }
- }
- }
- mLastScrollX = scrollX;
- mLastScrollY = scrollY;
- lastTick++;
-
- // detail 1: only one overlay, higher: all overlays
- if (detail == 1) break;
- }
+ // Update Overlays
+ int timePassed = get_elapsed_time(lastTick);
+ float dx = scrollX - mLastScrollX;
+ float dy = scrollY - mLastScrollY;
- //draw overlays
+ std::list<AmbientOverlay*>::iterator i;
for (i = mOverlays.begin(); i != mOverlays.end(); i++)
{
- if ((*i).image != NULL)
- {
- graphics->drawImagePattern ( (*i).image,
- 0 - (int)(*i).scrollX,
- 0 - (int)(*i).scrollY,
- graphics->getWidth() + (int)(*i).scrollX,
- graphics->getHeight() + (int)(*i).scrollY
- );
- };
- // detail 1: only one overlay, higher: all overlays
- if (detail == 1) break;
- };
-}
+ (*i)->update(timePassed, dx, dy);
+ }
+ mLastScrollX = scrollX;
+ mLastScrollY = scrollY;
+ lastTick = tick_time;
-void
-Map::setOverlay(Image *image, float speedX, float speedY, float parallax)
-{
- if (image != NULL)
+ // Draw overlays
+ for (i = mOverlays.begin(); i != mOverlays.end(); i++)
{
- AmbientOverlay newOverlay;
-
- newOverlay.image = image;
- newOverlay.parallax = parallax;
- newOverlay.scrollSpeedX = speedX;
- newOverlay.scrollSpeedY = speedY;
- newOverlay.scrollX = 0;
- newOverlay.scrollY = 0;
+ (*i)->draw(graphics, graphics->getWidth(), graphics->getHeight());
- mOverlays.push_back(newOverlay);
- }
+ // Detail 1: only one overlay, higher: all overlays
+ if (detail == 1)
+ break;
+ };
}
void
diff --git a/src/map.h b/src/map.h
index 317a0b59..961326b8 100644
--- a/src/map.h
+++ b/src/map.h
@@ -29,6 +29,7 @@
#include "properties.h"
+class AmbientOverlay;
class Graphics;
class Image;
class Tileset;
@@ -65,16 +66,6 @@ struct MetaTile
bool walkable; /**< Can beings walk on this tile */
};
-struct AmbientOverlay
-{
- Image *image;
- float parallax;
- float scrollX;
- float scrollY;
- float scrollSpeedX;
- float scrollSpeedY;
-};
-
/**
* A tile map.
*/
@@ -92,24 +83,22 @@ class Map : public Properties
~Map();
/**
- * Draws a map layer to the given graphics output.
+ * Initialize map overlays. Should be called after all the properties
+ * are set.
*/
- void draw(Graphics *graphics, int scrollX, int scrollY, int layer);
+ void initializeOverlays();
/**
- * Sets Overlay Graphic and Scrollspeed
+ * Draws a map layer to the given graphics output.
*/
- void setOverlay(Image *image, float speedX, float speedY, float parallax);
+ void draw(Graphics *graphics, int scrollX, int scrollY, int layer);
/**
* Draws the overlay graphic to the given graphics output.
*/
- void drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail);
-
- /**
- * Sets the size of the map. This will destroy any existing map data.
- */
- void setSize(int width, int height);
+ void
+ drawOverlay(Graphics *graphics, float scrollX, float scrollY,
+ int detail);
/**
* Adds a tileset to this map.
@@ -222,8 +211,7 @@ class Map : public Properties
int mOnClosedList, mOnOpenList;
//overlay Data
- AmbientOverlay mFoo;
- std::list<AmbientOverlay> mOverlays;
+ std::list<AmbientOverlay*> mOverlays;
float mLastScrollX;
float mLastScrollY;
};
diff --git a/src/net/network.h b/src/net/network.h
index 819115dd..9ffcbb6d 100644
--- a/src/net/network.h
+++ b/src/net/network.h
@@ -66,6 +66,6 @@ namespace Net
* registered handlers
*/
void flush();
-};
+}
#endif
diff --git a/src/properties.h b/src/properties.h
index 92690cd3..56e90c0e 100644
--- a/src/properties.h
+++ b/src/properties.h
@@ -26,6 +26,7 @@
#include <map>
#include <string>
+#include <sstream>
/**
* A class holding a set of properties.
@@ -39,16 +40,36 @@ class Properties
/**
* Get a map property.
*
- * @return the value of the given property or an empty string when it
+ * @param def default value, empty string by default
+ * @return the value of the given property or the given default when it
* doesn't exist.
*/
const std::string&
- getProperty(const std::string &name)
+ getProperty(const std::string &name, const std::string &def = "")
{
- const static std::string undefined = "";
PropertyMap::const_iterator i = mProperties.find(name);
+ return (i != mProperties.end()) ? i->second : def;
+ }
- return (i != mProperties.end()) ? i->second : undefined;
+ /**
+ * Gets a map property as a float.
+ *
+ * @param def default value, 0.0f by default
+ * @return the value of the given property, or 0.0f when it doesn't
+ * exist.
+ */
+ const float
+ getFloatProperty(const std::string &name, float def = 0.0f)
+ {
+ PropertyMap::const_iterator i = mProperties.find(name);
+ float ret = def;
+ if (i != mProperties.end())
+ {
+ std::stringstream ss;
+ ss.str(i->second);
+ ss >> ret;
+ }
+ return ret;
}
/**
diff --git a/src/resources/ambientoverlay.cpp b/src/resources/ambientoverlay.cpp
new file mode 100644
index 00000000..058b6083
--- /dev/null
+++ b/src/resources/ambientoverlay.cpp
@@ -0,0 +1,73 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "ambientoverlay.h"
+
+#include "image.h"
+
+#include "../graphics.h"
+
+AmbientOverlay::AmbientOverlay(Image *img, float parallax,
+ float speedX, float speedY):
+ mImage(img), mParallax(parallax),
+ mPosX(0), mPosY(0),
+ mSpeedX(speedX), mSpeedY(speedY)
+{
+ mImage->incRef();
+}
+
+AmbientOverlay::~AmbientOverlay()
+{
+ mImage->decRef();
+}
+
+void AmbientOverlay::update(int timePassed, float dx, float dy)
+{
+ // Self scrolling of the overlay
+ mPosX -= mSpeedX * timePassed / 10;
+ mPosY -= mSpeedY * timePassed / 10;
+
+ // Parallax scrolling
+ mPosX += dx * mParallax;
+ mPosY += dy * mParallax;
+
+ int imgW = mImage->getWidth();
+ int imgH = mImage->getHeight();
+
+ // Wrap values
+ while (mPosX > imgW)
+ mPosX -= imgW;
+ while (mPosX < 0)
+ mPosX += imgW;
+
+ while (mPosY > imgH)
+ mPosY -= imgH;
+ while (mPosY < 0)
+ mPosY += imgH;
+}
+
+void AmbientOverlay::draw(Graphics *graphics, int x, int y)
+{
+ graphics->drawImagePattern(mImage,
+ (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY);
+}
diff --git a/src/resources/ambientoverlay.h b/src/resources/ambientoverlay.h
new file mode 100644
index 00000000..a939cbb4
--- /dev/null
+++ b/src/resources/ambientoverlay.h
@@ -0,0 +1,57 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 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_RESOURCES_AMBIENTOVERLAY_H_
+#define _TMW_RESOURCES_AMBIENTOVERLAY_H_
+
+class Graphics;
+class Image;
+
+class AmbientOverlay
+{
+ public:
+ /**
+ * Constructor.
+ */
+ AmbientOverlay(Image *img, float parallax,
+ float speedX, float speedY);
+
+ /**
+ * Destructor.
+ */
+ ~AmbientOverlay();
+
+ void update(int timePassed, float dx, float dy);
+
+ void draw(Graphics *graphics, int x, int y);
+
+ private:
+ Image *mImage;
+ float mParallax;
+ float mPosX; /**< Current layer X position. */
+ float mPosY; /**< Current layer Y position. */
+ float mSpeedX; /**< Scroll speed in X direction. */
+ float mSpeedY; /**< Scroll speed in Y direction. */
+};
+
+#endif
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index c1ae911c..2aea3dc5 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -24,6 +24,7 @@
#include "mapreader.h"
#include <cassert>
+#include <iostream>
#include <zlib.h>
#include "resourcemanager.h"
@@ -51,7 +52,7 @@ inflateMemory(unsigned char *in, unsigned int inLength,
int ret;
z_stream strm;
- out = (unsigned char*)malloc(bufferSize);
+ out = (unsigned char*) malloc(bufferSize);
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
@@ -82,13 +83,13 @@ inflateMemory(unsigned char *in, unsigned int inLength,
ret = Z_DATA_ERROR;
case Z_DATA_ERROR:
case Z_MEM_ERROR:
- (void)inflateEnd(&strm);
+ (void) inflateEnd(&strm);
return ret;
}
if (ret != Z_STREAM_END)
{
- out = (unsigned char*)realloc(out, bufferSize * 2);
+ out = (unsigned char*) realloc(out, bufferSize * 2);
if (out == NULL)
{
@@ -105,10 +106,44 @@ inflateMemory(unsigned char *in, unsigned int inLength,
assert(strm.avail_in == 0);
outLength = bufferSize - strm.avail_out;
- (void)inflateEnd(&strm);
+ (void) inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
+int
+inflateMemory(unsigned char *in, unsigned int inLength,
+ unsigned char *&out)
+{
+ unsigned int outLength = 0;
+ int ret = inflateMemory(in, inLength, out, outLength);
+
+ if (ret != Z_OK || out == NULL)
+ {
+ if (ret == Z_MEM_ERROR)
+ {
+ logger->log("Error: Out of memory while decompressing map data!");
+ }
+ else if (ret == Z_VERSION_ERROR)
+ {
+ logger->log("Error: Incompatible zlib version!");
+ }
+ else if (ret == Z_DATA_ERROR)
+ {
+ logger->log("Error: Incorrect zlib compressed data!");
+ }
+ else
+ {
+ logger->log("Error: Unknown error while decompressing map data!");
+ }
+
+ free(out);
+ out = NULL;
+ outLength = 0;
+ }
+
+ return outLength;
+}
+
Map*
MapReader::readMap(const std::string &filename)
{
@@ -126,33 +161,17 @@ MapReader::readMap(const std::string &filename)
// Inflate the gzipped map data
unsigned char *inflated;
- unsigned int inflatedSize = 0;
- int ret = inflateMemory((unsigned char*)buffer,
- fileSize, inflated, inflatedSize);
+ unsigned int inflatedSize = inflateMemory((unsigned char*) buffer,
+ fileSize, inflated);
free(buffer);
- if (ret == Z_MEM_ERROR)
+ if (inflated == NULL)
{
- logger->log("Error: Out of memory while decompressing map data!");
- return NULL;
- }
- else if (ret == Z_VERSION_ERROR)
- {
- logger->log("Error: Incompatible zlib version!");
- return NULL;
- }
- else if (ret == Z_DATA_ERROR)
- {
- logger->log("Error: Incorrect zlib compressed data!");
- return NULL;
- }
- else if (ret != Z_OK || inflated == NULL)
- {
- logger->log("Error: Unknown error while decompressing map data!");
+ logger->log("Could not decompress map file (%s)\n", filename.c_str());
return NULL;
}
- xmlDocPtr doc = xmlParseMemory((char*)inflated, inflatedSize);
+ xmlDocPtr doc = xmlParseMemory((char*) inflated, inflatedSize);
free(inflated);
// Parse the inflated map data
@@ -214,31 +233,7 @@ MapReader::readMap(xmlNodePtr node, const std::string &path)
}
}
- //set Overlays
- int i = 0;
- ResourceManager *resman = ResourceManager::getInstance();
-
- while (map->hasProperty("overlay" + toString(i) + "image"))
- {
- Image *overlayImage = resman->getImage(map->getProperty("overlay" + toString(i) + "image"));
- float scrollX = 0.0f;
- float scrollY = 0.0f;
- float parallax = 0.0f;
- if (map->hasProperty("overlay" + toString(i) + "scrollX"))
- {
- scrollX = atof(map->getProperty("overlay" + toString(i) + "scrollX").c_str());
- }
- if (map->hasProperty("overlay" + toString(i) + "scrollY"))
- {
- scrollY = atof(map->getProperty("overlay" + toString(i) + "scrollY").c_str());
- }
- if (map->hasProperty("overlay" + toString(i) + "parallax"))
- {
- parallax = atof(map->getProperty("overlay" + toString(i) + "parallax").c_str());
- }
- map->setOverlay (overlayImage, scrollX, scrollY, parallax);
- i++;
- }
+ map->initializeOverlays();
return map;
}
@@ -284,8 +279,8 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
{
xmlFree(encoding);
- if (compression) {
- logger->log("Warning: no layer compression supported!");
+ if (compression && !xmlStrEqual(compression, BAD_CAST "gzip")) {
+ logger->log("Warning: only gzip layer compression supported!");
xmlFree(compression);
return;
}
@@ -313,12 +308,32 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
int binLen;
unsigned char *binData =
- php_base64_decode(charData, strlen((char*)charData),
- &binLen);
+ php_base64_decode(charData, strlen((char*)charData), &binLen);
delete[] charData;
if (binData) {
+ if (compression) {
+ if (xmlStrEqual(compression, BAD_CAST "gzip")) {
+ // Inflate the gzipped layer data
+ unsigned char *inflated;
+ unsigned int inflatedSize =
+ inflateMemory(binData, binLen, inflated);
+
+ free(binData);
+ binData = inflated;
+ binLen = inflatedSize;
+
+ if (inflated == NULL)
+ {
+ logger->log("Error: Could not decompress layer!");
+ xmlFree(compression);
+ return;
+ }
+ }
+ xmlFree(compression);
+ }
+
for (int i = 0; i < binLen - 3; i += 4) {
int gid = binData[i] |
binData[i + 1] << 8 |
@@ -351,6 +366,11 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
}
}
+ if (y < h)
+ std::cerr << "TOO SMALL!\n";
+ if (x)
+ std::cerr << "TOO SMALL!\n";
+
// There can be only one data element
break;
}