application_client.cpp

Go to the documentation of this file.
00001 /* MAINATINER: Bernard CURENT_EDITOR: Bernard */
00002 
00003 // #define WANT_TRACE
00004 
00005 #include "SDL.h"
00006 #include "SDL_ttf.h"
00007 
00008 #include "gfx.h"
00009 #include "sfx.h"
00010 
00011 #include "log.h"
00012 #include "settings.h"
00013 
00014 #include "application_client.h"
00015 #include "game_client.h"
00016 
00017 #include "translator.h"
00018 #include "platform.h"
00019 
00020 ApplicationClient::ApplicationClient()
00021 {
00022         TIN
00023 }
00024 
00025 
00026 ApplicationClient::~ApplicationClient()
00027 {
00028         TIN
00029 }
00030 
00031 ApplicationClient::ApplicationClient(ApplicationClient &copy)
00032 {
00033         TIN
00034         
00035         LOGE << "It is forbidden to make copy of ApplicationClient." << endl;
00036         DIE();
00037 }
00038 
00039 void ApplicationClient::init()
00040 {
00041         TIN
00042         
00043         // load user settings
00044         loadUserConfigFile(SETTING_CLIENT_CONFIG_FILE, SETTING_CLIENT_CONFIG_FILE_TEMPLATE);
00045 
00046         // Log - open logfile and set log level
00047         g_log.init(g_settings.getString(SETTING_LOGFILE_CLIENT).c_str(),
00048                            g_settings.isTrue(SETTING_TOSTDERR_CLIENT));
00049         g_log.set_loglevel(g_settings.getInt(SETTING_LOGLEVEL));
00050         
00051         LOGI << "Client setting and loging inicialized." << endl;
00052 
00053         // gfx
00054         mGFX.init();
00055         
00056         // sfx
00057         mSFX.init();
00058 
00059         // init for font rendering - SDL_ttf
00060         if (!TTF_WasInit() && TTF_Init() == -1)
00061         {
00062                 LOGE << "Unable to init TTF: " << TTF_GetError() << endl;
00063                 DIE();
00064         }
00065         
00066         // only a hack :-)
00067         g_translator.loadFile( locateFile(g_settings.getString(SETTING_TRANSLATION_FILE)).c_str() );
00068         
00069         //
00070         mConsole.init();
00071 
00072         
00073         // Enable key repeat
00074         if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) < 0)
00075         {
00076                 LOGE << "SDL_EnableKeyRepeat failed :-(" << endl;
00077         }
00078 
00079         // prepare tasks
00080         mTaskManager.add(FontManager::getRef());
00081         // probably task for music..
00082 }
00083 
00084 void ApplicationClient::run()
00085 {
00086         TIN
00087 
00088         
00089         // Maybe some menu should be started here
00090                 
00091         // Start engine - should be probably staret from
00092         // some menu :-)
00093         mGameClient.init();
00094         mGameClient.loadMap("example.map");
00095         mGameClient.run();
00096         mGameClient.clean();            
00097 }
00098 
00099 void ApplicationClient::clean()
00100 {
00101         TIN
00102 
00103         mConsole.clean();
00104                 
00105         TTF_Quit();
00106                 
00107         // sfx
00108         mSFX.clean();
00109         
00110         // gfx
00111         mGFX.clean();
00112         
00113         // save settings
00114         saveUserConfigFile(SETTING_CLIENT_CONFIG_FILE, SETTING_CLIENT_CONFIG_FILE_TEMPLATE);
00115 
00116         //cleanBasicSubsystems();
00117 }
00118 
00119 
00120 GFX& ApplicationClient::getGFX()
00121 {
00122         return mGFX;
00123 }
00124 
00125 SFX& ApplicationClient::getSFX()
00126 {
00127         return mSFX;
00128 }
00129 
00130 GameClient& ApplicationClient::getGame()
00131 {
00132         return mGameClient;
00133 }
00134         
00135 Game* ApplicationClient::getGameCommon()
00136 {
00137         return &mGameClient;
00138 }
00139 
00140 InputManager& ApplicationClient::getInputManager()
00141 { 
00142         TIN
00143 
00144         return mInputManager; 
00145 }
00146 
00147 Console& ApplicationClient::getConsole()
00148 {
00149         TIN
00150 
00151         return mConsole;
00152 }
00153 
00154 
00155 Commander& ApplicationClient::getCommander()
00156 {
00157         return mCommanderClient;
00158 }

Generated on Wed Apr 12 13:55:27 2006 for bjs by  doxygen 1.4.5