summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2006-03-09 01:20:48 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2006-03-09 01:20:48 +0000
commit78ab0ec914d3c5a97f162905afb3dede53f8b9ed (patch)
tree53e386c28d5621535c76c35c20f28b7dd6235ee3
parent3bd2abeeffe9fb9b23293975b159ee2ddc868e5b (diff)
downloadmana-78ab0ec914d3c5a97f162905afb3dede53f8b9ed.tar.gz
mana-78ab0ec914d3c5a97f162905afb3dede53f8b9ed.tar.bz2
mana-78ab0ec914d3c5a97f162905afb3dede53f8b9ed.tar.xz
mana-78ab0ec914d3c5a97f162905afb3dede53f8b9ed.zip
Use std::auto_ptr in some places.
-rw-r--r--ChangeLog3
-rw-r--r--src/game.cpp56
-rw-r--r--src/game.h22
-rw-r--r--src/gui/inventorywindow.cpp2
-rw-r--r--src/gui/trade.cpp13
-rw-r--r--src/gui/trade.h13
-rw-r--r--src/localplayer.cpp1
-rw-r--r--src/localplayer.h6
8 files changed, 56 insertions, 60 deletions
diff --git a/ChangeLog b/ChangeLog
index 353b4aad..dbf05f03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2006-03-09 Björn Steinbrink <B.Steinbrink@gmx.de>
+ * src/localplayer.cpp, src/game.cpp, src/gui/trade.cpp,
+ src/gui/inventorywindow.cpp, src/gui/trade.h, src/localplayer.h,
+ src/game.h: Use std::auto_ptr in some places.
* src/lockedarray.h: Use fill_n instead of for-loop.
* src/gui/browserbox.cpp: Make the MouseOverLink functor dynamic and
use a STL algorithm in one more place.
diff --git a/src/game.cpp b/src/game.cpp
index c1c81c67..10d87d12 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -180,7 +180,7 @@ void createGuiWindows(Network *network)
//newSkillWindow = new NewSkillDialog();
setupWindow = new Setup();
minimap = new Minimap();
- equipmentWindow = new EquipmentWindow(player_node->mEquipment);
+ equipmentWindow = new EquipmentWindow(player_node->mEquipment.get());
chargeDialog = new ChargeDialog();
tradeWindow = new TradeWindow(network);
//buddyWindow = new BuddyWindow();
@@ -250,7 +250,17 @@ void destroyGuiWindows()
}
Game::Game(Network *network):
- mNetwork(network)
+ mNetwork(network),
+ mBeingHandler(new BeingHandler()),
+ mBuySellHandler(new BuySellHandler()),
+ mChatHandler(new ChatHandler()),
+ mEquipmentHandler(new EquipmentHandler()),
+ mInventoryHandler(new InventoryHandler()),
+ mItemHandler(new ItemHandler()),
+ mNpcHandler(new NPCHandler()),
+ mPlayerHandler(new PlayerHandler()),
+ mSkillHandler(new SkillHandler()),
+ mTradeHandler(new TradeHandler())
{
createGuiWindows(network);
engine = new Engine(network);
@@ -276,42 +286,20 @@ Game::Game(Network *network):
joystick = new Joystick(0);
}
- mBeingHandler = new BeingHandler();
- mBuySellHandler = new BuySellHandler();
- mChatHandler = new ChatHandler();
- mEquipmentHandler = new EquipmentHandler();
- mInventoryHandler = new InventoryHandler();
- mItemHandler = new ItemHandler();
- mNpcHandler = new NPCHandler();
- mPlayerHandler = new PlayerHandler();
- mSkillHandler = new SkillHandler();
- mTradeHandler = new TradeHandler();
-
- network->registerHandler(mBeingHandler);
- network->registerHandler(mBuySellHandler);
- network->registerHandler(mChatHandler);
- network->registerHandler(mEquipmentHandler);
- network->registerHandler(mInventoryHandler);
- network->registerHandler(mItemHandler);
- network->registerHandler(mNpcHandler);
- network->registerHandler(mPlayerHandler);
- network->registerHandler(mSkillHandler);
- network->registerHandler(mTradeHandler);
+ network->registerHandler(mBeingHandler.get());
+ network->registerHandler(mBuySellHandler.get());
+ network->registerHandler(mChatHandler.get());
+ network->registerHandler(mEquipmentHandler.get());
+ network->registerHandler(mInventoryHandler.get());
+ network->registerHandler(mItemHandler.get());
+ network->registerHandler(mNpcHandler.get());
+ network->registerHandler(mPlayerHandler.get());
+ network->registerHandler(mSkillHandler.get());
+ network->registerHandler(mTradeHandler.get());
}
Game::~Game()
{
- delete mBeingHandler;
- delete mBuySellHandler;
- delete mChatHandler;
- delete mEquipmentHandler;
- delete mInventoryHandler;
- delete mItemHandler;
- delete mNpcHandler;
- delete mPlayerHandler;
- delete mSkillHandler;
- delete mTradeHandler;
-
delete engine;
delete player_node;
destroyGuiWindows();
diff --git a/src/game.h b/src/game.h
index ca7f0ed8..a44c8970 100644
--- a/src/game.h
+++ b/src/game.h
@@ -25,6 +25,7 @@
#define _TMW_GAME_
#include <iosfwd>
+#include <memory>
#define SPEECH_TIME 80
#define SPEECH_MAX_TIME 100
@@ -49,16 +50,17 @@ class Game
protected:
Network *mNetwork;
- MessageHandler *mBeingHandler;
- MessageHandler *mBuySellHandler;
- MessageHandler *mChatHandler;
- MessageHandler *mEquipmentHandler;
- MessageHandler *mInventoryHandler;
- MessageHandler *mItemHandler;
- MessageHandler *mNpcHandler;
- MessageHandler *mPlayerHandler;
- MessageHandler *mSkillHandler;
- MessageHandler *mTradeHandler;
+ typedef std::auto_ptr<MessageHandler> MessageHandlerPtr;
+ MessageHandlerPtr mBeingHandler;
+ MessageHandlerPtr mBuySellHandler;
+ MessageHandlerPtr mChatHandler;
+ MessageHandlerPtr mEquipmentHandler;
+ MessageHandlerPtr mInventoryHandler;
+ MessageHandlerPtr mItemHandler;
+ MessageHandlerPtr mNpcHandler;
+ MessageHandlerPtr mPlayerHandler;
+ MessageHandlerPtr mSkillHandler;
+ MessageHandlerPtr mTradeHandler;
};
/**
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 3b786f62..5227152c 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -53,7 +53,7 @@ InventoryWindow::InventoryWindow():
useButton = new Button("Use");
dropButton = new Button("Drop");
- items = new ItemContainer(player_node->mInventory);
+ items = new ItemContainer(player_node->mInventory.get());
invenScroll = new ScrollArea(items);
invenScroll->setPosition(8, 8);
invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index f7286fd2..9d10774b 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -45,7 +45,9 @@
TradeWindow::TradeWindow(Network *network):
Window("Trade: You"),
- mNetwork(network)
+ mNetwork(network),
+ myInventory(new Inventory()),
+ partnerInventory(new Inventory())
{
setContentSize(322, 150);
@@ -54,16 +56,13 @@ TradeWindow::TradeWindow(Network *network):
cancelButton = new Button("Cancel");
tradeButton = new Button("Trade");
- myInventory = new Inventory();
- partnerInventory = new Inventory();
-
- myItemContainer = new ItemContainer(myInventory);
+ myItemContainer = new ItemContainer(myInventory.get());
myItemContainer->setPosition(2, 2);
myScroll = new ScrollArea(myItemContainer);
myScroll->setPosition(8, 8);
- partnerItemContainer = new ItemContainer(partnerInventory);
+ partnerItemContainer = new ItemContainer(partnerInventory.get());
partnerItemContainer->setPosition(2, 58);
partnerScroll = new ScrollArea(partnerItemContainer);
@@ -137,8 +136,6 @@ TradeWindow::TradeWindow(Network *network):
TradeWindow::~TradeWindow()
{
- delete myInventory;
- delete partnerInventory;
}
void TradeWindow::addMoney(int amount)
diff --git a/src/gui/trade.h b/src/gui/trade.h
index d95cd9ce..3d6eef53 100644
--- a/src/gui/trade.h
+++ b/src/gui/trade.h
@@ -24,6 +24,8 @@
#ifndef _TMW_TRADE_H
#define _TMW_TRADE_H
+#include <memory>
+
#include <guichan/actionlistener.hpp>
#include "window.h"
@@ -110,13 +112,16 @@ class TradeWindow : public Window, gcn::ActionListener
*/
void action(const std::string& eventId);
- Inventory *myInventory;
- Inventory *partnerInventory;
+ private:
+ Network *mNetwork;
+
+ typedef std::auto_ptr<Inventory> InventoryPtr;
+ InventoryPtr myInventory;
+ InventoryPtr partnerInventory;
+
ItemContainer *myItemContainer;
ItemContainer *partnerItemContainer;
- private:
- Network *mNetwork;
gcn::Label *itemNameLabel;
gcn::Label *itemDescriptionLabel;
gcn::Label *moneyLabel;
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 89302ea2..cb648f63 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -47,7 +47,6 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
LocalPlayer::~LocalPlayer()
{
- delete mInventory;
}
void LocalPlayer::logic()
diff --git a/src/localplayer.h b/src/localplayer.h
index 3107657c..cd4809fb 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -24,6 +24,8 @@
#ifndef _TMW_LOCALPLAYER_H
#define _TMW_LOCALPLAYER_H
+#include <memory.h>
+
#include "player.h"
// TODO move into some sane place...
@@ -141,8 +143,8 @@ class LocalPlayer : public Player
float lastAttackTime; /**< Used to synchronize the charge dialog */
- Inventory *mInventory;
- Equipment *mEquipment;
+ std::auto_ptr<Inventory> mInventory;
+ std::auto_ptr<Equipment> mEquipment;
protected:
Network *mNetwork;