From 7a65eb17a322cb22e7940504797844114fb77d79 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 07:54:38 -0700 Subject: Fix some problems with deleting NPCs early --- src/beingmanager.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/beingmanager.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 3c8edf86..3b73d29f 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -96,7 +96,10 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) void BeingManager::destroyBeing(Being *being) { mBeings.remove(being); - delete being; + if (being == current_npc) + current_npc->handleDeath(); + else + delete being; } Being* BeingManager::findBeing(Uint32 id) @@ -193,6 +196,12 @@ void BeingManager::clear() mBeings.remove(player_node); } + if (current_npc) + { + mBeings.remove(current_npc); + current_npc->handleDeath(); + } + delete_all(mBeings); mBeings.clear(); -- cgit v1.2.3-60-g2f50 From f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 13:38:55 -0700 Subject: Fix NPC handling to not need a handle on the NPC The Being ID is used instead, as that is all that was ever really needed. --- src/beingmanager.cpp | 21 +++++++------- src/beingmanager.h | 10 ++++++- src/game.cpp | 10 +++---- src/gui/buy.cpp | 2 +- src/gui/buysell.cpp | 22 +++++++++++---- src/gui/buysell.h | 7 ++++- src/gui/npc_text.cpp | 21 ++++++++++---- src/gui/npc_text.h | 8 +++++- src/gui/npcintegerdialog.cpp | 14 +++++++-- src/gui/npcintegerdialog.h | 4 ++- src/gui/npclistdialog.cpp | 12 ++++++-- src/gui/npclistdialog.h | 5 +++- src/gui/npcstringdialog.cpp | 16 +++++++++-- src/gui/npcstringdialog.h | 5 +++- src/gui/sell.cpp | 2 +- src/net/beinghandler.cpp | 14 ++++++--- src/net/buysellhandler.cpp | 4 +-- src/net/npchandler.cpp | 27 ++++++++---------- src/net/playerhandler.cpp | 4 +-- src/npc.cpp | 67 ++------------------------------------------ src/npc.h | 15 +--------- 21 files changed, 142 insertions(+), 148 deletions(-) (limited to 'src/beingmanager.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 3b73d29f..273436bf 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -96,10 +96,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) void BeingManager::destroyBeing(Being *being) { mBeings.remove(being); - if (being == current_npc) - current_npc->handleDeath(); - else - delete being; + delete being; } Being* BeingManager::findBeing(Uint32 id) @@ -196,12 +193,6 @@ void BeingManager::clear() mBeings.remove(player_node); } - if (current_npc) - { - mBeings.remove(current_npc); - current_npc->handleDeath(); - } - delete_all(mBeings); mBeings.clear(); @@ -264,3 +255,13 @@ Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } + +bool BeingManager::hasBeing(Being *being) +{ + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) + { + if (being == *i) return true; + } + + return false; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index 11721709..02c83725 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -98,13 +98,21 @@ class BeingManager */ Beings& getAll(); + /** + * Returns true if the given being is in the manager's list, false + * otherwise. + * + * \param being the being to search for + */ + bool hasBeing(Being *being); + /** * Logic. */ void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index cb85fc5c..6f9dbb88 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -198,13 +198,13 @@ void createGuiWindows(Network *network) miniStatusWindow = new MiniStatusWindow; buyDialog = new BuyDialog(network); sellDialog = new SellDialog(network); - buySellDialog = new BuySellDialog; + buySellDialog = new BuySellDialog(network); inventoryWindow = new InventoryWindow; emoteWindow = new EmoteWindow; - npcTextDialog = new NpcTextDialog; - npcIntegerDialog = new NpcIntegerDialog; - npcListDialog = new NpcListDialog; - npcStringDialog = new NpcStringDialog; + npcTextDialog = new NpcTextDialog(network); + npcIntegerDialog = new NpcIntegerDialog(network); + npcListDialog = new NpcListDialog(network); + npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog; setupWindow = new Setup; minimap = new Minimap; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index c084c7c2..cad21ab5 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -132,7 +132,7 @@ void BuyDialog::action(const gcn::ActionEvent &event) if (event.getId() == "quit") { setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; return; } diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 8bf5f1f4..c1c934d1 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -24,10 +24,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -BuySellDialog::BuySellDialog(): - Window(_("Shop")) +BuySellDialog::BuySellDialog(Network *network): + Window(_("Shop")), mNetwork(network) { Button *buyButton = 0; static const char *buttonNames[] = { @@ -60,12 +63,19 @@ void BuySellDialog::logic() void BuySellDialog::action(const gcn::ActionEvent &event) { + setVisible(false); + int action; if (event.getId() == "Buy") { - current_npc->buy(); + action = 0; } else if (event.getId() == "Sell") { - current_npc->sell(); + action = 1; } else if (event.getId() == "Cancel") { - if (current_npc) current_npc->handleDeath(); + current_npc = 0; + return; } - setVisible(false); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(action); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 754bb551..197c1a2b 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -26,6 +26,8 @@ #include "window.h" +class Network; + /** * A dialog to choose between buying or selling at a shop. * @@ -40,7 +42,7 @@ class BuySellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuySellDialog(); + BuySellDialog(Network *network); /** * Check for current NPC @@ -51,6 +53,9 @@ class BuySellDialog : public Window, public gcn::ActionListener * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); + + private: + Network *mNetwork; }; #endif diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 1750cbd4..db0015e9 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcTextDialog::NpcTextDialog(): - Window(_("NPC")), +NpcTextDialog::NpcTextDialog(Network *network): + Window(_("NPC")), mNetwork(network), mState(NPC_TEXT_STATE_WAITING) { setResizable(true); @@ -97,14 +100,14 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) if (event.getId() == "ok") { if (mState == NPC_TEXT_STATE_NEXT && current_npc) { - current_npc->nextDialog(); + nextDialog(); addText("\n> Next\n"); } else if (mState == NPC_TEXT_STATE_CLOSE || (mState == NPC_TEXT_STATE_NEXT && !current_npc)) { setText(""); - if (current_npc) current_npc->nextDialog(); + if (current_npc) nextDialog(); setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } else return; } else return; @@ -114,10 +117,16 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) mState = NPC_TEXT_STATE_WAITING; } +void NpcTextDialog::nextDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); setText(mText); } - diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 00b11b3c..62486fff 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -28,6 +28,9 @@ #include "window.h" +#include "../npc.h" + +class Network; class TextBox; /** @@ -43,7 +46,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcTextDialog(); + NpcTextDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -74,6 +77,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener void showCloseButton(); + void nextDialog(int npcID = current_npc); + /** * Called when resizing the window. * @@ -82,6 +87,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener void widgetResized(const gcn::Event &event); private: + Network *mNetwork; gcn::ScrollArea *mScrollArea; TextBox *mTextBox; gcn::Button *mButton; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index f91b42da..f6d788df 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -28,13 +28,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcIntegerDialog::NpcIntegerDialog(): - Window(_("NPC Number Request")) +NpcIntegerDialog::NpcIntegerDialog(Network *network): + Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField; @@ -104,7 +107,12 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); - current_npc->integerInput(mValueField->getValue()); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(current_npc); + outMsg.writeInt32(mValueField->getValue()); + mValueField->reset(); } } diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index 6083338c..80a21848 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -26,6 +26,7 @@ #include "window.h" +class Network; class IntTextField; /** @@ -41,7 +42,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcIntegerDialog(); + NpcIntegerDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -81,6 +82,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener void setVisible(bool visible); private: + Network *mNetwork; gcn::Button *mDecButton; gcn::Button *mIncButton; IntTextField *mValueField; diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 8349cb4a..fc7d2979 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -31,13 +31,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcListDialog::NpcListDialog(): - Window(_("NPC")) +NpcListDialog::NpcListDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -115,7 +118,10 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { setVisible(false); reset(); - current_npc->dialogChoice(choice); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(choice); } } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index e7e2f9a9..a7b49506 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -29,6 +29,8 @@ #include +class Network; + /** * The npc list dialog. * @@ -43,7 +45,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * * @see Window::Window */ - NpcListDialog(); + NpcListDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -75,6 +77,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, void setVisible(bool visible); private: + Network *mNetwork; gcn::ListBox *mItemList; std::vector mItems; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 679c93e5..7ed05288 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -28,13 +28,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcStringDialog::NpcStringDialog(): - Window(_("NPC Text Request")) +NpcStringDialog::NpcStringDialog(Network *network): + Window(_("NPC Text Request")), mNetwork(network) { mValueField = new TextField(""); @@ -74,8 +77,15 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); - current_npc->stringInput(mValueField->getText()); + std::string text = mValueField->getText(); mValueField->setText(""); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); + outMsg.writeInt16(text.length() + 9); + outMsg.writeInt32(current_npc); + outMsg.writeString(text, text.length()); + outMsg.writeInt8(0); } bool NpcStringDialog::isInputFocused() diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index 31f9c9a0..43283219 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -26,6 +26,8 @@ #include +class Network; + /** * The npc integer input dialog. * @@ -39,7 +41,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcStringDialog(); + NpcStringDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -71,6 +73,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener void setVisible(bool visible); private: + Network *mNetwork; gcn::TextField *mValueField; std::string mDefault; }; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 14620aa6..51fc8f9f 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -133,7 +133,7 @@ void SellDialog::action(const gcn::ActionEvent &event) if (event.getId() == "quit") { setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; return; } diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 3e746eb5..982667d1 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -35,6 +35,10 @@ #include "../npc.h" #include "../player_relations.h" +#include "../gui/npc_text.h" + +extern NpcTextDialog *npcTextDialog; + const int EMOTION_TIME = 150; /**< Duration of emotion icon */ BeingHandler::BeingHandler(bool enableSync): @@ -204,7 +208,12 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_BEING_REMOVE: // A being should be removed or has died - dstBeing = beingManager->findBeing(msg->readInt32()); + id = msg->readInt32(); + + if (id == current_npc) + npcTextDialog->showCloseButton(); + + dstBeing = beingManager->findBeing(id); if (!dstBeing) break; @@ -213,9 +222,6 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (dstBeing == current_npc) - current_npc->handleDeath(); - if (msg->readInt8() == 1) dstBeing->setAction(Being::DEAD); else diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index a2442d70..714bc0ea 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -65,7 +65,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) sellDialog->setVisible(false); sellDialog->reset(); buySellDialog->setVisible(true); - current_npc = dynamic_cast(beingManager->findBeing(msg->readInt32())); + current_npc = msg->readInt32(); break; case SMSG_NPC_BUY: @@ -107,7 +107,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) } else { chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } break; diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index ae521bd5..405217bb 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -54,24 +54,21 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { int id; - NPC *temporaryNPC; switch (msg->getId()) { case SMSG_NPC_CHOICE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); break; case SMSG_NPC_MESSAGE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(false); npcTextDialog->setVisible(true); @@ -79,30 +76,28 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_CLOSE: id = msg->readInt32(); - temporaryNPC = dynamic_cast(beingManager->findBeing(id)); // If we're talking to that NPC, show the close button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showCloseButton(); // Otherwise, move on as an empty dialog doesn't help else - temporaryNPC->nextDialog(); + npcTextDialog->nextDialog(id); break; case SMSG_NPC_NEXT: id = msg->readInt32(); - temporaryNPC = dynamic_cast(beingManager->findBeing(id)); // If we're talking to that NPC, show the next button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showNextButton(); - else if (temporaryNPC) // Otherwise, move on as an empty dialog doesn't help - temporaryNPC->nextDialog(); + else + npcTextDialog->nextDialog(id); break; case SMSG_NPC_INT_INPUT: // Request for an integer - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setDefaultValue(0); npcIntegerDialog->setVisible(true); @@ -111,8 +106,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_STR_INPUT: // Request for a string - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); npcStringDialog->requestFocus(); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index ee1b2fd9..550753b7 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -93,7 +93,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } } deathListener; } @@ -147,8 +147,6 @@ void PlayerHandler::handleMessage(MessageIn *msg) // Switch the actual map, deleting the previous one if necessary engine->changeMap(mapPath); - if (current_npc) current_npc->handleDeath(); - float scrollOffsetX = 0.0f; float scrollOffsetY = 0.0f; diff --git a/src/npc.cpp b/src/npc.cpp index ecac2509..8fd8a86b 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -20,6 +20,7 @@ */ #include "animatedsprite.h" +#include "beingmanager.h" #include "npc.h" #include "particle.h" #include "text.h" @@ -33,7 +34,7 @@ extern NpcTextDialog *npcTextDialog; -NPC *current_npc = NULL; +int current_npc = NULL; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -113,60 +114,6 @@ void NPC::talk() outMsg.writeInt8(0); } -void NPC::nextDialog() -{ - if (!this || !mNetwork) return; - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(mId); -} - -void NPC::dialogChoice(char choice) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(mId); - outMsg.writeInt8(choice); -} - -void NPC::integerInput(int value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(mId); - outMsg.writeInt32(value); -} - -void NPC::stringInput(const std::string &value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(value.length() + 9); - outMsg.writeInt32(mId); - outMsg.writeString(value, value.length()); - outMsg.writeInt8(0); -} - -/* - * TODO Unify the buy() and sell() methods, without sacrificing readability of - * the code calling the method. buy(bool buySell) would be bad... - */ -void NPC::buy() -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(0); -} - -void NPC::sell() -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(1); -} - void NPC::updateCoords() { if (mName) @@ -174,13 +121,3 @@ void NPC::updateCoords() mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET); } } - -void NPC::handleDeath() -{ - if (this != current_npc) return; - - if (npcTextDialog->isVisible()) - npcTextDialog->showCloseButton(); - else - current_npc = NULL; -} diff --git a/src/npc.h b/src/npc.h index 81b6d51e..ef9fdc7d 100644 --- a/src/npc.h +++ b/src/npc.h @@ -42,19 +42,6 @@ class NPC : public Player virtual Type getType() const; void talk(); - void nextDialog(); - void dialogChoice(char choice); - void integerInput(int value); - void stringInput(const std::string &value); - - void buy(); - void sell(); - - /** - * Call this to ease clean up of the current NPC, without causing - * interface problems - */ - void handleDeath(); protected: Network *mNetwork; void updateCoords(); @@ -62,6 +49,6 @@ class NPC : public Player Text *mName; }; -extern NPC *current_npc; +extern int current_npc; #endif -- cgit v1.2.3-60-g2f50 From 0dde31c3db09113639fa443142995b6efcff6646 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 19:04:39 -0700 Subject: Fix NPC handling to not need a handle on the NPC Loosely based on TMW commit f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 Signed-off-by: Ira Rice --- src/beingmanager.cpp | 10 +++++++ src/beingmanager.h | 10 ++++++- src/game.cpp | 10 +++---- src/gui/buysell.cpp | 34 +++++++++++++++++------ src/gui/buysell.h | 7 ++++- src/gui/npc_text.cpp | 18 +++++++++--- src/gui/npc_text.h | 9 ++++-- src/gui/npcintegerdialog.cpp | 16 +++++++---- src/gui/npcintegerdialog.h | 4 ++- src/gui/npclistdialog.cpp | 16 +++++++---- src/gui/npclistdialog.h | 5 +++- src/gui/npcstringdialog.cpp | 22 +++++++++++---- src/gui/npcstringdialog.h | 5 +++- src/net/beinghandler.cpp | 13 ++++----- src/net/buysellhandler.cpp | 25 ++++++++++------- src/net/npchandler.cpp | 22 +++++++-------- src/net/playerhandler.cpp | 2 +- src/npc.cpp | 65 ++------------------------------------------ src/npc.h | 13 +++------ 19 files changed, 165 insertions(+), 141 deletions(-) (limited to 'src/beingmanager.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index b4ffa76c..d63e0dc5 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -253,3 +253,13 @@ Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } + +bool BeingManager::hasBeing(Being *being) +{ + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) + { + if (being == *i) return true; + } + + return false; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index 59a7c76a..32ba6242 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -99,13 +99,21 @@ class BeingManager */ Beings& getAll(); + /** + * Returns true if the given being is in the manager's list, false + * otherwise. + * + * \param being the being to search for + */ + bool hasBeing(Being *being); + /** * Logic. */ void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 16790cac..110b75cc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -195,13 +195,13 @@ void createGuiWindows(Network *network) miniStatusWindow = new MiniStatusWindow(); buyDialog = new BuyDialog(network); sellDialog = new SellDialog(network); - buySellDialog = new BuySellDialog(); + buySellDialog = new BuySellDialog(network); inventoryWindow = new InventoryWindow(); emoteWindow = new EmoteWindow(); - npcTextDialog = new NpcTextDialog(); - npcIntegerDialog = new NpcIntegerDialog(); - npcListDialog = new NpcListDialog(); - npcStringDialog = new NpcStringDialog(); + npcTextDialog = new NpcTextDialog(network); + npcIntegerDialog = new NpcIntegerDialog(network); + npcListDialog = new NpcListDialog(network); + npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); setupWindow = new Setup(); minimap = new Minimap(); diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 7d63f184..dc7deef6 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -25,10 +25,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -BuySellDialog::BuySellDialog(): - Window(_("Shop")) +BuySellDialog::BuySellDialog(Network *network): + Window(_("Shop")), mNetwork(network) { Button *buyButton = 0; static const char *buttonNames[] = { @@ -54,12 +57,27 @@ BuySellDialog::BuySellDialog(): void BuySellDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "Buy") { - current_npc->buy(); - } else if (event.getId() == "Sell") { - current_npc->sell(); - } else if (event.getId() == "Cancel") { + setVisible(false); + int action = 0; + + NPC::mTalking = false; + + if (event.getId() == "Buy") + { + action = 0; + } + else if (event.getId() == "Sell") + { + action = 1; + } + else if (event.getId() == "Cancel") + { current_npc = 0; + return; } - setVisible(false); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(action); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index c12e3c9b..747066a7 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -27,6 +27,8 @@ #include "window.h" +class Network; + /** * A dialog to choose between buying or selling at a shop. * @@ -41,12 +43,15 @@ class BuySellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuySellDialog(); + BuySellDialog(Network *network); /** * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); + + private: + Network *mNetwork; }; #endif diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index c28f1403..b94e8aa4 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -29,10 +29,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcTextDialog::NpcTextDialog(): - Window(_("NPC")) +NpcTextDialog::NpcTextDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -87,12 +90,19 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) setVisible(false); if (current_npc) - current_npc->nextDialog(); + nextDialog(); - current_npc = NULL; + current_npc = 0; } } +void NpcTextDialog::nextDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 63d41cd6..a72de5d0 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -29,6 +29,9 @@ #include "window.h" +#include "../npc.h" + +class Network; class TextBox; /** @@ -44,7 +47,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcTextDialog(); + NpcTextDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -71,6 +74,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener */ void addText(const std::string &string); + void nextDialog(int npcID = current_npc); + /** * Called when resizing the window. * @@ -79,7 +84,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener void widgetResized(const gcn::Event &event); private: - gcn::Button *okButton; + Network *mNetwork; gcn::ScrollArea *mScrollArea; TextBox *mTextBox; gcn::Button *mButton; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 9c49a630..132a7608 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcIntegerDialog::NpcIntegerDialog(): - Window(_("NPC Number Request")) +NpcIntegerDialog::NpcIntegerDialog(Network *network): + Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField(); @@ -104,11 +107,14 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); + NPC::mTalking = false; - if (current_npc) - current_npc->integerInput(mValueField->getValue()); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(current_npc); + outMsg.writeInt32(mValueField->getValue()); - current_npc = NULL; + current_npc = 0; mValueField->reset(); } } diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index cca8cb32..15bdee48 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -27,6 +27,7 @@ #include "window.h" +class Network; class IntTextField; /** @@ -42,7 +43,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcIntegerDialog(); + NpcIntegerDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -78,6 +79,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener void requestFocus(); private: + Network *mNetwork; gcn::Button *mDecButton; gcn::Button *mIncButton; IntTextField *mValueField; diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 2c4dfc04..73b00239 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -31,10 +31,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcListDialog::NpcListDialog(): - Window(_("NPC")) +NpcListDialog::NpcListDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -86,6 +89,7 @@ void NpcListDialog::parseItems(const std::string &itemString) void NpcListDialog::reset() { + NPC::mTalking = false; mItemList->setSelected(-1); mItems.clear(); } @@ -112,10 +116,12 @@ void NpcListDialog::action(const gcn::ActionEvent &event) setVisible(false); reset(); - if (current_npc) - current_npc->dialogChoice(choice); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(choice); - current_npc = NULL; + current_npc = 0; } } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index de3a7a77..0a0e9813 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -30,6 +30,8 @@ #include "window.h" +class Network; + /** * The npc list dialog. * @@ -44,7 +46,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * * @see Window::Window */ - NpcListDialog(); + NpcListDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -79,6 +81,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, void requestFocus(); private: + Network *mNetwork; gcn::ListBox *mItemList; gcn::ScrollArea *scrollArea; gcn::Button *okButton; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 140ca40f..f2c7434c 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcStringDialog::NpcStringDialog(): - Window(_("NPC Text Request")) +NpcStringDialog::NpcStringDialog(Network *network): + Window(_("NPC Text Request")), mNetwork(network) { mValueField = new TextField(""); @@ -64,12 +67,19 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); + NPC::mTalking = false; - if (current_npc) - current_npc->stringInput(mValueField->getText()); - - current_npc = NULL; + std::string text = mValueField->getText(); mValueField->setText(""); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); + outMsg.writeInt16(text.length() + 9); + outMsg.writeInt32(current_npc); + outMsg.writeString(text, text.length()); + outMsg.writeInt8(0); + + current_npc = 0; } bool NpcStringDialog::isInputFocused() diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index c8871184..ee620daf 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -27,6 +27,8 @@ #include "window.h" +class Network; + /** * The npc integer input dialog. * @@ -40,7 +42,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcStringDialog(); + NpcStringDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -70,6 +72,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener void requestFocus(); private: + Network *mNetwork; gcn::TextField *mValueField; gcn::Button *okButton; gcn::Button *cancelButton; diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index c11d22e7..bae14a05 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -196,7 +196,11 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_BEING_REMOVE: // A being should be removed or has died - dstBeing = beingManager->findBeing(msg->readInt32()); + id = msg->readInt32(); + dstBeing = beingManager->findBeing(id); + + if (id == current_npc) + current_npc = 0; if (!dstBeing) break; @@ -205,12 +209,7 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (dstBeing == current_npc) - current_npc = NULL; - - if (msg->readInt8() == 1) - dstBeing->setAction(Being::DEAD); - else + if (!(msg->readInt8() == 1)) beingManager->destroyBeing(dstBeing); break; diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 245b8a50..e9255540 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -66,7 +66,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) sellDialog->setVisible(false); sellDialog->reset(); buySellDialog->setVisible(true); - current_npc = dynamic_cast(beingManager->findBeing(msg->readInt32())); + current_npc = msg->readInt32(); break; case SMSG_NPC_BUY: @@ -89,7 +89,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) case SMSG_NPC_SELL: msg->readInt16(); // length n_items = (msg->getLength() - 4) / 10; - if (n_items > 0) { + if (n_items > 0) + { sellDialog->setMoney(player_node->mGp); sellDialog->reset(); sellDialog->setVisible(true); @@ -101,21 +102,25 @@ void BuySellHandler::handleMessage(MessageIn *msg) msg->readInt32(); // OCvalue Item *item = player_node->getInventory()->getItem(index); - if (item && !(item->isEquipped())) { + + if (item && !(item->isEquipped())) sellDialog->addItem(item, value); - } } } - else { + else + { chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); current_npc = 0; } break; case SMSG_NPC_BUY_RESPONSE: - if (msg->readInt8() == 0) { + if (msg->readInt8() == 0) + { chatWindow->chatLog(_("Thanks for buying"), BY_SERVER); - } else { + } + else + { // Reset player money since buy dialog already assumed purchase // would go fine buyDialog->setMoney(player_node->mGp); @@ -124,11 +129,11 @@ void BuySellHandler::handleMessage(MessageIn *msg) break; case SMSG_NPC_SELL_RESPONSE: - if (msg->readInt8() == 0) { + if (msg->readInt8() == 0) chatWindow->chatLog(_("Thanks for selling"), BY_SERVER); - } else { + else chatWindow->chatLog(_("Unable to sell"), BY_SERVER); - } + break; } } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index a59ee814..1067a57e 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -20,6 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "messagein.h" #include "npchandler.h" #include "protocol.h" @@ -49,15 +51,14 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { - int id; + Uint32 id; switch (msg->getId()) { case SMSG_NPC_CHOICE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); npcListDialog->requestFocus(); @@ -65,17 +66,16 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_MESSAGE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); npcTextDialog->setVisible(true); break; case SMSG_NPC_CLOSE: id = msg->readInt32(); - if (current_npc == dynamic_cast(beingManager->findBeing(id))) - current_npc = NULL; + if (current_npc == id) + current_npc = 0; break; case SMSG_NPC_NEXT: @@ -84,8 +84,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_INT_INPUT: // Request for an integer - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setVisible(true); npcIntegerDialog->requestFocus(); @@ -93,8 +93,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_STR_INPUT: // Request for a string - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); npcStringDialog->requestFocus(); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index f18c5d82..ffeb3fab 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -92,7 +92,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - current_npc = NULL; + current_npc = 0; } } deathListener; } diff --git a/src/npc.cpp b/src/npc.cpp index 832e6926..92ef4d82 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -21,6 +21,7 @@ */ #include "animatedsprite.h" +#include "beingmanager.h" #include "npc.h" #include "particle.h" #include "text.h" @@ -32,8 +33,8 @@ #include "resources/npcdb.h" -NPC *current_npc = 0; bool NPC::mTalking = false; +Uint32 current_npc = 0; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -117,68 +118,6 @@ void NPC::talk() outMsg.writeInt8(0); } -void NPC::nextDialog() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(mId); -} - -void NPC::dialogChoice(char choice) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(mId); - outMsg.writeInt8(choice); -} - -void NPC::integerInput(int value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(mId); - outMsg.writeInt32(value); -} - -void NPC::stringInput(const std::string &value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(value.length() + 9); - outMsg.writeInt32(mId); - outMsg.writeString(value, value.length()); - outMsg.writeInt8(0); -} - -/* - * TODO Unify the buy() and sell() methods, without sacrificing readability of - * the code calling the method. buy(bool buySell) would be bad... - */ -void NPC::buy() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(0); -} - -void NPC::sell() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(1); -} - void NPC::updateCoords() { if (mName) diff --git a/src/npc.h b/src/npc.h index 0dc9c742..e1bf9737 100644 --- a/src/npc.h +++ b/src/npc.h @@ -23,6 +23,8 @@ #ifndef NPC_H #define NPC_H +#include + #include "player.h" class Network; @@ -42,14 +44,7 @@ class NPC : public Player virtual Type getType() const; - void talk(); - void nextDialog(); - void dialogChoice(char choice); - void integerInput(int value); - void stringInput(const std::string &value); - - void buy(); - void sell(); + void talk();; static bool mTalking; @@ -60,6 +55,6 @@ class NPC : public Player Text *mName; }; -extern NPC *current_npc; +extern Uint32 current_npc; #endif -- cgit v1.2.3-60-g2f50 From 5dd5ed1987bdafa8d32edf10317a3f80dd8b2708 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Feb 2009 10:51:37 -0700 Subject: Extended job numbers based on what's actually used for Ragnarok's server. TODO: Make this externally configurable, so that specific servers can specify what they use specific sprite IDs for, as well as specifying good defaults as well, in case that configuration file isn't found. Signed-off-by: Ira Rice --- src/beingmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/beingmanager.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index d63e0dc5..a2d39150 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -69,11 +69,11 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) { Being *being; - if (job < 10) + if (job <= 25 || (job >= 4001 && job <= 4049)) being = new Player(id, job, mMap); - else if (job >= 100 && job < 200) + else if (job >= 46 && job <= 1000) being = new NPC(id, job, mMap, mNetwork); - else if (job >= 1000 && job < 1200) + else if (job > 1000 && job <= 2000) being = new Monster(id, job, mMap); else being = new Being(id, job, mMap); -- cgit v1.2.3-60-g2f50 From 6b0cff837b7adae56dc90d12e9c0e256e6aab134 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Feb 2009 10:55:08 -0700 Subject: Forgot to extend the player or NPC specifying fields as well. Signed-off-by: Ira Rice --- src/beingmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/beingmanager.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index a2d39150..d6d71a91 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -79,7 +79,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) being = new Being(id, job, mMap); // Player or NPC - if (job < 200) + if (job <= 1000 || (job >= 4001 && job <= 4049)) { MessageOut outMsg(mNetwork); outMsg.writeInt16(0x0094); -- cgit v1.2.3-60-g2f50 From c75511fffc77d517fbf854ec8bef791f055de44c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 26 Feb 2009 22:22:22 +0100 Subject: Got rid of Sint{8,16,32} and Uint32 for being ID Using unsigned rarely makes sense, especially when the server doesn't use it either. Other uses of unsigned should be reviewed. In all other cases, int is the fastest integer type on any architecture. Using 8 or 16 bits can basically only be a memory optimization. --- src/being.cpp | 2 +- src/being.h | 12 ++++++------ src/beingmanager.cpp | 16 ++++++++-------- src/beingmanager.h | 14 +++++++------- src/floor_item.cpp | 10 +++++----- src/floor_item.h | 20 ++++++++++---------- src/flooritemmanager.cpp | 9 ++++----- src/flooritemmanager.h | 7 +++---- src/gui/popupmenu.h | 4 +--- src/localplayer.cpp | 2 +- src/localplayer.h | 4 ++-- src/monster.cpp | 2 +- src/monster.h | 2 +- src/net/beinghandler.cpp | 6 +++--- src/net/buysellhandler.cpp | 8 ++++---- src/net/chathandler.cpp | 2 +- src/net/equipmenthandler.cpp | 6 +++--- src/net/inventoryhandler.cpp | 6 +++--- src/net/itemhandler.cpp | 2 +- src/net/npchandler.cpp | 2 +- src/net/playerhandler.cpp | 22 +++++++++++----------- src/net/skillhandler.cpp | 8 ++++---- src/net/tradehandler.cpp | 6 +++--- src/npc.cpp | 2 +- src/npc.h | 2 +- 25 files changed, 86 insertions(+), 90 deletions(-) (limited to 'src/beingmanager.cpp') diff --git a/src/being.cpp b/src/being.cpp index 902bd4e1..45019bf2 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -185,7 +185,7 @@ void Being::setSprite(int slot, int id, std::string color) mSpriteColors[slot] = color; } -void Being::setSpeech(const std::string &text, Uint32 time) +void Being::setSpeech(const std::string &text, int time) { mSpeech = text; diff --git a/src/being.h b/src/being.h index ef830e3a..8b2a1e7e 100644 --- a/src/being.h +++ b/src/being.h @@ -166,7 +166,7 @@ class Being : public Sprite * @param text The text that should appear. * @param time The amount of time the text should stay in milliseconds. */ - void setSpeech(const std::string &text, Uint32 time = 500); + void setSpeech(const std::string &text, int time = 500); /** * Puts a damage bubble above this being. @@ -285,12 +285,12 @@ class Being : public Sprite /** * Gets the sprite id. */ - Uint32 getId() const { return mId; } + int getId() const { return mId; } /** * Sets the sprite id. */ - void setId(Uint32 id) { mId = id; } + void setId(int id) { mId = id; } /** * Sets the map the being is on @@ -477,7 +477,7 @@ class Being : public Sprite */ virtual void handleStatusEffect(StatusEffect *effect, int effectId); - Uint32 mId; /**< Unique sprite id */ + int mId; /**< Unique sprite id */ Uint16 mWalkSpeed; /**< Walking speed */ Uint8 mDirection; /**< Facing direction */ Map *mMap; /**< Map on which this being resides */ @@ -496,8 +496,8 @@ class Being : public Sprite Text *mText; Uint16 mHairStyle, mHairColor; Gender mGender; - Uint32 mSpeechTime; - Sint32 mPx, mPy; /**< Pixel coordinates */ + int mSpeechTime; + int mPx, mPy; /**< Pixel coordinates */ Uint16 mStunMode; /**< Stun mode; zero if not stunned */ std::set mStatusEffects; /**< set of active status effects */ diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 15f683af..83e16f4c 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -67,7 +67,7 @@ void BeingManager::setPlayer(LocalPlayer *player) mBeings.push_back(player); } -Being* BeingManager::createBeing(Uint32 id, Uint16 job) +Being *BeingManager::createBeing(int id, Uint16 job) { Being *being; @@ -99,7 +99,7 @@ void BeingManager::destroyBeing(Being *being) delete being; } -Being* BeingManager::findBeing(Uint32 id) +Being *BeingManager::findBeing(int id) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -111,7 +111,7 @@ Being* BeingManager::findBeing(Uint32 id) return NULL; } -Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) +Being *BeingManager::findBeing(int x, int y, Being::Type type) { beingFinder.x = x; beingFinder.y = y; @@ -122,7 +122,7 @@ Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) return (i == mBeings.end()) ? NULL : *i; } -Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) +Being *BeingManager::findBeingByPixel(int x, int y) { BeingIterator itr = mBeings.begin(); BeingIterator itr_end = mBeings.end(); @@ -148,7 +148,7 @@ Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) return NULL; } -Being* BeingManager::findBeingByName(std::string name, Being::Type type) +Being *BeingManager::findBeingByName(std::string name, Being::Type type) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -161,7 +161,7 @@ Being* BeingManager::findBeingByName(std::string name, Being::Type type) return NULL; } -Beings& BeingManager::getAll() +Beings &BeingManager::getAll() { return mBeings; } @@ -202,7 +202,7 @@ void BeingManager::clear() } } -Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, +Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, Being::Type type) { Being *closestBeing = NULL; @@ -229,7 +229,7 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } -Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, +Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type) { Being *closestBeing = NULL; diff --git a/src/beingmanager.h b/src/beingmanager.h index 02c83725..6c0e0fda 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -49,7 +49,7 @@ class BeingManager /** * Create a being and add it to the list of beings. */ - Being *createBeing(Uint32 id, Uint16 job); + Being *createBeing(int id, Uint16 job); /** * Remove a Being. @@ -59,13 +59,13 @@ class BeingManager /** * Return a specific id Being. */ - Being* findBeing(Uint32 id); - Being* findBeingByPixel(Uint16 x, Uint16 y); + Being *findBeing(int id); + Being *findBeingByPixel(int x, int y); /** * Returns a being at specific coordinates. */ - Being* findBeing(Uint16 x, Uint16 y, Being::Type type = Being::UNKNOWN); + Being *findBeing(int x, int y, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to specific coordinates. @@ -76,13 +76,13 @@ class BeingManager * no being is returned. * @param type The type of being to look for. */ - Being* findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, + Being *findNearestLivingBeing(int x, int y, int maxdist, Being::Type type = Being::UNKNOWN); /** * Finds a being by name and (optionally) by type. */ - Being* findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); + Being *findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to another being. @@ -90,7 +90,7 @@ class BeingManager * \param maxdist maximal distance. If minimal distance is larger, * no being is returned */ - Being* findNearestLivingBeing(Being *aroundBeing, int maxdist, + Being *findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type = Being::UNKNOWN); /** diff --git a/src/floor_item.cpp b/src/floor_item.cpp index fbe606b4..000835ad 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -26,10 +26,10 @@ #include "resources/image.h" -FloorItem::FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, +FloorItem::FloorItem(int id, + int itemId, + int x, + int y, Map *map): mId(id), mX(x), @@ -51,7 +51,7 @@ FloorItem::~FloorItem() delete mItem; } -unsigned int FloorItem::getItemId() const +int FloorItem::getItemId() const { return mItem->getId(); } diff --git a/src/floor_item.h b/src/floor_item.h index 444c756a..7ca0f5a3 100644 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -42,10 +42,10 @@ class FloorItem : public Sprite /** * Constructor. */ - FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, + FloorItem(int id, + int itemId, + int x, + int y, Map *map); /** @@ -56,22 +56,22 @@ class FloorItem : public Sprite /** * Returns instance id of this item. */ - unsigned int getId() const { return mId; } + int getId() const { return mId; } /** * Returns the item id. */ - unsigned int getItemId() const; + int getItemId() const; /** * Returns the x coordinate. */ - unsigned short getX() const { return mX; } + int getX() const { return mX; } /** * Returns the y coordinate. */ - unsigned short getY() const { return mY; } + int getY() const { return mY; } /** * Returns the pixel y coordinate. @@ -88,8 +88,8 @@ class FloorItem : public Sprite void draw(Graphics *graphics, int offsetX, int offsetY) const; private: - unsigned int mId; - unsigned short mX, mY; + int mId; + int mX, mY; Item *mItem; Sprites::iterator mSpriteIterator; Map *mMap; diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp index 65556abb..65fb2146 100644 --- a/src/flooritemmanager.cpp +++ b/src/flooritemmanager.cpp @@ -29,8 +29,8 @@ FloorItemManager::~FloorItemManager() clear(); } -FloorItem* FloorItemManager::create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map) +FloorItem* FloorItemManager::create(int id, int itemId, + int x, int y, Map *map) { FloorItem *floorItem = new FloorItem(id, itemId, x, y, map); mFloorItems.push_back(floorItem); @@ -49,7 +49,7 @@ void FloorItemManager::clear() mFloorItems.clear(); } -FloorItem* FloorItemManager::findById(unsigned int id) +FloorItem *FloorItemManager::findById(int id) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) @@ -63,8 +63,7 @@ FloorItem* FloorItemManager::findById(unsigned int id) return NULL; } -FloorItem* FloorItemManager::findByCoordinates(unsigned short x, - unsigned short y) +FloorItem *FloorItemManager::findByCoordinates(int x, int y) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) diff --git a/src/flooritemmanager.h b/src/flooritemmanager.h index 3f96b587..704b39fd 100644 --- a/src/flooritemmanager.h +++ b/src/flooritemmanager.h @@ -32,15 +32,14 @@ class FloorItemManager public: ~FloorItemManager(); - FloorItem* create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map); + FloorItem* create(int id, int itemId, int x, int y, Map *map); void destroy(FloorItem *item); void clear(); - FloorItem* findById(unsigned int id); - FloorItem* findByCoordinates(unsigned short x, unsigned short y); + FloorItem* findById(int id); + FloorItem* findByCoordinates(int x, int y); private: typedef std::list FloorItems; diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 2694abd8..0a6877d9 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -22,8 +22,6 @@ #ifndef POPUP_MENU_H #define POPUP_MENU_H -#include // for Uint32 - #include "linkhandler.h" #include "window.h" @@ -68,7 +66,7 @@ class PopupMenu : public Window, public LinkHandler private: BrowserBox* mBrowserBox; - Uint32 mBeingId; + int mBeingId; FloorItem* mFloorItem; Item *mItem; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5b1500ff..18f25257 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -295,7 +295,7 @@ void LocalPlayer::walk(unsigned char dir) return; } - Sint16 dx = 0, dy = 0; + int dx = 0, dy = 0; if (dir & UP) dy--; if (dir & DOWN) diff --git a/src/localplayer.h b/src/localplayer.h index 2226671b..ba6e7670 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -228,8 +228,8 @@ class LocalPlayer : public Player Uint8 mAttr[6]; Uint8 mAttrUp[6]; - Sint16 ATK, MATK, DEF, MDEF, HIT, FLEE; - Sint16 ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; + int ATK, MATK, DEF, MDEF, HIT, FLEE; + int ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; Uint16 mStatPoint, mSkillPoint; Uint16 mStatsPointsToAttribute; diff --git a/src/monster.cpp b/src/monster.cpp index 610da492..2979e9fd 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -33,7 +33,7 @@ static const int NAME_X_OFFSET = 16; static const int NAME_Y_OFFSET = 16; -Monster::Monster(Uint32 id, Uint16 job, Map *map): +Monster::Monster(int id, Uint16 job, Map *map): Being(id, job, map), mText(0) { diff --git a/src/monster.h b/src/monster.h index 8d7f8ae7..ab6f85df 100644 --- a/src/monster.h +++ b/src/monster.h @@ -30,7 +30,7 @@ class Text; class Monster : public Being { public: - Monster(Uint32 id, Uint16 job, Map *map); + Monster(int id, Uint16 job, Map *map); ~Monster(); diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index b706b088..356d9509 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -69,16 +69,16 @@ BeingHandler::BeingHandler(bool enableSync): void BeingHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; Uint16 job, speed; Uint16 headTop, headMid, headBottom; Uint16 shoes, gloves; Uint16 weapon, shield; Uint16 gmstatus; - Sint16 param1; + int param1; int stunMode; Uint32 statusEffects; - Sint8 type; + int type; Uint16 status; Being *srcBeing, *dstBeing; int hairStyle, hairColor, flag; diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 65f8498a..520a1fe6 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -77,10 +77,10 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint32 value = msg->readInt32(); + int value = msg->readInt32(); msg->readInt32(); // DCvalue msg->readInt8(); // type - Sint16 itemId = msg->readInt16(); + int itemId = msg->readInt16(); buyDialog->addItem(itemId, value); } break; @@ -96,8 +96,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint16 index = msg->readInt16(); - Sint32 value = msg->readInt32(); + int index = msg->readInt16(); + int value = msg->readInt32(); msg->readInt32(); // OCvalue Item *item = player_node->getInventory()->getItem(index); diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index a3ccc4fb..8e108142 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -60,7 +60,7 @@ void ChatHandler::handleMessage(MessageIn *msg) Being *being; std::string chatMsg; std::string nick; - Sint16 chatMsgLength; + int chatMsgLength; switch (msg->getId()) { diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp index 9a3c396a..a31da38e 100644 --- a/src/net/equipmenthandler.cpp +++ b/src/net/equipmenthandler.cpp @@ -48,9 +48,9 @@ EquipmentHandler::EquipmentHandler() void EquipmentHandler::handleMessage(MessageIn *msg) { - Sint32 itemCount; - Sint16 index, equipPoint, itemId; - Sint8 type; + int itemCount; + int index, equipPoint, itemId; + int type; int mask, position; Item *item; Inventory *inventory = player_node->getInventory(); diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index a227701e..d78a7a45 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -61,9 +61,9 @@ InventoryHandler::InventoryHandler() void InventoryHandler::handleMessage(MessageIn *msg) { - Sint32 number; - Sint16 index, amount, itemId, equipType, arrow; - Sint16 identified, cards[4], itemType; + int number; + int index, amount, itemId, equipType, arrow; + int identified, cards[4], itemType; Inventory *inventory = player_node->getInventory(); Inventory *storage = player_node->getStorage(); diff --git a/src/net/itemhandler.cpp b/src/net/itemhandler.cpp index 8c4af4e4..b7ac23a8 100644 --- a/src/net/itemhandler.cpp +++ b/src/net/itemhandler.cpp @@ -41,7 +41,7 @@ void ItemHandler::handleMessage(MessageIn *msg) { Uint32 id; Uint16 x, y; - Sint16 itemId; + int itemId; switch (msg->getId()) { diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 2ecd4726..487b358f 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -50,7 +50,7 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; switch (msg->getId()) { diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 7790cdd0..d99a97a5 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -164,8 +164,8 @@ void PlayerHandler::handleMessage(MessageIn *msg) player_node->mY = y; logger->log("Adjust scrolling by %d:%d", - (int)scrollOffsetX, - (int)scrollOffsetY); + (int) scrollOffsetX, + (int) scrollOffsetY); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } @@ -173,7 +173,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_1: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); Uint32 value = msg->readInt32(); switch (type) @@ -301,10 +301,10 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_3: { - Sint32 type = msg->readInt32(); - Sint32 base = msg->readInt32(); - Sint32 bonus = msg->readInt32(); - Sint32 total = base + bonus; + int type = msg->readInt32(); + int base = msg->readInt32(); + int bonus = msg->readInt32(); + int total = base + bonus; switch (type) { case 0x000d: player_node->mAttr[LocalPlayer::STR] = total; @@ -325,9 +325,9 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_4: { - Sint16 type = msg->readInt16(); - Sint8 fail = msg->readInt8(); - Sint8 value = msg->readInt8(); + int type = msg->readInt16(); + int fail = msg->readInt8(); + int value = msg->readInt8(); if (fail != 1) break; @@ -404,7 +404,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_ARROW_MESSAGE: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); switch (type) { case 0: diff --git a/src/net/skillhandler.cpp b/src/net/skillhandler.cpp index e2185524..526698f4 100644 --- a/src/net/skillhandler.cpp +++ b/src/net/skillhandler.cpp @@ -51,14 +51,14 @@ void SkillHandler::handleMessage(MessageIn *msg) for (int k = 0; k < skillCount; k++) { - Sint16 skillId = msg->readInt16(); + int skillId = msg->readInt16(); msg->readInt16(); // target type msg->readInt16(); // unknown - Sint16 level = msg->readInt16(); - Sint16 sp = msg->readInt16(); + int level = msg->readInt16(); + int sp = msg->readInt16(); msg->readInt16(); // range std::string skillName = msg->readString(24); - Sint8 up = msg->readInt8(); + int up = msg->readInt8(); if (level != 0 || up != 0) { diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index c5465835..ab2eba31 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -140,8 +140,8 @@ void TradeHandler::handleMessage(MessageIn *msg) case SMSG_TRADE_ITEM_ADD: { - Sint32 amount = msg->readInt32(); - Sint16 type = msg->readInt16(); + int amount = msg->readInt32(); + int type = msg->readInt16(); msg->readInt8(); // identified flag msg->readInt8(); // attribute msg->readInt8(); // refine @@ -166,7 +166,7 @@ void TradeHandler::handleMessage(MessageIn *msg) tradeWindow->receivedOk(true); return; } - Sint16 quantity = msg->readInt16(); + int quantity = msg->readInt16(); switch (msg->readInt8()) { diff --git a/src/npc.cpp b/src/npc.cpp index 7ba25c08..5a4f9507 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -38,7 +38,7 @@ int current_npc = 0; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; -NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): +NPC::NPC(int id, Uint16 job, Map *map, Network *network): Player(id, job, map), mNetwork(network) { NPCInfo info = NPCDB::get(job); diff --git a/src/npc.h b/src/npc.h index 216fb2fe..63a0b953 100644 --- a/src/npc.h +++ b/src/npc.h @@ -33,7 +33,7 @@ class Text; class NPC : public Player { public: - NPC(Uint32 id, Uint16 job, Map *map, Network *network); + NPC(int id, Uint16 job, Map *map, Network *network); ~NPC(); -- cgit v1.2.3-60-g2f50 From 448d9076137fc5dde666a90820992a34a945cbf7 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 26 Feb 2009 22:22:22 +0100 Subject: Got rid of Sint{8,16,32} and Uint32 for being ID Using unsigned rarely makes sense, especially when the server doesn't use it either. Other uses of unsigned should be reviewed. In all other cases, int is the fastest integer type on any architecture. Using 8 or 16 bits can basically only be a memory optimization. --- src/being.cpp | 2 +- src/being.h | 12 ++++---- src/beingmanager.cpp | 16 +++++------ src/beingmanager.h | 14 +++++----- src/floor_item.cpp | 8 ++---- src/floor_item.h | 18 +++++------- src/flooritemmanager.cpp | 8 ++---- src/flooritemmanager.h | 7 ++--- src/gui/inventorywindow.cpp | 1 + src/gui/inventorywindow.h | 2 +- src/gui/popupmenu.cpp | 66 ++++++++++++++++++++++++++------------------ src/gui/popupmenu.h | 2 +- src/localplayer.cpp | 2 +- src/localplayer.h | 4 +-- src/monster.cpp | 2 +- src/monster.h | 2 +- src/net/beinghandler.cpp | 6 ++-- src/net/buysellhandler.cpp | 8 +++--- src/net/chathandler.cpp | 2 +- src/net/equipmenthandler.cpp | 6 ++-- src/net/inventoryhandler.cpp | 6 ++-- src/net/itemhandler.cpp | 2 +- src/net/npchandler.cpp | 2 +- src/net/playerhandler.cpp | 22 +++++++-------- src/net/skillhandler.cpp | 8 +++--- src/net/tradehandler.cpp | 6 ++-- src/npc.cpp | 4 +-- src/npc.h | 6 ++-- 28 files changed, 122 insertions(+), 122 deletions(-) (limited to 'src/beingmanager.cpp') diff --git a/src/being.cpp b/src/being.cpp index cebf6d1c..312904ad 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -179,7 +179,7 @@ void Being::setSprite(int slot, int id, std::string color) mSpriteColors[slot] = color; } -void Being::setSpeech(const std::string &text, Uint32 time) +void Being::setSpeech(const std::string &text, int time) { mSpeech = text; diff --git a/src/being.h b/src/being.h index 7fd0c7ef..49f95662 100644 --- a/src/being.h +++ b/src/being.h @@ -165,7 +165,7 @@ class Being : public Sprite * @param text The text that should appear. * @param time The amount of time the text should stay in milliseconds. */ - void setSpeech(const std::string &text, Uint32 time = 500); + void setSpeech(const std::string &text, int time = 500); /** * Puts a damage bubble above this being. @@ -282,12 +282,12 @@ class Being : public Sprite /** * Gets the sprite id. */ - Uint32 getId() const { return mId; } + int getId() const { return mId; } /** * Sets the sprite id. */ - void setId(Uint32 id) { mId = id; } + void setId(int id) { mId = id; } /** * Sets the map the being is on @@ -416,7 +416,7 @@ class Being : public Sprite */ void internalTriggerEffect(int effectId, bool sfx, bool gfx); - Uint32 mId; /**< Unique sprite id */ + int mId; /**< Unique sprite id */ Uint16 mWalkSpeed; /**< Walking speed */ Uint8 mDirection; /**< Facing direction */ Map *mMap; /**< Map on which this being resides */ @@ -437,8 +437,8 @@ class Being : public Sprite Text *mText; Uint16 mHairStyle, mHairColor; Gender mGender; - Uint32 mSpeechTime; - Sint32 mPx, mPy; /**< Pixel coordinates */ + int mSpeechTime; + int mPx, mPy; /**< Pixel coordinates */ Uint16 mStunMode; /**< Stun mode; zero if not stunned */ StatusEffects mStatusEffects; /**< Bitset of active status effects */ diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index d6d71a91..0cf783d8 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -65,7 +65,7 @@ void BeingManager::setPlayer(LocalPlayer *player) mBeings.push_back(player); } -Being* BeingManager::createBeing(Uint32 id, Uint16 job) +Being *BeingManager::createBeing(int id, Uint16 job) { Being *being; @@ -97,7 +97,7 @@ void BeingManager::destroyBeing(Being *being) delete being; } -Being* BeingManager::findBeing(Uint32 id) +Being *BeingManager::findBeing(int id) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -109,7 +109,7 @@ Being* BeingManager::findBeing(Uint32 id) return NULL; } -Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) +Being *BeingManager::findBeing(int x, int y, Being::Type type) { beingFinder.x = x; beingFinder.y = y; @@ -120,7 +120,7 @@ Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) return (i == mBeings.end()) ? NULL : *i; } -Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) +Being *BeingManager::findBeingByPixel(int x, int y) { BeingIterator itr = mBeings.begin(); BeingIterator itr_end = mBeings.end(); @@ -146,7 +146,7 @@ Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) return NULL; } -Being* BeingManager::findBeingByName(std::string name, Being::Type type) +Being *BeingManager::findBeingByName(std::string name, Being::Type type) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -159,7 +159,7 @@ Being* BeingManager::findBeingByName(std::string name, Being::Type type) return NULL; } -Beings& BeingManager::getAll() +Beings &BeingManager::getAll() { return mBeings; } @@ -200,7 +200,7 @@ void BeingManager::clear() } } -Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, +Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, Being::Type type) { Being *closestBeing = NULL; @@ -227,7 +227,7 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } -Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, +Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type) { Being *closestBeing = NULL; diff --git a/src/beingmanager.h b/src/beingmanager.h index 32ba6242..472e2c83 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -50,7 +50,7 @@ class BeingManager /** * Create a being and add it to the list of beings. */ - Being *createBeing(Uint32 id, Uint16 job); + Being *createBeing(int id, Uint16 job); /** * Remove a Being. @@ -60,13 +60,13 @@ class BeingManager /** * Return a specific id Being. */ - Being* findBeing(Uint32 id); - Being* findBeingByPixel(Uint16 x, Uint16 y); + Being *findBeing(int id); + Being *findBeingByPixel(int x, int y); /** * Returns a being at specific coordinates. */ - Being* findBeing(Uint16 x, Uint16 y, Being::Type type = Being::UNKNOWN); + Being *findBeing(int x, int y, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to specific coordinates. @@ -77,13 +77,13 @@ class BeingManager * no being is returned. * @param type The type of being to look for. */ - Being* findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, + Being *findNearestLivingBeing(int x, int y, int maxdist, Being::Type type = Being::UNKNOWN); /** * Finds a being by name and (optionally) by type. */ - Being* findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); + Being *findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to another being. @@ -91,7 +91,7 @@ class BeingManager * \param maxdist maximal distance. If minimal distance is larger, * no being is returned */ - Being* findNearestLivingBeing(Being *aroundBeing, int maxdist, + Being *findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type = Being::UNKNOWN); /** diff --git a/src/floor_item.cpp b/src/floor_item.cpp index 232c1aee..82506f8f 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -27,11 +27,7 @@ #include "resources/image.h" -FloorItem::FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, - Map *map): +FloorItem::FloorItem(int id, int itemId, int x, int y, Map *map): mId(id), mX(x), mY(y), @@ -52,7 +48,7 @@ FloorItem::~FloorItem() delete mItem; } -unsigned int FloorItem::getItemId() const +int FloorItem::getItemId() const { return mItem->getId(); } diff --git a/src/floor_item.h b/src/floor_item.h index 8485172c..0972a983 100644 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -43,11 +43,7 @@ class FloorItem : public Sprite /** * Constructor. */ - FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, - Map *map); + FloorItem(int id, int itemId, int x, int y, Map *map); /** * Destructor. @@ -57,22 +53,22 @@ class FloorItem : public Sprite /** * Returns instance id of this item. */ - unsigned int getId() const { return mId; } + int getId() const { return mId; } /** * Returns the item id. */ - unsigned int getItemId() const; + int getItemId() const; /** * Returns the x coordinate. */ - unsigned short getX() const { return mX; } + int getX() const { return mX; } /** * Returns the y coordinate. */ - unsigned short getY() const { return mY; } + int getY() const { return mY; } /** * Returns the pixel y coordinate. @@ -89,8 +85,8 @@ class FloorItem : public Sprite void draw(Graphics *graphics, int offsetX, int offsetY) const; private: - unsigned int mId; - unsigned short mX, mY; + int mId; + int mX, mY; Item *mItem; Sprites::iterator mSpriteIterator; Map *mMap; diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp index dbb93526..97b3ca5b 100644 --- a/src/flooritemmanager.cpp +++ b/src/flooritemmanager.cpp @@ -30,8 +30,7 @@ FloorItemManager::~FloorItemManager() clear(); } -FloorItem* FloorItemManager::create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map) +FloorItem* FloorItemManager::create(int id, int itemId, int x, int y, Map *map) { FloorItem *floorItem = new FloorItem(id, itemId, x, y, map); mFloorItems.push_back(floorItem); @@ -50,7 +49,7 @@ void FloorItemManager::clear() mFloorItems.clear(); } -FloorItem* FloorItemManager::findById(unsigned int id) +FloorItem *FloorItemManager::findById(int id) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) @@ -64,8 +63,7 @@ FloorItem* FloorItemManager::findById(unsigned int id) return NULL; } -FloorItem* FloorItemManager::findByCoordinates(unsigned short x, - unsigned short y) +FloorItem *FloorItemManager::findByCoordinates(int x, int y) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) diff --git a/src/flooritemmanager.h b/src/flooritemmanager.h index 5ff8fe5c..1a6e8e0a 100644 --- a/src/flooritemmanager.h +++ b/src/flooritemmanager.h @@ -33,15 +33,14 @@ class FloorItemManager public: ~FloorItemManager(); - FloorItem* create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map); + FloorItem* create(int id, int itemId, int x, int y, Map *map); void destroy(FloorItem *item); void clear(); - FloorItem* findById(unsigned int id); - FloorItem* findByCoordinates(unsigned short x, unsigned short y); + FloorItem* findById(int id); + FloorItem* findByCoordinates(int x, int y); private: typedef std::list FloorItems; diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index e8457337..347c36ac 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -39,6 +39,7 @@ #include "../inventory.h" #include "../item.h" +#include "../localplayer.h" #include "../resources/iteminfo.h" diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index a46a3fbb..83e98687 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -28,7 +28,7 @@ #include "window.h" -#include "../localplayer.h" +#include "../inventory.h" class Item; class ItemContainer; diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 7f82d1b5..ebaba977 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -30,6 +30,7 @@ #include "windowcontainer.h" #include "../being.h" +#include "../beingmanager.h" #include "../floor_item.h" #include "../item.h" #include "../localplayer.h" @@ -48,7 +49,7 @@ extern std::string tradePartnerName; PopupMenu::PopupMenu(): Window(), - mBeing(NULL), + mBeingId(0), mFloorItem(NULL), mItem(NULL) { @@ -66,16 +67,16 @@ PopupMenu::PopupMenu(): void PopupMenu::showPopup(int x, int y, Being *being) { - mBeing = being; + mBeingId = being->getId(); mBrowserBox->clearRows(); - switch (mBeing->getType()) + switch (being->getType()) { case Being::PLAYER: { - // Players can be traded with. Later also attack, follow and + // Players can be traded with. Later also follow and // add as buddy will be options in this menu. - const std::string &name = mBeing->getName(); + const std::string &name = being->getName(); mBrowserBox->addRow(strprintf(_("@@trade|Trade With %s@@"), name.c_str())); mBrowserBox->addRow(strprintf(_("@@attack|Attack %s@@"), name.c_str())); @@ -144,45 +145,56 @@ void PopupMenu::showPopup(int x, int y, FloorItem *floorItem) void PopupMenu::handleLink(const std::string& link) { + Being *being = beingManager->findBeing(mBeingId); + + if (!being) + { + mBeingId = 0; + mFloorItem = NULL; + mItem = NULL; + setVisible(false); + return; + } + // Talk To action - if (link == "talk" && mBeing && mBeing->getType() == Being::NPC && + if (link == "talk" && being && being->getType() == Being::NPC && current_npc == 0) { - dynamic_cast(mBeing)->talk(); + dynamic_cast(being)->talk(); } // Trade action - else if (link == "trade" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "trade" && being && being->getType() == Being::PLAYER) { - player_node->trade(mBeing); - tradePartnerName = mBeing->getName(); + player_node->trade(being); + tradePartnerName = being->getName(); } // Attack action - else if (link == "attack" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "attack" && being && being->getType() == Being::PLAYER) { - player_node->attack(mBeing, true); + player_node->attack(being, true); } - else if (link == "unignore" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "unignore" && being && being->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::NEUTRAL); + player_relations.setRelation(being->getName(), PlayerRelation::NEUTRAL); } - else if (link == "ignore" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "ignore" && being && being->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::IGNORED); + player_relations.setRelation(being->getName(), PlayerRelation::IGNORED); } - else if (link == "disregard" && mBeing && - mBeing->getType() == Being::PLAYER) + else if (link == "disregard" && being && + being->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::DISREGARDED); + player_relations.setRelation(being->getName(), PlayerRelation::DISREGARDED); } - else if (link == "friend" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "friend" && being && being->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::FRIEND); + player_relations.setRelation(being->getName(), PlayerRelation::FRIEND); } /* @@ -193,12 +205,12 @@ void PopupMenu::handleLink(const std::string& link) /* // Add Buddy action - else if ((link == "buddy") && mBeing && mBeing->isPlayer()) + else if ((link == "buddy") && being && being->isPlayer()) { if (!buddyWindow->isVisible()) buddyWindow->setVisible(true); - buddyWindow->addBuddy(mBeing->getName()); + buddyWindow->addBuddy(being->getName()); }*/ // Pick Up Floor Item action @@ -241,12 +253,12 @@ void PopupMenu::handleLink(const std::string& link) { new ItemAmountWindow(AMOUNT_ITEM_DROP, inventoryWindow, mItem); } - else if (link == "party-invite" && mBeing && - mBeing->getType() == Being::PLAYER) + else if (link == "party-invite" && being && + being->getType() == Being::PLAYER) { MessageOut outMsg(player_node->getNetwork()); outMsg.writeInt16(CMSG_PARTY_INVITE); - outMsg.writeInt32(mBeing->getId()); + outMsg.writeInt32(being->getId()); } // Unknown actions @@ -257,7 +269,7 @@ void PopupMenu::handleLink(const std::string& link) setVisible(false); - mBeing = NULL; + mBeingId = 0; mFloorItem = NULL; mItem = NULL; } diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index c62014f9..89152751 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -67,7 +67,7 @@ class PopupMenu : public Window, public LinkHandler private: BrowserBox* mBrowserBox; - Being* mBeing; + int mBeingId; FloorItem* mFloorItem; Item *mItem; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 2607b460..76d13a4b 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -318,7 +318,7 @@ void LocalPlayer::walk(unsigned char dir) return; } - Sint16 dx = 0, dy = 0; + int dx = 0, dy = 0; if (dir & UP) dy--; if (dir & DOWN) diff --git a/src/localplayer.h b/src/localplayer.h index 0ae99bb0..2fb8c615 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -228,8 +228,8 @@ class LocalPlayer : public Player Uint8 mAttr[6]; Uint8 mAttrUp[6]; - Sint16 ATK, MATK, DEF, MDEF, HIT, FLEE; - Sint16 ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; + int ATK, MATK, DEF, MDEF, HIT, FLEE; + int ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; Uint16 mStatPoint, mSkillPoint; Uint16 mStatsPointsToAttribute; diff --git a/src/monster.cpp b/src/monster.cpp index f5687ef6..61c867e9 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -34,7 +34,7 @@ static const int NAME_X_OFFSET = 16; static const int NAME_Y_OFFSET = 16; -Monster::Monster(Uint32 id, Uint16 job, Map *map): +Monster::Monster(int id, Uint16 job, Map *map): Being(id, job, map), mText(0) { diff --git a/src/monster.h b/src/monster.h index 776a215b..12297373 100644 --- a/src/monster.h +++ b/src/monster.h @@ -31,7 +31,7 @@ class Text; class Monster : public Being { public: - Monster(Uint32 id, Uint16 job, Map *map); + Monster(int id, Uint16 job, Map *map); ~Monster(); diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 71369031..4ff303ab 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -65,14 +65,14 @@ BeingHandler::BeingHandler(bool enableSync): void BeingHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; Uint16 job, speed; Uint16 headTop, headMid, headBottom; Uint16 shoes, gloves, cape, misc1, misc2; Uint16 weapon, shield; Uint16 gmstatus; - Sint16 param1; - Sint8 type; + int param1; + int type; Being *srcBeing, *dstBeing; int hairStyle, hairColor; diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index e9255540..5b8f0b68 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -78,10 +78,10 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint32 value = msg->readInt32(); + int value = msg->readInt32(); msg->readInt32(); // DCvalue msg->readInt8(); // type - Sint16 itemId = msg->readInt16(); + int itemId = msg->readInt16(); buyDialog->addItem(itemId, value); } break; @@ -97,8 +97,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint16 index = msg->readInt16(); - Sint32 value = msg->readInt32(); + int index = msg->readInt16(); + int value = msg->readInt32(); msg->readInt32(); // OCvalue Item *item = player_node->getInventory()->getItem(index); diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 6717f515..185ce7d8 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -61,7 +61,7 @@ void ChatHandler::handleMessage(MessageIn *msg) Being *being; std::string chatMsg; std::string nick; - Sint16 chatMsgLength; + int chatMsgLength; switch (msg->getId()) { diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp index fe158198..9a6f424e 100644 --- a/src/net/equipmenthandler.cpp +++ b/src/net/equipmenthandler.cpp @@ -49,9 +49,9 @@ EquipmentHandler::EquipmentHandler() void EquipmentHandler::handleMessage(MessageIn *msg) { - Sint32 itemCount; - Sint16 index, equipPoint, itemId; - Sint8 type; + int itemCount; + int index, equipPoint, itemId; + int type; int mask, position; Item *item; Inventory *inventory = player_node->getInventory(); diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index be128609..b0511080 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -62,9 +62,9 @@ InventoryHandler::InventoryHandler() void InventoryHandler::handleMessage(MessageIn *msg) { - Sint32 number; - Sint16 index, amount, itemId, equipType, arrow; - Sint16 identified, cards[4], itemType; + int number; + int index, amount, itemId, equipType, arrow; + int identified, cards[4], itemType; Inventory *inventory = player_node->getInventory(); Inventory *storage = player_node->getStorage(); diff --git a/src/net/itemhandler.cpp b/src/net/itemhandler.cpp index e38be454..d9d84248 100644 --- a/src/net/itemhandler.cpp +++ b/src/net/itemhandler.cpp @@ -42,7 +42,7 @@ void ItemHandler::handleMessage(MessageIn *msg) { Uint32 id; Uint16 x, y; - Sint16 itemId; + int itemId; switch (msg->getId()) { diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 1067a57e..1161bc36 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -51,7 +51,7 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; switch (msg->getId()) { diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index ffeb3fab..232cf075 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -166,8 +166,8 @@ void PlayerHandler::handleMessage(MessageIn *msg) player_node->mY = y; logger->log("Adjust scrolling by %d:%d", - (int)scrollOffsetX, - (int)scrollOffsetY); + (int) scrollOffsetX, + (int) scrollOffsetY); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } @@ -175,7 +175,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_1: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); Uint32 value = msg->readInt32(); switch (type) @@ -303,10 +303,10 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_3: { - Sint32 type = msg->readInt32(); - Sint32 base = msg->readInt32(); - Sint32 bonus = msg->readInt32(); - Sint32 total = base + bonus; + int type = msg->readInt32(); + int base = msg->readInt32(); + int bonus = msg->readInt32(); + int total = base + bonus; switch (type) { case 0x000d: player_node->mAttr[LocalPlayer::STR] = total; @@ -327,9 +327,9 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_4: { - Sint16 type = msg->readInt16(); - Sint8 fail = msg->readInt8(); - Sint8 value = msg->readInt8(); + int type = msg->readInt16(); + int fail = msg->readInt8(); + int value = msg->readInt8(); if (fail != 1) break; @@ -406,7 +406,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_ARROW_MESSAGE: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); switch (type) { case 0: diff --git a/src/net/skillhandler.cpp b/src/net/skillhandler.cpp index 8ef37101..be757d7c 100644 --- a/src/net/skillhandler.cpp +++ b/src/net/skillhandler.cpp @@ -52,14 +52,14 @@ void SkillHandler::handleMessage(MessageIn *msg) for (int k = 0; k < skillCount; k++) { - Sint16 skillId = msg->readInt16(); + int skillId = msg->readInt16(); msg->readInt16(); // target type msg->readInt16(); // unknown - Sint16 level = msg->readInt16(); - Sint16 sp = msg->readInt16(); + int level = msg->readInt16(); + int sp = msg->readInt16(); msg->readInt16(); // range std::string skillName = msg->readString(24); - Sint8 up = msg->readInt8(); + int up = msg->readInt8(); if (level != 0 || up != 0) { diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index 98f26cbd..fd772d01 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -141,8 +141,8 @@ void TradeHandler::handleMessage(MessageIn *msg) case SMSG_TRADE_ITEM_ADD: { - Sint32 amount = msg->readInt32(); - Sint16 type = msg->readInt16(); + int amount = msg->readInt32(); + int type = msg->readInt16(); msg->readInt8(); // identified flag msg->readInt8(); // attribute msg->readInt8(); // refine @@ -167,7 +167,7 @@ void TradeHandler::handleMessage(MessageIn *msg) tradeWindow->receivedOk(true); return; } - Sint16 quantity = msg->readInt16(); + int quantity = msg->readInt16(); switch (msg->readInt8()) { diff --git a/src/npc.cpp b/src/npc.cpp index 92ef4d82..c9250415 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -34,12 +34,12 @@ #include "resources/npcdb.h" bool NPC::mTalking = false; -Uint32 current_npc = 0; +int current_npc = 0; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; -NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): +NPC::NPC(int id, Uint16 job, Map *map, Network *network): Player(id, job, map), mNetwork(network) { NPCInfo info = NPCDB::get(job); diff --git a/src/npc.h b/src/npc.h index e1bf9737..137cd5f5 100644 --- a/src/npc.h +++ b/src/npc.h @@ -23,8 +23,6 @@ #ifndef NPC_H #define NPC_H -#include - #include "player.h" class Network; @@ -34,7 +32,7 @@ class Text; class NPC : public Player { public: - NPC(Uint32 id, Uint16 job, Map *map, Network *network); + NPC(int id, Uint16 job, Map *map, Network *network); ~NPC(); @@ -55,6 +53,6 @@ class NPC : public Player Text *mName; }; -extern Uint32 current_npc; +extern int current_npc; #endif -- cgit v1.2.3-60-g2f50 From aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 5 Mar 2009 23:13:55 -0700 Subject: Made some optimizations based on some profiling done by Octalot, as well as some other optimizations that I could see that cut down on some unneeded redraws, which in turn improved frame rates slightly. Signed-off-by: Ira Rice --- src/being.cpp | 61 +++++++++++-------------------- src/being.h | 18 +++++----- src/beingmanager.cpp | 15 +++----- src/gui/browserbox.cpp | 3 ++ src/gui/confirm_dialog.cpp | 18 +++++----- src/gui/debugwindow.cpp | 27 ++++++-------- src/gui/emotecontainer.cpp | 5 +-- src/gui/emoteshortcutcontainer.cpp | 34 ++++++++---------- src/gui/equipmentwindow.cpp | 3 ++ src/gui/inventorywindow.cpp | 3 ++ src/gui/itemcontainer.cpp | 40 +++++++++------------ src/gui/itemlinkhandler.cpp | 8 ++--- src/gui/itempopup.cpp | 3 ++ src/gui/itemshortcutcontainer.cpp | 73 ++++++++++++++++++-------------------- src/gui/listbox.cpp | 2 +- src/gui/menuwindow.cpp | 1 - src/gui/minimap.cpp | 3 ++ src/gui/ok_dialog.cpp | 15 ++++---- src/gui/playerbox.cpp | 3 ++ src/gui/progressbar.h | 1 + src/gui/radiobutton.cpp | 3 ++ src/gui/scrollarea.cpp | 6 ++++ src/gui/shoplistbox.cpp | 2 +- src/gui/shortcutcontainer.cpp | 32 +++++++---------- src/gui/speechbubble.cpp | 10 ++++-- src/gui/speechbubble.h | 3 +- src/gui/status.cpp | 3 ++ src/gui/table.cpp | 2 +- src/gui/textfield.cpp | 6 +++- src/gui/trade.cpp | 1 - src/gui/viewport.cpp | 35 ++++++++---------- src/gui/viewport.h | 24 +++++++++---- src/gui/widgets/dropdown.cpp | 22 ++++++------ src/gui/widgets/tab.cpp | 8 +++-- src/gui/widgets/tabbedarea.cpp | 17 ++------- src/gui/window.cpp | 3 ++ 36 files changed, 248 insertions(+), 265 deletions(-) (limited to 'src/beingmanager.cpp') diff --git a/src/being.cpp b/src/being.cpp index 312904ad..c31dae6d 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -70,6 +70,7 @@ Being::Being(int id, int job, Map *map): mAction(STAND), mWalkTime(0), mEmotion(0), mEmotionTime(0), + mSpeechTime(0), mAttackSpeed(350), mId(id), mWalkSpeed(150), @@ -81,7 +82,6 @@ Being::Being(int id, int job, Map *map): mEquippedWeapon(NULL), mHairStyle(1), mHairColor(0), mGender(GENDER_UNSPECIFIED), - mSpeechTime(0), mPx(0), mPy(0), mSprites(VECTOREND_SPRITE, NULL), mSpriteIDs(VECTOREND_SPRITE, 0), @@ -136,9 +136,7 @@ Being::~Being() instances--; if (instances == 0) - { delete_all(emotionSet); - } delete mSpeechBubble; delete mText; @@ -328,13 +326,10 @@ void Being::setAction(Action action) break; case ATTACK: if (mEquippedWeapon) - { currentAction = mEquippedWeapon->getAttackType(); - } else - { currentAction = ACTION_ATTACK; - } + for (int i = 0; i < VECTOREND_SPRITE; i++) { if (mSprites[i]) @@ -385,21 +380,13 @@ SpriteDirection Being::getSpriteDirection() const SpriteDirection dir; if (mDirection & UP) - { dir = DIRECTION_UP; - } else if (mDirection & DOWN) - { dir = DIRECTION_DOWN; - } else if (mDirection & RIGHT) - { dir = DIRECTION_RIGHT; - } else - { - dir = DIRECTION_LEFT; - } + dir = DIRECTION_LEFT; return dir; } @@ -445,7 +432,7 @@ void Being::logic() if (mSpeechTime > 0) mSpeechTime--; - // Remove text if speech boxes aren't being used + // Remove text and speechbubbles if speech boxes aren't being used if (mSpeechTime == 0 && mText) { delete mText; @@ -482,9 +469,7 @@ void Being::logic() } // Update particle effects - mChildParticleEffects.moveTo((float) mPx + 16.0f, - (float) mPy + 32.0f); - + mChildParticleEffects.moveTo((float) mPx + 16.0f, (float) mPy + 32.0f); } void Being::draw(Graphics *graphics, int offsetX, int offsetY) const @@ -493,16 +478,12 @@ void Being::draw(Graphics *graphics, int offsetX, int offsetY) const int py = mPy + offsetY; if (mUsedTargetCursor != NULL) - { mUsedTargetCursor->draw(graphics, px, py); - } for (int i = 0; i < VECTOREND_SPRITE; i++) { if (mSprites[i]) - { mSprites[i]->draw(graphics, px, py); - } } } @@ -511,8 +492,8 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) if (!mEmotion) return; - const int px = mPx + offsetX + 3; - const int py = mPy + offsetY - 60; + const int px = mPx - offsetX; + const int py = mPy - offsetY - 64; const int emotionIndex = mEmotion - 1; if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast()) @@ -521,20 +502,25 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) void Being::drawSpeech(int offsetX, int offsetY) { - const int px = mPx + offsetX; - const int py = mPy + offsetY; + const int px = mPx - offsetX; + const int py = mPy - offsetY; const int speech = (int) config.getValue("speech", NAME_IN_BUBBLE); // Draw speech above this being - if (mSpeechTime > 0 && (speech == NAME_IN_BUBBLE || - speech == NO_NAME_IN_BUBBLE)) + if (mSpeechTime == 0) + { + if (mSpeechBubble->isVisible()) + mSpeechBubble->setVisible(false); + } + else if (mSpeechTime > 0 && (speech == NAME_IN_BUBBLE || + speech == NO_NAME_IN_BUBBLE)) { const bool showName = (speech == NAME_IN_BUBBLE); if (mText) { delete mText; - mText = 0; + mText = NULL; } mSpeechBubble->setCaption(showName ? mName : "", mNameColor); @@ -550,6 +536,7 @@ void Being::drawSpeech(int offsetX, int offsetY) else if (mSpeechTime > 0 && speech == TEXT_OVERHEAD) { mSpeechBubble->setVisible(false); + // don't introduce a memory leak if (mText) delete mText; @@ -560,14 +547,12 @@ void Being::drawSpeech(int offsetX, int offsetY) else if (speech == NO_SPEECH) { mSpeechBubble->setVisible(false); + if (mText) delete mText; + mText = NULL; } - else if (mSpeechTime == 0) - { - mSpeechBubble->setVisible(false); - } } Being::Type Being::getType() const @@ -579,24 +564,18 @@ int Being::getOffset(char pos, char neg) const { // Check whether we're walking in the requested direction if (mAction != WALK || !(mDirection & (pos | neg))) - { return 0; - } int offset = (get_elapsed_time(mWalkTime) * 32) / mWalkSpeed; // We calculate the offset _from_ the _target_ location offset -= 32; if (offset > 0) - { offset = 0; - } // Going into negative direction? Invert the offset. if (mDirection & pos) - { offset = -offset; - } return offset; } diff --git a/src/being.h b/src/being.h index 49f95662..9b3bbde4 100644 --- a/src/being.h +++ b/src/being.h @@ -128,15 +128,16 @@ class Being : public Sprite */ enum { DOWN = 1, LEFT = 2, UP = 4, RIGHT = 8 }; - Uint16 mJob; /**< Job (player job, npc, monster, ) */ - Uint16 mX, mY; /**< Tile coordinates */ - Action mAction; /**< Action the being is performing */ - Uint16 mFrame; - Uint16 mWalkTime; - Uint8 mEmotion; /**< Currently showing emotion */ - Uint8 mEmotionTime; /**< Time until emotion disappears */ + Uint16 mJob; /**< Job (player job, npc, monster, ) */ + Uint16 mX, mY; /**< Tile coordinates */ + Action mAction; /**< Action the being is performing */ + int mFrame; + int mWalkTime; + int mEmotion; /**< Currently showing emotion */ + int mEmotionTime; /**< Time until emotion disappears */ + int mSpeechTime; - Uint16 mAttackSpeed; /**< Attack speed */ + int mAttackSpeed; /**< Attack speed */ /** * Constructor. @@ -437,7 +438,6 @@ class Being : public Sprite Text *mText; Uint16 mHairStyle, mHairColor; Gender mGender; - int mSpeechTime; int mPx, mPy; /**< Pixel coordinates */ Uint16 mStunMode; /**< Stun mode; zero if not stunned */ StatusEffects mStatusEffects; /**< Bitset of active status effects */ diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 0cf783d8..0c7a310a 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -151,9 +151,8 @@ Being *BeingManager::findBeingByName(std::string name, Being::Type type) for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { Being *being = (*i); - if (being->getName() == name - && (type == Being::UNKNOWN - || type == being->getType())) + if (being->getName() == name && + (type == Being::UNKNOWN || type == being->getType())) return being; } return NULL; @@ -187,17 +186,13 @@ void BeingManager::logic() void BeingManager::clear() { if (player_node) - { mBeings.remove(player_node); - } delete_all(mBeings); mBeings.clear(); if (player_node) - { mBeings.push_back(player_node); - } } Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, @@ -216,8 +211,7 @@ Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, if ((being->getType() == type || type == Being::UNKNOWN) && (d < dist || closestBeing == NULL) // it is closer - && being->mAction != Being::DEAD // no dead beings - ) + && being->mAction != Being::DEAD) // no dead beings { dist = d; closestBeing = being; @@ -243,8 +237,7 @@ Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, if ((being->getType() == type || type == Being::UNKNOWN) && (d < dist || closestBeing == NULL) // it is closer && being->mAction != Being::DEAD // no dead beings - && being != aroundBeing - ) + && being != aroundBeing) { dist = d; closestBeing = being; diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 18fa2ad4..b8f58dbb 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -244,6 +244,9 @@ void BrowserBox::mouseMoved(gcn::MouseEvent &event) void BrowserBox::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + if (mOpaque) { graphics->setColor(gcn::Color(BGCOLOR)); diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 2287a195..2bc330c0 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -24,6 +24,7 @@ #include "button.h" #include "confirm_dialog.h" +#include "gui.h" #include "scrollarea.h" #include "textbox.h" @@ -50,14 +51,16 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, int numRows = mTextBox->getNumberOfRows(); int width = getFont()->getWidth(title); int inWidth = yesButton->getWidth() + noButton->getWidth() + 5; + const int fontHeight = getFont()->getHeight(); if (numRows > 1) { - // 15 == height of each line of text (based on font heights) + // fontHeight == height of each line of text (based on font heights) // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + 15, 15 + (numRows * 15) + noButton->getHeight()); + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, - 3 + (numRows * 14))); + 3 + (numRows * fontHeight))); } else { @@ -65,16 +68,17 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, width = getFont()->getWidth(msg); if (width < inWidth) width = inWidth; - setContentSize(width + 15, 30 + noButton->getHeight()); + setContentSize(width + fontHeight, (2 * fontHeight) + + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17)); } yesButton->setPosition( (mTextBox->getMinWidth() - inWidth) / 2, - (numRows * 14) + noButton->getHeight() - 8); + ((numRows - 1) * fontHeight) + noButton->getHeight() + 2); noButton->setPosition( yesButton->getX() + yesButton->getWidth() + 5, - (numRows * 14) + noButton->getHeight() - 8); + ((numRows - 1) * fontHeight) + noButton->getHeight() + 2); add(mTextArea); add(yesButton); @@ -105,7 +109,5 @@ void ConfirmDialog::action(const gcn::ActionEvent &event) // Can we receive anything else anyway? if (event.getId() == "yes" || event.getId() == "no") - { scheduleDelete(); - } } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 68b70817..1e199314 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include #include "debugwindow.h" @@ -55,28 +53,27 @@ DebugWindow::DebugWindow(): place(0, 0, mFPSLabel); place(3, 0, mTileMouseLabel); - place(0, 1, mMusicFileLabel, 2); + place(0, 1, mMusicFileLabel, 3); place(3, 1, mParticleCountLabel); - place(0, 2, mMapLabel, 2); - place(0, 3, mMiniMapLabel, 2); + place(0, 2, mMapLabel, 4); + place(0, 3, mMiniMapLabel, 4); reflowLayout(375, 0); } void DebugWindow::logic() { + if (!isVisible()) + return; + // Get the current mouse position - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = (mouseX + viewport->getCameraX()) / 32; - int mouseTileY = (mouseY + viewport->getCameraY()) / 32; + int mouseTileX = (viewport->getMouseX() + viewport->getCameraX()) / 32; + int mouseTileY = (viewport->getMouseY() + viewport->getCameraY()) / 32; mFPSLabel->setCaption(toString(fps) + " FPS"); - mFPSLabel->adjustSize(); - mTileMouseLabel->setCaption("Mouse: " + - toString(mouseTileX) + ", " + toString(mouseTileY)); - mTileMouseLabel->adjustSize(); + mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + + toString(mouseTileY) + ")"); Map *currentMap = engine->getCurrentMap(); if (currentMap) @@ -84,20 +81,16 @@ void DebugWindow::logic() const std::string music = "Music: " + currentMap->getProperty("music"); mMusicFileLabel->setCaption(music); - mMusicFileLabel->adjustSize(); const std::string minimap = "MiniMap: " + currentMap->getProperty("minimap"); mMiniMapLabel->setCaption(minimap); - mMiniMapLabel->adjustSize(); const std::string map = "Map: " + currentMap->getProperty("_filename"); mMapLabel->setCaption(map); - mMapLabel->adjustSize(); } mParticleCountLabel->setCaption("Particle count: " + toString(Particle::particleCount)); - mParticleCountLabel->adjustSize(); } diff --git a/src/gui/emotecontainer.cpp b/src/gui/emotecontainer.cpp index c4cace55..9764ab9c 100644 --- a/src/gui/emotecontainer.cpp +++ b/src/gui/emotecontainer.cpp @@ -79,13 +79,14 @@ EmoteContainer::~EmoteContainer() void EmoteContainer::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + int columns = getWidth() / gridWidth; // Have at least 1 column if (columns < 1) - { columns = 1; - } for (int i = 0; i < mMaxEmote ; i++) { diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index e828df8b..f4cef106 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -76,6 +76,15 @@ EmoteShortcutContainer::~EmoteShortcutContainer() void EmoteShortcutContainer::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + + if (config.getValue("guialpha", 0.8) != mAlpha) + { + mAlpha = config.getValue("guialpha", 0.8); + mBackgroundImg->setAlpha(mAlpha); + } + Graphics *g = static_cast(graphics); graphics->setFont(getFont()); @@ -95,7 +104,8 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) if (emoteShortcut->getEmote(i)) { - mEmoteImg[emoteShortcut->getEmote(i) - 1]->draw(g, emoteX + 2, emoteY + 10); + mEmoteImg[emoteShortcut->getEmote(i) - 1]->draw(g, emoteX + 2, + emoteY + 10); } } @@ -112,12 +122,6 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) sprite->draw(g, tPosX, tPosY); } } - - if (config.getValue("guialpha", 0.8) != mAlpha) - { - mAlpha = config.getValue("guialpha", 0.8); - mBackgroundImg->setAlpha(mAlpha); - } } void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event) @@ -130,9 +134,7 @@ void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event) const int emoteId = emoteShortcut->getEmote(index); if (index == -1) - { return; - } if (emoteId) { @@ -153,19 +155,17 @@ void EmoteShortcutContainer::mousePressed(gcn::MouseEvent &event) const int index = getIndexFromGrid(event.getX(), event.getY()); if (index == -1) - { - return; - } + return; // Stores the selected emote if there is one. if (emoteShortcut->isEmoteSelected()) { - emoteShortcut->setEmote(index); - emoteShortcut->setEmoteSelected(0); + emoteShortcut->setEmote(index); + emoteShortcut->setEmoteSelected(0); } else if (emoteShortcut->getEmote(index)) { - mEmoteClicked = true; + mEmoteClicked = true; } } @@ -176,9 +176,7 @@ void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event) const int index = getIndexFromGrid(event.getX(), event.getY()); if (emoteShortcut->isEmoteSelected()) - { emoteShortcut->setEmoteSelected(0); - } if (index == -1) { @@ -197,9 +195,7 @@ void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event) } if (mEmoteClicked) - { mEmoteClicked = false; - } } } diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 6be55e1c..27ea38ff 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -99,6 +99,9 @@ EquipmentWindow::~EquipmentWindow() void EquipmentWindow::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + // Draw window graphics Window::draw(graphics); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 347c36ac..226b3178 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -113,6 +113,9 @@ InventoryWindow::~InventoryWindow() void InventoryWindow::logic() { + if (!isVisible()) + return; + Window::logic(); // It would be nicer if this update could be event based, needs some diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 79aeb227..02d6e66d 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -20,13 +20,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include #include #include "itemcontainer.h" #include "itempopup.h" +#include "viewport.h" #include "../graphics.h" #include "../inventory.h" @@ -72,6 +71,9 @@ ItemContainer::~ItemContainer() void ItemContainer::logic() { + if (!isVisible()) + return; + gcn::Widget::logic(); int i = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2 @@ -85,18 +87,19 @@ void ItemContainer::logic() void ItemContainer::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + int columns = getWidth() / gridWidth; // Have at least 1 column if (columns < 1) - { columns = 1; - } /* - * mOffset is used to compensate for some weirdness that eAthena inherited from - * Ragnarok Online. Inventory slots and cart slots are +2 from their actual index, - * while storage slots are +1. + * mOffset is used to compensate for some weirdness that eAthena inherited + * from Ragnarok Online. Inventory slots and cart slots are +2 from their + * actual index, while storage slots are +1. */ for (int i = mOffset; i < mInventory->getSize(); i++) { @@ -105,31 +108,25 @@ void ItemContainer::draw(gcn::Graphics *graphics) if (!item || item->getQuantity() <= 0) continue; - int itemX = ((i - 2) % columns) * gridWidth; - int itemY = ((i - 2) / columns) * gridHeight; + int itemX = ((i - mOffset) % columns) * gridWidth; + int itemY = ((i - mOffset) / columns) * gridHeight; // Draw selection image below selected item if (mSelectedItemIndex == i) - { - static_cast(graphics)->drawImage( - mSelImg, itemX, itemY); - } + static_cast(graphics)->drawImage(mSelImg, itemX, itemY); // Draw item icon Image* image = item->getImage(); + if (image) - { - static_cast(graphics)->drawImage( - image, itemX, itemY); - } + static_cast(graphics)->drawImage(image, itemX, itemY); // Draw item caption graphics->setFont(getFont()); graphics->setColor(0x000000); graphics->drawText( (item->isEquipped() ? "Eq." : toString(item->getQuantity())), - itemX + gridWidth / 2, - itemY + gridHeight - 11, + itemX + gridWidth / 2, itemY + gridHeight - 11, gcn::Graphics::CENTER); } } @@ -258,12 +255,9 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event) if (item) { - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); - mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); - mItemPopup->view(mouseX, mouseY); + mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } else { diff --git a/src/gui/itemlinkhandler.cpp b/src/gui/itemlinkhandler.cpp index 4a64d53f..06263ce2 100644 --- a/src/gui/itemlinkhandler.cpp +++ b/src/gui/itemlinkhandler.cpp @@ -23,10 +23,9 @@ #include #include -#include - #include "itemlinkhandler.h" #include "itempopup.h" +#include "viewport.h" #include "../resources/iteminfo.h" #include "../resources/itemdb.h" @@ -50,15 +49,12 @@ void ItemLinkHandler::handleLink(const std::string &link) if (id > 0) { const ItemInfo &iteminfo = ItemDB::get(id); - int mouseX, mouseY; - - SDL_GetMouseState(&mouseX, &mouseY); mItemPopup->setItem(iteminfo); if (mItemPopup->isVisible()) mItemPopup->setVisible(false); else - mItemPopup->view(mouseX, mouseY); + mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } } diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 88afcd5b..0f7e2d11 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -104,6 +104,9 @@ ItemPopup::~ItemPopup() void ItemPopup::setItem(const ItemInfo &item) { + if (item.getName() == mItemName->getCaption()) + return; + mItemName->setCaption(item.getName()); mItemName->setForegroundColor(getColor(item.getType())); mItemName->setWidth(boldFont->getWidth(item.getName())); diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 10ced157..e7a9afbe 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -19,7 +19,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include #include "itemshortcutcontainer.h" #include "itempopup.h" @@ -67,6 +66,9 @@ ItemShortcutContainer::~ItemShortcutContainer() void ItemShortcutContainer::logic() { + if (!isVisible()) + return; + gcn::Widget::logic(); int i = itemShortcut->getItemCount(); @@ -80,6 +82,15 @@ void ItemShortcutContainer::logic() void ItemShortcutContainer::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + + if (config.getValue("guialpha", 0.8) != mAlpha) + { + mAlpha = config.getValue("guialpha", 0.8); + mBackgroundImg->setAlpha(mAlpha); + } + Graphics *g = static_cast(graphics); graphics->setFont(getFont()); @@ -102,23 +113,23 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) Item *item = player_node->getInventory()->findItem(itemShortcut->getItem(i)); - if (item) { + + if (item) + { // Draw item icon. - const std::string label = - item->isEquipped() ? "Eq." : toString(item->getQuantity()); Image* image = item->getImage(); - if (image) { + + if (image) + { const std::string label = item->isEquipped() ? "Eq." : toString(item->getQuantity()); g->drawImage(image, itemX, itemY); - g->drawText( - label, - itemX + mBoxWidth / 2, - itemY + mBoxHeight - 14, - gcn::Graphics::CENTER); + g->drawText(label, itemX + mBoxWidth / 2, + itemY + mBoxHeight - 14, gcn::Graphics::CENTER); } } } + if (mItemMoved) { // Draw the item image being dragged by the cursor. @@ -129,18 +140,11 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) const int tPosY = mCursorPosY - (image->getHeight() / 2); g->drawImage(image, tPosX, tPosY); - g->drawText( - toString(mItemMoved->getQuantity()), - tPosX + mBoxWidth / 2, - tPosY + mBoxHeight - 14, - gcn::Graphics::CENTER); + g->drawText(toString(mItemMoved->getQuantity()), + tPosX + mBoxWidth / 2, tPosY + mBoxHeight - 14, + gcn::Graphics::CENTER); } } - - if (config.getValue("guialpha", 0.8) != mAlpha) - { - mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8)); - } } void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) @@ -152,10 +156,7 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) const int index = getIndexFromGrid(event.getX(), event.getY()); const int itemId = itemShortcut->getItem(index); - if (index == -1) - return; - - if (itemId < 0) + if (index == -1 || itemId < 0) return; Item *item = player_node->getInventory()->findItem(itemId); @@ -166,7 +167,8 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) itemShortcut->removeItem(index); } } - if (mItemMoved) { + if (mItemMoved) + { mCursorPosX = event.getX(); mCursorPosY = event.getY(); } @@ -176,6 +178,7 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) { const int index = getIndexFromGrid(event.getX(), event.getY()); + if (index == -1) return; @@ -199,12 +202,9 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) if (!item) return; - /* Convert relative to the window coordinates to absolute screen - * coordinates. - */ - int mx, my; - SDL_GetMouseState(&mx, &my); - viewport->showPopup(mx, my, item); + // Convert relative to the window coordinates to absolute screen + // coordinates. + viewport->showPopup(viewport->getMouseX(), viewport->getMouseY(), item); } } @@ -230,6 +230,7 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event) { itemShortcut->useItem(index); } + if (mItemClicked) mItemClicked = false; } @@ -241,22 +242,16 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) const int index = getIndexFromGrid(event.getX(), event.getY()); const int itemId = itemShortcut->getItem(index); - if (index == -1) - return; - - if (itemId < 0) + if (index == -1 || itemId < 0) return; Item *item = player_node->getInventory()->findItem(itemId); if (item) { - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); - mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); - mItemPopup->view(mouseX, mouseY); + mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } else { diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 45d14884..6d5c0ca8 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -39,7 +39,7 @@ ListBox::ListBox(gcn::ListModel *listModel): void ListBox::draw(gcn::Graphics *graphics) { - if (!mListModel) + if (!mListModel || !isVisible()) return; if (config.getValue("guialpha", 0.8) != mAlpha) diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 65bd7082..8a695865 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -90,7 +90,6 @@ void MenuWindow::draw(gcn::Graphics *graphics) drawChildren(graphics); } - void MenuWindowListener::action(const gcn::ActionEvent &event) { Window *window = NULL; diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 80c95dd7..2a97b949 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -113,6 +113,9 @@ void Minimap::draw(gcn::Graphics *graphics) { setVisible(mShow); + if (!isVisible()) + return; + Window::draw(graphics); if (!mShow) diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 23c4d465..9621b389 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -23,6 +23,7 @@ #include #include "button.h" +#include "gui.h" #include "ok_dialog.h" #include "scrollarea.h" #include "textbox.h" @@ -47,14 +48,15 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, mTextBox->setTextWrapped(msg, 260); int numRows = mTextBox->getNumberOfRows(); + const int fontHeight = getFont()->getHeight(); if (numRows > 1) { - // 15 == height of each line of text (based on font heights) // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + 15, 15 + (numRows * 15) + okButton->getHeight()); + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + fontHeight) + okButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, - 3 + (numRows * 14))); + 3 + (numRows * fontHeight))); } else { @@ -63,12 +65,12 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, width = getFont()->getWidth(msg); if (width < okButton->getWidth()) width = okButton->getWidth(); - setContentSize(width + 15, 30 + okButton->getHeight()); + setContentSize(width + fontHeight, 30 + okButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17)); } okButton->setPosition((mTextBox->getMinWidth() - okButton->getWidth()) / 2, - (numRows * 14) + okButton->getHeight() - 8); + ((numRows - 1) * fontHeight) + okButton->getHeight() + 2); add(mTextArea); add(okButton); @@ -93,7 +95,6 @@ void OkDialog::action(const gcn::ActionEvent &event) } // Can we receive anything else anyway? - if (event.getId() == "ok") { + if (event.getId() == "ok") scheduleDelete(); - } } diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index e7ee3afe..2a6cdb20 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -79,6 +79,9 @@ PlayerBox::~PlayerBox() void PlayerBox::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + if (mPlayer) { // Draw character diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h index ff146745..3c88f3a3 100644 --- a/src/gui/progressbar.h +++ b/src/gui/progressbar.h @@ -108,6 +108,7 @@ class ProgressBar : public gcn::Widget Uint8 mRed, mGreen, mBlue; Uint8 mRedToGo, mGreenToGo, mBlueToGo; std::string mText; + bool mUpdated; static ImageRect mBorder; static int mInstances; diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp index a8ab61c4..c839238b 100644 --- a/src/gui/radiobutton.cpp +++ b/src/gui/radiobutton.cpp @@ -70,6 +70,9 @@ RadioButton::~RadioButton() void RadioButton::drawBox(gcn::Graphics* graphics) { + if (!isVisible()) + return; + if (config.getValue("guialpha", 0.8) != mAlpha) { mAlpha = config.getValue("guialpha", 0.8); diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index d655ad52..43b27f23 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -149,6 +149,9 @@ void ScrollArea::init() void ScrollArea::logic() { + if (!isVisible()) + return; + gcn::ScrollArea::logic(); gcn::Widget *content = getContent(); @@ -171,6 +174,9 @@ void ScrollArea::logic() void ScrollArea::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + if (mVBarVisible) { drawUpButton(graphics); diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 6e70e022..776f26bc 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -58,7 +58,7 @@ void ShopListBox::setPlayersMoney(int money) void ShopListBox::draw(gcn::Graphics *gcnGraphics) { - if (!mListModel) + if (!mListModel || !isVisible()) return; if (config.getValue("guialpha", 0.8) != mAlpha) diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp index 13ff042d..50ec9d06 100644 --- a/src/gui/shortcutcontainer.cpp +++ b/src/gui/shortcutcontainer.cpp @@ -39,34 +39,28 @@ ShortcutContainer::ShortcutContainer(): void ShortcutContainer::widgetResized(const gcn::Event &event) { mGridWidth = getWidth() / mBoxWidth; + if (mGridWidth < 1) - { mGridWidth = 1; - } - - setHeight((mMaxItems / mGridWidth + - (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight); mGridHeight = getHeight() / mBoxHeight; + if (mGridHeight < 1) - { mGridHeight = 1; - } + + setHeight((mMaxItems / mGridWidth + + (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight); } int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const { - const gcn::Rectangle tRect = gcn::Rectangle( - 0, 0, mGridWidth * mBoxWidth, mGridHeight * mBoxHeight); - if (!tRect.isPointInRect(pointX, pointY)) - { - return -1; - } - const int index = ((pointY / mBoxHeight) * mGridWidth) + - pointX / mBoxWidth; - if (index >= mMaxItems) - { - return -1; - } + const gcn::Rectangle tRect = gcn::Rectangle(0, 0, mGridWidth * mBoxWidth, + mGridHeight * mBoxHeight); + + int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth; + + if (!tRect.isPointInRect(pointX, pointY) || index >= mMaxItems) + index = -1; + return index; } diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 209f964b..d54bf9ad 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -32,7 +32,8 @@ #include "../utils/gettext.h" SpeechBubble::SpeechBubble(): - Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml") + Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml"), + mText("") { setContentSize(140, 46); setShowTitle(false); @@ -67,10 +68,13 @@ void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color) mCaption->setForegroundColor(color); } -void SpeechBubble::setText(std::string mText, bool showName) +void SpeechBubble::setText(std::string text, bool showName) { + if ((text == mText) && (mCaption->getWidth() <= mSpeechBox->getMinWidth())) + return; + int width = mCaption->getWidth(); - mSpeechBox->setTextWrapped(mText, 130 > width ? 130 : width); + mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width); const int fontHeight = getFont()->getHeight(); const int numRows = showName ? mSpeechBox->getNumberOfRows() + 1 : diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index dce421ec..6b03cc85 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -35,11 +35,12 @@ class SpeechBubble : public Window void setCaption(const std::string &name, const gcn::Color &color = 0x000000); - void setText(std::string mText, bool showName = true); + void setText(std::string text, bool showName = true); void setLocation(int x, int y); unsigned int getNumRows(); private: + std::string mText; gcn::Label *mCaption; TextBox *mSpeechBox; ScrollArea *mSpeechArea; diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 49af3ae2..6419eabb 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -272,6 +272,9 @@ void StatusWindow::update() void StatusWindow::draw(gcn::Graphics *g) { + if (!isVisible()) + return; + update(); Window::draw(g); diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 29a33b7a..b2571495 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -265,7 +265,7 @@ void GuiTable::installActionListeners(void) // -- widget ops void GuiTable::draw(gcn::Graphics* graphics) { - if (!mModel) + if (!mModel || !isVisible()) return; if (config.getValue("guialpha", 0.8) != mAlpha) diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index ed83622d..054bc405 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -84,7 +84,11 @@ TextField::~TextField() void TextField::draw(gcn::Graphics *graphics) { - if (isFocused()) { + if (!isVisible()) + return; + + if (isFocused()) + { drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index ba2e2462..a12b94ed 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -117,7 +117,6 @@ void TradeWindow::widgetResized(const gcn::Event &event) Window::widgetResized(event); } - void TradeWindow::addMoney(int amount) { mMoneyLabel->setCaption(strprintf(_("You get %d GP."), amount)); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index f655888c..56274573 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -43,6 +43,8 @@ extern volatile int tick_time; Viewport::Viewport(): mMap(0), + mMouseX(0), + mMouseY(0), mPixelViewX(0.0f), mPixelViewY(0.0f), mTileViewX(0), @@ -148,18 +150,14 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) int viewYmax = (mMap->getHeight() * 32) - graphics->getHeight(); if (mMap) { - if (mPixelViewX < 0) { + if (mPixelViewX < 0) mPixelViewX = 0; - } - if (mPixelViewY < 0) { + if (mPixelViewY < 0) mPixelViewY = 0; - } - if (mPixelViewX > viewXmax) { + if (mPixelViewX > viewXmax) mPixelViewX = viewXmax; - } - if (mPixelViewY > viewYmax) { + if (mPixelViewY > viewYmax) mPixelViewY = viewYmax; - } } mTileViewX = (int) (mPixelViewX + 16) / 32; @@ -175,11 +173,10 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) if (mShowDebugPath) { // Get the current mouse position - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); + SDL_GetMouseState(&mMouseX, &mMouseY); - int mouseTileX = mouseX / 32 + mTileViewX; - int mouseTileY = mouseY / 32 + mTileViewY; + int mouseTileX = mMouseX / 32 + mTileViewX; + int mouseTileY = mMouseY / 32 + mTileViewY; Path debugPath = mMap->findPath(player_node->mX, player_node->mY, mouseTileX, mouseTileY); @@ -204,7 +201,6 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) player_node->setName(player_node->getName()); } - // Draw text if (textManager) { @@ -215,8 +211,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) Beings &beings = beingManager->getAll(); for (BeingIterator i = beings.begin(); i != beings.end(); i++) { - (*i)->drawSpeech(-(int) mPixelViewX, -(int) mPixelViewY); - (*i)->drawEmotion(graphics, -(int) mPixelViewX, -(int) mPixelViewY); + (*i)->drawSpeech((int) mPixelViewX, (int) mPixelViewY); + (*i)->drawEmotion(graphics, (int) mPixelViewX, (int) mPixelViewY); } // Draw contained widgets @@ -230,14 +226,13 @@ void Viewport::logic() if (!mMap || !player_node) return; - int mouseX, mouseY; - Uint8 button = SDL_GetMouseState(&mouseX, &mouseY); + Uint8 button = SDL_GetMouseState(&mMouseX, &mMouseY); if (mPlayerFollowMouse && button & SDL_BUTTON(1) && mWalkTime != player_node->mWalkTime) { - player_node->setDestination(mouseX / 32 + mTileViewX, - mouseY / 32 + mTileViewY); + player_node->setDestination(mMouseX / 32 + mTileViewX, + mMouseY / 32 + mTileViewY); mWalkTime = player_node->mWalkTime; } } @@ -343,9 +338,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) Being *target = beingManager->findBeingByPixel(x, y); if (target) - { player_node->setTarget(target); - } } } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index a131d162..12fdb187 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -115,30 +115,42 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ int getCameraY() const { return (int) mPixelViewY; } + /** + * Returns mouse x in pixels. + */ + int getMouseX() const { return mMouseX; } + + /** + * Returns mouse y in pixels. + */ + int getMouseY() const { return mMouseY; } + /** * Changes viewpoint by relative pixel coordinates. */ void scrollBy(float x, float y) { mPixelViewX += x; mPixelViewY += y; } private: - Map *mMap; /**< The current map. */ + Map *mMap; /**< The current map. */ int mScrollRadius; int mScrollLaziness; int mScrollCenterOffsetX; int mScrollCenterOffsetY; - float mPixelViewX; /**< Current viewpoint in pixels. */ - float mPixelViewY; /**< Current viewpoint in pixels. */ + int mMouseX; /**< Current mouse position in pixels. */ + int mMouseY; /**< Current mouse position in pixels. */ + float mPixelViewX; /**< Current viewpoint in pixels. */ + float mPixelViewY; /**< Current viewpoint in pixels. */ int mTileViewX; /**< Current viewpoint in tiles. */ int mTileViewY; /**< Current viewpoint in tiles. */ - bool mShowDebugPath; /**< Show a path from player to pointer. */ + bool mShowDebugPath; /**< Show a path from player to pointer. */ bool mPlayerFollowMouse; int mWalkTime; - PopupMenu *mPopupMenu; /**< Popup menu. */ + PopupMenu *mPopupMenu; /**< Popup menu. */ }; -extern Viewport *viewport; /**< The viewport */ +extern Viewport *viewport; /**< The viewport */ #endif diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index ed4d260b..9fcf173c 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -75,12 +75,15 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea, int gridy[4] = {0, 3, 28, 31}; int a = 0, x, y; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { - skin.grid[a] = boxBorder->getSubImage( - gridx[x], gridy[y], - gridx[x + 1] - gridx[x] + 1, - gridy[y + 1] - gridy[y] + 1); + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { + skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], + gridx[x + 1] - + gridx[x] + 1, + gridy[y + 1] - + gridy[y] + 1); skin.grid[a]->setAlpha(mAlpha); a++; } @@ -109,16 +112,15 @@ DropDown::~DropDown() void DropDown::draw(gcn::Graphics* graphics) { + if (!isVisible()) + return; + int h; if (mDroppedDown) - { h = mFoldedUpHeight; - } else - { h = getHeight(); - } if (config.getValue("guialpha", 0.8) != mAlpha) { diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 263e5bbd..97f6010c 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -36,7 +36,7 @@ int Tab::mInstances = 0; float Tab::mAlpha = config.getValue("guialpha", 0.8); -enum{ +enum { TAB_STANDARD, // 0 TAB_HIGHLIGHTED, // 1 TAB_SELECTED, // 2 @@ -95,8 +95,10 @@ void Tab::init() { tab[mode] = resman->getImage(data[mode].file); a = 0; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { tabImg[mode].grid[a] = tab[mode]->getSubImage( data[x].gridX, data[y].gridY, data[x + 1].gridX - data[x].gridX + 1, diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index aaa3463f..2c454b69 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -41,9 +41,8 @@ Tab* TabbedArea::getTab(const std::string &name) while (itr != itr_end) { if ((*itr).first->getCaption() == name) - { return static_cast((*itr).first); - } + ++itr; } return NULL; @@ -52,9 +51,7 @@ Tab* TabbedArea::getTab(const std::string &name) void TabbedArea::draw(gcn::Graphics *graphics) { if (mTabs.empty()) - { return; - } drawChildren(graphics); } @@ -65,9 +62,8 @@ gcn::Widget* TabbedArea::getWidget(const std::string &name) while (itr != itr_end) { if ((*itr).first->getCaption() == name) - { return (*itr).second; - } + ++itr; } @@ -92,9 +88,7 @@ void TabbedArea::addTab(Tab *tab, gcn::Widget *widget) mTabs.push_back(std::pair(tab, widget)); if (!mSelectedTab) - { setSelectedTab(tab); - } adjustTabPositions(); adjustSize(); @@ -108,15 +102,10 @@ void TabbedArea::removeTab(Tab *tab) { int index = getSelectedTabIndex(); - if (index == (int)mTabs.size() - 1 - && mTabs.size() == 1) - { + if (index == (int)mTabs.size() - 1 && mTabs.size() == 1) tabIndexToBeSelected = -1; - } else - { tabIndexToBeSelected = index - 1; - } } TabContainer::iterator iter; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 516b4138..e285c3c4 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -169,6 +169,9 @@ void Window::setWindowContainer(WindowContainer *wc) void Window::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + Graphics *g = static_cast(graphics); g->drawImageRect(0, 0, getWidth(), getHeight(), border); -- cgit v1.2.3-60-g2f50 From 17f9d5abcb05da185486ccfba293f3a8c9eab437 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 +++++ src/beingmanager.h | 4 +++- src/game.cpp | 5 +++-- src/gui/chat.cpp | 2 ++ src/gui/setup.cpp | 11 +++++++++-- src/gui/setup.h | 4 ++++ src/gui/setup_colors.cpp | 5 ++--- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 + src/gui/window.cpp | 2 ++ src/main.cpp | 1 - src/player_relations.cpp | 24 ++++++++++++++---------- src/player_relations.h | 2 ++ 13 files changed, 48 insertions(+), 20 deletions(-) (limited to 'src/beingmanager.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 73fa683a..23d91526 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -54,6 +54,11 @@ BeingManager::BeingManager(Network *network): { } +BeingManager::~BeingManager() +{ + clear(); +} + void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 6c0e0fda..d0690798 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -36,6 +36,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -112,7 +114,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player and current NPC (if any) + * Destroys all beings except the local player */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 74a52ddf..ae708adf 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -204,7 +204,6 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog; - setupWindow = new Setup; minimap = new Minimap; equipmentWindow = new EquipmentWindow; tradeWindow = new TradeWindow(network); @@ -341,11 +340,12 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() { - delete player_node; destroyGuiWindows(); delete beingManager; @@ -353,6 +353,7 @@ Game::~Game() delete joystick; delete particleEngine; delete engine; + delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 8ecb5f63..55bc2696 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -108,6 +108,8 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; + delete mItemLinkHandler; + delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 148e8b75..62d79d4d 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -64,9 +64,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Disable this button when the windows aren't created yet + // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) - btn->setEnabled(statusWindow != NULL); + mResetWindows = btn; } TabbedArea *panel = new TabbedArea; @@ -101,6 +101,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() @@ -140,3 +142,8 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } + +void Setup::setInGame(bool inGame) +{ + mResetWindows->setEnabled(inGame); +} \ No newline at end of file diff --git a/src/gui/setup.h b/src/gui/setup.h index e4eb0902..075c88bf 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -31,6 +31,7 @@ #include "../guichanfwd.h" class SetupTab; +class Button; /** * The setup dialog. @@ -50,6 +51,8 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); + void setInGame(bool inGame); + /** * Event handling method. */ @@ -57,6 +60,7 @@ class Setup : public Window, public gcn::ActionListener private: std::list mTabs; + gcn::Button *mResetWindows; }; #endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 49c99996..2610be03 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -57,9 +57,8 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // Replace this later with a more appropriate link handler. For now, this'll - // do, as it'll do nothing when clicked on. - mPreview->setLinkHandler(new ItemLinkHandler); + // don't do anything with links + mPreview->setLinkHandler(NULL); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 61bb9ce9..6112f0e3 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -163,7 +163,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete mTable; + delete_all(mSkillList); } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 1371a78e..274f9a48 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -98,6 +98,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable() { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 8eaaf31d..be63ff21 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -142,6 +142,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index 2c2ff0b6..06093946 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1027,7 +1027,6 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; - delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index c82876e1..14df3f01 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -28,6 +28,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -37,7 +39,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -92,6 +93,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -345,24 +351,22 @@ private: -static std::vector player_ignore_strategies; - std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } diff --git a/src/player_relations.h b/src/player_relations.h index 1eb4ede6..dd363d41 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -94,6 +94,7 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); + ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -232,6 +233,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- cgit v1.2.3-60-g2f50