void load_film_profile(FilmProfileType type, bool reload_mml) { switch (type) { case FILM_PROFILE_DEFAULT: film_profile = alephone1_1; break; case FILM_PROFILE_MARATHON_2: film_profile = marathon2; break; case FILM_PROFILE_MARATHON_INFINITY: film_profile = marathon_infinity; break; case FILM_PROFILE_ALEPH_ONE_1_0: film_profile = alephone1_0; break; } if (reload_mml) { ResetAllMMLValues(); LoadBaseMMLScripts(); Plugins::instance()->load_mml(); } }
static void initialize_application(void) { #if defined(__WIN32__) && defined(__MINGW32__) if (LoadLibrary("exchndl.dll")) option_debug = true; #endif // SDL_putenv(const_cast<char*>("SDL_VIDEO_ALLOW_SCREENSAVER=1")); // Initialize SDL int retval = SDL_Init(SDL_INIT_VIDEO | (option_nosound ? 0 : SDL_INIT_AUDIO) | (option_nojoystick ? 0 : SDL_INIT_JOYSTICK) | (option_debug ? SDL_INIT_NOPARACHUTE : 0)); if (retval < 0) { const char *sdl_err = SDL_GetError(); if (sdl_err) fprintf(stderr, "Couldn't initialize SDL (%s)\n", sdl_err); else fprintf(stderr, "Couldn't initialize SDL\n"); exit(1); } #if defined(HAVE_SDL_IMAGE) IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG); #endif // We only want text input events at specific times SDL_StopTextInput(); // Find data directories, construct search path InitDefaultStringSets(); #if defined(unix) || defined(__NetBSD__) || defined(__OpenBSD__) || (defined(__APPLE__) && defined(__MACH__) && !defined(HAVE_BUNDLE_NAME)) default_data_dir = PKGDATADIR; const char *home = getenv("HOME"); if (home) local_data_dir = home; local_data_dir += ".alephone"; log_dir = local_data_dir; #elif defined(__APPLE__) && defined(__MACH__) bundle_data_dir = bundle_resource_path; bundle_data_dir += "DataFiles"; data_search_path.push_back(bundle_data_dir); #ifndef SCENARIO_IS_BUNDLED { char* buf = getcwd(0, 0); default_data_dir = buf; free(buf); } #endif log_dir = app_log_directory; preferences_dir = app_preferences_directory; local_data_dir = app_support_directory; #elif defined(__WIN32__) char file_name[MAX_PATH]; GetModuleFileName(NULL, file_name, sizeof(file_name)); char *sep = strrchr(file_name, '\\'); *sep = '\0'; default_data_dir = file_name; char login[17]; DWORD len = 17; bool hasName = (GetUserName((LPSTR) login, &len) == TRUE); if (!hasName || strpbrk(login, "\\/:*?\"<>|") != NULL) strcpy(login, "Bob User"); DirectorySpecifier legacy_data_dir = file_name; legacy_data_dir += "Prefs"; legacy_data_dir += login; SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, file_name); local_data_dir = file_name; local_data_dir += "AlephOne"; log_dir = local_data_dir; #else default_data_dir = ""; local_data_dir = ""; //#error Data file paths must be set for this platform. #endif #if defined(__WIN32__) #define LIST_SEP ';' #else #define LIST_SEP ':' #endif // in case we need to redo search path later: size_t dsp_insert_pos = data_search_path.size(); size_t dsp_delete_pos = (size_t)-1; if (arg_directory != "") { default_data_dir = arg_directory; dsp_delete_pos = data_search_path.size(); data_search_path.push_back(arg_directory); } const char *data_env = getenv("ALEPHONE_DATA"); if (data_env) { // Read colon-separated list of directories string path = data_env; string::size_type pos; while ((pos = path.find(LIST_SEP)) != string::npos) { if (pos) { string element = path.substr(0, pos); data_search_path.push_back(element); } path.erase(0, pos + 1); } if (!path.empty()) data_search_path.push_back(path); } else { if (arg_directory == "") { dsp_delete_pos = data_search_path.size(); data_search_path.push_back(default_data_dir); } #if defined(__WIN32__) data_search_path.push_back(legacy_data_dir); #endif data_search_path.push_back(local_data_dir); } // Subdirectories #if defined(__MACH__) && defined(__APPLE__) DirectorySpecifier legacy_preferences_dir = local_data_dir; #elif defined(__WIN32__) DirectorySpecifier legacy_preferences_dir = legacy_data_dir; SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, file_name); preferences_dir = file_name; preferences_dir += "AlephOne"; #else preferences_dir = local_data_dir; #endif saved_games_dir = local_data_dir + "Saved Games"; quick_saves_dir = local_data_dir + "Quick Saves"; image_cache_dir = local_data_dir + "Image Cache"; recordings_dir = local_data_dir + "Recordings"; screenshots_dir = local_data_dir + "Screenshots"; #if defined(__APPLE__) && defined(__MACH__) if (app_screenshots_directory) screenshots_dir = app_screenshots_directory; #endif DirectorySpecifier local_mml_dir = local_data_dir + "MML"; DirectorySpecifier local_themes_dir = local_data_dir + "Themes"; // Setup resource manager initialize_resources(); init_physics_wad_data(); initialize_fonts(false); load_film_profile(FILM_PROFILE_DEFAULT, false); // Parse MML files LoadBaseMMLScripts(); // Check for presence of strings if (!TS_IsPresent(strERRORS) || !TS_IsPresent(strFILENAMES)) { fprintf(stderr, "Can't find required text strings (missing MML?).\n"); exit(1); } // Check for presence of files (one last chance to change data_search_path) if (!have_default_files()) { char chosen_dir[256]; if (alert_choose_scenario(chosen_dir)) { // remove original argument (or fallback) from search path if (dsp_delete_pos < data_search_path.size()) data_search_path.erase(data_search_path.begin() + dsp_delete_pos); // add selected directory where command-line argument would go data_search_path.insert(data_search_path.begin() + dsp_insert_pos, chosen_dir); default_data_dir = chosen_dir; // Parse MML files again, now that we have a new dir to search initialize_fonts(false); LoadBaseMMLScripts(); } } initialize_fonts(true); Plugins::instance()->enumerate(); #if defined(__WIN32__) || (defined(__MACH__) && defined(__APPLE__)) preferences_dir.CreateDirectory(); transition_preferences(legacy_preferences_dir); #endif // Load preferences initialize_preferences(); local_data_dir.CreateDirectory(); saved_games_dir.CreateDirectory(); quick_saves_dir.CreateDirectory(); { std::string scen = Scenario::instance()->GetName(); if (scen.length()) scen.erase(std::remove_if(scen.begin(), scen.end(), char_is_not_filesafe), scen.end()); if (!scen.length()) scen = "Unknown"; quick_saves_dir += scen; quick_saves_dir.CreateDirectory(); } image_cache_dir.CreateDirectory(); recordings_dir.CreateDirectory(); screenshots_dir.CreateDirectory(); local_mml_dir.CreateDirectory(); local_themes_dir.CreateDirectory(); WadImageCache::instance()->initialize_cache(); #ifndef HAVE_OPENGL graphics_preferences->screen_mode.acceleration = _no_acceleration; #endif if (force_fullscreen) graphics_preferences->screen_mode.fullscreen = true; if (force_windowed) // takes precedence over fullscreen because windowed is safer graphics_preferences->screen_mode.fullscreen = false; write_preferences(); Plugins::instance()->load_mml(); // SDL_WM_SetCaption(application_name, application_name); // #if defined(HAVE_SDL_IMAGE) && !(defined(__APPLE__) && defined(__MACH__)) // SDL_WM_SetIcon(IMG_ReadXPMFromArray(const_cast<char**>(alephone_xpm)), 0); // #endif atexit(shutdown_application); #if !defined(DISABLE_NETWORKING) // Initialize SDL_net if (SDLNet_Init () < 0) { fprintf (stderr, "Couldn't initialize SDL_net (%s)\n", SDLNet_GetError()); exit(1); } #endif if (TTF_Init() < 0) { fprintf (stderr, "Couldn't initialize SDL_ttf (%s)\n", TTF_GetError()); exit(1); } HTTPClient::Init(); // Initialize everything mytm_initialize(); // initialize_fonts(); SoundManager::instance()->Initialize(*sound_preferences); initialize_marathon_music_handler(); initialize_keyboard_controller(); initialize_gamma(); alephone::Screen::instance()->Initialize(&graphics_preferences->screen_mode); initialize_marathon(); initialize_screen_drawing(); initialize_dialogs(); initialize_terminal_manager(); initialize_shape_handler(); initialize_fades(); initialize_images_manager(); load_environment_from_preferences(); initialize_game_state(); }