From 09aa8de52cb962f1ceebfb1fd44f2c54a924fc5c Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Mon, 22 Jul 2024 21:43:25 -0400 Subject: 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 --- apps/plugins/puzzles/src/spectre.h | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 apps/plugins/puzzles/src/spectre.h (limited to 'apps/plugins/puzzles/src/spectre.h') 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 @@ +#ifndef PUZZLES_SPECTRE_H +#define PUZZLES_SPECTRE_H + +struct SpectrePatchParams { + /* + * A patch of Spectre tiling is identified by giving + * + * - the coordinates of the central Spectre, using a + * combinatorial coordinate system similar to the Hat tiling in + * hat.h + * + * - the orientation of that Spectre, as a number from 0 to 11 (a + * multiple of 30 degrees), with 0 representing the 'head' of + * the Spectre facing upwards, and numbers counting + * anticlockwise. + * + * Coordinates are a sequence of small non-negative integers. The + * valid range for each coordinate depends on the next coordinate, + * or on final_hex if it's the last one in the list. The largest + * valid range is {0,...,7}. + * + * 'final_hex' is one of the letters GDJLXPSFY. + * spectre_valid_hex_letter() will check that. + */ + int orientation; + size_t ncoords; + unsigned char *coords; + char final_hex; +}; + +bool spectre_valid_hex_letter(char c); + +/* + * Fill in SpectrePatchParams with a randomly selected set of + * coordinates, in enough detail to generate a patch of tiling filling + * a w x h area. The unit of measurement is 1/(2*sqrt(2)) of a Spectre + * edge, i.e. such that a single Spectre edge at 45 degrees would + * correspond to the vector (2,2). + * + * The 'coords' field of the structure will be filled in with a new + * dynamically allocated array. Any previous pointer in that field + * will be overwritten. + */ +void spectre_tiling_randomise(struct SpectrePatchParams *params, int w, int h, + random_state *rs); + +/* + * Validate a SpectrePatchParams to ensure it contains no illegal + * coordinates. Returns NULL if it's acceptable, or an error string if + * not. + */ +const char *spectre_tiling_params_invalid( + const struct SpectrePatchParams *params); + +/* + * Generate the actual set of Spectre tiles from a SpectrePatchParams, + * passing each one to a callback. The callback receives the vertices + * of each point, in the form of an array of 4*14 integers. Each + * vertex is represented by four consecutive integers in this array, + * with the first two giving the x coordinate and the last two the y + * coordinate. Each pair of integers a,b represent a single coordinate + * whose value is a + b*sqrt(3). The unit of measurement is as above. + */ +typedef void (*spectre_tile_callback_fn)(void *ctx, const int *coords); + +#define SPECTRE_NVERTICES 14 + +void spectre_tiling_generate( + const struct SpectrePatchParams *params, int w, int h, + spectre_tile_callback_fn cb, void *cbctx); + +#endif -- cgit v1.2.3