2 * puzzles.h: header file for my puzzle collection
5 #ifndef PUZZLES_PUZZLES_H
6 #define PUZZLES_PUZZLES_H
15 #define lenof(array) ( sizeof(array) / sizeof(*(array)) )
31 #define IGNOREARG(x) ( (x) = (x) )
33 typedef struct frontend frontend;
34 typedef struct midend_data midend_data;
35 typedef struct random_state random_state;
36 typedef struct game_params game_params;
37 typedef struct game_state game_state;
38 typedef struct game_drawstate game_drawstate;
43 void fatal(char *fmt, ...);
44 void frontend_default_colour(frontend *fe, float *output);
45 void draw_rect(frontend *fe, int x, int y, int w, int h, int colour);
46 void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour);
47 void draw_polygon(frontend *fe, int *coords, int npoints,
48 int fill, int colour);
49 void start_draw(frontend *fe);
50 void draw_update(frontend *fe, int x, int y, int w, int h);
51 void end_draw(frontend *fe);
52 void deactivate_timer(frontend *fe);
53 void activate_timer(frontend *fe);
58 midend_data *midend_new(frontend *fe);
59 void midend_free(midend_data *me);
60 void midend_set_params(midend_data *me, game_params *params);
61 void midend_size(midend_data *me, int *x, int *y);
62 void midend_new_game(midend_data *me, char *seed);
63 void midend_restart_game(midend_data *me);
64 int midend_process_key(midend_data *me, int x, int y, int button);
65 void midend_redraw(midend_data *me);
66 float *midend_colours(midend_data *me, int *ncolours);
67 void midend_timer(midend_data *me, float tplus);
68 int midend_num_presets(midend_data *me);
69 void midend_fetch_preset(midend_data *me, int n,
70 char **name, game_params **params);
75 void *smalloc(int size);
76 void *srealloc(void *p, int size);
78 char *dupstr(char *s);
80 ( (type *) smalloc (sizeof (type)) )
81 #define snewn(number, type) \
82 ( (type *) smalloc ((number) * sizeof (type)) )
83 #define sresize(array, number, type) \
84 ( (type *) srealloc ((array), (number) * sizeof (type)) )
89 random_state *random_init(char *seed, int len);
90 unsigned long random_upto(random_state *state, unsigned long limit);
91 void random_free(random_state *state);
94 * Game-specific routines
96 extern const char *const game_name;
97 game_params *default_params(void);
98 int game_fetch_preset(int i, char **name, game_params **params);
99 void free_params(game_params *params);
100 game_params *dup_params(game_params *params);
101 char *new_game_seed(game_params *params);
102 game_state *new_game(game_params *params, char *seed);
103 game_state *dup_game(game_state *state);
104 void free_game(game_state *state);
105 game_state *make_move(game_state *from, int x, int y, int button);
106 void game_size(game_params *params, int *x, int *y);
107 float *game_colours(frontend *fe, game_state *state, int *ncolours);
108 game_drawstate *game_new_drawstate(game_state *state);
109 void game_free_drawstate(game_drawstate *ds);
110 void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
111 game_state *newstate, float t);
112 float game_anim_length(game_state *oldstate, game_state *newstate);
114 #endif /* PUZZLES_PUZZLES_H */