1 /*
2     Copyright (c) 2011   John Darrington
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 3 of the License,  or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 
19 #ifndef __GBK_GAME_H__
20 #define __GBK_GAME_H__
21 
22 
23 #include <glib-object.h>
24 #include <gtk/gtk.h>
25 #include "cube.h"
26 #include "cubeview.h"
27 
28 #define GBK_TYPE_GAME                  (gbk_game_get_type ())
29 #define GBK_GAME(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GBK_TYPE_GAME, GbkGame))
30 #define GBK_IS_GAME(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GBK_TYPE_GAME))
31 #define GBK_GAME_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GBK_TYPE_GAME, GbkGameClass))
32 #define GBK_IS_GAME_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GBK_TYPE_GAME))
33 #define GBK_GAME_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GBK_TYPE_GAME, GbkGameClass))
34 
35 typedef struct _GbkGame GbkGame;
36 typedef struct _GbkGameClass GbkGameClass;
37 
38 enum mode
39 {
40   MODE_NONE = 0,
41   MODE_RECORD,
42   MODE_PLAY,
43   MODE_REWIND,
44 };
45 
46 struct GbkList
47 {
48   struct GbkList *prev;
49   struct GbkList *next;
50   const struct move_data *data;
51   gboolean marked;
52 };
53 
54 
55 struct _GbkGame
56 {
57   GObject parent_instance;
58 
59   /* instance members */
60 
61   /* The toplevel window in which the game is played */
62   GtkWindow *toplevel;
63 
64   /* The cube */
65   GbkCube *cube;
66 
67   /* The cubeview which we'll consider as the master one */
68   GbkCubeview *masterview;
69 
70   /* A linked list of all the views, including the master */
71   GSList *views;
72 
73   enum mode mode;
74 
75 
76   /* This is the end iterator.  It represents ONE MOVE
77      PAST the most recent move */
78   struct GbkList end_of_moves;
79 
80   /* Begin iterator. One BEFORE the first move */
81   struct GbkList start_of_moves;
82 
83   /* The "current" move.  That is, the place in the queue that we are now.
84      When not replaying, it's always equal to most_recent.prev
85    */
86   struct GbkList *iter;
87 
88   int posn;
89   int total;
90 
91   /* Id of the animate complete signal */
92   gulong animate_complete_id;
93 
94   guint mesg_id;
95 };
96 
97 struct _GbkGameClass
98 {
99   GObjectClass parent_class;
100 
101   /* class members */
102 };
103 
104 /* used by GBK_TYPE_GAME */
105 GType gbk_game_get_type (void);
106 
107 /*
108  * Method definitions.
109  */
110 
111 GObject *gbk_game_new (GbkCube * cube);
112 
113 void gbk_game_rewind (GbkGame * game);
114 void gbk_game_replay (GbkGame * game);
115 void gbk_game_stop_replay (GbkGame * game);
116 void gbk_game_set_mark (GbkGame * game);
117 
118 void gbk_game_next_move (GbkGame * game);
119 void gbk_game_prev_move (GbkGame * game);
120 
121 gboolean gbk_game_at_start (GbkGame * game);
122 gboolean gbk_game_at_end (GbkGame * game);
123 
124 void gbk_game_reset (GbkGame * game);
125 
126 void gbk_game_remove_view (GbkGame * game, GbkCubeview * cv);
127 
128 void gbk_game_add_view (GbkGame * game, GbkCubeview * cv, gboolean master);
129 
130 void gbk_game_dump_moves (GbkGame * game);
131 
132 struct GbkList *gbk_game_insert_move (GbkGame * game, struct move_data *move,
133 				      struct GbkList *where);
134 void gbk_game_delete_moves (GbkGame * game, struct GbkList *from);
135 
136 
137 #endif /* __GAME_H__ */
138