Remove arbitrary restriction on Net minimum game size. (Awww, cute
[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
4efb3868 40#define ALIGN_VNORMAL 0x000
41#define ALIGN_VCENTRE 0x100
42
43#define ALIGN_HLEFT 0x000
44#define ALIGN_HCENTRE 0x001
45#define ALIGN_HRIGHT 0x002
46
47#define FONT_FIXED 0
48#define FONT_VARIABLE 1
49
720a8fb7 50/*
51 * Platform routines
52 */
53void fatal(char *fmt, ...);
2ef96bd6 54void frontend_default_colour(frontend *fe, float *output);
4efb3868 55void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize,
56 int align, int colour, char *text);
2ef96bd6 57void draw_rect(frontend *fe, int x, int y, int w, int h, int colour);
58void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour);
59void draw_polygon(frontend *fe, int *coords, int npoints,
60 int fill, int colour);
4efb3868 61void clip(frontend *fe, int x, int y, int w, int h);
62void unclip(frontend *fe);
2ef96bd6 63void start_draw(frontend *fe);
64void draw_update(frontend *fe, int x, int y, int w, int h);
65void end_draw(frontend *fe);
66void deactivate_timer(frontend *fe);
67void activate_timer(frontend *fe);
fd1a1a2b 68void status_bar(frontend *fe, char *text);
720a8fb7 69
70/*
7f77ea24 71 * midend.c
72 */
2ef96bd6 73midend_data *midend_new(frontend *fe);
7f77ea24 74void midend_free(midend_data *me);
75void midend_set_params(midend_data *me, game_params *params);
76void midend_size(midend_data *me, int *x, int *y);
77void midend_new_game(midend_data *me, char *seed);
78void midend_restart_game(midend_data *me);
7f77ea24 79int midend_process_key(midend_data *me, int x, int y, int button);
2ef96bd6 80void midend_redraw(midend_data *me);
81float *midend_colours(midend_data *me, int *ncolours);
82void midend_timer(midend_data *me, float tplus);
eb2ad6f1 83int midend_num_presets(midend_data *me);
84void midend_fetch_preset(midend_data *me, int n,
85 char **name, game_params **params);
fd1a1a2b 86int midend_wants_statusbar(midend_data *me);
7f77ea24 87
88/*
720a8fb7 89 * malloc.c
90 */
91void *smalloc(int size);
92void *srealloc(void *p, int size);
93void sfree(void *p);
94char *dupstr(char *s);
95#define snew(type) \
96 ( (type *) smalloc (sizeof (type)) )
97#define snewn(number, type) \
98 ( (type *) smalloc ((number) * sizeof (type)) )
99#define sresize(array, number, type) \
7f77ea24 100 ( (type *) srealloc ((array), (number) * sizeof (type)) )
720a8fb7 101
102/*
4efb3868 103 * misc.c
104 */
105int rand_upto(int limit);
106
107/*
720a8fb7 108 * random.c
109 */
720a8fb7 110random_state *random_init(char *seed, int len);
111unsigned long random_upto(random_state *state, unsigned long limit);
112void random_free(random_state *state);
113
114/*
115 * Game-specific routines
116 */
0c490335 117extern const char *const game_name;
7f77ea24 118game_params *default_params(void);
eb2ad6f1 119int game_fetch_preset(int i, char **name, game_params **params);
7f77ea24 120void free_params(game_params *params);
eb2ad6f1 121game_params *dup_params(game_params *params);
720a8fb7 122char *new_game_seed(game_params *params);
123game_state *new_game(game_params *params, char *seed);
124game_state *dup_game(game_state *state);
125void free_game(game_state *state);
126game_state *make_move(game_state *from, int x, int y, int button);
7f77ea24 127void game_size(game_params *params, int *x, int *y);
2ef96bd6 128float *game_colours(frontend *fe, game_state *state, int *ncolours);
129game_drawstate *game_new_drawstate(game_state *state);
130void game_free_drawstate(game_drawstate *ds);
131void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
87ed82be 132 game_state *newstate, float anim_time, float flash_time);
2ef96bd6 133float game_anim_length(game_state *oldstate, game_state *newstate);
87ed82be 134float game_flash_length(game_state *oldstate, game_state *newstate);
fd1a1a2b 135int game_wants_statusbar(void);
720a8fb7 136
137#endif /* PUZZLES_PUZZLES_H */