summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--src/engine.cpp10
-rw-r--r--src/engine.h4
-rw-r--r--src/game.cpp77
4 files changed, 42 insertions, 51 deletions
diff --git a/ChangeLog b/ChangeLog
index 3b3c2d4a..2b3a695a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2005-09-14 Björn Steinbrink <B.Steinbrink@gmx.de>
+ * src/engine.cpp, src/engine.h, src/game.cpp: Moved Map management
+ code completely into engine.cpp.
* src/net/messagein.cpp, src/net/messagein.h, src/net/messageout.cpp,
src/net/messageout.h: Added stream operators for char, short and long
reading and writing.
diff --git a/src/engine.cpp b/src/engine.cpp
index 956fbfa6..6c28d1c2 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -48,6 +48,7 @@
#include "resources/image.h"
#include "resources/iteminfo.h"
#include "resources/itemmanager.h"
+#include "resources/mapreader.h"
#include "resources/resourcemanager.h"
extern Being *autoTarget;
@@ -191,12 +192,19 @@ Map *Engine::getCurrentMap()
return mCurrentMap;
}
-void Engine::setCurrentMap(Map *newMap)
+void Engine::changeMap(const std::string &mapPath)
{
+ Map *newMap = MapReader::readMap(mapPath);
+
+ if (!newMap) {
+ logger->error("Could not find map file");
+ }
+
std::string oldMusic = "";
if (mCurrentMap) {
oldMusic = mCurrentMap->getProperty("music");
+ delete mCurrentMap;
}
std::string newMusic = newMap->getProperty("music");
diff --git a/src/engine.h b/src/engine.h
index 725f07e9..03b33b5e 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -24,6 +24,8 @@
#ifndef _ENGINE_H
#define _ENGINE_H
+#include <iosfwd>
+
extern int camera_x, camera_y;
class Image;
@@ -54,7 +56,7 @@ class Engine
/**
* Sets the currently active map.
*/
- void setCurrentMap(Map *newMap);
+ void changeMap(const std::string &mapName);
/**
* Performs engine logic.
diff --git a/src/game.cpp b/src/game.cpp
index 3729ee48..e6ad0fac 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -65,8 +65,6 @@
#include "net/network.h"
#include "net/protocol.h"
-#include "resources/mapreader.h"
-
extern Graphics *graphics;
@@ -81,7 +79,6 @@ int server_tick;
int fps = 0, frame = 0, current_npc = 0;
bool displayPathToMouse = false;
unsigned short startX = 0, startY = 0;
-int gameTime = 0;
Being *autoTarget = NULL;
Engine *engine = NULL;
SDL_Joystick *joypad = NULL; /**< Joypad object */
@@ -271,16 +268,7 @@ void destroyGuiWindows()
void do_init()
{
- Map *tiledMap = MapReader::readMap(map_path);
-
- if (!tiledMap)
- {
- logger->error("Could not find map file!");
- }
- else
- {
- engine->setCurrentMap(tiledMap);
- }
+ engine->changeMap(map_path);
// Initialize timers
tick_time = 0;
@@ -288,7 +276,7 @@ void do_init()
SDL_AddTimer(1000, nextSecond, NULL); // Seconds counter
// Initialize beings
- player_node = createBeing(account_ID, 0, tiledMap);
+ player_node = createBeing(account_ID, 0, engine->getCurrentMap());
player_node->x = startX;
player_node->y = startY;
player_node->speed = 150;
@@ -338,7 +326,7 @@ void game()
engine = new Engine();
do_init();
- gameTime = tick_time;
+ int gameTime = tick_time;
while (state != EXIT)
{
@@ -1433,47 +1421,38 @@ void do_parse()
logger->log("Warping to %s (%d, %d)", map_path.c_str(), x, y);
- Map *oldMap = tiledMap;
- tiledMap = MapReader::readMap(map_path);
+ engine->changeMap(map_path);
+ tiledMap = engine->getCurrentMap();
- if (tiledMap)
- {
- empty_floor_items();
+ empty_floor_items();
- // Remove the player, so it is not deleted
- beings.remove(player_node);
+ // Remove the player, so it is not deleted
+ beings.remove(player_node);
- // Delete all beings except the local player
- std::list<Being *>::iterator i;
- for (i = beings.begin(); i != beings.end(); i++)
- {
- delete (*i);
- }
- beings.clear();
+ // Delete all beings except the local player
+ std::list<Being *>::iterator i;
+ for (i = beings.begin(); i != beings.end(); i++)
+ {
+ delete (*i);
+ }
+ beings.clear();
- autoTarget = NULL;
- current_npc = 0;
+ autoTarget = NULL;
+ current_npc = 0;
- // Re-add the local player node
- beings.push_back(player_node);
+ // Re-add the local player node
+ beings.push_back(player_node);
- player_node->action = Being::STAND;
- player_node->frame = 0;
- player_node->x = x;
- player_node->y = y;
- player_node->setMap(tiledMap);
+ player_node->action = Being::STAND;
+ player_node->frame = 0;
+ player_node->x = x;
+ player_node->y = y;
+ player_node->setMap(tiledMap);
- // Send "map loaded"
- writeWord(0, 0x007d);
- writeSet(2);
- flush();
- engine->setCurrentMap(tiledMap);
- }
- else
- {
- logger->error("Could not find map file");
- }
- if (oldMap) delete oldMap;
+ // Send "map loaded"
+ writeWord(0, 0x007d);
+ writeSet(2);
+ flush();
}
break;