1441 Commits

Author SHA1 Message Date
d7c873313e benchmark.pl: replace use of Perl <> with <<>>.
I've only just found out that it has the effect of treating the argv
words not as plain filenames, but as arguments to Perl default 'open',
i.e. if they end in | then the text before that is treated as a
command. That's not what was intended!
2019-01-25 20:27:49 +00:00
ced51ada36 Replace fe->preset_menu when we change midend.
Thanks to Rocco Matano for reporting that in the -DCOMBINED version of
the Windows front end, switching games causes a crash because the
presets menu from the old midend is still left over in fe, and its
presence inhibits the setup code from making a new one. Now we throw
it out at the same time as we throw out the old midend itself.

Also, the condition 'if (!fe->preset_menu)' was misguided. I think the
point of that was to avoid pointlessly tearing down and rebuilding the
preset menu when we're _not_ changing game - but that's a cost too
small to worry about if it causes the slightest trouble. Now
fe->preset_menu should always be NULL at that point in the function,
so I've replaced the if with an assert.
2018-12-12 22:18:00 +00:00
0a5d13bcd5 Fix GTK 2 crash introduced by previous commit.
Moving the snaffle_colours() call earlier is fine in GTK 3, where the
potential call to frontend_default_colour doesn't depend on the window
already having been created. But it falls over in GTK 2 where it does.

Moved the non-headless-mode version of that call back to where it was
before the --screenshot change.
2018-11-25 00:46:48 +00:00
d9e03f50da Don't initialise GTK in --screenshot mode.
I had this idea today and immediately wondered why I'd never had it
before!

To generate the puzzle screenshots used on the website and as program
icons, we run the GTK front end with the --screenshot option, which
sets up GTK, insists on connecting to an X server (or other display),
draws the state of a puzzle on a Cairo surface, writes that surface
out to a .png file, and exits.

But there's no reason we actually need the GTK setup during that
process, especially because the surface we do the drawing on is our
_own_ surface, not even one provided to us by GTK. We could just set
up a Cairo surface by itself, draw on it, and save it to a file.
Calling gtk_init is not only pointless, but actively inconvenient,
because it means the build script depends on having an X server
available for the sole purpose of making gtk_init not complain.

So now I've simplified things, by adding a 'headless' flag in
new_window and the frontend structure, which suppresses all uses of
actual GTK, leaving only the Cairo surface setup and enough supporting
stuff (like colours) to generate the puzzle image. One awkward build
dependency removed.

This means that --screenshot no longer works in GTK 2, which I don't
care about, because it only needs to run on _one_ platform.
2018-11-23 23:44:17 +00:00
db3b531e2c Add missing 'static' to game-internal declarations.
Another thing I spotted while trawling the whole source base was that
a couple of games had omitted 'static' on a lot of their internal
functions. Checking with nm, there turned out to be quite a few more
than I'd spotted by eye, so this should fix them all.

Also added one missing 'const', on the lookup table nbits[] in Tracks.
2018-11-13 22:06:19 +00:00
47cec547e5 Unruly, Group: reference-count the 'immutable' array.
I noticed this during the bool trawl: both of these games have an
array of flags indicating which grid squares are immutable starting
clues, and copy it in every call to dup_game, which is completely
unnecessary because it doesn't change during play. So now each one
lives in a reference-counted structure, as per my usual practice in
similar cases elsewhere.
2018-11-13 21:58:14 +00:00
cdc0563123 Add missing binary 'matching' to .gitignore. 2018-11-13 21:54:11 +00:00
53798c08d4 Add a missing const in unfinished/sokoban.c.
I noticed this when I temporarily enabled compilation of all the
unfinished puzzles while doing the bool trawl.
2018-11-13 21:52:26 +00:00
5f5b284c0b Use C99 bool within source modules.
This is the main bulk of this boolification work, but although it's
making the largest actual change, it should also be the least
disruptive to anyone interacting with this code base downstream of me,
because it doesn't modify any interface between modules: all the
inter-module APIs were updated one by one in the previous commits.
This just cleans up the code within each individual source file to use
bool in place of int where I think that makes things clearer.
2018-11-13 21:48:24 +00:00
a550ea0a47 Replace TRUE/FALSE with C99 true/false throughout.
This commit removes the old #defines of TRUE and FALSE from puzzles.h,
and does a mechanical search-and-replace throughout the code to
replace them with the C99 standard lowercase spellings.
2018-11-13 21:48:24 +00:00
064da87682 Adopt C99 bool in the grid.c API.
More or less trivially: the only affected declaration is the
has_incentre flag in struct grid_face.
2018-11-13 21:48:24 +00:00
08915945e6 Adopt C99 bool in the shared Latin-square API.
latin_check now returns bool, and latin_solver_diff_set takes a bool
'extreme' flag. Should be non-disruptive.
2018-11-13 21:48:24 +00:00
33b55db48e Adopt C99 bool in the tree234 API.
The only affected function here is splitpos234, which I don't think
these puzzles are even using at the moment.
2018-11-13 21:48:24 +00:00
836a5c4ea7 Adopt C99 bool in misc.c functions.
The 'decode' flag to obfuscate_bitmap and the 'wrap' flag to
move_cursor are the only ones affected here.
2018-11-13 21:48:24 +00:00
8fb4cd031a Adopt C99 bool in the findloop API.
This shouldn't be a disruptive change at all: findloop_run and
findloop_is_loop_edge now return bool in place of int, but client code
should automatically adjust without needing any changes.
2018-11-13 21:48:24 +00:00
20b56788bc Adopt C99 bool in the edsf API.
Now the flag passed to edsf_merge to say whether two items are the
same or opposite is a bool, and so is the flag returned via a pointer
argument from edsf_canonify.

