00001 /* MAINATINER: Bernard CURENT_EDITOR: Bernard */ 00002 00003 // #define WANT_TRACE 00004 00005 #include "SDL.h" 00006 #include "log.h" 00007 #include "settings.h" 00008 #include "platform.h" 00009 #include "globals.h" 00010 00011 #include "application.h" 00012 #include "translator.h" 00013 #include "params.h" 00014 00015 using namespace std; 00016 00017 00018 Application::Application() 00019 { 00020 initBasicSubsystems(); 00021 } 00022 00023 Application::~Application() 00024 { 00025 cleanBasicSubsystems(); 00026 } 00027 00028 void Application::initBasicSubsystems() 00029 { 00030 TIN 00031 00032 00033 // Global setting 00034 if ( !g_settings.loadSettings(locateFile(MAIN_SETTING_FILE).c_str()) ) 00035 LOGE << "Unable to load setttings file " << locateFile(MAIN_SETTING_FILE) 00036 << " using defaults." << endl; 00037 00038 LOGI << "Global setting loaded." << endl; 00039 00040 // SDL 00041 if ( SDL_Init(SDL_INIT_TIMER) < 0 ) 00042 { 00043 LOGE << "SDL_Init failed: " << SDL_GetError() << endl; 00044 DIE(); 00045 } 00046 00047 // loading translations 00048 // TODO: There should be some value default and then some algorithm 00049 // to decide using locales probably 00050 g_translator.loadFile( locateFile(g_settings.getString(SETTING_TRANSLATION_FILE)).c_str() ); 00051 00052 // loading parameters of all game objects 00053 gParams.load(); 00054 } 00055 00056 00057 void Application::cleanBasicSubsystems() 00058 { 00059 TIN 00060 00061 // SDL 00062 SDL_Quit(); 00063 00064 00065 } 00066 00067 void Application::loadUserConfigFile(const char *file, const char *file_template) 00068 { 00069 // "create" config file 00070 checkConfigFile( 00071 g_settings.getString(file), 00072 g_settings.getString(file_template) 00073 ); 00074 00075 // load it 00076 string conffile = locateFile(g_settings.getString(file)); 00077 if ( !g_settings.loadSettings(conffile.c_str()) ) 00078 { 00079 LOGE << "Unable to load config file " << conffile 00080 << " using defaults." << endl; 00081 } 00082 } 00083 00084 00085 void Application::saveUserConfigFile(const char *file, const char *file_template) 00086 { 00087 // "create" config file 00088 checkConfigFile( 00089 g_settings.getString(file), 00090 g_settings.getString(file_template) 00091 ); 00092 00093 // save it 00094 string conffile = locateFile(g_settings.getString(file)); 00095 if ( !g_settings.saveSettings(conffile.c_str()) ) 00096 { 00097 LOGE << "Unable to save config file " << conffile << endl; 00098 } 00099 } 00100 00101 00102 TaskManager& Application::getTaskManager() 00103 { 00104 return mTaskManager; 00105 }
1.4.5