720a8fb7 |
1 | /* |
2 | * puzzles.h: header file for my puzzle collection |
3 | */ |
4 | |
5 | #ifndef PUZZLES_PUZZLES_H |
6 | #define PUZZLES_PUZZLES_H |
7 | |
8 | #ifndef TRUE |
9 | #define TRUE 1 |
10 | #endif |
11 | #ifndef FALSE |
12 | #define FALSE 0 |
13 | #endif |
14 | |
15 | #define lenof(array) ( sizeof(array) / sizeof(*(array)) ) |
16 | |
17 | enum { |
18 | LEFT_BUTTON = 0x1000, |
19 | MIDDLE_BUTTON, |
1482ee76 |
20 | RIGHT_BUTTON, |
21 | CURSOR_UP, |
22 | CURSOR_DOWN, |
23 | CURSOR_LEFT, |
c71454c0 |
24 | CURSOR_RIGHT, |
25 | CURSOR_UP_LEFT, |
26 | CURSOR_DOWN_LEFT, |
27 | CURSOR_UP_RIGHT, |
28 | CURSOR_DOWN_RIGHT |
720a8fb7 |
29 | }; |
30 | |
4e7ef6e6 |
31 | #define IGNOREARG(x) ( (x) = (x) ) |
7f77ea24 |
32 | |
2ef96bd6 |
33 | typedef struct frontend frontend; |
c8230524 |
34 | typedef struct config_item config_item; |
7f77ea24 |
35 | typedef struct midend_data midend_data; |
36 | typedef struct random_state random_state; |
37 | typedef struct game_params game_params; |
38 | typedef struct game_state game_state; |
2ef96bd6 |
39 | typedef struct game_drawstate game_drawstate; |
7f77ea24 |
40 | |
4efb3868 |
41 | #define ALIGN_VNORMAL 0x000 |
42 | #define ALIGN_VCENTRE 0x100 |
43 | |
44 | #define ALIGN_HLEFT 0x000 |
45 | #define ALIGN_HCENTRE 0x001 |
46 | #define ALIGN_HRIGHT 0x002 |
47 | |
48 | #define FONT_FIXED 0 |
49 | #define FONT_VARIABLE 1 |
50 | |
720a8fb7 |
51 | /* |
c8230524 |
52 | * Structure used to pass configuration data between frontend and |
53 | * game |
54 | */ |
95709966 |
55 | enum { C_STRING, C_CHOICES, C_BOOLEAN, C_END }; |
c8230524 |
56 | struct config_item { |
57 | /* |
58 | * `name' is never dynamically allocated. |
59 | */ |
60 | char *name; |
61 | /* |
62 | * `type' contains one of the above values. |
63 | */ |
64 | int type; |
65 | /* |
95709966 |
66 | * For C_STRING, `sval' is always dynamically allocated and |
67 | * non-NULL. For C_BOOLEAN and C_END, `sval' is always NULL. |
68 | * For C_CHOICES, `sval' is non-NULL, _not_ dynamically |
69 | * allocated, and contains a set of option strings separated by |
70 | * a delimiter. The delimeter is also the first character in |
71 | * the string, so for example ":Foo:Bar:Baz" gives three |
72 | * options `Foo', `Bar' and `Baz'. |
c8230524 |
73 | */ |
74 | char *sval; |
75 | /* |
95709966 |
76 | * For C_BOOLEAN, this is TRUE or FALSE. For C_CHOICES, it |
c8230524 |
77 | * indicates the chosen index from the `sval' list. In the |
78 | * above example, 0==Foo, 1==Bar and 2==Baz. |
79 | */ |
80 | int ival; |
81 | }; |
82 | |
83 | /* |
720a8fb7 |
84 | * Platform routines |
85 | */ |
86 | void fatal(char *fmt, ...); |
2ef96bd6 |
87 | void frontend_default_colour(frontend *fe, float *output); |
4efb3868 |
88 | void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize, |
89 | int align, int colour, char *text); |
2ef96bd6 |
90 | void draw_rect(frontend *fe, int x, int y, int w, int h, int colour); |
91 | void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour); |
92 | void draw_polygon(frontend *fe, int *coords, int npoints, |
93 | int fill, int colour); |
4efb3868 |
94 | void clip(frontend *fe, int x, int y, int w, int h); |
95 | void unclip(frontend *fe); |
2ef96bd6 |
96 | void start_draw(frontend *fe); |
97 | void draw_update(frontend *fe, int x, int y, int w, int h); |
98 | void end_draw(frontend *fe); |
99 | void deactivate_timer(frontend *fe); |
100 | void activate_timer(frontend *fe); |
fd1a1a2b |
101 | void status_bar(frontend *fe, char *text); |
720a8fb7 |
102 | |
103 | /* |
7f77ea24 |
104 | * midend.c |
105 | */ |
48d70ca9 |
106 | midend_data *midend_new(frontend *fe, void *randseed, int randseedsize); |
7f77ea24 |
107 | void midend_free(midend_data *me); |
108 | void midend_set_params(midend_data *me, game_params *params); |
109 | void midend_size(midend_data *me, int *x, int *y); |
5928817c |
110 | void midend_new_game(midend_data *me); |
7f77ea24 |
111 | void midend_restart_game(midend_data *me); |
7f77ea24 |
112 | int midend_process_key(midend_data *me, int x, int y, int button); |
2ef96bd6 |
113 | void midend_redraw(midend_data *me); |
114 | float *midend_colours(midend_data *me, int *ncolours); |
115 | void midend_timer(midend_data *me, float tplus); |
eb2ad6f1 |
116 | int midend_num_presets(midend_data *me); |
117 | void midend_fetch_preset(midend_data *me, int n, |
118 | char **name, game_params **params); |
fd1a1a2b |
119 | int midend_wants_statusbar(midend_data *me); |
5928817c |
120 | enum { CFG_SETTINGS, CFG_SEED }; |
121 | config_item *midend_get_config(midend_data *me, int which, char **wintitle); |
122 | char *midend_set_config(midend_data *me, int which, config_item *cfg); |
7f77ea24 |
123 | |
124 | /* |
720a8fb7 |
125 | * malloc.c |
126 | */ |
127 | void *smalloc(int size); |
128 | void *srealloc(void *p, int size); |
129 | void sfree(void *p); |
ab30d7be |
130 | char *dupstr(const char *s); |
720a8fb7 |
131 | #define snew(type) \ |
132 | ( (type *) smalloc (sizeof (type)) ) |
133 | #define snewn(number, type) \ |
134 | ( (type *) smalloc ((number) * sizeof (type)) ) |
135 | #define sresize(array, number, type) \ |
7f77ea24 |
136 | ( (type *) srealloc ((array), (number) * sizeof (type)) ) |
720a8fb7 |
137 | |
138 | /* |
4efb3868 |
139 | * misc.c |
140 | */ |
077f3cbe |
141 | void free_cfg(config_item *cfg); |
4efb3868 |
142 | |
143 | /* |
720a8fb7 |
144 | * random.c |
145 | */ |
720a8fb7 |
146 | random_state *random_init(char *seed, int len); |
48d70ca9 |
147 | unsigned long random_bits(random_state *state, int bits); |
720a8fb7 |
148 | unsigned long random_upto(random_state *state, unsigned long limit); |
149 | void random_free(random_state *state); |
150 | |
151 | /* |
152 | * Game-specific routines |
153 | */ |
0c490335 |
154 | extern const char *const game_name; |
c8230524 |
155 | const int game_can_configure; |
7f77ea24 |
156 | game_params *default_params(void); |
eb2ad6f1 |
157 | int game_fetch_preset(int i, char **name, game_params **params); |
7f77ea24 |
158 | void free_params(game_params *params); |
eb2ad6f1 |
159 | game_params *dup_params(game_params *params); |
c8230524 |
160 | config_item *game_configure(game_params *params); |
161 | game_params *custom_params(config_item *cfg); |
162 | char *validate_params(game_params *params); |
48d70ca9 |
163 | char *new_game_seed(game_params *params, random_state *rs); |
5928817c |
164 | char *validate_seed(game_params *params, char *seed); |
720a8fb7 |
165 | game_state *new_game(game_params *params, char *seed); |
166 | game_state *dup_game(game_state *state); |
167 | void free_game(game_state *state); |
168 | game_state *make_move(game_state *from, int x, int y, int button); |
7f77ea24 |
169 | void game_size(game_params *params, int *x, int *y); |
2ef96bd6 |
170 | float *game_colours(frontend *fe, game_state *state, int *ncolours); |
171 | game_drawstate *game_new_drawstate(game_state *state); |
172 | void game_free_drawstate(game_drawstate *ds); |
173 | void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate, |
87ed82be |
174 | game_state *newstate, float anim_time, float flash_time); |
2ef96bd6 |
175 | float game_anim_length(game_state *oldstate, game_state *newstate); |
87ed82be |
176 | float game_flash_length(game_state *oldstate, game_state *newstate); |
fd1a1a2b |
177 | int game_wants_statusbar(void); |
720a8fb7 |
178 | |
179 | #endif /* PUZZLES_PUZZLES_H */ |