The latter requires client code to be updated to match (otherwise
you'll get a pointer type error), so I've done that update in Loopy,
which is edsf's only current in-tree client.
2018-11-13 21:48:24 +00:00
f6965b92e1 Adopt C99 bool in the printing API.
Not many changes here: the 'dotted' flag passed to print_line_dotted
is bool, and so is the printing_in_colour flag passed to
print_get_colour. Also ps_init() takes a bool.

line_dotted is also a method in the drawing API structure, but it's
not actually filled in for any non-print-oriented implementation of
that API. So only front ends that do platform-specific _printing_
should need to make a corresponding change. In-tree, for example,
windows.c needed a fix because it prints via Windows GDI, but gtk.c
didn't have to do anything, because its CLI-based printing facility
just delegates to ps.c.
2018-11-13 21:48:24 +00:00
cd6cadbecf Adopt C99 bool in the midend API.
This changes parameters of midend_size and midend_print_puzzle, the
return types of midend_process_key, midend_wants_statusbar,
midend_can_format_as_text_now and midend_can_{undo,redo}, the 'bval'
field in struct config_item, and finally the return type of the
function pointer passed to midend_deserialise and identify_game.

The last of those changes requires a corresponding fix in clients of
midend_deserialise and identify_game, so in this commit I've also
updated all the in-tree front ends to match. I expect downstream front
ends will need to do the same when they merge this change.
2018-11-13 21:46:39 +00:00
a76d269cf2 Adopt C99 bool in the game backend API.
encode_params, validate_params and new_desc now take a bool parameter;
fetch_preset, can_format_as_text_now and timing_state all return bool;
and the data fields is_timed, wants_statusbar and can_* are all bool.
All of those were previously typed as int, but semantically boolean.

This commit changes the API declarations in puzzles.h, updates all the
games to match (including the unfinisheds), and updates the developer
docs as well.
2018-11-13 21:34:42 +00:00
0f77798ae2 Add a #include of <stdbool.h>.
This is the first commit in a series which will adopt C99 bool
throughout the code base where it makes sense to do so.
2018-11-13 21:31:32 +00:00
b732fda2cf Undead: remove an unused structure field.
I noticed that state->common, which is shared between all the game
states in an undo chain, has a 'solved' flag in it. That's not right -
solvedness as a property of a particular state on the chain belongs in
the game_state itself, and having-at-one-point-been-solved-ness as a
persistent property of the whole chain belongs in the game_ui.

Fortunately, the game isn't actually doing it wrong:
state->common->solved is set once and then never read, so it must have
been left in from early abandoned code. Now removed.
2018-11-07 19:17:47 +00:00
3189fb484d Fix an inaccurate comment.
latin_solver_diff_set takes a boolean input parameter to indicate
whether the 'Extreme'-level variant of set elimination is permitted.
But it's commented in the header file as having a boolean _output_
parameter which it sets if it _ended up_ using that variant. Probably
the latter was how it worked in an early draft, and I changed my mind
later without changing the comment.
2018-11-06 18:37:23 +00:00
baed0e3eec Fix a misuse of errno.
In menu_save_event, we checked ctx.error to see if an errno value had
been left in it by the savefile_write callback, but if so, then we
were passing the _current_ value of errno to strerror() in place of
the saved value in ctx.error.

This may well have been benign, but I spotted it in an eyeball review
just now and thought I'd better fix it before it bit anyone.
2018-11-06 18:37:23 +00:00
f281644b0b Fix OSX build failure from latest XCode update.
To begin with, the toolchain no longer lets me build for x86-32 -
apparently MacOS is now 64-bit only.

Also, the linker now gives an error about a missing libgcc_s variant
for -mmacosx-version-min=10.4, and indeed 10.5. So I've bumped the
minimum supported OS version to 10.6.

That in turn required some changes in osx.m itself, because bumping
the min OS version caused some API deprecations to show up. Luckily I
turned out to have left myself a comment some time ago telling me what
I was going to need to do about one of them :-)
2018-10-06 18:38:33 +01:00
d8d506455e Net: highlight more errors in locked tiles.
If a locked tile has an edge pointing at a barrier, or at another
locked tile without a matching edge, colour that edge red.
2018-09-23 16:36:30 +01:00
cafa36b0e3 Net: rename 'loop' to 'err' in UI code.
In preparation for highlighting other kinds of errors.
No intended functional change.
2018-09-23 16:36:24 +01:00
cd9c544230 Dominosa: some more solver thoughts.
I've been playing this game a fair bit recently, and it's probably
time I jotted down some of the deductions I've been doing in my own
brain that the game doesn't know about. (Also I had an algorithmic
thought about the area-parity technique.)
2018-09-21 08:55:27 +01:00
55be8e50db cube.c: Prohibit unsolvable single row/column game
For cube games, the minimum for any dimension should be 2, as there is
no net of the cube that is only one row/column. The previous logic
would permit a 1x7 game (for example) that could never be solved.
2018-09-13 09:11:33 +01:00
1db5961b8b Fix docs link from the JS Rectangles page.
It pointed to rectangles.html, which doesn't exist, in place of
rect.html which does.
2018-07-24 18:38:00 +01:00
11aab0d7c8 Tracks: stop drawing background for clues in game_print.
This makes the clue numbers actually visible in the printed output,
instead of black on black.
2018-07-20 19:21:52 +01:00
1d9cf25f27 Fix return value from newgame_undo_deserialise_read.
The read function used by midend_deserialise and friends is expected
never to perform a partial read (the main deserialisation code always
knows how many bytes it can expect to see), so it's specified to
return simply TRUE or FALSE for success/failure, rather than the
number of bytes read.

