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
;
40 #define ALIGN_VNORMAL 0x000
41 #define ALIGN_VCENTRE 0x100
43 #define ALIGN_HLEFT 0x000
44 #define ALIGN_HCENTRE 0x001
45 #define ALIGN_HRIGHT 0x002
48 #define FONT_VARIABLE 1
53 void fatal(char *fmt
, ...);
54 void frontend_default_colour(frontend
*fe
, float *output
);
55 void draw_text(frontend
*fe
, int x
, int y
, int fonttype
, int fontsize
,
56 int align
, int colour
, char *text
);
57 void draw_rect(frontend
*fe
, int x
, int y
, int w
, int h
, int colour
);
58 void draw_line(frontend
*fe
, int x1
, int y1
, int x2
, int y2
, int colour
);
59 void draw_polygon(frontend
*fe
, int *coords
, int npoints
,
60 int fill
, int colour
);
61 void clip(frontend
*fe
, int x
, int y
, int w
, int h
);
62 void unclip(frontend
*fe
);
63 void start_draw(frontend
*fe
);
64 void draw_update(frontend
*fe
, int x
, int y
, int w
, int h
);
65 void end_draw(frontend
*fe
);
66 void deactivate_timer(frontend
*fe
);
67 void activate_timer(frontend
*fe
);
68 void status_bar(frontend
*fe
, char *text
);
73 midend_data
*midend_new(frontend
*fe
);
74 void midend_free(midend_data
*me
);
75 void midend_set_params(midend_data
*me
, game_params
*params
);
76 void midend_size(midend_data
*me
, int *x
, int *y
);
77 void midend_new_game(midend_data
*me
, char *seed
);
78 void midend_restart_game(midend_data
*me
);
79 int midend_process_key(midend_data
*me
, int x
, int y
, int button
);
80 void midend_redraw(midend_data
*me
);
81 float *midend_colours(midend_data
*me
, int *ncolours
);
82 void midend_timer(midend_data
*me
, float tplus
);
83 int midend_num_presets(midend_data
*me
);
84 void midend_fetch_preset(midend_data
*me
, int n
,
85 char **name
, game_params
**params
);
86 int midend_wants_statusbar(midend_data
*me
);
91 void *smalloc(int size
);
92 void *srealloc(void *p
, int size
);
94 char *dupstr(char *s
);
96 ( (type *) smalloc (sizeof (type)) )
97 #define snewn(number, type) \
98 ( (type *) smalloc ((number) * sizeof (type)) )
99 #define sresize(array, number, type) \
100 ( (type *) srealloc ((array), (number) * sizeof (type)) )
105 int rand_upto(int limit
);
110 random_state
*random_init(char *seed
, int len
);
111 unsigned long random_upto(random_state
*state
, unsigned long limit
);
112 void random_free(random_state
*state
);
115 * Game-specific routines
117 extern const char *const game_name
;
118 game_params
*default_params(void);
119 int game_fetch_preset(int i
, char **name
, game_params
**params
);
120 void free_params(game_params
*params
);
121 game_params
*dup_params(game_params
*params
);
122 char *new_game_seed(game_params
*params
);
123 game_state
*new_game(game_params
*params
, char *seed
);
124 game_state
*dup_game(game_state
*state
);
125 void free_game(game_state
*state
);
126 game_state
*make_move(game_state
*from
, int x
, int y
, int button
);
127 void game_size(game_params
*params
, int *x
, int *y
);
128 float *game_colours(frontend
*fe
, game_state
*state
, int *ncolours
);
129 game_drawstate
*game_new_drawstate(game_state
*state
);
130 void game_free_drawstate(game_drawstate
*ds
);
131 void game_redraw(frontend
*fe
, game_drawstate
*ds
, game_state
*oldstate
,
132 game_state
*newstate
, float anim_time
, float flash_time
);
133 float game_anim_length(game_state
*oldstate
, game_state
*newstate
);
134 float game_flash_length(game_state
*oldstate
, game_state
*newstate
);
135 int game_wants_statusbar(void);
137 #endif /* PUZZLES_PUZZLES_H */