/* Function: al_play_sample */ bool al_play_sample(ALLEGRO_SAMPLE *spl, float gain, float pan, float speed, ALLEGRO_PLAYMODE loop, ALLEGRO_SAMPLE_ID *ret_id) { static int next_id = 0; unsigned int i; ASSERT(spl); if (ret_id != NULL) { ret_id->_id = -1; ret_id->_index = 0; } for (i = 0; i < _al_vector_size(&auto_samples); i++) { ALLEGRO_SAMPLE_INSTANCE **slot = _al_vector_ref(&auto_samples, i); ALLEGRO_SAMPLE_INSTANCE *splinst = (*slot); if (!al_get_sample_instance_playing(splinst)) { int *id = _al_vector_ref(&auto_sample_ids, i); if (!do_play_sample(splinst, spl, gain, pan, speed, loop)) break; if (ret_id != NULL) { ret_id->_index = (int) i; ret_id->_id = *id = ++next_id; } return true; } } return false; }
/* Carefully destroy a menu item... If the item is part of a menu, it must be * removed from it. */ static void destroy_menu_item(ALLEGRO_MENU_ITEM *item) { ASSERT(item); if (!item->parent) { /* This normally won't happen. */ _al_destroy_menu_item_at(item, -1); } else { size_t i; for (i = 0; i < _al_vector_size(&item->parent->items); ++i) { if (*(ALLEGRO_MENU_ITEM **)_al_vector_ref(&item->parent->items, i) == item) { /* Notify the platform that the item is to be removed. */ _al_destroy_menu_item_at(item, i); /* Remove the command from the look-up vector. */ if (item->id != 0) { _AL_MENU_ID *menu_id; size_t j; for (j = 0; j < _al_vector_size(&menu_ids); ++j) { menu_id = (_AL_MENU_ID *) _al_vector_ref(&menu_ids, j); if (menu_id->menu == item->parent && menu_id->unique_id == item->unique_id) { _al_vector_delete_at(&menu_ids, j); break; } } } /* Remove the menu from the parent's list. */ _al_vector_delete_at(&item->parent->items, i); break; } } } if (item->caption) al_ustr_free(item->caption); if (item->popup) { /* Delete the sub-menu. Must set the parent/display to NULL ahead of time to * avoid recursing back here. */ item->popup->parent = NULL; item->popup->display = NULL; al_destroy_menu(item->popup); } if (item->icon) { al_destroy_bitmap(item->icon); } al_free(item); }
static void win_shutdown(void) { ALLEGRO_SYSTEM *s; ALLEGRO_DISPLAY_INTERFACE *display_driver; ASSERT(vt); /* Close all open displays. */ s = al_get_system_driver(); while (_al_vector_size(&s->displays) > 0) { ALLEGRO_DISPLAY **dptr = _al_vector_ref(&s->displays, 0); ALLEGRO_DISPLAY *d = *dptr; _al_destroy_display_bitmaps(d); al_destroy_display(d); } _al_vector_free(&s->displays); display_driver = vt->get_display_driver(); if (display_driver && display_driver->shutdown) { display_driver->shutdown(); } _al_win_shutdown_time(); if (using_higher_res_timer) { timeEndPeriod(1); } al_free(vt); vt = NULL; ASSERT(_al_win_system); al_free(_al_win_system); }
static void restore_mode_if_last_fullscreen_display(ALLEGRO_SYSTEM_XGLX *s, ALLEGRO_DISPLAY_XGLX *d) { bool last_fullscreen = true; size_t i; /* If any other fullscreen display is still active on the same adapter, * we must not touch the video mode. */ for (i = 0; i < s->system.displays._size; i++) { ALLEGRO_DISPLAY_XGLX **slot = _al_vector_ref(&s->system.displays, i); ALLEGRO_DISPLAY_XGLX *living = *slot; if (living == d) continue; /* Check for fullscreen displays on the same adapter. */ if (living->adapter == d->adapter && (living->display.flags & ALLEGRO_FULLSCREEN)) { last_fullscreen = false; } } if (last_fullscreen) { ALLEGRO_DEBUG("restore mode.\n"); _al_xglx_restore_video_mode(s, d->adapter); } else { ALLEGRO_DEBUG("*not* restoring mode.\n"); } }
/* ljoy_get_joystick: [primary thread] * * Returns the address of a ALLEGRO_JOYSTICK structure for the device * number NUM. */ static ALLEGRO_JOYSTICK *ljoy_get_joystick(int num) { ALLEGRO_JOYSTICK *ret = NULL; unsigned i; ASSERT(num >= 0); al_lock_mutex(config_mutex); for (i = 0; i < _al_vector_size(&joysticks); i++) { ALLEGRO_JOYSTICK_LINUX **slot = _al_vector_ref(&joysticks, i); ALLEGRO_JOYSTICK_LINUX *joy = *slot; if (ACTIVE_STATE(joy->config_state)) { if (num == 0) { ret = (ALLEGRO_JOYSTICK *)joy; break; } num--; } } al_unlock_mutex(config_mutex); return ret; }
void _al_xwin_destroy_mouse_cursor(ALLEGRO_MOUSE_CURSOR *cursor) { ALLEGRO_MOUSE_CURSOR_XGLX *xcursor = (ALLEGRO_MOUSE_CURSOR_XGLX *)cursor; ALLEGRO_SYSTEM *sys = al_get_system_driver(); ALLEGRO_SYSTEM_XGLX *sysx = (ALLEGRO_SYSTEM_XGLX *)sys; unsigned i; _al_mutex_lock(&sysx->lock); for (i = 0; i < _al_vector_size(&sys->displays); i++) { ALLEGRO_DISPLAY_XGLX **slot = _al_vector_ref(&sys->displays, i); ALLEGRO_DISPLAY_XGLX *glx = *slot; if (glx->current_cursor == xcursor->cursor) { if (!glx->cursor_hidden) XUndefineCursor(sysx->x11display, glx->window); glx->current_cursor = None; } } XFreeCursor(sysx->x11display, xcursor->cursor); al_free(xcursor); _al_mutex_unlock(&sysx->lock); }
/* Function: al_stop_sample */ void al_stop_sample(ALLEGRO_SAMPLE_ID *spl_id) { int *id; ASSERT(spl_id->_id != -1); ASSERT(spl_id->_index < (int) _al_vector_size(&auto_samples)); ASSERT(spl_id->_index < (int) _al_vector_size(&auto_sample_ids)); id = _al_vector_ref(&auto_sample_ids, spl_id->_index); if (*id == spl_id->_id) { ALLEGRO_SAMPLE_INSTANCE **slot, *spl; slot = _al_vector_ref(&auto_samples, spl_id->_index); spl = (*slot); al_stop_sample_instance(spl); } }
/* * Must be called before the D3D device is reset (e.g., when * resizing a window). All non-synced display bitmaps must be * synced to memory. */ void _al_d3d_prepare_bitmaps_for_reset(ALLEGRO_DISPLAY_D3D *disp) { unsigned int i; if (disp->device_lost) return; if (!_al_d3d_render_to_texture_supported()) return; al_lock_mutex(_al_d3d_lost_device_mutex); for (i = 0; i < created_bitmaps._size; i++) { ALLEGRO_BITMAP_D3D **bptr = (ALLEGRO_BITMAP_D3D **)_al_vector_ref(&created_bitmaps, i); ALLEGRO_BITMAP_D3D *bmp = *bptr; ALLEGRO_BITMAP *al_bmp = (ALLEGRO_BITMAP *)bmp; if (bmp->display == disp) { //d3d_sync_bitmap_memory(al_bmp); if (!al_bmp->preserve_texture) { bmp->modified = false; } else if (!bmp->is_backbuffer && bmp->modified && !(al_bmp->flags & ALLEGRO_MEMORY_BITMAP)) { _al_d3d_sync_bitmap(al_bmp); bmp->modified = false; } } } al_unlock_mutex(_al_d3d_lost_device_mutex); }
/* * Refresh the texture memory. This must be done after a device is * lost or after it is reset. */ void _al_d3d_refresh_texture_memory(void) { unsigned int i; for (i = 0; i < created_bitmaps._size; i++) { ALLEGRO_BITMAP_D3D **bptr = (ALLEGRO_BITMAP_D3D **)_al_vector_ref(&created_bitmaps, i); ALLEGRO_BITMAP_D3D *bmp = *bptr; ALLEGRO_BITMAP *al_bmp = (ALLEGRO_BITMAP *)bmp; ALLEGRO_DISPLAY_D3D *bmps_display = (ALLEGRO_DISPLAY_D3D *)al_bmp->display; if ((al_bmp->flags & ALLEGRO_MEMORY_BITMAP) || (al_bmp->parent)) { continue; } d3d_create_textures(bmps_display, bmp->texture_w, bmp->texture_h, al_bmp->flags, &bmp->video_texture, /*&bmp->system_texture*/0, al_bmp->format); d3d_sync_bitmap_texture(al_bmp, 0, 0, al_bmp->w, al_bmp->h); if (_al_d3d_render_to_texture_supported()) { bmps_display->device->UpdateTexture( (IDirect3DBaseTexture9 *)bmp->system_texture, (IDirect3DBaseTexture9 *)bmp->video_texture); } } }
static void win_shutdown(void) { ALLEGRO_SYSTEM *s; ASSERT(vt); /* Close all open displays. */ s = al_get_system_driver(); while (_al_vector_size(&s->displays) > 0) { ALLEGRO_DISPLAY **dptr = _al_vector_ref(&s->displays, 0); ALLEGRO_DISPLAY *d = *dptr; al_destroy_display(d); } _al_vector_free(&s->displays); #ifdef ALLEGRO_CFG_D3D _al_d3d_shutdown_display(); #endif _al_win_shutdown_time(); if (using_higher_res_timer) { timeEndPeriod(1); } al_free(vt); vt = NULL; ASSERT(_al_win_system); al_free(_al_win_system); }
static void ljoy_merge(void) { unsigned i; config_needs_merging = false; num_joysticks = 0; for (i = 0; i < _al_vector_size(&joysticks); i++) { ALLEGRO_JOYSTICK_LINUX **slot = _al_vector_ref(&joysticks, i); ALLEGRO_JOYSTICK_LINUX *joy = *slot; switch (joy->config_state) { case LJOY_STATE_UNUSED: break; case LJOY_STATE_BORN: case LJOY_STATE_ALIVE: joy->config_state = LJOY_STATE_ALIVE; num_joysticks++; break; case LJOY_STATE_DYING: inactivate_joy(joy); break; } } ALLEGRO_DEBUG("Merge done, num_joysticks=%d\n", num_joysticks); }
/* Function: al_find_menu */ ALLEGRO_MENU *al_find_menu(ALLEGRO_MENU *haystack, uint16_t id) { int index; return !al_find_menu_item(haystack, id, &haystack, &index) ? NULL : (*(ALLEGRO_MENU_ITEM **)_al_vector_ref(&haystack->items, index))->popup; }
/* ljoy_exit_joystick: [primary thread] * Shut down the joystick driver. */ static void ljoy_exit_joystick(void) { int i; #ifdef SUPPORT_HOTPLUG if (inotify_fd != -1) { _al_unix_stop_watching_fd(inotify_fd); close(inotify_fd); inotify_fd = -1; } hotplug_ended = true; al_signal_cond(hotplug_cond); al_join_thread(hotplug_thread, NULL); #endif al_destroy_mutex(config_mutex); config_mutex = NULL; for (i = 0; i < (int)_al_vector_size(&joysticks); i++) { ALLEGRO_JOYSTICK_LINUX **slot = _al_vector_ref(&joysticks, i); inactivate_joy(*slot); al_free(*slot); } _al_vector_free(&joysticks); num_joysticks = 0; }
static bool init_touch_input(void) { unsigned i; ALLEGRO_SYSTEM* system; if (installed) return false; if (!_al_win_init_touch_input_api()) return false; memset(&touch_input_state, 0, sizeof(touch_input_state)); _al_event_source_init(&touch_input.es); _al_event_source_init(&touch_input.mouse_emulation_es); touch_input.mouse_emulation_mode = ALLEGRO_MOUSE_EMULATION_TRANSPARENT; installed = true; system = al_get_system_driver(); for (i = 0; i < _al_vector_size(&system->displays); ++i) { bool r; ALLEGRO_DISPLAY_WIN *win_display = *((ALLEGRO_DISPLAY_WIN**)_al_vector_ref(&system->displays, i)); r = _al_win_register_touch_window(win_display->window, 0); ALLEGRO_INFO("registering touch window %p: %d\n", win_display, r); if (!r) { ALLEGRO_ERROR("RegisterTouchWindow failed: %s\n", get_error_desc(GetLastError())); return false; } } return true; }
/* Look through all the bitmaps associated with all the shaders and c;ear their * shader field */ void _al_glsl_unuse_shaders(void) { unsigned i; al_lock_mutex(shaders_mutex); for (i = 0; i < _al_vector_size(&shaders); i++) { unsigned j; ALLEGRO_SHADER *shader = *((ALLEGRO_SHADER **)_al_vector_ref(&shaders, i)); for (j = 0; j < _al_vector_size(&shader->bitmaps); j++) { ALLEGRO_BITMAP *bitmap = *((ALLEGRO_BITMAP **)_al_vector_ref(&shader->bitmaps, j)); _al_set_bitmap_shader_field(bitmap, NULL); } } al_unlock_mutex(shaders_mutex); }
/* stream_free: * This function is ALLEGRO_MIXER aware and frees the memory associated with * the sample or mixer, and detaches any attached streams or mixers. */ static void stream_free(ALLEGRO_SAMPLE_INSTANCE *spl) { if (spl) { /* Make sure we free the mixer buffer and de-reference the attached * streams if this is a mixer stream. */ if (spl->is_mixer) { ALLEGRO_MIXER *mixer = (ALLEGRO_MIXER *)spl; int i; _al_kcm_stream_set_mutex(&mixer->ss, NULL); for (i = _al_vector_size(&mixer->streams) - 1; i >= 0; i--) { ALLEGRO_SAMPLE_INSTANCE **slot = _al_vector_ref(&mixer->streams, i); ALLEGRO_SAMPLE_INSTANCE *spl = *slot; spl->parent.u.ptr = NULL; } _al_vector_free(&mixer->streams); if (spl->spl_data.buffer.ptr) { ASSERT(spl->spl_data.free_buf); al_free(spl->spl_data.buffer.ptr); spl->spl_data.buffer.ptr = NULL; } spl->spl_data.free_buf = false; } ASSERT(! spl->spl_data.free_buf); al_free(spl); } }
void _al_d3d_destroy_display_format_list(void) { /* Free the display format list */ for (int j = 0; j < (int)_al_vector_size(&eds_list); j++) { void **eds = (void **)_al_vector_ref(&eds_list, j); al_free(*eds); } _al_vector_free(&eds_list); }
/* Function: al_stop_samples */ void al_stop_samples(void) { unsigned int i; for (i = 0; i < _al_vector_size(&auto_samples); i++) { ALLEGRO_SAMPLE_INSTANCE **slot = _al_vector_ref(&auto_samples, i); ALLEGRO_SAMPLE_INSTANCE *spl = (*slot); al_stop_sample_instance(spl); } }
/* [gtk thread] */ static void build_menu(GtkWidget *gmenu, ALLEGRO_MENU *amenu) { size_t i; for (i = 0; i < _al_vector_size(&amenu->items); ++i) { ALLEGRO_MENU_ITEM *aitem = * (ALLEGRO_MENU_ITEM **) _al_vector_ref(&amenu->items, i); GtkWidget *gitem = build_menu_item(aitem); gtk_menu_shell_append(GTK_MENU_SHELL(gmenu), gitem); } }
/* Destroy all sample instances, and frees the associated vectors. */ static void free_sample_vector(void) { int j; for (j = 0; j < (int) _al_vector_size(&auto_samples); j++) { ALLEGRO_SAMPLE_INSTANCE **slot = _al_vector_ref(&auto_samples, j); al_destroy_sample_instance(*slot); } _al_vector_free(&auto_samples); _al_vector_free(&auto_sample_ids); }
/* joydx_exit_joystick: [primary thread] * Shuts down the DirectInput joystick devices. */ static void joydx_exit_joystick(void) { int i; ALLEGRO_SYSTEM *system; size_t j; ALLEGRO_DEBUG("Entering joydx_exit_joystick\n"); ASSERT(joydx_thread); /* stop the thread */ SetEvent(STOP_EVENT); WaitForSingleObject(joydx_thread, INFINITE); CloseHandle(joydx_thread); joydx_thread = NULL; /* free thread resources */ CloseHandle(STOP_EVENT); STOP_EVENT = NULL; DeleteCriticalSection(&joydx_thread_cs); /* The toplevel display is assumed to have the input acquired. Release it. */ system = al_get_system_driver(); for (j = 0; j < _al_vector_size(&system->displays); j++) { ALLEGRO_DISPLAY_WIN **pwin_disp = _al_vector_ref(&system->displays, j); ALLEGRO_DISPLAY_WIN *win_disp = *pwin_disp; if (win_disp->window == GetForegroundWindow()) { ALLEGRO_DEBUG("Requesting window unacquire joystick devices\n"); _al_win_wnd_call_proc(win_disp->window, _al_win_joystick_dinput_unacquire, win_disp); } } /* destroy the devices */ for (i = 0; i < MAX_JOYSTICKS; i++) { joydx_inactivate_joy(&joydx_joystick[i]); } joydx_num_joysticks = 0; for (i = 0; i < MAX_JOYSTICKS; i++) { JOYSTICK_WAKER(i) = NULL; } /* destroy the DirectInput interface */ IDirectInput8_Release(joystick_dinput); joystick_dinput = NULL; /* release module handle */ FreeLibrary(_al_dinput_module); _al_dinput_module = NULL; ALLEGRO_DEBUG("Leaving joydx_exit_joystick\n"); }
void _al_d3d_score_display_settings(ALLEGRO_EXTRA_DISPLAY_SETTINGS *ref) { for (int i = 0; i < (int)_al_vector_size(&eds_list); i++) { ALLEGRO_EXTRA_DISPLAY_SETTINGS *eds, **peds; peds = (ALLEGRO_EXTRA_DISPLAY_SETTINGS **)_al_vector_ref(&eds_list, i); eds = *peds; eds->score = _al_score_display_settings(eds, ref); eds->index = i; } qsort(eds_list._items, eds_list._size, eds_list._itemsize, _al_display_settings_sorter); }
ALLEGRO_DISPLAY *_al_sdl_find_display(uint32_t window_id) { unsigned int i; ALLEGRO_SYSTEM *s = al_get_system_driver(); for (i = 0; i < _al_vector_size(&s->displays); i++) { void **v = (void **)_al_vector_ref(&s->displays, i); ALLEGRO_DISPLAY_SDL *d = *v; if (SDL_GetWindowID(d->window) == window_id) { return &d->display; break; } } return NULL; }
/* Function: al_backup_dirty_bitmaps */ void al_backup_dirty_bitmaps(ALLEGRO_DISPLAY *display) { unsigned int i; for (i = 0; i < display->bitmaps._size; i++) { ALLEGRO_BITMAP **bptr = (ALLEGRO_BITMAP **)_al_vector_ref(&display->bitmaps, i); ALLEGRO_BITMAP *bmp = *bptr; if (_al_get_bitmap_display(bmp) == display) { if (bmp->vt && bmp->vt->backup_dirty_bitmap) { bmp->vt->backup_dirty_bitmap(bmp); } } } }
static void transfer_display_bitmaps_to_any_other_display( ALLEGRO_SYSTEM_XGLX *s, ALLEGRO_DISPLAY *d) { size_t i; ALLEGRO_DISPLAY *living = NULL; ASSERT(s->system.displays._size > 1); for (i = 0; i < s->system.displays._size; i++) { ALLEGRO_DISPLAY **slot = _al_vector_ref(&s->system.displays, i); living = *slot; if (living != d) break; } ALLEGRO_DEBUG("transferring display bitmaps to other display.\n"); for (i = 0; i < d->bitmaps._size; i++) { ALLEGRO_BITMAP **add = _al_vector_alloc_back(&(living->bitmaps)); ALLEGRO_BITMAP **ref = _al_vector_ref(&d->bitmaps, i); *add = *ref; (*add)->_display = living; } }
/* Function: al_set_default_mixer */ bool al_set_default_mixer(ALLEGRO_MIXER *mixer) { ASSERT(mixer != NULL); if (mixer != default_mixer) { int i; default_mixer = mixer; /* Destroy all current sample instances, recreate them, and * attach them to the new mixer */ for (i = 0; i < (int) _al_vector_size(&auto_samples); i++) { ALLEGRO_SAMPLE_INSTANCE **slot = _al_vector_ref(&auto_samples, i); int *id = _al_vector_ref(&auto_sample_ids, i); *id = 0; al_destroy_sample_instance(*slot); *slot = al_create_sample_instance(NULL); if (!*slot) { ALLEGRO_ERROR("al_create_sample failed\n"); goto Error; } if (!al_attach_sample_instance_to_mixer(*slot, default_mixer)) { ALLEGRO_ERROR("al_attach_mixer_to_sample failed\n"); goto Error; } } } return true; Error: free_sample_vector(); default_mixer = NULL; return false; }
/* Function: al_get_display_menu */ ALLEGRO_MENU *al_get_display_menu(ALLEGRO_DISPLAY *display) { size_t i; ASSERT(display); /* Search through the display_menus vector to see if this display has * a menu associated with it. */ for (i = 0; i < _al_vector_size(&display_menus); ++i) { DISPLAY_MENU *dm = (DISPLAY_MENU *) _al_vector_ref(&display_menus, i); if (dm->display == display) return dm->menu; } return NULL; }
/* All public functions that take a menu and id parameter have two interpretations: * * 1) If id > 0, then it represents an id anywhere within the menu structure, * including child menus. If there are non-unique IDs, the first one found is * returned, but the exact order is undefined. (IDs are meant to be unique.) * * 2) If id <= 0, then its absolute value represents an ordered index for that * exact menu. * * If the parameters are valid, it returns a pointer to the corresponding * MENU_ITEM, and the menu/id parameters are set to the item's parent and its * index. Otherwise (on invalid parameters), it returns NULL and the menu/id * parameters are left undefined. * * (Note that the private OS specific functions always take a direct index.) */ static ALLEGRO_MENU_ITEM *interpret_menu_id_param(ALLEGRO_MENU **menu, int *id) { if (*id > 0) { if (!al_find_menu_item(*menu, *id, menu, id)) return NULL; } else { *id = (0 - *id); if ((size_t) *id >= _al_vector_size(&((*menu)->items))) return NULL; } return *(ALLEGRO_MENU_ITEM **) _al_vector_ref(&((*menu)->items), (size_t) *id); }
static ALLEGRO_JOYSTICK_LINUX *ljoy_by_device_name( const ALLEGRO_USTR *device_name) { unsigned i; for (i = 0; i < _al_vector_size(&joysticks); i++) { ALLEGRO_JOYSTICK_LINUX **slot = _al_vector_ref(&joysticks, i); ALLEGRO_JOYSTICK_LINUX *joy = *slot; if (joy && al_ustr_equal(device_name, joy->device_name)) return joy; } return NULL; }
/* Internal function: _al_foreach_destructor * Call the callback for each registered object. * [thread-safe] */ void _al_foreach_destructor(_AL_DTOR_LIST *dtors, void (*callback)(void *object, void (*func)(void *), void *udata), void *userdata) { _al_mutex_lock(&dtors->mutex); { unsigned int i; for (i = 0; i < _al_vector_size(&dtors->dtors); i++) { DTOR *dtor = _al_vector_ref(&dtors->dtors, i); callback(dtor->object, dtor->func, userdata); } } _al_mutex_unlock(&dtors->mutex); }