/* $Id: main.cpp,v 1.58.2.1 2006/01/20 11:23:30 chfreund Exp $ */ #include "main.hpp" #include #include #include #include "constants.hpp" #include "global.hpp" #include "wopsettings.hpp" #include "server.hpp" #include "client.hpp" #include "string.hpp" #include "replayer.hpp" #include "signalhandler.hpp" #include "version.hpp" #include "../sdlwidgets/fontfactory.h" /**********************************************************/ int main( int nArgs, char* arg[] ) { // #if ! (defined(__APPLE__) && defined(WIN32)) // String logFilename; // logFilename.format( "/tmp/wop_%i.log", getpid() ); // REDIRECT_LOG( logFilename ); // #endif LOG( 1 ) INFO( "This is WoP version %s\n", getWopVersion().getString().c_str() ); LOG( 1 ) INFO( "main: Start\n" ); // Create settings object and load settings: // First read settings specified in the command line followed by // settings in the configuration file, if present. Note that the // destructor of settings will write a configuration file in the // home directory, if none could be found in readSettings. WopSettings* settings = WopSettings::getInstance(); // If help is explicitely demanded, print help of level 0 and exit. if( nArgs > 1 && !strcmp(arg[1], "help") ) { LOG( 1 ) INFO( "You asked for help, here you are:\n\n" ); settings->printHelp( 0, 0 ); return 0; } // If we could not read all settings properly, print a hint on // how to get some help and exit. ASSERT( settings->readSettings(const_cast(arg), nArgs), "could not completely interpret settings in command line\n " "or configuration file. To get more information about the\n " "settings type \"wop help\".\n" ); // If exclusive help on key configuration was demanded, print // this help and exit. if( settings->getSetting("keyhelp") ) { LOG( 1 ) INFO( "You asked for the list of key configurations:\n\n" ); settings->printHelp( 10, 10 ); return 0; } LOG( 2 ) INFO( "main: Initializing SDL\n" ); Uint32 sdlFlags = 0; if ( settings->getDebug() ) sdlFlags |= SDL_INIT_NOPARACHUTE; ASSERT( ! SDL_Init( sdlFlags ), "main: Couldn't initialize SDL\n" ); ASSERT( ! SDLNet_Init(), "main: Couldn't initialize SDL_net\n" ); const SDL_version* sdlVersion = SDL_Linked_Version(); LOG( 2 ) INFO( "main: using SDL version %d.%d.%d\n", sdlVersion->major, sdlVersion->minor, sdlVersion->patch ); Loader::setWopPath( arg[0] ); int programMode = settings->getMode(); Server* server = NULL; Client* client = NULL; Replayer* replayer = NULL; switch ( programMode ) { case SERVER: { server = NEW Server; server->run(); break; } case CLIENT: { client = NEW Client; client->run(); break; } case REPLAY: { String replayPath; ASSERT( settings->getReplayFileName( replayPath ), "main: cannot find replay file %s\n", replayPath.getString() ); replayer = NEW Replayer( replayPath.getString() ); replayer->run(); break; } } delete server; delete client; delete replayer; // remove all singletons WopSettings::deleteInstance(); AttachableRegistrar::deleteInstance(); Audio::deleteInstance(); Loader::deleteInstance(); SignalHandler::deleteInstance(); FontFactory::deleteInstance(); quit(); return 0; } /**********************************************************/ static void quit() { LOG( 1 ) INFO( "main: shutting down SDL\n" ); SDLNet_Quit(); SDL_Quit(); LOG( 1 ) INFO( "main: done\n" ); } /**********************************************************/