This probably wasn't breaking anything, since in the case of
deserialising from an internal memory buffer a short read could only
arise due to an outright bug constructing the buffer. But now I've
spotted it, I should fix it.
2018-06-21 19:02:21 +01:00
3618f6a07f Fix NUL-termination bug in saving from Javascript.
The JS code that retrieves the save-file data from emcc.c doesn't
receive a separate length value, but instead expects the data to be in
the form of a NUL-terminated string. But emcc.c wasn't NUL-terminating
it, so the save data could come out with random cruft on the end.
2018-06-21 18:54:08 +01:00
506b07352a misc.c: Fix implementation of free_keys.
The previous version attempted to free the first element multiple times.
2018-06-14 23:39:49 +01:00
5a697b3df9 Parallelise the build script.
Using the new feature I added to bob where it defines the variable
'nproc' to give you a sensible value to use with make -j.
2018-06-01 07:24:15 +01:00
85d87f4e8a Fix Makefile.nestedvm so that it works with make -j.
Instead of repeatedly reusing the file name 'PuzzleEngine.class' in
the main build directory, now each puzzle's NestedVM translation is
left in a separate subdirectory so that they don't collide with each
other. A bonus is that we don't have to rename the file back and forth
between the rule that builds it and the one that consumes it.
2018-06-01 07:24:15 +01:00
32f96080ad Enable 64-bit osx build and fix a warning.
OS X is beginning to show a warning when a 32-bit application is
opened, so it's high time that this gets enabled. Fix a clang warning
exposed by this build.
2018-06-01 06:50:15 +01:00
7edbee6cb2 Enable high resolution on osx
This consists of setting a flag in the Info.plist. Everything in the
game is resolution-independent, of course, and has been thoroughly
tested on other platforms. The only issue I found is cosmetic: The
rounded window corners become more dramatic and don't look as good
against the square status bar.

