diff options
| author | Franklin Wei <git@fwei.tk> | 2017-08-23 14:20:07 -0400 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2017-08-23 14:22:09 -0400 |
| commit | 3c514f8e20ea8762025a12f9edbea27967e31d76 (patch) | |
| tree | ed44527b00a128ce85f507e1abda8dbbbf7de4cb /apps/plugins/puzzles/src | |
| parent | 4dd300d9f0229269aa8f9a46b07a5aa65f882985 (diff) | |
| download | rockbox-3c514f8e20ea8762025a12f9edbea27967e31d76.zip rockbox-3c514f8e20ea8762025a12f9edbea27967e31d76.tar.gz rockbox-3c514f8e20ea8762025a12f9edbea27967e31d76.tar.bz2 rockbox-3c514f8e20ea8762025a12f9edbea27967e31d76.tar.xz | |
puzzles: misc. changes and sync with upstream
This brings puzzles up-to-date with Simon's tree, along with the
rockbox-specific changes I made. Note that I also got rid of some
of the ugly floating-point code in rbwrappers.c and replaced it
with wrappers for our fixed-point library.
Change-Id: Ibfb79acb15517116a26de1c3ea89e025146b9e2e
Diffstat (limited to 'apps/plugins/puzzles/src')
| -rw-r--r-- | apps/plugins/puzzles/src/Buildscr | 15 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/Makefile.doc | 14 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/README | 4 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/icons/tracks.sav | 2 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/loopy.c | 19 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/map.c | 2 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/midend.c | 2 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/misc.c | 17 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/net.c | 4 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/netslide.c | 4 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/puzzles.but | 10 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/puzzles.h | 4 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/range.c | 3 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/rect.c | 4 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/tracks.c | 2 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/untangle.c | 21 | ||||
| -rw-r--r-- | apps/plugins/puzzles/src/website.url | 2 | ||||
| -rwxr-xr-x | apps/plugins/puzzles/src/winiss.pl | 2 |
18 files changed, 83 insertions, 48 deletions
diff --git a/apps/plugins/puzzles/src/Buildscr b/apps/plugins/puzzles/src/Buildscr index 910981f..c720844 100644 --- a/apps/plugins/puzzles/src/Buildscr +++ b/apps/plugins/puzzles/src/Buildscr @@ -51,14 +51,10 @@ enddelegate # Build the Windows binaries and installer, and the CHM file. in puzzles do make -f Makefile.doc clean -in puzzles do make -f Makefile.doc chm -in puzzles do make -f Makefile.doc # build help file for installer +in puzzles do make -f Makefile.doc # build help files for installer in puzzles do mason.pl --args '{"version":"$(Version)","descfile":"gamedesc.txt"}' winwix.mc > puzzles.wxs in puzzles do perl winiss.pl $(Version) gamedesc.txt > puzzles.iss delegate windows - # Ignore the poorly controlled return value from HHC, and instead - # just test that the output file was generated. - in puzzles with htmlhelp do/win hhc puzzles.hhp & type puzzles.chm >nul # FIXME: Cygwin alternative? in puzzles with visualstudio do/win nmake -f Makefile.vc clean in puzzles with visualstudio do/win nmake -f Makefile.vc VER=-DVER=$(Version) @@ -67,12 +63,11 @@ delegate windows # provide a 'more info' URL, and an optional -n option to provide a # program name, and that it can take multiple .exe filename # arguments and sign them all in place. - ifneq "$(winsigncode)" "" in puzzles do $(winsigncode) -i http://www.chiark.greenend.org.uk/~sgtatham/puzzles/ *.exe + ifneq "$(winsigncode)" "" in puzzles do $(winsigncode) -i https://www.chiark.greenend.org.uk/~sgtatham/puzzles/ *.exe # Build installers. in puzzles with wix do/win candle puzzles.wxs && light -ext WixUIExtension -sval puzzles.wixobj in puzzles with innosetup do/win iscc puzzles.iss - ifneq "$(winsigncode)" "" in puzzles do $(winsigncode) -i http://www.chiark.greenend.org.uk/~sgtatham/puzzles/ -n "Simon Tatham's Portable Puzzle Collection Installer" puzzles.msi Output/installer.exe - return puzzles/puzzles.chm + ifneq "$(winsigncode)" "" in puzzles do $(winsigncode) -i https://www.chiark.greenend.org.uk/~sgtatham/puzzles/ -n "Simon Tatham's Portable Puzzle Collection Installer" puzzles.msi Output/installer.exe return puzzles/*.exe return puzzles/Output/installer.exe return puzzles/puzzles.msi @@ -114,9 +109,7 @@ in puzzles do chmod +x *.exe # return puzzles/puzzles.armv4.cab #enddelegate -# Build the help file and the HTML docs. -in puzzles do make -f Makefile.doc clean # remove CHM-target HTML -in puzzles do make -f Makefile.doc # and rebuild help file... +# Build the HTML docs. in puzzles do mkdir doc in puzzles do mkdir devel in puzzles/doc do halibut --html -Chtml-contents-filename:index.html -Chtml-index-filename:indexpage.html -Chtml-template-filename:%k.html -Chtml-template-fragment:%k ../puzzles.but diff --git a/apps/plugins/puzzles/src/Makefile.doc b/apps/plugins/puzzles/src/Makefile.doc index c7d6946..0fd28db 100644 --- a/apps/plugins/puzzles/src/Makefile.doc +++ b/apps/plugins/puzzles/src/Makefile.doc @@ -1,17 +1,17 @@ -all: puzzles.hlp puzzles.txt HACKING +all: puzzles.chm puzzles.hlp puzzles.txt HACKING preprocessed.but: puzzles.but sed 's/PREFIX-/$(BINPREFIX)/g' puzzles.but > preprocessed.but -puzzles.hlp puzzles.txt: preprocessed.but - halibut --winhelp=puzzles.hlp --text=puzzles.txt preprocessed.but +puzzles.chm: preprocessed.but + halibut --chm=puzzles.chm preprocessed.but +puzzles.hlp: preprocessed.but + halibut --winhelp=puzzles.hlp preprocessed.but +puzzles.txt: preprocessed.but + halibut --text=puzzles.txt preprocessed.but HACKING: devel.but halibut --text=HACKING devel.but -chm: puzzles.hhp -puzzles.hhp: puzzles.but chm.but - halibut --html puzzles.but chm.but - clean: rm -f puzzles.hlp puzzles.txt preprocessed.but HACKING *.html *.hh[pck] diff --git a/apps/plugins/puzzles/src/README b/apps/plugins/puzzles/src/README index 890db56..0083012 100644 --- a/apps/plugins/puzzles/src/README +++ b/apps/plugins/puzzles/src/README @@ -1,6 +1,6 @@ This is the README accompanying the source code to Simon Tatham's puzzle collection. The collection's web site is at -<http://www.chiark.greenend.org.uk/~sgtatham/puzzles/>. +<https://www.chiark.greenend.org.uk/~sgtatham/puzzles/>. If you've obtained the source code by downloading a .tar.gz archive from the Puzzles web site, you should find several Makefiles in the @@ -51,4 +51,4 @@ application and for the web site. It is generated from a Halibut source file (puzzles.but), which is the preferred form for modification. To generate the manual in other formats, rebuild it, or learn about Halibut, visit the Halibut website at -<http://www.chiark.greenend.org.uk/~sgtatham/halibut/>. +<https://www.chiark.greenend.org.uk/~sgtatham/halibut/>. diff --git a/apps/plugins/puzzles/src/icons/tracks.sav b/apps/plugins/puzzles/src/icons/tracks.sav index ca30644..d13ef95 100644 --- a/apps/plugins/puzzles/src/icons/tracks.sav +++ b/apps/plugins/puzzles/src/icons/tracks.sav @@ -1,6 +1,6 @@ SAVEFILE:41:Simon Tatham's Portable Puzzle Collection VERSION :1:1 -GAME :12:Train Tracks +GAME :12:Tracks PARAMS :5:6x6dt CPARAMS :5:6x6dt SEED :15:145870397370785 diff --git a/apps/plugins/puzzles/src/loopy.c b/apps/plugins/puzzles/src/loopy.c index 652b9ec..7d3436a 100644 --- a/apps/plugins/puzzles/src/loopy.c +++ b/apps/plugins/puzzles/src/loopy.c @@ -3054,6 +3054,24 @@ static char *interpret_move(const game_state *state, game_ui *ui, state->lines[e_next - g->edges] != state->lines[i]) break; + if (e_next == e) { + /* + * Special case: we might have come all the + * way round a loop and found our way back to + * the same edge we started from. In that + * situation, we must terminate not only this + * while loop, but the 'for' outside it that + * was tracing in both directions from the + * starting edge, because if we let it trace + * in the second direction then we'll only + * find ourself traversing the same loop in + * the other order and generate an encoded + * move string that mentions the same set of + * edges twice. + */ + goto autofollow_done; + } + dot = (e_next->dot1 != dot ? e_next->dot1 : e_next->dot2); if (movelen > movesize - 40) { movesize = movesize * 5 / 4 + 128; @@ -3064,6 +3082,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, (int)(e_this - g->edges), button_char); } } + autofollow_done:; } } diff --git a/apps/plugins/puzzles/src/map.c b/apps/plugins/puzzles/src/map.c index f1af38b..54073ba 100644 --- a/apps/plugins/puzzles/src/map.c +++ b/apps/plugins/puzzles/src/map.c @@ -2779,7 +2779,7 @@ static void draw_square(drawing *dr, game_drawstate *ds, draw_circle(dr, COORD(x) + (xo+1)*TILESIZE/5, COORD(y) + (yo+1)*TILESIZE/5, - TILESIZE/7, COL_0 + c, COL_0 + c); + TILESIZE/4, COL_0 + c, COL_0 + c); } /* diff --git a/apps/plugins/puzzles/src/midend.c b/apps/plugins/puzzles/src/midend.c index 6dbdd33..f80a7fa 100644 --- a/apps/plugins/puzzles/src/midend.c +++ b/apps/plugins/puzzles/src/midend.c @@ -1701,7 +1701,7 @@ void midend_serialise(midend *me, */ if (me->ourgame->is_timed) { char buf[80]; - ftoa(buf, 80, me->elapsed); + ftoa(buf, me->elapsed); wr("TIME", buf); } diff --git a/apps/plugins/puzzles/src/misc.c b/apps/plugins/puzzles/src/misc.c index 9904aee..2bf35d3 100644 --- a/apps/plugins/puzzles/src/misc.c +++ b/apps/plugins/puzzles/src/misc.c @@ -361,16 +361,21 @@ void draw_text_outline(drawing *dr, int x, int y, int fonttype, } -/* kludge for non-compliant sprintf() */ +/* kludge for sprintf() in Rockbox not supporting "%-8.8s" */ void copy_left_justified(char *buf, size_t sz, const char *str) { + size_t len = strlen(str); + assert(sz > 0); memset(buf, ' ', sz - 1); - int len = strlen(str); - if(len <= sz - 1) - memcpy(buf, str, len); - else - fatal("overrun"); + assert(len <= sz - 1); + memcpy(buf, str, len); buf[sz - 1] = 0; } +/* another kludge for platforms without %g support in *printf() */ +int ftoa(char *buf, float f) +{ + return sprintf(buf, "%d.%06d", (int)f, (int)((f - (int)f)*1e6)); +} + /* vim: set shiftwidth=4 tabstop=8: */ diff --git a/apps/plugins/puzzles/src/net.c b/apps/plugins/puzzles/src/net.c index 9289afb..f479f03 100644 --- a/apps/plugins/puzzles/src/net.c +++ b/apps/plugins/puzzles/src/net.c @@ -259,7 +259,7 @@ static char *encode_params(const game_params *params, int full) if (full && params->barrier_probability) { len += sprintf(ret+len, "b"); - len += ftoa(ret + len, 400, params->barrier_probability); + len += ftoa(ret + len, params->barrier_probability); } if (full && !params->unique) ret[len++] = 'a'; @@ -295,7 +295,7 @@ static config_item *game_configure(const game_params *params) ret[3].name = "Barrier probability"; ret[3].type = C_STRING; - ftoa(buf, 80, params->barrier_probability); + ftoa(buf, params->barrier_probability); ret[3].sval = dupstr(buf); ret[3].ival = 0; diff --git a/apps/plugins/puzzles/src/netslide.c b/apps/plugins/puzzles/src/netslide.c index 96ac8e7..bb9b099 100644 --- a/apps/plugins/puzzles/src/netslide.c +++ b/apps/plugins/puzzles/src/netslide.c @@ -243,7 +243,7 @@ static char *encode_params(const game_params *params, int full) if (full && params->barrier_probability) { len += sprintf(ret+len, "b"); - len += ftoa(ret + len, 400, params->barrier_probability); + len += ftoa(ret + len, params->barrier_probability); } /* Shuffle limit is part of the limited parameters, because we have to * provide the target move count. */ @@ -281,7 +281,7 @@ static config_item *game_configure(const game_params *params) ret[3].name = "Barrier probability"; ret[3].type = C_STRING; - ftoa(buf, 80, params->barrier_probability); + ftoa(buf, params->barrier_probability); ret[3].sval = dupstr(buf); ret[3].ival = 0; diff --git a/apps/plugins/puzzles/src/puzzles.but b/apps/plugins/puzzles/src/puzzles.but index 2508fe3..2c448b8 100644 --- a/apps/plugins/puzzles/src/puzzles.but +++ b/apps/plugins/puzzles/src/puzzles.but @@ -13,6 +13,12 @@ \cfg{html-contents-depth-1}{2} \cfg{html-leaf-contains-contents}{true} +\cfg{chm-filename}{puzzles.chm} +\cfg{chm-contents-filename}{index.html} +\cfg{chm-template-filename}{%k.html} +\cfg{chm-head-end}{<link rel="stylesheet" type="text/css" href="chm.css">} +\cfg{chm-extra-file}{chm.css} + \cfg{info-filename}{puzzles.info} \cfg{ps-filename}{puzzles.ps} @@ -65,13 +71,13 @@ with the game binaries or the code, except pretending you wrote them yourself, or suing me if anything goes wrong. The most recent versions, and \i{source code}, can be found at -\I{website}\W{http://www.chiark.greenend.org.uk/~sgtatham/puzzles/}\cw{http://www.chiark.greenend.org.uk/~sgtatham/puzzles/}. +\I{website}\W{https://www.chiark.greenend.org.uk/~sgtatham/puzzles/}\cw{https://www.chiark.greenend.org.uk/~sgtatham/puzzles/}. Please report \I{feedback}\i{bugs} to \W{mailto:anakin@pobox.com}\cw{anakin@pobox.com}. You might find it helpful to read this article before reporting a bug: -\W{http://www.chiark.greenend.org.uk/~sgtatham/bugs.html}\cw{http://www.chiark.greenend.org.uk/~sgtatham/bugs.html} +\W{https://www.chiark.greenend.org.uk/~sgtatham/bugs.html}\cw{https://www.chiark.greenend.org.uk/~sgtatham/bugs.html} \ii{Patches} are welcome. Especially if they provide a new front end (to make all these games run on another platform), or a new game. diff --git a/apps/plugins/puzzles/src/puzzles.h b/apps/plugins/puzzles/src/puzzles.h index 03af2ca..fbfcfce 100644 --- a/apps/plugins/puzzles/src/puzzles.h +++ b/apps/plugins/puzzles/src/puzzles.h @@ -381,6 +381,10 @@ void draw_text_outline(drawing *dr, int x, int y, int fonttype, * less than buffer size. */ void copy_left_justified(char *buf, size_t sz, const char *str); +/* An ugly, but working float-to-string implementation for platforms + * that don't have one */ +int ftoa(char *buf, float f); + /* * dsf.c */ diff --git a/apps/plugins/puzzles/src/range.c b/apps/plugins/puzzles/src/range.c index 588178c..4dd39b9 100644 --- a/apps/plugins/puzzles/src/range.c +++ b/apps/plugins/puzzles/src/range.c @@ -1159,7 +1159,8 @@ static int game_can_format_as_text_now(const game_params *params) static char *game_text_format(const game_state *state) { - int cellsize, r, c, i, w_string, h_string, n_string; + int r, c, i, w_string, h_string, n_string; + char cellsize; char *ret, *buf, *gridline; int const w = state->params.w, h = state->params.h; diff --git a/apps/plugins/puzzles/src/rect.c b/apps/plugins/puzzles/src/rect.c index 0c06c74..247138c 100644 --- a/apps/plugins/puzzles/src/rect.c +++ b/apps/plugins/puzzles/src/rect.c @@ -165,7 +165,7 @@ static char *encode_params(const game_params *params, int full) if (full && params->expandfactor) { sprintf(data + strlen(data), "e"); - ftoa(data + strlen(data), 256, params->expandfactor); + ftoa(data + strlen(data), params->expandfactor); } if (full && !params->unique) strcat(data, "a"); @@ -194,7 +194,7 @@ static config_item *game_configure(const game_params *params) ret[2].name = "Expansion factor"; ret[2].type = C_STRING; - ftoa(buf, 80, params->expandfactor); + ftoa(buf, params->expandfactor); ret[2].sval = dupstr(buf); ret[2].ival = 0; diff --git a/apps/plugins/puzzles/src/tracks.c b/apps/plugins/puzzles/src/tracks.c index 43428a1..0c06c59 100644 --- a/apps/plugins/puzzles/src/tracks.c +++ b/apps/plugins/puzzles/src/tracks.c @@ -2620,7 +2620,7 @@ static void game_print(drawing *dr, const game_state *state, int tilesize) #endif const struct game thegame = { - "Train Tracks", "games.tracks", "tracks", + "Tracks", "games.tracks", "tracks", default_params, game_fetch_preset, NULL, decode_params, diff --git a/apps/plugins/puzzles/src/untangle.c b/apps/plugins/puzzles/src/untangle.c index 47e839e..441c865 100644 --- a/apps/plugins/puzzles/src/untangle.c +++ b/apps/plugins/puzzles/src/untangle.c @@ -1122,6 +1122,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, if (bestd <= DRAG_THRESHOLD * DRAG_THRESHOLD) { ui->dragpoint = best; + ui->cursorpoint = -1; ui->newpoint.x = x; ui->newpoint.y = y; ui->newpoint.d = ds->tilesize; @@ -1183,25 +1184,28 @@ static char *interpret_move(const game_state *state, game_ui *ui, bestd = 0; for (i = 0; i < n; i++) { + long px, py, dx, dy, d; + float angle; + int right_direction; if(i == ui->cursorpoint) continue; - long px = state->pts[i].x * ds->tilesize / state->pts[i].d; - long py = state->pts[i].y * ds->tilesize / state->pts[i].d; - long dx = px - state->pts[ui->cursorpoint].x * ds->tilesize / state->pts[ui->cursorpoint].d; - long dy = py - state->pts[ui->cursorpoint].y * ds->tilesize / state->pts[ui->cursorpoint].d; - long d = dx*dx + dy*dy; + px = state->pts[i].x * ds->tilesize / state->pts[i].d; + py = state->pts[i].y * ds->tilesize / state->pts[i].d; + dx = px - state->pts[ui->cursorpoint].x * ds->tilesize / state->pts[ui->cursorpoint].d; + dy = py - state->pts[ui->cursorpoint].y * ds->tilesize / state->pts[ui->cursorpoint].d; + d = dx*dx + dy*dy; /* Figure out if this point falls into a 90 degree * range extending from the current point */ - float angle = atan2(-dy, dx); /* negate y to adjust for raster coordinates */ + angle = atan2(-dy, dx); /* negate y to adjust for raster coordinates */ /* offset to [0..2*PI] */ if(angle < 0) angle += 2*PI; - int right_direction = FALSE; + right_direction = FALSE; if((button == CURSOR_UP && (1*PI/4 <= angle && angle <= 3*PI/4)) || (button == CURSOR_LEFT && (3*PI/4 <= angle && angle <= 5*PI/4)) || @@ -1284,7 +1288,10 @@ static char *interpret_move(const game_state *state, game_ui *ui, return dupstr(buf); } else if(ui->cursorpoint < 0) + { ui->cursorpoint = 0; + return ""; + } } return NULL; diff --git a/apps/plugins/puzzles/src/website.url b/apps/plugins/puzzles/src/website.url index 2ab37f6..2913e62 100644 --- a/apps/plugins/puzzles/src/website.url +++ b/apps/plugins/puzzles/src/website.url @@ -1,2 +1,2 @@ [InternetShortcut] -URL=http://www.chiark.greenend.org.uk/~sgtatham/puzzles/ +URL=https://www.chiark.greenend.org.uk/~sgtatham/puzzles/ diff --git a/apps/plugins/puzzles/src/winiss.pl b/apps/plugins/puzzles/src/winiss.pl index eca02d3..3200337 100755 --- a/apps/plugins/puzzles/src/winiss.pl +++ b/apps/plugins/puzzles/src/winiss.pl @@ -48,7 +48,7 @@ print 'VersionInfoTextVersion=Version '.$ver."\n"; print 'AppVersion=r'.$ver."\n"; print 'VersionInfoVersion=0.0.'.$integer_date.'.0'."\n"; print 'AppPublisher=Simon Tatham'."\n"; -print 'AppPublisherURL=http://www.chiark.greenend.org.uk/~sgtatham/puzzles/'."\n"; +print 'AppPublisherURL=https://www.chiark.greenend.org.uk/~sgtatham/puzzles/'."\n"; print 'DefaultDirName={pf}\Simon Tatham\'s Portable Puzzle Collection'."\n"; print 'DefaultGroupName=Simon Tatham\'s Puzzles'."\n"; # print 'SetupIconFile=fixmethinkoneup.ico'."\n"; |