632f9b24e4b5ff91b5b0b46e292a43f9ef1ff74a
[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 CURSOR_UP,
22 CURSOR_DOWN,
23 CURSOR_LEFT,
24 CURSOR_RIGHT
25 };
26
27 #define IGNORE(x) ( (x) = (x) )
28
29 typedef struct frontend frontend;
30 typedef struct midend_data midend_data;
31 typedef struct random_state random_state;
32 typedef struct game_params game_params;
33 typedef struct game_state game_state;
34 typedef struct game_drawstate game_drawstate;
35
36 /*
37 * Platform routines
38 */
39 void fatal(char *fmt, ...);
40 void frontend_default_colour(frontend *fe, float *output);
41 void draw_rect(frontend *fe, int x, int y, int w, int h, int colour);
42 void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour);
43 void draw_polygon(frontend *fe, int *coords, int npoints,
44 int fill, int colour);
45 void start_draw(frontend *fe);
46 void draw_update(frontend *fe, int x, int y, int w, int h);
47 void end_draw(frontend *fe);
48 void deactivate_timer(frontend *fe);
49 void activate_timer(frontend *fe);
50
51 /*
52 * midend.c
53 */
54 midend_data *midend_new(frontend *fe);
55 void midend_free(midend_data *me);
56 void midend_set_params(midend_data *me, game_params *params);
57 void midend_size(midend_data *me, int *x, int *y);
58 void midend_new_game(midend_data *me, char *seed);
59 void midend_restart_game(midend_data *me);
60 int midend_process_key(midend_data *me, int x, int y, int button);
61 void midend_redraw(midend_data *me);
62 float *midend_colours(midend_data *me, int *ncolours);
63 void midend_timer(midend_data *me, float tplus);
64
65 /*
66 * malloc.c
67 */
68 void *smalloc(int size);
69 void *srealloc(void *p, int size);
70 void sfree(void *p);
71 char *dupstr(char *s);
72 #define snew(type) \
73 ( (type *) smalloc (sizeof (type)) )
74 #define snewn(number, type) \
75 ( (type *) smalloc ((number) * sizeof (type)) )
76 #define sresize(array, number, type) \
77 ( (type *) srealloc ((array), (number) * sizeof (type)) )
78
79 /*
80 * random.c
81 */
82 random_state *random_init(char *seed, int len);
83 unsigned long random_upto(random_state *state, unsigned long limit);
84 void random_free(random_state *state);
85
86 /*
87 * Game-specific routines
88 */
89 game_params *default_params(void);
90 void free_params(game_params *params);
91 char *new_game_seed(game_params *params);
92 game_state *new_game(game_params *params, char *seed);
93 game_state *dup_game(game_state *state);
94 void free_game(game_state *state);
95 game_state *make_move(game_state *from, int x, int y, int button);
96 void game_size(game_params *params, int *x, int *y);
97 float *game_colours(frontend *fe, game_state *state, int *ncolours);
98 game_drawstate *game_new_drawstate(game_state *state);
99 void game_free_drawstate(game_drawstate *ds);
100 void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
101 game_state *newstate, float t);
102 float game_anim_length(game_state *oldstate, game_state *newstate);
103
104 #endif /* PUZZLES_PUZZLES_H */