gnome-games r8452 - trunk/libgames-support
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8452 - trunk/libgames-support
- Date: Tue, 6 Jan 2009 18:19:07 +0000 (UTC)
Author: chpe
Date: Tue Jan 6 18:19:06 2009
New Revision: 8452
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8452&view=rev
Log:
Simplify code, and make a few g_warning()s into _games_debug_print()s.
Modified:
trunk/libgames-support/games-card-theme-fixed.c
trunk/libgames-support/games-card-theme-pysol.c
trunk/libgames-support/games-sound.c
Modified: trunk/libgames-support/games-card-theme-fixed.c
==============================================================================
--- trunk/libgames-support/games-card-theme-fixed.c (original)
+++ trunk/libgames-support/games-card-theme-fixed.c Tue Jan 6 18:19:06 2009
@@ -25,6 +25,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
+#include "games-debug.h"
#include "games-find-file.h"
#include "games-files.h"
#include "games-preimage.h"
@@ -49,7 +50,6 @@
CardSize slot_size;
CardSize card_size;
- guint theme_loaded : 1;
guint size_available : 1;
};
@@ -74,8 +74,9 @@
key_file = g_key_file_new ();
if (!g_key_file_load_from_file (key_file, path, 0, &error)) {
- g_warning ("Failed to load prerendered card theme from %s: %s\n", path,
- error->message);
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Failed to load prerendered card theme from %s: %s\n", path,
+ error->message);
g_error_free (error);
goto loser;
}
@@ -84,13 +85,15 @@
g_key_file_get_integer_list (key_file, "Card Theme", "Sizes", &n_sizes,
&error);
if (error) {
- g_warning ("Failed to get card sizes: %s\n", error->message);
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Failed to get card sizes: %s\n", error->message);
g_error_free (error);
goto loser;
}
if (n_sizes == 0) {
- g_warning ("Card theme contains no sizes\n");
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Card theme contains no sizes\n");
goto loser;
}
@@ -106,15 +109,17 @@
width = g_key_file_get_integer (key_file, group, "Width", &err);
if (err) {
- g_warning ("Error loading width for size %d: %s\n", sizes[i],
- err->message);
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Error loading width for size %d: %s\n", sizes[i],
+ err->message);
g_error_free (err);
goto loser;
}
height = g_key_file_get_integer (key_file, group, "Height", &err);
if (err) {
- g_warning ("Error loading height for size %d: %s\n", sizes[i],
- err->message);
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Error loading height for size %d: %s\n", sizes[i],
+ err->message);
g_error_free (err);
goto loser;
}
@@ -135,34 +140,6 @@
return retval;
}
-static GdkPixbuf *
-games_card_theme_fixed_load_card (GamesCardThemeFixed *theme,
- int card_id)
-{
- GdkPixbuf *pixbuf;
- GError *error = NULL;
- char name[64], filename[64];
- char *path;
-
- if (!theme->size_available)
- return NULL;
-
- games_card_get_name_by_id_snprintf (name, sizeof (name), card_id);
- g_snprintf (filename, sizeof (filename), "%s.png", name);
- path = g_build_filename (theme->themesizepath, filename, NULL);
-
- pixbuf = gdk_pixbuf_new_from_file (path, &error);
- if (!pixbuf) {
- g_warning ("Failed to load card image %s: %s\n", filename,
- error->message);
- g_error_free (error);
- }
-
- g_free (path);
-
- return pixbuf;
-}
-
static void
games_card_theme_fixed_init (GamesCardThemeFixed *theme)
{
@@ -174,8 +151,6 @@
theme->size_available = FALSE;
- theme->theme_loaded = FALSE;
-
theme->card_size.width = theme->card_size.height = theme->slot_size.width =
theme->slot_size.width = -1;
}
@@ -250,7 +225,9 @@
theme->size_available = TRUE;
theme->card_size = size;
} else {
- g_warning ("No prerendered size available for %d:%d\n", width, height);
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "No prerendered size available for %d:%d\n",
+ width, height);
theme->size_available = FALSE;
/* FIXMEchpe: at least use the smallest available size here, or
@@ -289,8 +266,26 @@
{
GamesCardThemeFixed *theme = (GamesCardThemeFixed *) card_theme;
GdkPixbuf *pixbuf;
+ GError *error = NULL;
+ char name[64], filename[64];
+ char *path;
+
+ if (!theme->size_available)
+ return NULL;
- pixbuf = games_card_theme_fixed_load_card (theme, card_id);
+ games_card_get_name_by_id_snprintf (name, sizeof (name), card_id);
+ g_snprintf (filename, sizeof (filename), "%s.png", name);
+ path = g_build_filename (theme->themesizepath, filename, NULL);
+
+ pixbuf = gdk_pixbuf_new_from_file (path, &error);
+ if (!pixbuf) {
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Failed to load card image %s: %s\n",
+ filename, error->message);
+ g_error_free (error);
+ }
+
+ g_free (path);
return pixbuf;
}
Modified: trunk/libgames-support/games-card-theme-pysol.c
==============================================================================
--- trunk/libgames-support/games-card-theme-pysol.c (original)
+++ trunk/libgames-support/games-card-theme-pysol.c Tue Jan 6 18:19:06 2009
@@ -23,6 +23,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
+#include "games-debug.h"
#include "games-find-file.h"
#include "games-files.h"
#include "games-preimage.h"
@@ -271,44 +272,6 @@
return TRUE;
}
-static GdkPixbuf *
-games_card_theme_pysol_load_card (PySolConfigTxtData *data,
- int card_id)
-{
- GdkPixbuf *pixbuf;
- char *path;
- GError *error = NULL;
-
- if (G_UNLIKELY (card_id == GAMES_CARD_SLOT)) {
- path = g_build_filename (data->base_path, "bottom01.gif" /* FIXMEchpe ext! */, NULL);
- } else if (G_UNLIKELY (card_id == GAMES_CARD_BACK)) {
- path = g_build_filename (data->base_path, data->back_filename, NULL);
- } else {
- static const char suit_char[] = "cdhs";
- int suit, rank;
- char filename[32];
-
- suit = card_id / 13;
- rank = card_id % 13;
-
- if (G_UNLIKELY (suit == 4)) /* Joker */
- return NULL; /* FIXMEchpe */
-
- g_snprintf (filename, sizeof (filename), "%02d%c%s", rank + 1, suit_char[suit], data->ext);
- path = g_build_filename (data->base_path, filename, NULL);
- }
-
- pixbuf = gdk_pixbuf_new_from_file (path, &error);
- if (!pixbuf) {
- g_warning ("Failed to load card ID %d: %s\n", card_id, error->message);
- g_error_free (error);
- }
-
- g_free (path);
-
- return pixbuf;
-}
-
static void
games_card_theme_pysol_init (GamesCardThemePysol *theme)
{
@@ -345,9 +308,39 @@
games_card_theme_pysol_get_card_pixbuf (GamesCardTheme *card_theme,
int card_id)
{
+ PySolConfigTxtData *data = card_theme->theme_info->data;
GdkPixbuf *pixbuf;
+ char *path;
+ GError *error = NULL;
+
+ if (G_UNLIKELY (card_id == GAMES_CARD_SLOT)) {
+ path = g_build_filename (data->base_path, "bottom01.gif" /* FIXMEchpe ext! */, NULL);
+ } else if (G_UNLIKELY (card_id == GAMES_CARD_BACK)) {
+ path = g_build_filename (data->base_path, data->back_filename, NULL);
+ } else {
+ static const char suit_char[] = "cdhs";
+ int suit, rank;
+ char filename[32];
- pixbuf = games_card_theme_pysol_load_card (card_theme->theme_info->data, card_id);
+ suit = card_id / 13;
+ rank = card_id % 13;
+
+ if (G_UNLIKELY (suit == 4)) /* Joker */
+ return NULL; /* FIXMEchpe */
+
+ g_snprintf (filename, sizeof (filename), "%02d%c%s", rank + 1, suit_char[suit], data->ext);
+ path = g_build_filename (data->base_path, filename, NULL);
+ }
+
+ pixbuf = gdk_pixbuf_new_from_file (path, &error);
+ if (!pixbuf) {
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Failed to load card ID %d: %s\n",
+ card_id, error->message);
+ g_error_free (error);
+ }
+
+ g_free (path);
return pixbuf;
}
Modified: trunk/libgames-support/games-sound.c
==============================================================================
--- trunk/libgames-support/games-sound.c (original)
+++ trunk/libgames-support/games-sound.c Tue Jan 6 18:19:06 2009
@@ -159,7 +159,8 @@
SDL_Init (SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, buf_size) < 0) {
- g_warning ("Error calling Mix_OpenAudio\n");
+ _games_debug_print (GAMES_DEBUG_SOUND,
+ "Error calling Mix_OpenAudio\n");
return;
}
#endif /* HAVE_SDL_MIXER */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]