if( SDL_Init( SDL_INIT_VIDEO ) < 0 ){ // THIS MUST BE DONE BEFORE ALL OTHER THINGS!!
error("(in initSDL()): Failed initializing SDL Video : %s.\n\n", SDL_GetError());
return false;
}
if(!ConsoleInfo::init()) // THIS MUST BE DONE SECOND!!
return false;
if(!registerCVarsAndCCmds())
return false;
if(!readSystemConfig())
log("Heul doch!\n");//return false;
if(!Display::init())
return false;
if(!Renderer::init())
return false;
if(!ConsoleInfo::initFrontEnd())
return false;
if(!Sound::init())
return false;
if(!Gui::init())
return false;
Gui::loadingMenu->open();
if(!Network::init())
return false;
if(!Input::init())
return false;
if(!readKeybindings())
return false;
if(!readAutoexec())
return false;
Gui::loadingMenu->close();
return true;
}
/*!
This function quits the game with nearly no shutdown. This one should be used in case of bad errors.
It just calls #endLog() and SDL_Quit().
*/
void System::errorQuit(){
log("\n###### ERROR QUIT #######\n");
endLog();
SDL_Quit();
exit(-1);
}
/*!
This function quits the game, after shutting down all subsystems.
This one brings the system down CAREFULLY and so it should be used whenever the uses chooses to quit.
\see #errorQuit()
*/
void System::normalQuit(){
log("\n####### NORMAL QUIT ########\n");
if(Game::wasInit())
Game::shutdown();
if(Gui::wasHudInit())
Gui::shutdownHud();
if(Renderer::wasParticleSystemInit())
Renderer::shutdownParticleSystem();
if(Gui::wasInit())
Gui::shutdown();
writeKeybindings();
if(Input::wasInit())
Input::shutdown();
if(Network::wasInit())
Network::shutdown();
if(Sound::wasInit())
Sound::shutdown();
if(ConsoleInfo::wasFrontEndInit())
ConsoleInfo::shutdownFrontEnd();
if(Renderer::wasInit())
Renderer::shutdown();
if(Display::wasInit())
Display::shutdown();
writeSystemConfig();
unregisterCVarsAndCCmds();
if(ConsoleInfo::wasInit())
ConsoleInfo::shutdown();
SDL_Quit();
log("### THE EAGLE HAS LANDED ###\n");
endLog();
// THINKABOUTME: hier SDLQuit?
exit(0);
}
/*!
This functions creates all game specific console variables and commands and registers them to the console. This requires that the console has been initialized.
This function should be executed as soon as possible in the initialization process, because most other init-functions will use this console variables.
\return \c true on success \c false on errors (most likely the console wasn't initialized).
*/
bool System::registerCVarsAndCCmds(){
if(!ConsoleInfo::wasInit()){
error("(in createAndRegisterCVars()): Console not initialized.\n\n");
error("(in deleteAndUnregisterCVars()): Console not initialized.\n\n");
return false;
}
Display::unregisterCVarsAndCCmds();
Renderer::unregisterCVarsAndCCmds();
ConsoleInfo::unregisterCVarsAndCCmds();
Gui::unregisterCVarsAndCCmds();
Sound::unregisterCVarsAndCCmds();
Network::unregisterCVarsAndCCmds();
Input::unregisterCVarsAndCCmds();
Game::unregisterCVarsAndCCmds();
return true;
}
/*!
This functions reads the \c sysinit.config file in the \c configs directory, which contains all settings for the game.
The Console must be initialized and all neccessary cvars and ccmds should be registered (see #createAndRegisterCVars()).
If the file doesn't exist the function will set all values to their default and return false.
This should be executed early in the initialization process, because most other init-functions will read out the cvars that are set here to do their init-stuff.
\warning Since \c sysinit.config is overwritten by #writeSysinit(), autoexec.config should be used for additional manual editing.
\return \c true on success \c false on errors (file not found ot not parsable, ...)
error("(in readKeybindings()): Couldn't execute 'configs/keybindings.config'. Using default bindings.\n\n");
// TODO: bind default keys !!!
return false;
}else{
log("Keybindings read.\n");
return true;
}
}
/*!
This functions reads the \c autoexec.config file in the \c configs directory. The purpose of this file is to allow expirienced users to write their own console scripts and have them executed automatically on every startup.
If the file doesn't exist the function will return false (which isn't a big deal here).
\return \c true on success \c false on errors (file not found ot not parsable, ...)
This functions writes the \c sysinit.config file in the \c configs directory, which contains all settings for the game. Should be executed right before the game quits to save all settings.
\return \c true on success \c false on errors (file could not be opened, ...)
*/
bool System::writeSystemConfig(){
int i;
log("\n");
log("==============================\n");
log("=== Writing sysinit.config ===\n");
log("==============================\n");
log("\n");
FILE* f = fopen("configs/system.config", "wt");
if( f == NULL ){
warn("(in writeSystemConfig()): Couldn't open 'configs/system.config'.\n\n");