1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/*
* Copyright (C) 2003,2005 Benjamin Otte <otte@gnome.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/
#ifndef __GAME_GAME_H__
#define __GAME_GAME_H__
#include <libgame/game-info.h>
#include <libgame/game-highscore.h>
#include <libgame/game-container.h>
G_BEGIN_DECLS
#define GAME_TYPE_GAME (game_game_get_type ())
#define GAME_GAME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GAME_TYPE_GAME, GameGame))
#define GAME_GAME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GAME_TYPE_GAME, GameGameClass))
#define GAME_IS_GAME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GAME_TYPE_GAME))
#define GAME_IS_GAME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GAME_TYPE_GAME))
#define GAME_GAME_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GAME_TYPE_GAME, GameGameClass))
typedef const char * (* GameTranslateFunc) (const char *string, gpointer data);
typedef struct _GameGraphic GameGraphic;
typedef struct _GameGraphicClass GameGraphicClass;
typedef struct _GameMatch GameMatch;
typedef struct _GameMatchClass GameMatchClass;
typedef struct _GameResource GameResource;
typedef struct _GameDataResource GameDataResource;
typedef struct _GameGame GameGame;
typedef struct _GameGameClass GameGameClass;
struct _GameGame
{
GObject parent;
/* static information structs about the game */
const GameInfoKey * keys;
const GameInfoScore * scores;
/*< private >*/
gchar * name;
gchar * nick;
gchar * description;
gchar * version;
GHashTable * default_resources; /* loaded default resources: name => GameResource */
GameGraphic * icon; /* the icon to use */
GameGraphic * viewport; /* default thing you see when no game is running */
GameMatch * match; /* the current match */
guint frame_rate; /* the frame rate is controlled by the game */
GRand * rand;
guint32 seed;
guint max_players;
GameHighScore * player_scores;
GameHighScore * system_scores;
GameRecorder * recorder;
GameTranslateFunc translate_func;
gpointer translate_data;
GDestroyNotify translate_free;
GHashTable * resources; /* resource-name / GMappedFile - only when PLAYING */
guint tick;
GameContainerData objects;
GList * tick_objects;
GQueue * flush_requests; /* objects that have queued a flush */
/* sublists of objects */
GameContainer * players;
/* debugging */
gboolean ticking;
};
struct _GameGameClass
{
GObjectClass parent_class;
/* signals */
void (* tick) (GameGame * game,
guint tick);
void (* start) (GameGame * game);
void (* end) (GameGame * game);
void (* paused) (GameGame * game,
gboolean paused);
void (* load_resource) (GameGame * game,
const gchar * resource_name,
guchar ** resource,
gsize * length,
GError ** error);
};
GType game_game_get_type (void) G_GNUC_CONST;
GameGame * game_game_new (const gchar * name,
const gchar * version,
const GameInfoKey * keys,
const GameInfoScore * scores);
GameGame * game_game_load (const char * name,
GError ** error);
GameGame * game_game_load_from_file (const char * name,
GError ** error);
void game_game_set_translate_func (GameGame * game,
GameTranslateFunc func,
gpointer data,
GDestroyNotify notify);
const char * game_game_translate (GameGame * game,
const char * string);
void game_game_set_frame_rate (GameGame * game,
guint milis_per_frame);
guint game_game_get_frame_rate (GameGame * game);
void game_game_set_max_players (GameGame * game,
guint max_players);
guint game_game_get_max_players (GameGame * game);
GameResource * game_game_get_resource (GameGame * game,
const char * name);
GameDataResource *game_game_load_resource (GameGame * game,
const char * filename);
GameObject * game_game_spawn_object (GameGame * game,
const char * name);
GameContainer * game_game_get_players (GameGame * game);
guint game_game_get_player_count (GameGame * game);
const gchar * game_game_get_name (GameGame * game);
const gchar * game_game_get_version (GameGame * game);
guint game_game_get_tick (GameGame * game);
void game_game_set_seed (GameGame * game,
guint32 seed);
gboolean game_random_boolean (GameGame * game);
gint32 game_random_int (GameGame * game);
gint32 game_random_int_range (GameGame * game,
gint32 begin,
gint32 end);
double game_random_double (GameGame * game);
double game_random_double_range (GameGame * game,
double begin,
double end);
GameObject * game_game_add_object (GameGame * game,
GType object_type,
...) G_GNUC_NULL_TERMINATED;
GameObject * game_game_add_object_valist (GameGame * game,
GType object_type,
va_list varargs);
GameObject * game_game_add_objectv (GameGame * game,
GType object_type,
guint n_parameters,
GParameter * parameters);
void game_game_flush (GameGame * game);
gboolean game_game_save (GameGame * game,
const char * filename);
const guchar * game_game_load_old_resource (GameGame * game,
const char * resource_name,
gsize * length,
GError ** error);
/* debugging */
void game_game_print (GameGame * game);
G_END_DECLS
#endif /* __GAME_GAME_H__ */
|