diff options
author | Bertram <bertram@cegetel.net> | 2009-10-22 02:31:21 +0200 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2009-10-22 02:31:21 +0200 |
commit | 3c6d873fe5584c41a0038758e52ecca843c1e182 (patch) | |
tree | 198cef1684e7a198c4017dbd8732629fb1270bca /src | |
parent | 4720134d58cd5fe0846ed911b360ed75641cb874 (diff) | |
download | mana-3c6d873fe5584c41a0038758e52ecca843c1e182.tar.gz mana-3c6d873fe5584c41a0038758e52ecca843c1e182.tar.bz2 mana-3c6d873fe5584c41a0038758e52ecca843c1e182.tar.xz mana-3c6d873fe5584c41a0038758e52ecca843c1e182.zip |
Optimized game startup sequence for eAthena in order to cope a bit better with network errors.
Unfortunately, it isn't enough: The bug seems to be elsewhere...
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 9 | ||||
-rw-r--r-- | src/game.cpp | 115 | ||||
-rw-r--r-- | src/main.cpp | 13 |
3 files changed, 74 insertions, 63 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index 2cb48ba0..a938aace 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -97,6 +97,11 @@ bool Engine::changeMap(const std::string &mapPath) particleEngine->setMap(newMap); viewport->setMap(newMap); + delete mCurrentMap; + mCurrentMap = newMap; + + Net::getGameHandler()->mapLoaded(mapPath); + // Initialize map-based particle effects if (newMap) newMap->initializeParticleEffects(particleEngine); @@ -107,10 +112,6 @@ bool Engine::changeMap(const std::string &mapPath) if (newMusic != oldMusic) sound.playMusic(newMusic); - delete mCurrentMap; - mCurrentMap = newMap; - - Net::getGameHandler()->mapLoaded(mapPath); return true; } diff --git a/src/game.cpp b/src/game.cpp index aea478b5..0d09be01 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -212,6 +212,23 @@ int get_elapsed_time(int start_time) } /** + * Initialize every game sub-engines in the right order + */ +static void initEngines() +{ + engine = new Engine; + + beingManager = new BeingManager; + commandHandler = new CommandHandler; + floorItemManager = new FloorItemManager; + channelManager = new ChannelManager; + effectManager = new EffectManager; + + particleEngine = new Particle(NULL); + particleEngine->setupEngine(); +} + +/** * Create all the various globally accessible gui windows */ static void createGuiWindows() @@ -301,60 +318,50 @@ Game::Game(): { done = false; - createGuiWindows(); - - mWindowMenu = new WindowMenu; - windowContainer->add(mWindowMenu); - - engine = new Engine; - - beingManager = new BeingManager; - commandHandler = new CommandHandler; - floorItemManager = new FloorItemManager; - channelManager = new ChannelManager; - effectManager = new EffectManager; - - particleEngine = new Particle(NULL); - particleEngine->setupEngine(); - - // Initialize logic and seconds counters - tick_time = 0; - mLogicCounterId = SDL_AddTimer(MILLISECONDS_IN_A_TICK, nextTick, NULL); - mSecondsCounterId = SDL_AddTimer(1000, nextSecond, NULL); - - // Initialize frame limiting - config.addListener("fpslimit", this); - optionChanged("fpslimit"); - - // Initialize beings - beingManager->setPlayer(player_node); - - Joystick::init(); - // TODO: The user should be able to choose which one to use - // Open the first device - if (Joystick::getNumberOfJoysticks() > 0) - joystick = new Joystick(0); - - // fade out logon-music here too to give the desired effect of "flowing" - // into the game. - sound.fadeOutMusic(1000); - map_path = map_path.substr(0, map_path.rfind(".")); - - if (!map_path.empty()) - engine->changeMap(map_path); - - setupWindow->setInGame(true); - - /* - * To prevent the server from sending data before the client - * has initialized, I've modified it to wait for a "ping" - * from the client to complete its initialization - * - * Note: This only affects the latest eAthena version. This - * packet is handled by the older version, but its response - * is ignored by the client - */ - Net::getGameHandler()->ping(tick_time); + createGuiWindows(); + + mWindowMenu = new WindowMenu; + windowContainer->add(mWindowMenu); + + initEngines(); + + // Initialize logic and seconds counters + tick_time = 0; + mLogicCounterId = SDL_AddTimer(MILLISECONDS_IN_A_TICK, nextTick, NULL); + mSecondsCounterId = SDL_AddTimer(1000, nextSecond, NULL); + + // This part is eAthena specific + // For TMWserv, the map is obtained + // with the GPMSG_PLAYER_MAP_CHANGE flag. + map_path = map_path.substr(0, map_path.rfind(".")); + if (!map_path.empty()) + engine->changeMap(map_path); + + // Initialize beings + beingManager->setPlayer(player_node); + + /* + * To prevent the server from sending data before the client + * has initialized, I've modified it to wait for a "ping" + * from the client to complete its initialization + * + * Note: This only affects the latest eAthena version. This + * packet is handled by the older version, but its response + * is ignored by the client + */ + Net::getGameHandler()->ping(tick_time); + + // Initialize frame limiting + config.addListener("fpslimit", this); + optionChanged("fpslimit"); + + Joystick::init(); + // TODO: The user should be able to choose which one to use + // Open the first device + if (Joystick::getNumberOfJoysticks() > 0) + joystick = new Joystick(0); + + setupWindow->setInGame(true); } Game::~Game() diff --git a/src/main.cpp b/src/main.cpp index 761f825d..92cbae77 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1092,6 +1092,14 @@ int main(int argc, char *argv[]) case STATE_CONNECT_GAME: logger->log("State: CONNECT GAME"); + + // Allow any alpha opacity + SkinLoader::instance()->setMinimumOpacity(-1.0f); + + // Fade out logon-music here too to give the desired effect + // of "flowing" into the game. + sound.fadeOutMusic(1000); + Net::getGameHandler()->connect(); currentDialog = new ConnectionDialog(STATE_SWITCH_CHARACTER); break; @@ -1103,11 +1111,6 @@ int main(int argc, char *argv[]) Net::getGameHandler()->inGame(); - // Allow any alpha opacity - SkinLoader::instance()->setMinimumOpacity(-1.0f); - - sound.fadeOutMusic(1000); - delete setupButton; delete desktop; setupButton = NULL; |