06e96246b4864d6979d34b3330f8d48db88c5b3e
[sgt/puzzles] / puzzles.h
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,
20 RIGHT_BUTTON
21 };
22
23 #define IGNORE(x) ( (x) = (x) )
24
25 typedef struct midend_data midend_data;
26 typedef struct random_state random_state;
27 typedef struct game_params game_params;
28 typedef struct game_state game_state;
29
30 /*
31 * Platform routines
32 */
33 void fatal(char *fmt, ...);
34
35 /*
36 * midend.c
37 */
38 midend_data *midend_new(void);
39 void midend_free(midend_data *me);
40 void midend_set_params(midend_data *me, game_params *params);
41 void midend_size(midend_data *me, int *x, int *y);
42 void midend_new_game(midend_data *me, char *seed);
43 void midend_restart_game(midend_data *me);
44 void midend_undo(midend_data *me);
45 void midend_redo(midend_data *me);
46 int midend_process_key(midend_data *me, int x, int y, int button);
47
48 /*
49 * malloc.c
50 */
51 void *smalloc(int size);
52 void *srealloc(void *p, int size);
53 void sfree(void *p);
54 char *dupstr(char *s);
55 #define snew(type) \
56 ( (type *) smalloc (sizeof (type)) )
57 #define snewn(number, type) \
58 ( (type *) smalloc ((number) * sizeof (type)) )
59 #define sresize(array, number, type) \
60 ( (type *) srealloc ((array), (number) * sizeof (type)) )
61
62 /*
63 * random.c
64 */
65 random_state *random_init(char *seed, int len);
66 unsigned long random_upto(random_state *state, unsigned long limit);
67 void random_free(random_state *state);
68
69 /*
70 * Game-specific routines
71 */
72 game_params *default_params(void);
73 void free_params(game_params *params);
74 char *new_game_seed(game_params *params);
75 game_state *new_game(game_params *params, char *seed);
76 game_state *dup_game(game_state *state);
77 void free_game(game_state *state);
78 game_state *make_move(game_state *from, int x, int y, int button);
79 void game_size(game_params *params, int *x, int *y);
80
81 #endif /* PUZZLES_PUZZLES_H */