Increasing the resolution also exposes two graphical quirks that I
don't think are new. Curved rails in Tracks seem to be made of short
segments that don't quite connect, but I don't see this on Android,
and on closer inspection this is already present on low resolution in
OS X. Lines in Untangle, and also Galaxies, that are at a multiple of
45 degrees seem thinner than other lines, but I also see this on
Android — I think it's just more obvious on high resolution, and could
be adjusted with antialiasing. Everything else looks as it should, for
example when moving a window between low and high dpi displays.
2018-06-01 06:50:00 +01:00
5141e5b3e7 Bump the source and target versions used in javac.
I've just upgraded my build machine to Ubuntu 18.04, which has come
with a version of javac that complains about both -source 1.3 and
-target 1.3. Both are surely pretty out of date anyway, so the path of
least resistance is to just increase them to the earliest version that
javac doesn't currently complain is deprecated.
2018-05-14 18:26:07 +01:00
113aad8b3e Stop using deprecated gdk_beep().
Switched over to gdk_display_beep(), which should work in any GTK2 or
GTK3 environment. (This code base doesn't care about GTK1 any more.)
2018-05-09 16:10:15 +01:00
31384ca9c0 Buildscr: make long parts of the build conditionalisable.
If I want to rebuild just the Javascript puzzles (for example) in
circumstances where I don't expect to need a great many
edit-compile-link cycles, it's easier to get bob to do it for me than
to remember how to set up the development tools on my path. But it
takes ages to run the whole build script if I also have to wait for
the Windows, Mac and Java puzzles to be built, not to mention the
initial Unix build that runs for no purpose other than generating the
icon images.

So now I can run the build with various time-consuming parts
conditioned out, for development purposes. Of course, the default is
still to build absolutely everything.
2018-04-28 12:06:41 +01:00
e53c097fb7 latin.c: remove a rogue array overrun.
Oops! This was left over from an early development version of commits
4408476b7 and 000ebc507, in which I initially arranged for each
adjacency list to be terminated with the sentinel value -1 instead of
separately storing an array of the lists' lengths.

I later changed the representation to make randomising the algorithm
easier (it's much easier to shuffle an array uniformly at random if
you _don't_ have to faff endlessly to work out its length). But this
write of a no-longer- needed sentinel value in the client code must
have survived the rewrite by mistake, and also somehow evaded all my
pre-commit testing with valgrind and asan.

A user reported that the Towers Javascript version was crashing on
startup, and I think this is the cause, because it seems to fix it for
me.
2018-04-28 12:02:43 +01:00
a1663d6650 C89 build fixes.
Recent changes introduced a couple of non-C89-compatible mixed
declarations and code.
2018-04-25 19:24:06 +01:00
441b11b310 Make static keyword come first everywhere.
I somehow missed these instances as well. Oh well.
2018-04-25 06:48:57 +01:00
b3da23806e Move `static' keyword to beginning of declaration.
Rockbox's GCC warns about this with -Wextra.
2018-04-24 21:32:56 +01:00
19f46dce8c Add request_keys() to the rest of the unfinished games.
I just realized that only "Group" received the request_keys() field in the
game struct for some reason.
2018-04-24 21:32:45 +01:00
f04923abbc Build fix: stop initialising an auto char array.
Checking with the standards, I think this is legal C99, but not legal
C89 - and we are compiling in C89 mode. Why _every_ version of gcc
didn't object, given all the warning and pedantry options, I'm not
sure, but one did, so I should fix it.
2018-04-23 18:42:13 +01:00
60a929a250 Add a request_keys() function with a midend wrapper.
This function gives the front end a way to find out what keys the back
end requires; and as such it is mostly useful for ports without a
keyboard. It is based on changes originally found in Chris Boyle's
Android port, though some modifications were needed to make it more
flexible.
2018-04-22 17:04:50 +01:00
3d04dd3335 Remove maxflow completely.
Its ability to solve general network flow problems was never actually
used in this code base; it was _always_ used for the restricted
problem of finding a matching in an unweighted bipartite graph. So now
I've switched all its clients over to the new matching.c, maxflow is
no longer needed.
2018-04-22 17:04:50 +01:00
dcc4d82b23 Convert Tents to use matching instead of maxflow.
Tents needs to construct maximal matchings in two different
situations. One is the completion check during play, in which the
existence of a perfect matching between tents and trees is part of the
win condition; the other is the initial grid generation, in which we
find a _maximal_ matching between the tents we've already placed and
all the possible neighbouring squares that are candidates for the tree
positions. Both of those are switched over.
2018-04-22 17:04:50 +01:00
000ebc5078 Use the new matching() for latin.c.
The new client code is a lot smaller and nicer, because we can throw
away the col[] and num[] permutations entirely.

Of course, this also means that every puzzle that incorporated latin.c
now has to link against matching.c instead of maxflow.c - but since I
centralised that secondary dependency into Recipe a few commits ago,
it's trivial to switch them all over at once.
2018-04-22 16:45:59 +01:00