From 05a12d5568111fa13759026442ed358605bf9a28 Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Thu, 23 Feb 2006 16:02:00 +0000 Subject: A bunch of mostly cosmetic cleanups. --- src/being.cpp | 35 +++++------------------------------ src/being.h | 10 ++++++++-- src/beingmanager.cpp | 7 +++---- src/beingmanager.h | 1 + src/engine.cpp | 9 +++++++-- src/gui/equipmentwindow.h | 3 +-- src/gui/minimap.cpp | 23 ++++++----------------- src/gui/minimap.h | 5 ++--- src/gui/windowcontainer.cpp | 12 +++--------- src/gui/windowcontainer.h | 11 ++++------- src/inventory.cpp | 40 ++++++++++++++++++++-------------------- src/inventory.h | 2 +- src/logindata.h | 1 + src/main.cpp | 6 +++--- src/main.h | 2 +- src/net/loginhandler.cpp | 2 +- src/openglgraphics.cpp | 1 - 17 files changed, 67 insertions(+), 103 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index 2fb13607..253c2d24 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -314,11 +314,10 @@ void Being::setWeaponById(Uint16 weapon) } } -int -Being::getXOffset() const +int Being::getOffset(char pos, char neg) const { - // Only beings walking to the left or the right have an x offset - if (action != WALK || !(direction & (LEFT | RIGHT))) { + // Check whether we're walking in the requested direction + if (action != WALK || !(direction & (pos | neg))) { return 0; } @@ -330,32 +329,8 @@ Being::getXOffset() const offset = 0; } - // Going to the left? Invert the offset. - if (direction & LEFT) { - offset = -offset; - } - - return offset; -} - -int -Being::getYOffset() const -{ - // Only beings walking up or down have an y offset - if (action != WALK || !(direction & (UP | DOWN))) { - return 0; - } - - int offset = (get_elapsed_time(walk_time) * 32) / mWalkSpeed; - - // We calculate the offset _from_ the _target_ location - offset -= 32; - if (offset > 0) { - offset = 0; - } - - // Going up? Invert the offset. - if (direction & UP) { + // Going into negative direction? Invert the offset. + if (direction & pos) { offset = -offset; } diff --git a/src/being.h b/src/being.h index 45cfb15d..db6afbb8 100644 --- a/src/being.h +++ b/src/being.h @@ -278,13 +278,13 @@ class Being : public Sprite * Get the current X pixel offset. */ int - getXOffset() const; + getXOffset() const { return getOffset(LEFT, RIGHT); } /** * Get the current Y pixel offset. */ int - getYOffset() const; + getYOffset() const { return getOffset(UP, DOWN); } protected: /** @@ -293,6 +293,12 @@ class Being : public Sprite void setPath(std::list path); + /** + * Calculates the offset in the given directions. + * If walking in direction 'neg' the value is negated. + */ + int getOffset(char pos, char neg) const; + Uint32 mId; /**< Unique sprite id */ Uint16 mWeapon; /**< Weapon picture id */ Uint16 mWalkSpeed; /**< Walking speed */ diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index e6c88041..311cfa91 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -95,7 +95,7 @@ void BeingManager::destroyBeing(Being *being) Being* BeingManager::findBeing(Uint32 id) { - for (Beings::iterator i = mBeings.begin(); i != mBeings.end(); i++) + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { Being *being = (*i); if (being->getId() == id) { @@ -111,7 +111,7 @@ Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) beingFinder.y = y; beingFinder.type = type; - Beings::iterator i = find_if(mBeings.begin(), mBeings.end(), beingFinder); + BeingIterator i = find_if(mBeings.begin(), mBeings.end(), beingFinder); return (i == mBeings.end()) ? NULL : *i; } @@ -128,8 +128,7 @@ void BeingManager::clear() mBeings.remove(player_node); } - Beings::iterator i; - for (i = mBeings.begin(); i != mBeings.end(); i++) + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { delete (*i); } diff --git a/src/beingmanager.h b/src/beingmanager.h index e50e804c..2347021c 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -31,6 +31,7 @@ class Map; class Network; typedef std::list Beings; +typedef Beings::iterator BeingIterator; class BeingManager { diff --git a/src/engine.cpp b/src/engine.cpp index 4a637777..879a6b21 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -136,7 +136,12 @@ void Engine::changeMap(std::string mapPath) std::string oldMusic = ""; // Notify the minimap and beingManager about the map change - minimap->setMap(newMap); + Image *mapImage = NULL; + if (newMap->hasProperty("minimap")) { + ResourceManager *resman = ResourceManager::getInstance(); + mapImage = resman->getImage(newMap->getProperty("minimap")); + } + minimap->setMapImage(mapImage); beingManager->setMap(newMap); if (mCurrentMap) { @@ -252,7 +257,7 @@ void Engine::draw(Graphics *graphics) // Draw player nickname, speech, and emotion sprite as needed Beings *beings = beingManager->getAll(); - for (Beings::iterator i = beings->begin(); i != beings->end(); i++) + for (BeingIterator i = beings->begin(); i != beings->end(); i++) { (*i)->drawSpeech(graphics, -map_x, -map_y); (*i)->drawName(graphics, -map_x, -map_y); diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 651c593a..d55adb16 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -22,7 +22,7 @@ */ #ifndef _TMW_EQUIPMENT_H -#define _TMW_EQUIPMENT_H +#define _TMW_EQUIPMENT_H #include "window.h" @@ -56,7 +56,6 @@ class EquipmentWindow : public Window Spriteset *itemset; Equipment *mEquipment; - }; extern EquipmentWindow *equipmentWindow; diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 1165d7bb..e19a8c62 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -26,10 +26,8 @@ #include "../being.h" #include "../beingmanager.h" #include "../graphics.h" -#include "../map.h" #include "../resources/image.h" -#include "../resources/resourcemanager.h" Minimap::Minimap(): Window("Map"), @@ -48,32 +46,23 @@ Minimap::~Minimap() } } -void Minimap::setMap(Map *map) +void Minimap::setMapImage(Image *img) { if (mMapImage) { mMapImage->decRef(); } - if (map->hasProperty("minimap")) - { - ResourceManager *resman = ResourceManager::getInstance(); - mMapImage = resman->getImage(map->getProperty("minimap")); + mMapImage = img; - if (mMapImage != NULL) - { - setVisible(true); - mMapImage->setAlpha(0.7); - } - else - { - setVisible(false); - } + if (mMapImage) + { + setVisible(true); + mMapImage->setAlpha(0.7); } else { setVisible(false); - mMapImage = NULL; } } diff --git a/src/gui/minimap.h b/src/gui/minimap.h index 14db195b..53b18630 100644 --- a/src/gui/minimap.h +++ b/src/gui/minimap.h @@ -26,7 +26,6 @@ #include "window.h" -class Map; class Image; /** @@ -48,9 +47,9 @@ class Minimap : public Window ~Minimap(); /** - * Sets the map that should be displayed. + * Sets the map image that should be displayed. */ - void setMap(Map *map); + void setMapImage(Image *img); /** * Draws the minimap. diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp index b79e39de..3803b652 100644 --- a/src/gui/windowcontainer.cpp +++ b/src/gui/windowcontainer.cpp @@ -23,23 +23,17 @@ #include "windowcontainer.h" -WindowContainer::WindowContainer() -{ -} - void WindowContainer::logic() { - std::list::iterator i = deathList.begin(); - for (i= deathList.begin(); i != deathList.end(); i++) { + for (WidgetIterator i = mDeathList.begin(); i != mDeathList.end(); i++) { delete (*i); } - - deathList.clear(); + mDeathList.clear(); gcn::Container::logic(); } void WindowContainer::scheduleDelete(gcn::Widget *widget) { - deathList.push_back(widget); + mDeathList.push_back(widget); } diff --git a/src/gui/windowcontainer.h b/src/gui/windowcontainer.h index 533e42e4..b860fa3c 100644 --- a/src/gui/windowcontainer.h +++ b/src/gui/windowcontainer.h @@ -33,11 +33,6 @@ */ class WindowContainer : public gcn::Container { public: - /** - * Constructor. - */ - WindowContainer(); - /** * Do GUI logic. This functions adds automatic deletion of objects that * volunteered to be deleted. @@ -50,11 +45,13 @@ class WindowContainer : public gcn::Container { */ void scheduleDelete(gcn::Widget *widget); - protected: + private: /** * List of widgets that are scheduled to be deleted. */ - std::list deathList; + typedef std::list Widgets; + typedef Widgets::iterator WidgetIterator; + Widgets mDeathList; }; #endif diff --git a/src/inventory.cpp b/src/inventory.cpp index 6cfcb921..65f21292 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -27,15 +27,15 @@ Inventory::Inventory() { - items = new Item[INVENTORY_SIZE]; + mItems = new Item[INVENTORY_SIZE]; for (int i = 0; i < INVENTORY_SIZE; i++) { - items[i].setInvIndex(i); + mItems[i].setInvIndex(i); } } Inventory::~Inventory() { - delete [] items; + delete [] mItems; } Item* Inventory::getItem(int index) @@ -45,7 +45,7 @@ Item* Inventory::getItem(int index) return 0; } - return &items[index]; + return &mItems[index]; } void Inventory::addItem(int id, int quantity, bool equipment) @@ -55,27 +55,27 @@ void Inventory::addItem(int id, int quantity, bool equipment) void Inventory::addItem(int index, int id, int quantity, bool equipment) { - items[index].setId(id); - items[index].increaseQuantity(quantity); - items[index].setEquipment(equipment); + mItems[index].setId(id); + mItems[index].increaseQuantity(quantity); + mItems[index].setEquipment(equipment); } void Inventory::clear() { for (int i = 0; i < INVENTORY_SIZE; i++) { - items[i].setId(-1); - items[i].setQuantity(0); - items[i].setEquipped(false); + mItems[i].setId(-1); + mItems[i].setQuantity(0); + mItems[i].setEquipped(false); } } void Inventory::removeItem(int id) { for (int i = 0; i < INVENTORY_SIZE; i++) { - if (items[i].getId() == id) { - items[i].setId(-1); - items[i].setQuantity(0); + if (mItems[i].getId() == id) { + mItems[i].setId(-1); + mItems[i].setQuantity(0); } } } @@ -83,7 +83,7 @@ void Inventory::removeItem(int id) bool Inventory::contains(Item *item) { for (int i = 0; i < INVENTORY_SIZE; i++) { - if (items[i].getId() == item->getId()) { + if (mItems[i].getId() == item->getId()) { return true; } } @@ -94,7 +94,7 @@ bool Inventory::contains(Item *item) int Inventory::getFreeSlot() { for (int i = 2; i < INVENTORY_SIZE; i++) { - if (items[i].getId() == -1) { + if (mItems[i].getId() == -1) { return i; } } @@ -103,16 +103,16 @@ int Inventory::getFreeSlot() int Inventory::getNumberOfSlotsUsed() { - int NumberOfFilledSlot = 0; + int numberOfFilledSlot = 0; for (int i = 0; i < INVENTORY_SIZE; i++) { - if (items[i].getId() > -1 || items[i].getQuantity() > 0) + if (mItems[i].getId() > -1 || mItems[i].getQuantity() > 0) { - NumberOfFilledSlot++; + numberOfFilledSlot++; } } - return NumberOfFilledSlot; + return numberOfFilledSlot; } int Inventory::getLastUsedSlot() @@ -120,7 +120,7 @@ int Inventory::getLastUsedSlot() int i; for (i = INVENTORY_SIZE - 1; i >= 0; i--) { - if ((items[i].getId() != -1) && (items[i].getQuantity() > 0)) { + if ((mItems[i].getId() != -1) && (mItems[i].getQuantity() > 0)) { break; } } diff --git a/src/inventory.h b/src/inventory.h index b1f4fb01..40bcafbb 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -80,7 +80,7 @@ class Inventory int getLastUsedSlot(); protected: - Item *items; /**< The holder of items */ + Item *mItems; /**< The holder of items */ }; #endif diff --git a/src/logindata.h b/src/logindata.h index c7bee88a..f4fcd1b1 100644 --- a/src/logindata.h +++ b/src/logindata.h @@ -34,6 +34,7 @@ struct LoginData int account_ID; int session_ID1; int session_ID2; + char sex; bool remember; }; diff --git a/src/main.cpp b/src/main.cpp index 4e47f7e4..af6d21e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,7 +76,7 @@ #include "resources/resourcemanager.h" // Account infos -char sex, n_server, n_character; +char n_server, n_character; Spriteset *hairset = NULL, *playerset = NULL; Graphics *graphics; @@ -443,7 +443,7 @@ void charLogin(Network *network, LoginData *loginData) outMsg.writeInt32(loginData->session_ID1); outMsg.writeInt32(loginData->session_ID2); outMsg.writeInt16(0); // unknown - outMsg.writeInt8(sex); + outMsg.writeInt8(loginData->sex); // We get 4 useless bytes before the real answer comes in network->skip(4); @@ -465,7 +465,7 @@ void mapLogin(Network *network, LoginData *loginData) outMsg.writeInt32(player_node->mCharId); outMsg.writeInt32(loginData->session_ID1); outMsg.writeInt32(loginData->session_ID2); - outMsg.writeInt8(sex); + outMsg.writeInt8(loginData->sex); // We get 4 useless bytes before the real answer comes in network->skip(4); diff --git a/src/main.h b/src/main.h index 2f86c916..5506bbb1 100644 --- a/src/main.h +++ b/src/main.h @@ -67,7 +67,7 @@ enum { LEN_MIN_PASSWORD = 4 }; -extern char sex, n_server, n_character; +extern char n_server, n_character; extern unsigned char state; extern std::string errorMessage; extern Sound sound; diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index aca08e6a..195e54e9 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -59,7 +59,7 @@ void LoginHandler::handleMessage(MessageIn *msg) mLoginData->account_ID = msg->readInt32(); mLoginData->session_ID2 = msg->readInt32(); msg->skip(30); // unknown - sex = msg->readInt8(); + mLoginData->sex = msg->readInt8(); for (int i = 0; i < n_server; i++) { diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index efe875bc..5e2cb500 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -25,7 +25,6 @@ #include "openglgraphics.h" -#include #include #ifdef __APPLE__ -- cgit v1.2.3-70-g09d2