summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2011-10-16 13:46:37 -0700
committerBenjamin Otte <otte@redhat.com>2011-10-16 22:32:55 -0700
commite5444cd401bfe8489fb579d7d4b2e698472ce782 (patch)
treeb3c0b28f6a06911b6284c2fff20ff2e999277fef
parent67fc10c553ca1f4d7831a19a8bbfd5985eadc43c (diff)
animation: Remove ability to specify a duration per frame
This momentarily breaks bomber, but will be fixed in later commits.
-rw-r--r--games/bomber/main.c4
-rw-r--r--libgame/game-animation.c61
-rw-r--r--libgame/game-animation.h4
3 files changed, 16 insertions, 53 deletions
diff --git a/games/bomber/main.c b/games/bomber/main.c
index 3aae815..aca55f1 100644
--- a/games/bomber/main.c
+++ b/games/bomber/main.c
@@ -119,12 +119,12 @@ load_graphics (GameGame *game, GError **error)
for (i = 0; i < G_N_ELEMENTS (animations); i++) {
base = game_animation_new_from_files (game, &animations[i].size,
- animations[i].pattern, animations[i].duration, error);
+ animations[i].pattern, error);
if (!base)
return FALSE;
if (animations[i].mask_pattern) {
mask = game_animation_new_from_files (game, &animations[i].size,
- animations[i].mask_pattern, animations[i].duration, error);
+ animations[i].mask_pattern, error);
if (!mask) {
g_object_unref (base);
return FALSE;
diff --git a/libgame/game-animation.c b/libgame/game-animation.c
index 625c754..61c8d2d 100644
--- a/libgame/game-animation.c
+++ b/libgame/game-animation.c
@@ -29,10 +29,6 @@ enum {
PROP_ANIMATE
};
-typedef struct {
- cairo_surface_t * surface;
- guint duration;
-} GameAnimationFrame;
static GameGraphicClass *parent_class = NULL;
static void
@@ -68,26 +64,12 @@ game_animation_update_image (GameAnimation *anim, cairo_surface_t *surface)
}
static void
-game_animation_start (GameAnimation *anim)
+game_animation_add_image (GameAnimation *anim, cairo_surface_t *surface)
{
- GameAnimationFrame *frame;
-
- if (anim->frames->len > 0) {
- frame = &g_array_index(anim->frames, GameAnimationFrame, 0);
- game_animation_update_image (anim, frame->surface);
- }
- anim->current = 0;
- anim->current_time = 0;
-}
-
-static void
-game_animation_add_image (GameAnimation *anim, cairo_surface_t *surface, guint duration)
-{
- GameAnimationFrame frame = { surface, duration };
- g_array_append_val (anim->frames, frame);
+ g_ptr_array_add (anim->frames, surface);
if (anim->frames->len == 1)
- game_animation_start (anim);
+ game_animation_update_image (anim, surface);
}
static void
@@ -104,22 +86,15 @@ game_animation_set_property (GObject *obj, guint param_id, const GValue *value,
G_OBJECT_WARN_INVALID_PROPERTY_ID (anim, param_id, pspec);
break;
}
- game_animation_start (anim);
}
static void
game_animation_dispose (GObject *object)
{
GameAnimation *anim = GAME_ANIMATION (object);
- GameAnimationFrame *frame;
- guint i;
if (anim->frames) {
- for (i = 0; i < anim->frames->len; i++) {
- frame = &g_array_index(anim->frames, GameAnimationFrame, i);
- cairo_surface_destroy (frame->surface);
- }
- g_array_free (anim->frames, TRUE);
+ g_ptr_array_free (anim->frames, TRUE);
anim->frames = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
@@ -129,7 +104,6 @@ static gboolean
game_animation_copy (GameObject *odest, GameObject *osrc)
{
guint i;
- GameAnimationFrame *frame;
GameAnimation *dest = GAME_ANIMATION (odest);
GameAnimation *src = GAME_ANIMATION (osrc);
@@ -138,9 +112,7 @@ game_animation_copy (GameObject *odest, GameObject *osrc)
dest->animate = src->animate;
for (i = 0; i < src->frames->len; i++) {
- frame = &g_array_index(src->frames, GameAnimationFrame, i);
- cairo_surface_reference (frame->surface);
- game_animation_add_image (dest, frame->surface, frame->duration);
+ game_animation_add_image (dest, cairo_surface_reference (g_ptr_array_index (src->frames, i)));
}
return TRUE;
@@ -149,20 +121,15 @@ game_animation_copy (GameObject *odest, GameObject *osrc)
static void
game_animation_tick (GameObject *object)
{
- GameAnimationFrame *frame;
GameAnimation *anim = GAME_ANIMATION (object);
- if (!anim->animate)
+ if (!anim->animate || anim->frames->len == 0)
return;
- anim->current_time += object->game->frame_rate;
- frame = &g_array_index(anim->frames, GameAnimationFrame, anim->current);
- while (anim->current_time > frame->duration) {
- anim->current_time -= frame->duration;
- anim->current = (anim->current + 1) % anim->frames->len;
- frame = &g_array_index(anim->frames, GameAnimationFrame, anim->current);
- }
- game_animation_update_image (anim, frame->surface);
+ anim->current++;
+ if (anim->current >= anim->frames->len)
+ anim->current = 0;
+ game_animation_update_image (anim, g_ptr_array_index (anim->frames, anim->current));
}
static void
@@ -191,7 +158,7 @@ game_animation_init (GTypeInstance *instance, gpointer g_class)
{
GameAnimation *anim = GAME_ANIMATION (instance);
- anim->frames = g_array_new (FALSE, FALSE, sizeof (GameAnimationFrame));
+ anim->frames = g_ptr_array_new_with_free_func ((GDestroyNotify) cairo_surface_destroy);
}
GType
@@ -220,7 +187,7 @@ game_animation_get_type ()
GameGraphic *
game_animation_new_from_files (GameGame *game, const GameRectangle *size,
- const char *pattern, guint delay, GError **error)
+ const char *pattern, GError **error)
{
static const GameRectangle default_size = { 0.0, 0.0, 1.0, 1.0 };
GPatternSpec *spec;
@@ -232,8 +199,6 @@ game_animation_new_from_files (GameGame *game, const GameRectangle *size,
g_return_val_if_fail (GAME_IS_GAME (game), NULL);
g_return_val_if_fail (pattern != NULL, NULL);
- if (delay == 0)
- delay = game->frame_rate;
if (size == NULL)
size = &default_size;
@@ -259,7 +224,7 @@ game_animation_new_from_files (GameGame *game, const GameRectangle *size,
for (walk = list; walk; walk = walk->next) {
cairo_surface_t *surface = game_cairo_surface_from_file (walk->data, NULL);
if (surface)
- game_animation_add_image (anim, surface, delay);
+ game_animation_add_image (anim, surface);
g_free (walk->data);
}
g_slist_free (list);
diff --git a/libgame/game-animation.h b/libgame/game-animation.h
index 60b2081..fc5b8c0 100644
--- a/libgame/game-animation.h
+++ b/libgame/game-animation.h
@@ -40,9 +40,8 @@ struct _GameAnimation {
GameImage image;
/*< private >*/
- GArray * frames;
+ GPtrArray * frames;
guint current;
- guint current_time;
gboolean animate;
};
@@ -55,7 +54,6 @@ GType game_animation_get_type (void) G_GNUC_CONST;
GameGraphic * game_animation_new_from_files (GameGame * game,
const GameRectangle * size,
const char * pattern,
- guint delay,
GError ** error);