summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--src/game.cpp78
-rw-r--r--src/game.h7
-rw-r--r--src/main.cpp2
4 files changed, 59 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index dce152d8..37089f9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-26 Björn Steinbrink <B.Steinbrink@gmx.de>
+
+ * src/game.cpp, src/game.h, src/main.cpp: Moved some setup code out of
+ the game loop into the setup functions. Setup functions are now called
+ from the outside.
+
2006-01-22 Eugenio Favalli <elvenprogrammer@gmail.com>
* The Mana World.dev, src/main.cpp: Updated Dev-Cpp project file, fixed
diff --git a/src/game.cpp b/src/game.cpp
index edc1789f..2387a041 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -115,6 +115,17 @@ DebugWindow *debugWindow;
BeingManager *beingManager = NULL;
+BeingHandler *beingHandler;
+BuySellHandler *buySellHandler;
+ChatHandler *chatHandler;
+EquipmentHandler *equipmentHandler;
+InventoryHandler *inventoryHandler;
+ItemHandler *itemHandler;
+NPCHandler *npcHandler;
+PlayerHandler *playerHandler;
+SkillHandler *skillHandler;
+TradeHandler *tradeHandler;
+
const int MAX_TIME = 10000;
/**
@@ -253,6 +264,9 @@ void destroyGuiWindows()
void do_init(Network *network)
{
+ createGuiWindows(network);
+ engine = new Engine(network);
+
beingManager = new BeingManager(network);
// Initialize timers
@@ -288,6 +302,28 @@ void do_init(Network *network)
logger->log("Buttons: %i", SDL_JoystickNumButtons(joypad));
}
}
+
+ beingHandler = new BeingHandler();
+ buySellHandler = new BuySellHandler();
+ chatHandler = new ChatHandler();
+ equipmentHandler = new EquipmentHandler();
+ inventoryHandler = new InventoryHandler();
+ itemHandler = new ItemHandler();
+ npcHandler = new NPCHandler();
+ playerHandler = new PlayerHandler();
+ skillHandler = new SkillHandler();
+ tradeHandler = new TradeHandler();
+
+ network->registerHandler(beingHandler);
+ network->registerHandler(buySellHandler);
+ network->registerHandler(chatHandler);
+ network->registerHandler(equipmentHandler);
+ network->registerHandler(inventoryHandler);
+ network->registerHandler(itemHandler);
+ network->registerHandler(npcHandler);
+ network->registerHandler(playerHandler);
+ network->registerHandler(skillHandler);
+ network->registerHandler(tradeHandler);
}
bool saveScreenshot(SDL_Surface *screenshot)
@@ -316,34 +352,8 @@ bool saveScreenshot(SDL_Surface *screenshot)
void game(Network *network)
{
- createGuiWindows(network);
- engine = new Engine(network);
- do_init(network);
-
int gameTime = tick_time;
- BeingHandler beingHandler;
- BuySellHandler buySellHandler;
- ChatHandler chatHandler;
- EquipmentHandler equipmentHandler;
- InventoryHandler inventoryHandler;
- ItemHandler itemHandler;
- NPCHandler npcHandler;
- PlayerHandler playerHandler;
- SkillHandler skillHandler;
- TradeHandler tradeHandler;
-
- network->registerHandler(&beingHandler);
- network->registerHandler(&buySellHandler);
- network->registerHandler(&chatHandler);
- network->registerHandler(&equipmentHandler);
- network->registerHandler(&inventoryHandler);
- network->registerHandler(&itemHandler);
- network->registerHandler(&npcHandler);
- network->registerHandler(&playerHandler);
- network->registerHandler(&skillHandler);
- network->registerHandler(&tradeHandler);
-
while (!done)
{
// Handle all necessary game logic
@@ -372,16 +382,24 @@ void game(Network *network)
network->flush();
network->dispatchMessages();
}
-
- do_exit(network);
}
-void do_exit(Network *network)
+void do_exit()
{
+ delete beingHandler;
+ delete buySellHandler;
+ delete chatHandler;
+ delete equipmentHandler;
+ delete inventoryHandler;
+ delete itemHandler;
+ delete npcHandler;
+ delete playerHandler;
+ delete skillHandler;
+ delete tradeHandler;
+
delete engine;
delete player_node;
destroyGuiWindows();
- network->disconnect();
if (joypad != NULL)
{
diff --git a/src/game.h b/src/game.h
index 38633560..a1a3cc22 100644
--- a/src/game.h
+++ b/src/game.h
@@ -30,7 +30,6 @@
#define SPEECH_MAX_TIME 100
class Network;
-class NPC;
extern std::string map_path;
extern int fps;
@@ -67,14 +66,14 @@ void game(Network*);
void do_input(Network*);
/**
- * Parse data received from map server into input buffer
+ * Initialize
*/
-void do_parse(Network*);
+void do_init(Network*);
/**
* Clean the engine
*/
-void do_exit(Network*);
+void do_exit();
/**
* Returns elapsed time. (Warning: very unsafe function, it supposes the delay
diff --git a/src/main.cpp b/src/main.cpp
index 5fe43598..9c45614b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -607,7 +607,9 @@ int main(int argc, char *argv[])
login_wallpaper = NULL;
logger->log("State: GAME");
+ do_init(network);
game(network);
+ do_exit();
state = EXIT_STATE;
break;