From 391203d83ed7a72b54fb7d7c72dbe35db14f0ea9 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 28 Aug 2006 23:04:08 +0000 Subject: Merged trunk development between revisions 2530 and 2618 to the 0.1.0 branch. --- src/map.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/map.h') diff --git a/src/map.h b/src/map.h index a91b815f..317a0b59 100644 --- a/src/map.h +++ b/src/map.h @@ -41,6 +41,8 @@ typedef Tilesets::iterator TilesetIterator; typedef std::list Sprites; typedef Sprites::iterator SpriteIterator; +extern volatile int tick_time; + /** * A meta tile stores additional information about a location on a tile map. * This is information that doesn't need to be repeated for each tile in each @@ -63,6 +65,16 @@ 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. */ @@ -80,10 +92,20 @@ class Map : public Properties ~Map(); /** - * Draws the map to the given graphics output. + * Draws a map layer to the given graphics output. */ void draw(Graphics *graphics, int scrollX, int scrollY, int layer); + /** + * Sets Overlay Graphic and Scrollspeed + */ + void setOverlay(Image *image, float speedX, float speedY, float parallax); + + /** + * 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. */ @@ -198,6 +220,12 @@ class Map : public Properties // Pathfinding members int mOnClosedList, mOnOpenList; + + //overlay Data + AmbientOverlay mFoo; + std::list mOverlays; + float mLastScrollX; + float mLastScrollY; }; #endif -- cgit v1.2.3-70-g09d2 From 19e15c87a1fc74f71fd6f9a743201a24ac582997 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 2 Nov 2006 21:26:57 +0000 Subject: Merged trunk changes from revision 2716 to 2756 into the 0.1.0 branch. --- ChangeLog | 150 +++++++++++++++++++++++++++--------- NEWS | 6 ++ The Mana World.dev | 27 ++++++- configure.ac | 3 + debian/rules | 8 +- debian/tmw-data.dirs | 1 + debian/tmw-data.install | 1 + debian/tmw-music.install | 2 - src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 29 +++---- src/gui/buy.cpp | 11 ++- src/gui/buysell.cpp | 2 + src/gui/inventorywindow.cpp | 1 + src/gui/trade.cpp | 10 +-- src/map.cpp | 137 +++++++++++---------------------- src/map.h | 32 +++----- src/net/network.h | 2 +- src/properties.h | 29 ++++++- src/resources/ambientoverlay.cpp | 73 ++++++++++++++++++ src/resources/ambientoverlay.h | 57 ++++++++++++++ src/resources/mapreader.cpp | 128 ++++++++++++++++++------------- tmw.cbp | 41 +++++++++- tools/Purger.java | 159 +++++++++++++++++++++++++++++++++++++++ tools/Reorganize.java | 29 ++++--- 25 files changed, 689 insertions(+), 253 deletions(-) create mode 100644 src/resources/ambientoverlay.cpp create mode 100644 src/resources/ambientoverlay.h create mode 100644 tools/Purger.java (limited to 'src/map.h') diff --git a/ChangeLog b/ChangeLog index a650bcb9..ce76ecdb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,43 +1,123 @@ 2006-11-02 Björn Steinbrink - * src/gui/register.cpp, src/gui/register.h: Fixed a memory leak and a - double deletion. - * src/main.cpp, src/CMakeLists.txt, src/net/loginhandler.cpp, - src/net/charserverhandler.h, src/net/maploginhandler.h, - src/net/maploginhandler.cpp, src/net/loginhandler.h, src/Makefile.am: - Removed some cruft that was needed for eAthena. - * src/localplayer.cpp, src/game.cpp, src/gui/trade.cpp, - src/gui/sell.cpp, src/gui/char_select.cpp, src/gui/serverdialog.cpp, - src/gui/chat.cpp, src/gui/buy.cpp, src/gui/status.cpp, - src/beingmanager.cpp, src/npc.cpp, src/main.cpp, src/CMakeLists.txt, - src/net/connection.cpp, src/net/accountserver, - src/net/accountserver/account.h, src/net/accountserver/internal.h, - src/net/accountserver/accountserver.cpp, - src/net/accountserver/accountserver.h, - src/net/accountserver/account.cpp, src/net/accountserver/internal.cpp, - src/net/internal.cpp, src/net/network.h, - src/net/charserverhandler.cpp, src/net/connection.h, - src/net/gameserver, src/net/gameserver/gameserver.cpp, - src/net/gameserver/player.h, src/net/gameserver/internal.h, - src/net/gameserver/gameserver.h, src/net/gameserver/internal.cpp, - src/net/gameserver/player.cpp, src/net/internal.h, - src/net/messagehandler.cpp, src/net/chatserver, - src/net/chatserver/internal.h, src/net/chatserver/chatserver.cpp, - src/net/chatserver/chatserver.h, src/net/chatserver/internal.cpp, - src/net/network.cpp, src/Makefile.am: Network layer refactoring. + * src/gui/register.cpp, src/gui/register.h: Fixed a memory leak and a + double deletion. + * src/main.cpp, src/CMakeLists.txt, src/net/loginhandler.cpp, + src/net/charserverhandler.h, src/net/maploginhandler.h, + src/net/maploginhandler.cpp, src/net/loginhandler.h, src/Makefile.am: + Removed some cruft that was needed for eAthena. + * src/localplayer.cpp, src/game.cpp, src/gui/trade.cpp, + src/gui/sell.cpp, src/gui/char_select.cpp, src/gui/serverdialog.cpp, + src/gui/chat.cpp, src/gui/buy.cpp, src/gui/status.cpp, + src/beingmanager.cpp, src/npc.cpp, src/main.cpp, src/CMakeLists.txt, + src/net/connection.cpp, src/net/accountserver, + src/net/accountserver/account.h, src/net/accountserver/internal.h, + src/net/accountserver/accountserver.cpp, + src/net/accountserver/accountserver.h, + src/net/accountserver/account.cpp, src/net/accountserver/internal.cpp, + src/net/internal.cpp, src/net/network.h, + src/net/charserverhandler.cpp, src/net/connection.h, + src/net/gameserver, src/net/gameserver/gameserver.cpp, + src/net/gameserver/player.h, src/net/gameserver/internal.h, + src/net/gameserver/gameserver.h, src/net/gameserver/internal.cpp, + src/net/gameserver/player.cpp, src/net/internal.h, + src/net/messagehandler.cpp, src/net/chatserver, + src/net/chatserver/internal.h, src/net/chatserver/chatserver.cpp, + src/net/chatserver/chatserver.h, src/net/chatserver/internal.cpp, + src/net/network.cpp, src/Makefile.am: Network layer refactoring. 2006-11-01 Björn Steinbrink - * CMake/Modules/FindLibXml2.cmake, CMake/Modules/FindENet.cmake, - CMake/Modules/FindLibcurl.cmake, CMake/Modules/FindGuichan.cmake, - src/CMakeLists.txt, src/main.h, data/graphics/tiles/CMakeLists.txt, - data/graphics/items/CMakeLists.txt, data/graphics/gui/CMakeLists.txt, - data/graphics/images/ambient/CMakeLists.txt, - data/graphics/images/CMakeLists.txt, - data/graphics/sprites/CMakeLists.txt, data/graphics/CMakeLists.txt, - data/maps/CMakeLists.txt, data/sfx/CMakeLists.txt, - data/help/CMakeLists.txt, data/icons/CMakeLists.txt, - data/CMakeLists.txt, CMakeLists.txt: Added CMake support. + * CMake/Modules/FindLibXml2.cmake, CMake/Modules/FindENet.cmake, + CMake/Modules/FindLibcurl.cmake, CMake/Modules/FindGuichan.cmake, + src/CMakeLists.txt, src/main.h, data/graphics/tiles/CMakeLists.txt, + data/graphics/items/CMakeLists.txt, data/graphics/gui/CMakeLists.txt, + data/graphics/images/ambient/CMakeLists.txt, + data/graphics/images/CMakeLists.txt, + data/graphics/sprites/CMakeLists.txt, data/graphics/CMakeLists.txt, + data/maps/CMakeLists.txt, data/sfx/CMakeLists.txt, + data/help/CMakeLists.txt, data/icons/CMakeLists.txt, + data/CMakeLists.txt, CMakeLists.txt: Added CMake support. + +2006-10-24 Philipp Sehmisch + + * /data/graphics/images/ambient/night.png: Added graphic for night + ambient effect. + +2006-10-23 Bjørn Lindeijer + + * configure.ac: Added zlib check before PhysFS check. The PhysFS check + was failing on MSYS because of a missing -lz. + +2006-10-12 Yohann Ferreira + + * debian/rules, debian/tmw-data.install, debian/tmw-data.dirs, + debian/tmw-music.install: Updating debian files for bug fixing. + +2006-10-12 Frode Lindeijer + + * /data/graphics/sprites/npcs.png: Updated the clothes salesman, + it was way out of date. + +2006-10-12 Cédric Borgese + + * data/graphics/tiles/Woodland_x3.png : Enlarge the trunk and the + base of the trees in the woodland tileset. + +2006-10-09 Yohann Ferreira + + * src/gui/buysell.cpp, src/gui/buy.cpp : A little tweak to the buy + dialogs. + +2006-10-07 Bjørn Lindeijer + + * src/resources/mapreader.cpp: Added support for gzip compressed map + layers. + * configure.ac, The Mana World.dev: Increased version to 0.0.22. + * src/map.cpp: Removed unused setSize method. Also introduced + initializeOverlays method and removed the confusing setOverlay (which + actually added one). + * src/properties.h: Added convenience method to read a property as a + float. + * src/map.cpp, src/resources/ambientoverlay.cpp, + src/resources/ambientoverlay.h: Resolved some weirdness involving + the terms scroll and speed. + +2006-10-07 Eugenio Favalli + + * The Mana World.dev, tmw.cbp: Updated project files. + +2006-10-03 Bjørn Lindeijer + + * data/graphics/sprites/item006.xml, + data/graphics/sprites/item007.xml, + data/graphics/sprites/item008.xml, + data/graphics/sprites/item009.xml, + data/graphics/sprites/item006.png, + data/graphics/sprites/item007.png, + data/graphics/sprites/item008.png, + data/graphics/sprites/item009.png, + data/graphics/sprites/item010.xml, + data/graphics/sprites/item010.png: Removed empty frames from + headgears. + +2006-10-03 Björn Steinbrink + + * src/map.cpp, src/map.h, src/Makefile.am, + src/resources/mapreader.cpp, src/resources/ambientoverlay.cpp, + src/resources/ambientoverlay.h: Turned AmbientOverlay into a class. + Cleaned up the associated code. + +2006-10-01 Eugenio Favalli + + * tools/Purger.java: Added a tool to purge old accounts from eAthena's + database files. + +2006-10-01 Bjørn Lindeijer + + * src/game.cpp, src/gui/trade.cpp, src/gui/inventorywindow.cpp: + Accepted patches by GDO and VictorSan that fix problems with hiding + windows using h and problems with trade window positioning. 2006-09-28 Björn Steinbrink diff --git a/NEWS b/NEWS index 2b77dca3..4cb3dbb8 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +0.0.22 (...) +- Added support for gzip compressed map layer data +- Fixed problem with OpenGL related redefinition +- Fixed problems with hiding windows using h +- Fixed trade window positioning + 0.0.21 (17 September 2006) - Added item pickup messages to the chat dialog - Added XP bar to ministatus in the top left diff --git a/The Mana World.dev b/The Mana World.dev index c449291e..bff3b310 100644 --- a/The Mana World.dev +++ b/The Mana World.dev @@ -31,20 +31,20 @@ CompilerSettings=0010001001000001001101 [VersionInfo] Major=0 -Minor=0 -Release=20 +Minor=1 +Release=0 Build=0 LanguageID=1033 CharsetID=1252 CompanyName=The Mana World Development Team -FileVersion=0.0.20 +FileVersion=0.1.0 FileDescription=The Mana World InternalName=tmw.exe LegalCopyright=2004-2006 (C) LegalTrademarks= OriginalFilename=tmw.exe ProductName=The Mana World MMORPG -ProductVersion=0.0.20 +ProductVersion=0.1.0 AutoIncBuildNr=0 [Unit8] @@ -2457,3 +2457,22 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit236] +FileName=src\resources\ambientoverlay.cpp +CompileCpp=1 +Folder=resources +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit237] +FileName=src\resources\ambientoverlay.h +CompileCpp=1 +Folder=resources +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= diff --git a/configure.ac b/configure.ac index ce4c6cc5..d32aee08 100755 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,9 @@ AC_MSG_ERROR([ *** Unable to find SDL library (http://www.libsdl.org/)])) AC_CHECK_HEADERS([SDL.h], , AC_MSG_ERROR([ *** SDL library found but cannot find headers (http://www.libsdl.org/)])) +AC_CHECK_LIB([z], [inflate], , +AC_MSG_ERROR([ *** Unable to find zlib (http://www.gzip.org/zlib/)])) + AC_CHECK_LIB([physfs], [PHYSFS_init], , AC_MSG_ERROR([ *** Unable to find PhysFS library (http://icculus.org/physfs/)])) AC_CHECK_HEADERS([physfs.h], , diff --git a/debian/rules b/debian/rules index da8deaba..b44be0bc 100755 --- a/debian/rules +++ b/debian/rules @@ -17,7 +17,13 @@ DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) config.status: dh_testdir - ./autogen.sh + + echo "Generating build information using aclocal, autoheader, automake and autoconf." +# Regerate configuration files + aclocal + autoheader + automake --gnu --add-missing --copy + autoconf CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=/usr/share/man6/man --infodir=/usr/share/doc/tmw --datadir=/usr/share/games --bindir=/usr/games --with-opengl diff --git a/debian/tmw-data.dirs b/debian/tmw-data.dirs index aebeb3f8..654af36d 100644 --- a/debian/tmw-data.dirs +++ b/debian/tmw-data.dirs @@ -7,6 +7,7 @@ usr/share/games/tmw/data/graphics usr/share/games/tmw/data/graphics/gui usr/share/games/tmw/data/graphics/sprites usr/share/games/tmw/data/graphics/images +usr/share/games/tmw/data/graphics/items usr/share/games/tmw/data/graphics/tiles usr/share/games/tmw/data/maps usr/share/games/tmw/data/sfx diff --git a/debian/tmw-data.install b/debian/tmw-data.install index 71b34a98..74499687 100644 --- a/debian/tmw-data.install +++ b/debian/tmw-data.install @@ -4,6 +4,7 @@ data/graphics/gui/*.png usr/share/games/tmw/data/graphics/gui data/graphics/sprites/*.png usr/share/games/tmw/data/graphics/sprites data/graphics/sprites/*.xml usr/share/games/tmw/data/graphics/sprites data/graphics/images/*.png usr/share/games/tmw/data/graphics/images +data/graphics/items/*.png usr/share/games/tmw/data/graphics/items data/graphics/tiles/*.png usr/share/games/tmw/data/graphics/tiles data/maps/*.tmx.gz usr/share/games/tmw/data/maps data/sfx/*.ogg usr/share/games/tmw/data/sfx diff --git a/debian/tmw-music.install b/debian/tmw-music.install index b4a17199..b3494726 100644 --- a/debian/tmw-music.install +++ b/debian/tmw-music.install @@ -1,3 +1 @@ data/music/*.ogg usr/share/games/tmw/data/music -data/music/*.mp3 usr/share/games/tmw/data/music - 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 #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::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::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::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 mOverlays; + std::list 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 #include +#include /** * 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 +#include #include #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; } diff --git a/tmw.cbp b/tmw.cbp index 89a38bcb..492ace6f 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -28,8 +28,6 @@ - - @@ -42,6 +40,11 @@ + + + + + + + + + + + + + + + + + + +