`There's always one'. Add nullgame to .cvsignore.
[sgt/puzzles] / puzzles.h
CommitLineData
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
17enum {
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 33typedef struct frontend frontend;
7f77ea24 34typedef struct midend_data midend_data;
35typedef struct random_state random_state;
36typedef struct game_params game_params;
37typedef struct game_state game_state;
2ef96bd6 38typedef struct game_drawstate game_drawstate;
7f77ea24 39
720a8fb7 40/*
41 * Platform routines
42 */
43void fatal(char *fmt, ...);
2ef96bd6 44void frontend_default_colour(frontend *fe, float *output);
45void draw_rect(frontend *fe, int x, int y, int w, int h, int colour);
46void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour);
47void draw_polygon(frontend *fe, int *coords, int npoints,
48 int fill, int colour);
49void start_draw(frontend *fe);
50void draw_update(frontend *fe, int x, int y, int w, int h);
51void end_draw(frontend *fe);
52void deactivate_timer(frontend *fe);
53void activate_timer(frontend *fe);
720a8fb7 54
55/*
7f77ea24 56 * midend.c
57 */
2ef96bd6 58midend_data *midend_new(frontend *fe);
7f77ea24 59void midend_free(midend_data *me);
60void midend_set_params(midend_data *me, game_params *params);
61void midend_size(midend_data *me, int *x, int *y);
62void midend_new_game(midend_data *me, char *seed);
63void midend_restart_game(midend_data *me);
7f77ea24 64int midend_process_key(midend_data *me, int x, int y, int button);
2ef96bd6 65void midend_redraw(midend_data *me);
66float *midend_colours(midend_data *me, int *ncolours);
67void midend_timer(midend_data *me, float tplus);
eb2ad6f1 68int midend_num_presets(midend_data *me);
69void midend_fetch_preset(midend_data *me, int n,
70 char **name, game_params **params);
7f77ea24 71
72/*
720a8fb7 73 * malloc.c
74 */
75void *smalloc(int size);
76void *srealloc(void *p, int size);
77void sfree(void *p);
78char *dupstr(char *s);
79#define snew(type) \
80 ( (type *) smalloc (sizeof (type)) )
81#define snewn(number, type) \
82 ( (type *) smalloc ((number) * sizeof (type)) )
83#define sresize(array, number, type) \
7f77ea24 84 ( (type *) srealloc ((array), (number) * sizeof (type)) )
720a8fb7 85
86/*
87 * random.c
88 */
720a8fb7 89random_state *random_init(char *seed, int len);
90unsigned long random_upto(random_state *state, unsigned long limit);
91void random_free(random_state *state);
92
93/*
94 * Game-specific routines
95 */
0c490335 96extern const char *const game_name;
7f77ea24 97game_params *default_params(void);
eb2ad6f1 98int game_fetch_preset(int i, char **name, game_params **params);
7f77ea24 99void free_params(game_params *params);
eb2ad6f1 100game_params *dup_params(game_params *params);
720a8fb7 101char *new_game_seed(game_params *params);
102game_state *new_game(game_params *params, char *seed);
103game_state *dup_game(game_state *state);
104void free_game(game_state *state);
105game_state *make_move(game_state *from, int x, int y, int button);
7f77ea24 106void game_size(game_params *params, int *x, int *y);
2ef96bd6 107float *game_colours(frontend *fe, game_state *state, int *ncolours);
108game_drawstate *game_new_drawstate(game_state *state);
109void game_free_drawstate(game_drawstate *ds);
110void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
87ed82be 111 game_state *newstate, float anim_time, float flash_time);
2ef96bd6 112float game_anim_length(game_state *oldstate, game_state *newstate);
87ed82be 113float game_flash_length(game_state *oldstate, game_state *newstate);
720a8fb7 114
115#endif /* PUZZLES_PUZZLES_H */