00001
00002
00003
00004
00005
00006
00007
00009
00016 #include "utils.h"
00017 #include "defs.h"
00018 #include "audio.h"
00019 #include "video.h"
00020 #include "script.h"
00021 #include "mode_manager.h"
00022 #include "input.h"
00023 #include "system.h"
00024 #include "global.h"
00025 #include "main_options.h"
00026
00027 using namespace std;
00028 using namespace hoa_utils;
00029
00030 namespace hoa_main {
00031
00032 bool ParseProgramOptions(int32 &return_code, int32 argc, char **argv) {
00033
00034 vector<string> options(argv, argv + argc);
00035 return_code = 0;
00036
00037 for (uint32 i = 1; i < options.size(); i++) {
00038 if (options[i] == "-c" || options[i] == "--check") {
00039 if (CheckFiles() == true) {
00040 return_code = 0;
00041 }
00042 else {
00043 return_code = 1;
00044 }
00045 return false;
00046 }
00047 else if (options[i] == "-d" || options[i] == "--debug") {
00048 if ((i + 1) >= options.size()) {
00049 cerr << "Option " << options[i] << " requires an argument." << endl;
00050 PrintUsage();
00051 return_code = 1;
00052 return false;
00053 }
00054 if (EnableDebugging(options[i + 1]) == false) {
00055 return_code = 1;
00056 return false;
00057 }
00058 i++;
00059 }
00060 else if (options[i] == "-h" || options[i] == "--help") {
00061 PrintUsage();
00062 return_code = 0;
00063 return false;
00064 }
00065 else if (options[i] == "-i" || options[i] == "--info") {
00066 if (PrintSystemInformation() == true) {
00067 return_code = 0;
00068 }
00069 else {
00070 return_code = 1;
00071 }
00072 return false;
00073 }
00074 else if (options[i] == "-r" || options[i] == "--reset") {
00075 if (ResetSettings() == true) {
00076 return_code = 0;
00077 }
00078 else {
00079 return_code = 1;
00080 }
00081 return_code = 0;
00082 return false;
00083 }
00084 else if (options[i] == "-t" || options[i] == "--test") {
00085 if ((i + 1) >= options.size()) {
00086 cerr << "Option " << options[i] << " requires an argument." << endl;
00087 PrintUsage();
00088 return_code = 1;
00089 return false;
00090 }
00091
00092
00093
00094
00095
00096 i++;
00097 }
00098 else if (options[i] == "-v" || options[i] == "--version") {
00099 if (IsLatestVersion())
00100 cout << "This is the latest version of Allacrost" << endl;
00101 else
00102 cout << "A newer version of Allacrost (" << GetLatestVersion() << ") is available!" << endl;
00103 return false;
00104 }
00105 else {
00106 cerr << "Unrecognized option: " << options[i] << endl;
00107 PrintUsage();
00108 return_code = 1;
00109 return false;
00110 }
00111 }
00112
00113 return true;
00114 }
00115
00116
00117
00118
00119 void PrintUsage() {
00120 cout << "usage: allacrost [options]" << endl;
00121 cout << " --check/-c :: checks all files for integrity" << endl;
00122 cout << " --debug/-d <args> :: enables debug statements in specifed sections of the" << endl;
00123 cout << " program, where <args> can be:" << endl;
00124 cout << " all, audio, battle, boot, data, global, input," << endl;
00125 cout << " map, mode_manager, pause, quit, scene, system" << endl;
00126 cout << " utils, video" << endl;
00127 cout << " --help/-h :: prints this help menu" << endl;
00128 cout << " --info/-i :: prints information about the user's system" << endl;
00129 cout << " --reset/-r :: resets game configuration to use default settings" << endl;
00130 cout << " --test/-t <arg> :: executes requested testing code and then exits" << endl;
00131 cout << " --version/-v :: checks for newer versions of Allacrost online" << endl;
00132 }
00133
00134
00135
00136 bool EnableDebugging(string vars) {
00137 if (vars.empty()) {
00138 cerr << "ERROR: debug specifier string is empty" << endl;
00139 return false;
00140 }
00141
00142
00143 vector<string> args;
00144
00145
00146 uint32 sbegin = 0;
00147 while (vars[sbegin] == ' ' || vars[sbegin] == '\t') {
00148 sbegin++;
00149 if (sbegin >= vars.size()) {
00150 cerr << "ERROR: no white-space characters in debug specifier string" << endl;
00151 return false;
00152 }
00153 }
00154
00155
00156
00157 for (uint32 i = sbegin; i < vars.size(); i++) {
00158 if (vars[i] == ' ' || vars[i] == '\t') {
00159 args.push_back(vars.substr(sbegin, i - sbegin));
00160 sbegin = i + 1;
00161 }
00162 }
00163 args.push_back(vars.substr(sbegin, vars.size() - sbegin));
00164
00165
00166 for (uint32 i = 0; i < args.size(); i++) {
00167 if (args[i] == "all") {
00168
00169
00170
00171
00172 hoa_audio::AUDIO_DEBUG = true;
00173 hoa_battle::BATTLE_DEBUG = true;
00174 hoa_boot::BOOT_DEBUG = true;
00175 hoa_script::SCRIPT_DEBUG = true;
00176 hoa_mode_manager::MODE_MANAGER_DEBUG = true;
00177 hoa_input::INPUT_DEBUG = true;
00178 hoa_system::SYSTEM_DEBUG = true;
00179 hoa_global::GLOBAL_DEBUG = true;
00180 hoa_map::MAP_DEBUG = true;
00181 hoa_menu::MENU_DEBUG = true;
00182 hoa_pause::PAUSE_DEBUG = true;
00183 hoa_quit::QUIT_DEBUG = true;
00184 hoa_shop::SHOP_DEBUG = true;
00185 hoa_scene::SCENE_DEBUG = true;
00186 hoa_utils::UTILS_DEBUG = true;
00187 hoa_video::VIDEO_DEBUG = true;
00188 }
00189 else if (args[i] == "audio") {
00190 hoa_audio::AUDIO_DEBUG = true;
00191 }
00192 else if (args[i] == "battle") {
00193 hoa_battle::BATTLE_DEBUG = true;
00194 }
00195 else if (args[i] == "boot") {
00196 hoa_boot::BOOT_DEBUG = true;
00197 }
00198 else if (args[i] == "data") {
00199 hoa_script::SCRIPT_DEBUG = true;
00200 }
00201 else if (args[i] == "mode_manager") {
00202 hoa_mode_manager::MODE_MANAGER_DEBUG = true;
00203 }
00204 else if (args[i] == "input") {
00205 hoa_input::INPUT_DEBUG = true;
00206 }
00207 else if (args[i] == "system") {
00208 hoa_system::SYSTEM_DEBUG = true;
00209 }
00210 else if (args[i] == "global") {
00211 hoa_global::GLOBAL_DEBUG = true;
00212 }
00213 else if (args[i] == "map") {
00214 hoa_map::MAP_DEBUG = true;
00215 }
00216 else if (args[i] == "menu") {
00217 hoa_menu::MENU_DEBUG = true;
00218 }
00219 else if (args[i] == "pause") {
00220 hoa_pause::PAUSE_DEBUG = true;
00221 }
00222 else if (args[i] == "quit") {
00223 hoa_quit::QUIT_DEBUG = true;
00224 }
00225 else if (args[i] == "scene") {
00226 hoa_scene::SCENE_DEBUG = true;
00227 }
00228 else if (args[i] == "shop") {
00229 hoa_shop::SHOP_DEBUG = true;
00230 }
00231 else if (args[i] == "utils") {
00232 hoa_utils::UTILS_DEBUG = true;
00233 }
00234 else if (args[i] == "video") {
00235 hoa_video::VIDEO_DEBUG = true;
00236 }
00237 else {
00238 cerr << "ERROR: invalid debug argument: " << args[i] << endl;
00239 return false;
00240 }
00241 }
00242
00243 return true;
00244 }
00245
00246
00247
00248
00249 bool PrintSystemInformation() {
00250 printf("\n===== System Information\n");
00251
00252
00253 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0) {
00254 cerr << "ERROR: Unable to initialize SDL: " << SDL_GetError() << endl;
00255 return false;
00256 }
00257 atexit(SDL_Quit);
00258
00259 printf("SDL version (compiled): %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
00260 printf("SDL version (linked): %d.%d.%d\n", SDL_Linked_Version()->major, SDL_Linked_Version()->minor, SDL_Linked_Version()->patch);
00261
00262 SDL_Joystick *js_test;
00263 int32 js_num = SDL_NumJoysticks();
00264 printf("Number of joysticks found: %d\n", js_num);
00265 for (int32 i = 0; i < js_num; i++) {
00266 printf(" Joystick #%d\n", i);
00267 printf(" Joystick Name: %s\n", SDL_JoystickName(i));
00268 js_test = SDL_JoystickOpen(i);
00269 if (js_test == NULL)
00270 printf(" ERROR: SDL was unable to open joystick #%d!\n", i);
00271 else {
00272 printf(" Number Axes: %d\n", SDL_JoystickNumAxes(js_test));
00273 printf(" Number Buttons: %d\n", SDL_JoystickNumButtons(js_test));
00274 printf(" Number Trackballs: %d\n", SDL_JoystickNumBalls(js_test));
00275 printf(" Number Hat Switches: %d\n", SDL_JoystickNumHats(js_test));
00276 SDL_JoystickClose(js_test);
00277 }
00278 }
00279
00280 printf("\n===== Video Information\n");
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 printf("SDL_ttf version (compiled): %d.%d.%d\n", SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_PATCHLEVEL);
00296
00297
00298 char video_driver[80];
00299 SDL_VideoDriverName(video_driver, 80);
00300 printf("Name of video driver: %s\n", video_driver);
00301
00302 const SDL_VideoInfo *user_video;
00303 user_video = SDL_GetVideoInfo();
00304 cout << " Best available video mode" << endl;
00305 cout << " Creates hardware surfaces: ";
00306 if (user_video->hw_available == 1) cout << "yes\n";
00307 else cout << "no\n";
00308 cout << " Has window manager available: ";
00309 if (user_video->wm_available == 1) cout << "yes\n";
00310 else cout << "no\n";
00311 cout << " Hardware to hardware blits accelerated: ";
00312 if (user_video->blit_hw == 1) cout << "yes\n";
00313 else cout << "no\n";
00314 cout << " Hardware to hardware colorkey blits accelerated: ";
00315 if (user_video->blit_hw_CC == 1) cout << "yes\n";
00316 else cout << "no\n";
00317 cout << " Hardware to hardware alpha blits accelerated: ";
00318 if (user_video->blit_hw_A == 1) cout << "yes\n";
00319 else cout << "no\n";
00320 cout << " Software to hardware blits acceleerated: ";
00321 if (user_video->blit_sw == 1) cout << "yes\n";
00322 else cout << "no\n";
00323 cout << " Software to hardware colorkey blits accelerated: ";
00324 if (user_video->blit_sw_CC == 1) cout << "yes\n";
00325 else cout << "no\n";
00326 cout << " Software to hardware alpha blits accelerated: ";
00327 if (user_video->blit_sw_A == 1) cout << "yes\n";
00328 else cout << "no\n";
00329 cout << " Color fills accelerated: ";
00330 if (user_video->blit_fill == 1) cout << "yes\n";
00331 else cout << "no\n";
00332 cout << " Total video memory: " << user_video->video_mem << " kilobytes" << endl;
00333
00334
00335 printf("\n===== Audio Information\n");
00336
00337 hoa_audio::AudioManager = hoa_audio::GameAudio::SingletonCreate();
00338 if (hoa_audio::AudioManager->SingletonInitialize() == false) {
00339 cerr << "ERROR: unable to initialize the AudioManager" << endl;
00340 return false;
00341 }
00342 else {
00343 hoa_audio::AudioManager->DEBUG_PrintInfo();
00344 }
00345 hoa_audio::GameAudio::SingletonDestroy();
00346
00347 printf("\n");
00348
00349 return true;
00350 }
00351
00352
00353
00354 bool ResetSettings() {
00355 cerr << "This option is not yet implemented." << endl;
00356
00357
00358 return false;
00359 }
00360
00361
00362
00363
00364
00365 bool CheckFiles() {
00366 cout << "This option is not yet implemented." << endl;
00367 return false;
00368 }
00369
00370
00371
00372 void DEBUG_TestCode(uint32 code) {
00373
00374 if (code == 0) {
00375 cout << "0: This is not a real test code id, it just prints this message" << endl;
00376 }
00377
00378
00379
00380
00381
00382
00383
00384 else {
00385 cerr << "MAIN ERROR: no definition for test code id number: " << code << endl;
00386 }
00387 }
00388
00389 }