00001
00002
00003
00004
00005
00006
00007
00009
00028 #include <ctime>
00029 #ifdef __MACH__
00030 #include <unistd.h>
00031 #include <string>
00032 #endif
00033
00034 #include "utils.h"
00035 #include "defs.h"
00036
00037 #include "main_options.h"
00038
00039 #include "audio.h"
00040 #include "video.h"
00041 #include "input.h"
00042 #include "script.h"
00043 #include "system.h"
00044 #include "global.h"
00045 #include "mode_manager.h"
00046
00047 #include "boot.h"
00048 #include "map.h"
00049
00050 using namespace std;
00051 using namespace hoa_utils;
00052 using namespace hoa_audio;
00053 using namespace hoa_video;
00054 using namespace hoa_mode_manager;
00055 using namespace hoa_input;
00056 using namespace hoa_system;
00057 using namespace hoa_global;
00058 using namespace hoa_script;
00059 using namespace hoa_boot;
00060 using namespace hoa_map;
00061
00062
00075 void QuitAllacrost() {
00076
00077
00078
00079
00080 GameModeManager::SingletonDestroy();
00081
00082
00083 GameGlobal::SingletonDestroy();
00084
00085
00086 GameAudio::SingletonDestroy();
00087 GameInput::SingletonDestroy();
00088 GameScript::SingletonDestroy();
00089 GameSystem::SingletonDestroy();
00090 GameVideo::SingletonDestroy();
00091 }
00092
00093
00098 bool InitializeEngine() {
00099
00100 if (SDL_Init(SDL_INIT_TIMER) != 0) {
00101 cerr << "MAIN ERROR: Unable to initialize SDL: " << SDL_GetError() << endl;
00102 return false;
00103 }
00104
00105
00106 AudioManager = GameAudio::SingletonCreate();
00107 InputManager = GameInput::SingletonCreate();
00108 VideoManager = GameVideo::SingletonCreate();
00109 ScriptManager = GameScript::SingletonCreate();
00110 SystemManager = GameSystem::SingletonCreate();
00111 ModeManager = GameModeManager::SingletonCreate();
00112 GlobalManager = GameGlobal::SingletonCreate();
00113
00114 if (VideoManager->SingletonInitialize() == false) {
00115 cerr << "ERROR: unable to initialize VideoManager" << endl;
00116 return false;
00117 }
00118
00119 if (VideoManager->LoadMenuSkin("black_sleet", "img/menus/black_sleet_skin.png", "img/menus/black_sleet_texture.png") == false) {
00120 return false;
00121 }
00122
00123 if (VideoManager->LoadFont("img/fonts/vtc_switchblade_romance.ttf", "default", 18) == false) {
00124 return false;
00125 }
00126
00127 VideoManager->SetFontShadowXOffset("default", 1);
00128 VideoManager->SetFontShadowYOffset("default", -2);
00129 VideoManager->SetFontShadowStyle("default", VIDEO_TEXT_SHADOW_BLACK);
00130
00131 VideoManager->SetFontShadowXOffset("default", 1);
00132 VideoManager->SetFontShadowYOffset("default", -2);
00133 VideoManager->SetFontShadowStyle("default", VIDEO_TEXT_SHADOW_BLACK);
00134
00135 if (!VideoManager->LoadFont("img/fonts/vtc_switchblade_romance.ttf", "map", 24)) {
00136 return false;
00137 }
00138
00139 VideoManager->SetFontShadowXOffset("map", 0);
00140 VideoManager->SetFontShadowYOffset("map", 0);
00141 VideoManager->SetFontShadowStyle("map", VIDEO_TEXT_SHADOW_BLACK);
00142
00143 if (!VideoManager->LoadFont("img/fonts/vtc_switchblade_romance.ttf", "battle", 20)) {
00144 return false;
00145 }
00146
00147 VideoManager->SetFontShadowXOffset("battle", 1);
00148 VideoManager->SetFontShadowYOffset("battle", -2);
00149 VideoManager->SetFontShadowStyle("battle", VIDEO_TEXT_SHADOW_BLACK);
00150
00151
00152 if (!VideoManager->LoadFont("img/fonts/vtc_switchblade_romance.ttf", "battle_dmg", 24)) {
00153 return false;
00154 }
00155
00156 VideoManager->SetFontShadowXOffset("battle_dmg", 1);
00157 VideoManager->SetFontShadowYOffset("battle_dmg", -2);
00158 VideoManager->SetFontShadowStyle("battle_dmg", VIDEO_TEXT_SHADOW_BLACK);
00159
00160 if (AudioManager->SingletonInitialize() == false) {
00161 cerr << "ERROR: unable to initialize AudioManager" << endl;
00162 return false;
00163 }
00164 if (ScriptManager->SingletonInitialize() == false) {
00165 cerr << "ERROR: unable to initialize ScriptManager" << endl;
00166 return false;
00167 }
00168 hoa_defs::BindEngineToLua();
00169 if (ModeManager->SingletonInitialize() == false) {
00170 cerr << "ERROR: unable to initialize ModeManager" << endl;
00171 return false;
00172 }
00173 if (SystemManager->SingletonInitialize() == false) {
00174 cerr << "ERROR: unable to initialize SystemManager" << endl;
00175 return false;
00176 }
00177 if (InputManager->SingletonInitialize() == false) {
00178 cerr << "ERROR: unable to initialize InputManager" << endl;
00179 return false;
00180 }
00181 if (GlobalManager->SingletonInitialize() == false) {
00182 cerr << "ERROR: unable to initialize GlobalManager" << endl;
00183 return false;
00184 }
00185
00186
00187 SDL_WM_SetCaption("Hero of Allacrost", "Hero of Allacrost");
00188
00189
00190 #ifdef _WIN32
00191 SDL_WM_SetIcon(SDL_LoadBMP("img/logos/program_icon.bmp"), NULL);
00192 #else
00193
00194 SDL_WM_SetIcon(SDL_LoadBMP("img/logos/program_icon.bmp"), NULL);
00195 #endif
00196
00197
00198 SDL_ShowCursor(SDL_DISABLE);
00199
00200
00201 SDL_EnableUNICODE(1);
00202
00203
00204 SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
00205 SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
00206 SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);
00207 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
00208 SDL_EventState(SDL_VIDEOEXPOSE, SDL_IGNORE);
00209 SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
00210
00211 SystemManager->InitializeTimers();
00212
00213 return true;
00214 }
00215
00216
00217
00218
00219 int32 main(int32 argc, char *argv[]) {
00220
00221 atexit(SDL_Quit);
00222 atexit(QuitAllacrost);
00223
00224
00225 #ifdef __MACH__
00226 string path;
00227 path = argv[0];
00228
00229 path.erase(path.find_last_of('/'));
00230
00231 path.erase(path.find_last_of('/'));
00232
00233 path.append ("/Resources/");
00234 chdir(path.c_str());
00235 #elif defined(__linux__) || defined(__FreeBSD__)
00236
00237
00238 if (ifstream("dat/config/settings.lua") == NULL)
00239 chdir(DATADIR);
00240 #endif
00241
00242
00243 srand(static_cast<unsigned int>(time(NULL)));
00244
00245
00246 int32 return_code;
00247
00248
00249 if (hoa_main::ParseProgramOptions(return_code, argc, argv) == false) {
00250 return return_code;
00251 }
00252
00253 if (InitializeEngine() == false) {
00254 cerr << "ERROR: failed to initialize game engine, exiting..." << endl;
00255 return 1;
00256 }
00257
00258
00259 while (SystemManager->NotDone()) {
00260
00261 VideoManager->Clear();
00262 ModeManager->Draw();
00263 VideoManager->Display(SystemManager->GetUpdateTime());
00264
00265
00266 InputManager->EventHandler();
00267
00268
00269 AudioManager->Update();
00270
00271
00272 SystemManager->UpdateTimers();
00273
00274
00275 ModeManager->Update();
00276 }
00277
00278 return EXIT_SUCCESS;
00279 }