summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/spectre.h
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2024-07-22 21:43:25 -0400
committerFranklin Wei <franklin@rockbox.org>2024-07-22 21:44:08 -0400
commit09aa8de52cb962f1ceebfb1fd44f2c54a924fc5c (patch)
tree182bd4efb2dc8ca4fcb369d8cccab0c0f290d054 /apps/plugins/puzzles/src/spectre.h
parentc72030f98c953a82ed6f5c7132ad000c3d5f4a16 (diff)
downloadrockbox-09aa8de52cb962f1ceebfb1fd44f2c54a924fc5c.tar.gz
rockbox-09aa8de52cb962f1ceebfb1fd44f2c54a924fc5c.zip
puzzles: resync with upstream
This brings the puzzles source in sync with Simon's branch, commit fd304c5 (from March 2024), with some added Rockbox-specific compatibility changes: https://www.franklinwei.com/git/puzzles/commit/?h=rockbox-devel&id=516830d9d76bdfe64fe5ccf2a9b59c33f5c7c078 There are quite a lot of backend changes, including a new "Mosaic" puzzle. In addition, some new frontend changes were necessary: - New "Preferences" menu to access the user preferences system. - Enabled spacebar input for several games. Change-Id: I94c7df674089c92f32d5f07025f6a1059068af1e
Diffstat (limited to 'apps/plugins/puzzles/src/spectre.h')
-rw-r--r--apps/plugins/puzzles/src/spectre.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/apps/plugins/puzzles/src/spectre.h b/apps/plugins/puzzles/src/spectre.h
new file mode 100644
index 0000000000..97d7595e3a
--- /dev/null
+++ b/apps/plugins/puzzles/src/spectre.h
@@ -0,0 +1,72 @@
1#ifndef PUZZLES_SPECTRE_H
2#define PUZZLES_SPECTRE_H
3
4struct SpectrePatchParams {
5 /*
6 * A patch of Spectre tiling is identified by giving
7 *
8 * - the coordinates of the central Spectre, using a
9 * combinatorial coordinate system similar to the Hat tiling in
10 * hat.h
11 *
12 * - the orientation of that Spectre, as a number from 0 to 11 (a
13 * multiple of 30 degrees), with 0 representing the 'head' of
14 * the Spectre facing upwards, and numbers counting
15 * anticlockwise.
16 *
17 * Coordinates are a sequence of small non-negative integers. The
18 * valid range for each coordinate depends on the next coordinate,
19 * or on final_hex if it's the last one in the list. The largest
20 * valid range is {0,...,7}.
21 *
22 * 'final_hex' is one of the letters GDJLXPSFY.
23 * spectre_valid_hex_letter() will check that.
24 */
25 int orientation;
26 size_t ncoords;
27 unsigned char *coords;
28 char final_hex;
29};
30
31bool spectre_valid_hex_letter(char c);
32
33/*
34 * Fill in SpectrePatchParams with a randomly selected set of
35 * coordinates, in enough detail to generate a patch of tiling filling
36 * a w x h area. The unit of measurement is 1/(2*sqrt(2)) of a Spectre
37 * edge, i.e. such that a single Spectre edge at 45 degrees would
38 * correspond to the vector (2,2).
39 *
40 * The 'coords' field of the structure will be filled in with a new
41 * dynamically allocated array. Any previous pointer in that field
42 * will be overwritten.
43 */
44void spectre_tiling_randomise(struct SpectrePatchParams *params, int w, int h,
45 random_state *rs);
46
47/*
48 * Validate a SpectrePatchParams to ensure it contains no illegal
49 * coordinates. Returns NULL if it's acceptable, or an error string if
50 * not.
51 */
52const char *spectre_tiling_params_invalid(
53 const struct SpectrePatchParams *params);
54
55/*
56 * Generate the actual set of Spectre tiles from a SpectrePatchParams,
57 * passing each one to a callback. The callback receives the vertices
58 * of each point, in the form of an array of 4*14 integers. Each
59 * vertex is represented by four consecutive integers in this array,
60 * with the first two giving the x coordinate and the last two the y
61 * coordinate. Each pair of integers a,b represent a single coordinate
62 * whose value is a + b*sqrt(3). The unit of measurement is as above.
63 */
64typedef void (*spectre_tile_callback_fn)(void *ctx, const int *coords);
65
66#define SPECTRE_NVERTICES 14
67
68void spectre_tiling_generate(
69 const struct SpectrePatchParams *params, int w, int h,
70 spectre_tile_callback_fn cb, void *cbctx);
71
72#endif