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