ResourceCache::ResourceCache() { PHYSFS_init(NULL); PHYSFS_addToSearchPath("data/images.zip", 1); PHYSFS_addToSearchPath("data/sounds.zip", 1); al_init_image_addon(); al_init_acodec_addon(); al_set_physfs_file_interface(); }
static void CreateGameCore(Framework *fw, std::atomic<bool> *isComplete) { TRACE_FN; // FIXME: The allegro file interface is a TLS, so we need to reset it if there's a new thread. al_set_physfs_file_interface(); UString ruleset = fw->Settings->getString("GameRules"); UString language = fw->Settings->getString("Language"); fw->gamecore.reset(new GameCore(*fw)); fw->gamecore->Load(ruleset, language); *isComplete = true; }
static unsigned int init_datafile(char *argv[]) { /* load main game datafile (usually a zip) into memory */ if (!PHYSFS_init(argv[0])) { fprintf(stderr, "Could not init PhysFS\n"); return false; } PHYSFS_addToSearchPath(DATAPACKNAME, 1); al_set_standard_file_interface(); al_set_physfs_file_interface(); return true; }
// Initializes the the GDATA struct _Bool data_init(void) { // Create a window to display things on: 800x600 pixels al_set_new_display_flags(ALLEGRO_RESIZABLE | ALLEGRO_OPENGL); al_set_new_display_refresh_rate(60); data->display = al_create_display(res_width, res_height); if(data->display == NULL) { al_show_native_message_box(data->display, "Error!", "Display Error:", "Failed to create window!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return false; } // Sets the physfs file interface to be used for loading files al_set_physfs_file_interface(); PHYSFS_mount("images", NULL, 1); PHYSFS_mount("fonts", NULL, 1); PHYSFS_mount("buttons", NULL, 1); // Well, looks like we're gonna have to draw our own mouse *SIGH* al_hide_mouse_cursor(data->display); data->cursor = al_load_bitmap("cursor_darkgrey.png"); if(data->cursor == NULL) { al_show_native_message_box(data->display, "Error!", "Cursor Error:", "Failed to locate cursor!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return false; } // Set the title of the window al_set_window_title(data->display, "SpeedRun!"); // Sets the window's icon data->icon = al_load_bitmap("speedrundisplayicon.png"); if(data->icon == NULL) { al_show_native_message_box(data->display, "Error!", "Icon Error:", "Failed to locate icon!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return false; } al_set_display_icon(data->display, data->icon); // Load a font data->font = al_load_ttf_font("times.ttf", 25, 0); data->b_font = al_load_ttf_font("impact.ttf", 25, 0); if(data->font == NULL || data->b_font == NULL) { al_show_native_message_box(data->display, "Error!", "Font Error:", "Failed to load font!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return false; } // Make and set a color to draw with data->text_color = al_map_rgba(80, 112, 255, 255); // Set background color data->background_color = al_map_rgba(0, 0, 0, 0); // Install the keyboard handler if(!al_install_keyboard()) { al_show_native_message_box(data->display, "Error!", "Keyboard Error:", "Failed to install keyboard handler!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return false; } // Install the mouse handler if(!al_install_mouse()) { al_show_native_message_box(data->display, "Error!", "Mouse Error:", "Failed to install mouse handler!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return false; } // Detect and set refresh rate int refresh_rate = al_get_display_refresh_rate(data->display); if(refresh_rate == 0) { refresh_rate = 60; } // Install timer with refresh rate data->timer = al_create_timer(1.0/refresh_rate); if(data->timer == NULL) { al_show_native_message_box(data->display, "Error!", "Timer Error:", "Failed to initialize timer!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return 1; } al_start_timer(data->timer); // Start the event queues to handle keyboard input, mouse input, display input and timer input data->queue = al_create_event_queue(); al_register_event_source(data->queue, (ALLEGRO_EVENT_SOURCE*)data->timer); data->queue2 = al_create_event_queue(); al_register_event_source(data->queue2, al_get_keyboard_event_source()); al_register_event_source(data->queue2, (ALLEGRO_EVENT_SOURCE*)data->display); al_register_event_source(data->queue2, al_get_mouse_event_source()); // Set the quit and gamestarted flags to false initially data->exit = false; data->gamestarted = false; data->options = false; data->highscores = false; data->howtoplay = false; al_start_timer(data->timer); return true; }