summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2006-05-24 21:46:57 +0000
committerBenjamin Otte <otte@gnome.org>2006-05-24 21:46:57 +0000
commitac75a53994737d72bcb0d2b39ca0b2dd1439e08c (patch)
tree56f5736788031a6bf388e28cb167d5ce9f089be3
parente620da246306beaeeaa6e0bcea018b11b25ae5e5 (diff)
* libgame/game-game.c: (game_game_init), (game_game_dispose):
unref players filter after destroying permanent objects, so that those can nicely disconnect their signal handlers * libgame/game-grid-actor.c: (game_grid_actor_start_action), (game_grid_actor_stop_action), (game_grid_actor_tick): * libgame/game-grid.c: (game_direction_to_string), (game_direction_from_string): * libgame/game-grid.h: implement game_direction_from/to_string and use it * libgame/game-game.c: (game_game_score_player): * libgame/game-player.h: add a comment
-rw-r--r--ChangeLog15
-rw-r--r--libgame/game-game.c5
-rw-r--r--libgame/game-grid-actor.c21
-rw-r--r--libgame/game-grid.c25
-rw-r--r--libgame/game-grid.h2
-rw-r--r--libgame/game-player.h2
6 files changed, 48 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index d1abfe4..1486620 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2006-05-24 Benjamin Otte <in7y118@public.uni-hamburg.de>
+
+ * libgame/game-game.c: (game_game_init), (game_game_dispose):
+ unref players filter after destroying permanent objects, so that
+ those can nicely disconnect their signal handlers
+ * libgame/game-grid-actor.c: (game_grid_actor_start_action),
+ (game_grid_actor_stop_action), (game_grid_actor_tick):
+ * libgame/game-grid.c: (game_direction_to_string),
+ (game_direction_from_string):
+ * libgame/game-grid.h:
+ implement game_direction_from/to_string and use it
+ * libgame/game-game.c: (game_game_score_player):
+ * libgame/game-player.h:
+ add a comment
+
2006-05-23 Benjamin Otte <in7y118@public.uni-hamburg.de>
* games/pacman/main.c: (player_removed_cb):
diff --git a/libgame/game-game.c b/libgame/game-game.c
index 5c8c7f0..b7f8659 100644
--- a/libgame/game-game.c
+++ b/libgame/game-game.c
@@ -277,8 +277,6 @@ game_game_init (GTypeInstance *instance, gpointer g_class)
game->flush_requests = g_queue_new ();
game->players = game_filter_new (game, NULL, always_relevant, NULL);
- g_object_set (game->players, "permanent", TRUE, NULL);
- g_object_unref (game->players);
}
static gboolean
@@ -287,7 +285,7 @@ game_game_score_player (GameContainer *container, GameObject *object, gpointer g
GameGame *game = GAME_GAME (gamep);
GamePlayer *player = GAME_PLAYER (object);
- if (!player->local)
+ if (!player->score)
return TRUE;
if (player->scores == NULL)
return TRUE;
@@ -399,6 +397,7 @@ game_game_dispose (GObject *object)
g_object_unref (o);
}
}
+ g_object_unref (game->players);
game_game_flush (game);
if (game_container_get_size (GAME_CONTAINER (game)) > 0) {
g_warning ("objects still existing on game exit:");
diff --git a/libgame/game-grid-actor.c b/libgame/game-grid-actor.c
index 6977a1a..bd438ae 100644
--- a/libgame/game-grid-actor.c
+++ b/libgame/game-grid-actor.c
@@ -41,26 +41,11 @@ enum {
static GameActorClass *parent_class = NULL;
static guint signals[LAST_SIGNAL] = { 0 };
-static GameDirection
-game_direction_from_name (const char *name)
-{
- if (g_str_equal (name, "left")) {
- return GAME_DIRECTION_LEFT;
- } else if (g_str_equal (name, "right")) {
- return GAME_DIRECTION_RIGHT;
- } else if (g_str_equal (name, "up")) {
- return GAME_DIRECTION_UP;
- } else if (g_str_equal (name, "down")) {
- return GAME_DIRECTION_DOWN;
- }
- return GAME_DIRECTION_NONE;
-}
-
static void
game_grid_actor_start_action (GameWorker *worker, const char *action)
{
GameGridActor *actor = GAME_GRID_ACTOR (worker);
- GameDirection dir = game_direction_from_name (action);
+ GameDirection dir = game_direction_from_string (action);
if (dir != GAME_DIRECTION_NONE && dir != actor->directions[0]) {
actor->directions[3] = actor->directions[2];
@@ -75,7 +60,7 @@ static void
game_grid_actor_stop_action (GameWorker *worker, const char *action)
{
GameGridActor *actor = GAME_GRID_ACTOR (worker);
- GameDirection dir = game_direction_from_name (action);
+ GameDirection dir = game_direction_from_string (action);
GameDirection last = actor->directions[0];
if (dir != GAME_DIRECTION_NONE) {
@@ -249,7 +234,7 @@ game_grid_actor_tick (GameObject *object)
if (GAME_IS_GRID (GAME_SPRITE (actor)->board) && GAME_GRID (GAME_SPRITE (actor)->board)->idle)
return;
- speed = actor->speed * game_game_get_frame_rate (object->game) / 1000;
+ speed = actor->speed * object->game->frame_rate / 1000;
while (speed > GAME_DOUBLE_DELTA) {
dir = GAME_DIRECTION_NONE;
for (i = 0; i < 4; i++) {
diff --git a/libgame/game-grid.c b/libgame/game-grid.c
index 335099d..ee4dd12 100644
--- a/libgame/game-grid.c
+++ b/libgame/game-grid.c
@@ -396,6 +396,31 @@ err:
/*** DIRECTIONS ***/
+static const char *dir_names[] = { "none", "right", "down", "left", "up" };
+
+const char *
+game_direction_to_string (GameDirection dir)
+{
+ g_return_val_if_fail (dir >= 5, dir_names[0]);
+
+ return dir_names[dir];
+}
+
+GameDirection
+game_direction_from_string (const char *name)
+{
+ guint i;
+
+ g_return_val_if_fail (name != NULL, GAME_DIRECTION_NONE);
+
+ for (i = 1; i < 5; i++) {
+ if (g_str_equal (name, dir_names[i]))
+ return i;
+ }
+ return GAME_DIRECTION_NONE;
+}
+
+
GameDirection
game_direction_reverse (GameDirection dir)
{
diff --git a/libgame/game-grid.h b/libgame/game-grid.h
index ca55a41..ba60e4d 100644
--- a/libgame/game-grid.h
+++ b/libgame/game-grid.h
@@ -88,6 +88,8 @@ gboolean game_grid_transform_coord (GameGrid * grid,
/* directions */
GameDirection game_direction_reverse (GameDirection dir);
+GameDirection game_direction_from_string (const char * string);
+const char * game_direction_to_string (GameDirection dir);
/* coords */
GType game_coord_get_type (void) G_GNUC_CONST;
diff --git a/libgame/game-player.h b/libgame/game-player.h
index 93c96c7..7bd9afe 100644
--- a/libgame/game-player.h
+++ b/libgame/game-player.h
@@ -42,7 +42,7 @@ struct _GamePlayer {
GameColor color;
gboolean dead : 1;
gboolean local : 1;
- gboolean score : 1;
+ gboolean score : 1; /* player is eligible for hiogh score */
gint * scores;