static gboolean window_configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, WindowState *state) { _games_debug_print (GAMES_DEBUG_WINDOW_STATE, "[window %p] configure event current %dx%d new %dx%d [state: is-maximised:%s is-fullscreen:%s]\n", state->window, state->width, state->height, event->width, event->height, state->is_maximised ? "t" : "f", state->is_fullscreen ? "t" : "f"); if (!state->is_maximised && !state->is_fullscreen && (state->width != event->width || state->height != event->height)) { state->width = event->width; state->height = event->height; _games_debug_print (GAMES_DEBUG_WINDOW_STATE, "[window %p] scheduling save of new window size\n", state->window); if (state->timeout_id == 0) { state->timeout_id = g_timeout_add_seconds (WINDOW_STATE_TIMEOUT, (GSourceFunc) window_state_timeout_cb, state); } } return FALSE; }
static gboolean window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, WindowState *state) { _games_debug_print (GAMES_DEBUG_WINDOW_STATE, "[window %p] state event, mask:%x new-state:%x current state: is-maximised:%s is-fullscreen:%s\n", state->window, event->changed_mask, event->new_window_state, state->is_maximised ? "t" : "f", state->is_fullscreen ? "t" : "f"); if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) { state->is_maximised = (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0; games_conf_set_boolean (state->group, window_state_key_name[STATE_KEY_MAXIMISED], state->is_maximised); } if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) { state->is_fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0; games_conf_set_boolean (state->group, window_state_key_name[STATE_KEY_FULLSCREEN], state->is_fullscreen); } _games_debug_print (GAMES_DEBUG_WINDOW_STATE, " > new state: is-maximised:%s is-fullscreen:%s\n", state->is_maximised ? "t" : "f", state->is_fullscreen ? "t" : "f"); return FALSE; }
/* Initializes the games-sound support */ static void games_sound_init (void) { #if defined(HAVE_GSTREAMER) GError *err = NULL; g_assert (g_thread_supported ()); pipeline = gst_element_factory_make ("playbin", "playbin"); if (pipeline == NULL) return; threads = g_thread_pool_new ((GFunc) games_sound_thread_run, NULL, 10, FALSE, &err); sound_init = TRUE; #elif defined(HAVE_SDL_MIXER) const int audio_rate = MIX_DEFAULT_FREQUENCY; const int audio_format = MIX_DEFAULT_FORMAT; const int audio_channels = 2; const size_t buf_size = 1024; SDL_Init (SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE); if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, buf_size) < 0) { _games_debug_print (GAMES_DEBUG_SOUND, "Error calling Mix_OpenAudio\n"); return; } #endif /* HAVE_SDL_MIXER */ }
/** * games_runtime_init: * * Initialises the runtime file localisator. This also calls setlocale, * and initialises gettext support and gnome-games debug support. * * NOTE: This must be called before using ANY other glib/gtk/etc function! * * Returns: %TRUE iff initialisation succeeded */ gboolean games_runtime_init (const char *name) { gboolean retval; setlocale (LC_ALL, ""); #if defined(HAVE_GNOME) || defined(HAVE_RSVG_GNOMEVFS) || defined(HAVE_GSTREAMER) /* If we're going to use gconf, gnome-vfs, or gstreamer, we need to * init threads before calling any glib functions. */ g_thread_init (NULL); /* May call any glib function after this point */ #endif _games_profile_start ("games_runtime_init"); _games_debug_init (); app_name = g_strdup (name); bindtextdomain (GETTEXT_PACKAGE, games_runtime_get_directory (GAMES_RUNTIME_LOCALE_DIRECTORY)); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #ifdef G_OS_WIN32 { const char *path; path = games_runtime_get_directory (GAMES_RUNTIME_MODULE_DIRECTORY); _games_debug_print (GAMES_DEBUG_RUNTIME, "Relocation path: %s\n", path ? path : "(null)"); retval = path != NULL; } #else retval = TRUE; #endif #if defined(ENABLE_CARD_THEME_FORMAT_KDE) || defined(ENABLE_CARD_THEME_FORMAT_SLICED) || defined(ENABLE_CARD_THEME_FORMAT_PYSOL) if (strcmp (app_name, "aisleriot") == 0 || strcmp (app_name, "blackjack") == 0) { gpl_version = 3; } else #endif gpl_version = 2; _games_profile_end ("games_runtime_init"); return retval; }
/* This function is called as a separate thread, playing the sound. */ static void games_sound_thread_run (gchar * data, gchar * user_data) { const char *dir; char *uri; gboolean done = FALSE; GstBus *bus; bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); /* Set URL for sound to play. */ dir = games_runtime_get_directory (GAMES_RUNTIME_SOUND_DIRECTORY); uri = g_strdup_printf ("file:///%s/%s.ogg", dir, (char *) data); g_object_set (G_OBJECT (pipeline), "uri", uri, NULL); g_free (uri); /* Set playbin to playing state. */ gst_element_set_state (pipeline, GST_STATE_PLAYING); do { GstMessage *message; /* wait for message on the bus */ message = gst_bus_timed_pop (bus, GST_CLOCK_TIME_NONE); switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_EOS: done = TRUE; break; case GST_MESSAGE_ERROR:{ GError *err; gchar *debug; gst_message_parse_error (message, &err, &debug); _games_debug_print (GAMES_DEBUG_SOUND, "Error playing sound: %s\n", err->message); g_error_free (err); g_free (debug); done = TRUE; break; } default: break; } gst_message_unref (message); } while (!done); gst_element_set_state (pipeline, GST_STATE_NULL); }
static gboolean window_state_timeout_cb (WindowState *state) { games_conf_set_integer (state->group, window_state_key_name[STATE_KEY_WIDTH], state->width); games_conf_set_integer (state->group, window_state_key_name[STATE_KEY_HEIGHT], state->height); _games_debug_print (GAMES_DEBUG_WINDOW_STATE, "[window %p] timeout: persisting width:%d height:%d\n", state->window, state->width, state->height); state->timeout_id = 0; return FALSE; }
static void games_card_textures_cache_finalize (GObject *object) { GamesCardTexturesCache *cache = GAMES_CARD_TEXTURES_CACHE (object); GamesCardTexturesCachePrivate *priv = cache->priv; g_free (priv->cards); #ifdef GNOME_ENABLE_DEBUG _GAMES_DEBUG_IF (GAMES_DEBUG_CARD_CACHE) { _games_debug_print (GAMES_DEBUG_CARD_CACHE, "GamesCardTexturesCache %p statistics: %u calls with %u hits and %u misses for a hit/total of %.3f\n", cache, priv->n_calls, priv->cache_hits, priv->n_calls - priv->cache_hits, priv->n_calls > 0 ? (double) priv->cache_hits / (double) priv->n_calls : 0.0); } #endif G_OBJECT_CLASS (games_card_textures_cache_parent_class)->finalize (object); }
static void games_sound_sdl_play (const gchar *filename) { Mix_Chunk *wave = NULL; gchar *name, *path; name = g_strdup_printf ("%s.ogg", filename); path = games_runtime_get_file (GAMES_RUNTIME_SOUND_DIRECTORY, name); g_free (name); wave = Mix_LoadWAV (path); if (wave == NULL) { _games_debug_print (GAMES_DEBUG_SOUND, "Error playing sound %s: %s\n", path, Mix_GetError ()); } Mix_PlayChannel (-1, wave, 0); g_free (path); }
static void games_card_textures_cache_clear (GamesCardTexturesCache *cache) { GamesCardTexturesCachePrivate *priv = cache->priv; int i; _games_debug_print (GAMES_DEBUG_CARD_CACHE, "games_card_textures_cache_clear\n"); for (i = 0; i < GAMES_CARDS_TOTAL; i++) { CoglHandle handle = priv->cards[i]; if (handle != COGL_INVALID_HANDLE && !IS_FAILED_HANDLE (handle)) { cogl_texture_unref (handle); } priv->cards[i] = COGL_INVALID_HANDLE; } }