/* Function: al_install_system */ bool al_install_system(int version, int (*atexit_ptr)(void (*)(void))) { ALLEGRO_SYSTEM bootstrap; ALLEGRO_SYSTEM *real_system; int library_version = al_get_allegro_version(); if (active_sysdrv) { return true; } /* Note: We cannot call logging functions yet. * TODO: Maybe we want to do the check after the "bootstrap" system * is available at least? */ if (!compatible_versions(version, library_version)) return false; _al_tls_init_once(); _al_vector_init(&_al_system_interfaces, sizeof(ALLEGRO_SYSTEM_INTERFACE *)); /* Set up a bootstrap system so the calls expecting it don't freak out */ memset(&bootstrap, 0, sizeof(bootstrap)); active_sysdrv = &bootstrap; read_allegro_cfg(); #ifdef ALLEGRO_BCC32 /* This supresses exceptions on floating point divide by zero */ _control87(MCW_EM, MCW_EM); #endif /* Register builtin system drivers */ _al_register_system_interfaces(); /* Check for a user-defined system driver first */ real_system = find_system(&_user_system_interfaces); /* If a user-defined driver is not found, look for a builtin one */ if (real_system == NULL) { real_system = find_system(&_al_system_interfaces); } if (real_system == NULL) { active_sysdrv = NULL; return false; } active_sysdrv = real_system; active_sysdrv->mouse_wheel_precision = 1; ALLEGRO_INFO("Allegro version: %s\n", ALLEGRO_VERSION_STR); if (strcmp(al_get_app_name(), "") == 0) { al_set_app_name(NULL); } _al_add_exit_func(shutdown_system_driver, "shutdown_system_driver"); _al_dtor_list = _al_init_destructors(); _al_init_events(); _al_init_pixels(); _al_init_iio_table(); _al_init_convert_bitmap_list(); _al_init_timers(); #ifdef ALLEGRO_CFG_SHADER_GLSL _al_glsl_init_shaders(); #endif if (active_sysdrv->vt->heartbeat_init) active_sysdrv->vt->heartbeat_init(); if (atexit_ptr && atexit_virgin) { #ifndef ALLEGRO_ANDROID atexit_ptr(al_uninstall_system); #endif atexit_virgin = false; } /* Clear errnos set while searching for config files. */ al_set_errno(0); active_sysdrv->installed = true; _al_srand(time(NULL)); return true; }
/* _install_allegro: * Initialises the Allegro library, activating the system driver. */ static int _install_allegro(int system_id, int *errno_ptr, int (*atexit_ptr)(void (*func)(void))) { RGB black_rgb = {0, 0, 0, 0}; char tmp1[64], tmp2[64]; int i; #ifndef ALLEGRO_USE_CONSTRUCTOR /* call constructor functions manually */ extern void _initialize_datafile_types(); extern void _midi_constructor(); extern void _mouse_constructor(); _initialize_datafile_types(); _midi_constructor(); _mouse_constructor(); _register_bitmap_file_type_init(); _register_sample_file_type_init(); _register_font_file_type_init(); #endif if (errno_ptr) allegro_errno = errno_ptr; else allegro_errno = &errno; /* set up default palette structures */ for (i=0; i<256; i++) black_palette[i] = black_rgb; for (i=16; i<256; i++) desktop_palette[i] = desktop_palette[i & 15]; /* lock some important variables */ LOCK_VARIABLE(screen); LOCK_VARIABLE(gfx_driver); LOCK_VARIABLE(gfx_capabilities); LOCK_VARIABLE(_last_bank_1); LOCK_VARIABLE(_last_bank_2); LOCK_VARIABLE(_gfx_bank); LOCK_VARIABLE(_drawing_mode); LOCK_VARIABLE(_drawing_pattern); LOCK_VARIABLE(_drawing_x_anchor); LOCK_VARIABLE(_drawing_y_anchor); LOCK_VARIABLE(_drawing_x_mask); LOCK_VARIABLE(_drawing_y_mask); LOCK_VARIABLE(_current_palette); LOCK_VARIABLE(os_type); /* nasty stuff to set up the config system before the system driver */ system_driver = _system_driver_list[0].driver; /* needed in case set_config_file was called before allegro_init */ _reload_config(); reload_config_texts(NULL); if (system_id == SYSTEM_AUTODETECT) system_id = get_config_id(uconvert_ascii("system", tmp1), uconvert_ascii("system", tmp2), SYSTEM_AUTODETECT); system_driver = NULL; /* initialise the system driver */ usetc(allegro_error, 0); for (i=0; _system_driver_list[i].driver; i++) { if ((_system_driver_list[i].id == system_id) || ((_system_driver_list[i].autodetect) && (system_id == SYSTEM_AUTODETECT))) { system_driver = _system_driver_list[i].driver; system_driver->name = system_driver->desc = get_config_text(system_driver->ascii_name); if (system_driver->init() != 0) { system_driver = NULL; if (system_id != SYSTEM_AUTODETECT) break; } else break; } } if (!system_driver) return -1; /* disable close button */ set_close_button_callback(NULL); /* detect CPU type */ check_cpu(); #if defined(ALLEGRO_UNIX) || defined(ALLEGRO_WINDOWS) /* detect filename encoding used by libc */ /* XXX This should be done for all platforms but I'm not set up to check * that all platforms have been covered before making the 4.2.3 release. * --pw */ _al_detect_filename_encoding(); #endif /* set up screensaver policy */ _screensaver_policy = get_config_int(uconvert_ascii("system", tmp1), uconvert_ascii("disable_screensaver", tmp2), FULLSCREEN_DISABLED); /* install shutdown handler */ if (_allegro_count == 0) { if (atexit_ptr) atexit_ptr(allegro_exit_stub); } _allegro_count++; TRACE(PREFIX_I "Allegro initialised (instance %d)\n", _allegro_count); return 0; }