Nick Bowler [Wed, 7 Dec 2022 05:16:41 +0000 (00:16 -0500)]
Improve exposure mask calculation.
By assuming that a >= b, the computation of
board_left(a) & board_right(b)
can be simplified to
board_left(a-b) << a.
which avoids some computation. A similar improvement can be done
for board_above/board_below. Add a new board_rect function that
incorporates these improvements, and use it to generate exposure
update bitmaps in the Motif UI.
A new test case exhaustively tests all possible inputs to this
function.
Furthermore, update board_above and board_below to have simpler
implementations.
Nick Bowler [Wed, 7 Dec 2022 03:40:10 +0000 (22:40 -0500)]
Improve game_check_goal implementation slightly.
It seems that, at least on x86, GCC can generate very slightly more
compact code by "expanding" the goal bitmap to match the game format,
rather what is currently done ("shrinking" the game bitmap to match
the goal format).
Add a sanity test case that checks the result of this function, which
makes such a change straightforward to do.
Nick Bowler [Wed, 30 Nov 2022 04:20:48 +0000 (23:20 -0500)]
Generate and install "locolor" icons.
Since we now have the capability to generate nice enough 16-colour
icons, let's install them into the "locolor" theme.
It also turns out that icon installation was broken by the recent
rework, so as a bonus the "hicolor" icons are installed again too.
In an attempt to avoid this happening in the future, add a new
installcheck procedure which does a very basic sanity check.
Nick Bowler [Wed, 30 Nov 2022 01:41:07 +0000 (20:41 -0500)]
Add a funky dithered 16-colour mode to ewmhicon.
This adds a new option, --w32vga, which generates icons targeting the
16-colour "VGA" palette used by Windows. This is the 8 combinations
of 0/max RGB values, plus the same set with the values halved, plus
a light gray.
This option enables a hand-coded pattern that approximates the desired
colours, and gives much more pleasing results in low colour modes.
Nick Bowler [Wed, 30 Nov 2022 02:24:52 +0000 (21:24 -0500)]
Improve portability of icon generating rules.
Using $* in target rules is not portable; POSIX specifies that it is
only valid in inference rules and this is the case with several make
implementations.
Although this is a minor issue since the icons won't normally be
generated when building from a release, it is easy enough to fix.
Nick Bowler [Wed, 30 Nov 2022 01:57:25 +0000 (20:57 -0500)]
Make colour macros more flexible.
Instead of COLOUR0_PRIMARY et al. expanding directly to X11 colour
names, allow the process to be hooked to generate other forms of
colour definitions.
The ewmhicon test program is adapted to use this to generate its
colourmap. This also avoids some apparently nonportable C macro
usage, as preprocessing the following code:
#define A(x) x
#define B(x) x
#define C (x)
A(B C)
expands to x (the desired result) with GCC but B(x) on HP-UX cc.
Nick Bowler [Wed, 30 Nov 2022 01:42:42 +0000 (20:42 -0500)]
Make EWMH icon generation more abstract.
Replace the low level EWMH icon drawing functions with new ones that are
much more generic: instead of the specific icon format these new ones
produce 1-byte-per-pixel images with user-controlled byte values.
These new functions will hopefully be useful for other kinds of icon
formats. In particular, to directly create colour-index bitmaps without
working backwards from the ARGB values generated currently.
Then for the actual EWMH icon support wrap it all up in a single
function that allocates and creates all of the icon data in one shot,
using the new generic functions under the hood. This simplifies the
calling code somewhat.
As a bonus, the overall code size seems to be reduced.
Nick Bowler [Tue, 29 Nov 2022 02:01:06 +0000 (21:01 -0500)]
Improve configure --help output.
The AC_PATH_XTRA macro includes a pretty non-specific help message, we
can hack it a bit to produce a description more consistent with other
UI options.
Nick Bowler [Sun, 27 Nov 2022 16:43:01 +0000 (11:43 -0500)]
x11: Fix redraw on window resize.
It turns out that relying on expose events to trigger redraw of certain
tiles when enlarging is not actually a good idea. No expose events will
be generated if the new portion of the window is obscured while resizing,
which means tiles along the bottom or right edge of the game/goal areas
may not get redrawn when they should be.
We can avoid the redundant drawing on resize another way. Instead of
redrawing immediately in response to resize or expose events, we just
mark those tiles as needing update and only actually redraw after a
short delay, which is hopefully enough to catch the expose events
directly generated by the resize.
Nick Bowler [Fri, 18 Nov 2022 04:12:14 +0000 (23:12 -0500)]
Restructure icon rebuild rules a bit.
The way that the build-icons rule is currently handled means that
'make install' is triggering compilation of the ewmhicon test program,
even if the icons are already available.
This is undesirable as 'make install' should normally not cause anything
to be compiled like that. Split up the rules so that nothing gets built
until after the rule has actually determined that one or more icons are
missing.
Nick Bowler [Fri, 18 Nov 2022 03:45:07 +0000 (22:45 -0500)]
Avoid Gnulib std-gnu11 module.
It has come to my attention that this module rewrites AC_PROG_CC in
a way that actually breaks Automake's AM_PROG_CC_C_O functionality.
This results in the "compile" script not being included or used in
packages bootstrapped with Autoconf 2.69.
With later versions of Autoconf things work because this module
doesn't touch things and thus disables itself.
I don't care about building with C11 one way or the other. Let's
just skip the module.
Nick Bowler [Wed, 16 Nov 2022 05:16:29 +0000 (00:16 -0500)]
x11: Improve redraw of empty spaces.
When the game area is showing only the middle portion with the empty
border, we can clear this with 4 or fewer draw calls instead of 16.
Let's handle this as a special case in the tile drawing code.
Moreover, we don't need to draw anything in these spaces on expose
events, as the exposed areas are already filled with the background.
Nick Bowler [Wed, 16 Nov 2022 03:25:18 +0000 (22:25 -0500)]
Fix build on older Motif without XmPIXMAP_AND_STRING.
It seems that not all versions of Motif support labels with a labelType
of XmPIXMAP_AND_STRING. This mode is used in the about dialog to
display the program's icon, but it's silly to fail compilation over
this.
Add a configure test to check if this feature is available, and fall
back to XmSTRING (which will render without the icon).
Nick Bowler [Wed, 16 Nov 2022 03:09:48 +0000 (22:09 -0500)]
Fix curses build on HP-UX.
On HP-UX, it seems that "lines" and "label_width" are defined as
object-like macros in <term.h> which causes dumb build failures
since this code is using those identifiers as variables.
Not too much hassle to just use a different name instead.
Nick Bowler [Sat, 18 Jun 2022 01:39:50 +0000 (21:39 -0400)]
Combine motifgui.dat / motifstr.str into one file.
Pull in updated gen-tree.awk with support for comments, and use a
special comment syntax to allow simple strtab definitions in a single
file. This allows keeping the menu label definitions together with the
menu tree, and reduces the number of generated headers to worry about.
Nick Bowler [Sun, 12 Jun 2022 15:51:27 +0000 (11:51 -0400)]
curses: Begin to implement a game menu system.
Add the skeleton for very simple control interface based on function
keys. Show labels along the bottom row for up to 10 functions, with
each corresponding to the first 10 function keys (or esc+number).
For now, hardcode two functions: new game and exit. More to come.
Nick Bowler [Wed, 8 Jun 2022 03:55:32 +0000 (23:55 -0400)]
Don't use leaveok() in curses.
Hiding the cursor seems unreliable, so when curs_set doesn't actually
work I think it's better to keep the cursor in some innocuous location
rather than having it randomly move around in the game area.
Nick Bowler [Wed, 8 Jun 2022 03:51:59 +0000 (23:51 -0400)]
Ensure manpages are distributed.
It seems using dist_man_MANS in an Automake conditional doesn't actually
ensure the manpage is distributed, so we need to just use man_MANS in
the conditional and EXTRA_DIST unconditionally.
Nick Bowler [Wed, 8 Jun 2022 03:44:01 +0000 (23:44 -0400)]
Add basic keyboard control to curses UI.
Since the mouse support in curses is not always available, we need to
provide a keyboard-based alternative. The arrow keys move a cursor
around the positions in the game area, and space moves the selected
tile.
Nick Bowler [Tue, 7 Jun 2022 00:01:41 +0000 (20:01 -0400)]
Fix reconfiguration when using --without-x.
We need to consider the user's selection when checking whether or not
to build the Motif UI, because the cached result may have come from a
prior configure run.
Nick Bowler [Sun, 5 Jun 2022 20:42:45 +0000 (16:42 -0400)]
Add initial curses-based UI.
To start getting an idea of what it takes to implement a game like this
with many different frontends, let's start by implementing a text-mode
user interface based on curses.
Nick Bowler [Sat, 12 Mar 2022 23:16:39 +0000 (18:16 -0500)]
Reduce redrawing on resize events.
It is a waste of time redrawing parts of the window on resize that
will be redrawn due to expose events immediately afterwards. This
is particularly noticeable when the program is first started and
everything is drawn twice.
Nick Bowler [Sat, 12 Mar 2022 22:36:07 +0000 (17:36 -0500)]
Restructure motif code a bit.
Move the game input callback into motif.c, which essentially brings all
the user input parts together in one file and all the display parts in
the other file.
Nick Bowler [Sat, 12 Mar 2022 21:31:12 +0000 (16:31 -0500)]
Report changed positions from game_do_move.
Instead of manually comparing positions before and after the move,
we can just alter the definition of game_do_move to return this
information, since it has already done most of the work internally.
Nick Bowler [Sat, 12 Mar 2022 21:11:02 +0000 (16:11 -0500)]
Only redraw changed tiles when right clicking.
By changing the definition of game_check_goal to return a bit-mask
of mismatched positions, we can just pass that to the redraw mask to
reduce the amount of rendering needed.
Nick Bowler [Sat, 12 Mar 2022 21:15:24 +0000 (16:15 -0500)]
Add build-time option to help debug X11 rendering.
Add #define that can be manually set in config.h to enable additional
debug drawing. This is intended purely for development. Currently this
causes the system to highlight tiles before they are redrawn, in order
to watch things like expose handling and tile movement.
Nick Bowler [Thu, 10 Mar 2022 04:44:39 +0000 (23:44 -0500)]
Track elapsed time of the game.
Since this is a speed solving game, it is kind of important to know
how much time it took to solve the puzzle. Start by adding a timer to
the game state so we can print elapsed time at the end. Related GUI
elements will be coming later.
The game will no longer start immediately. When the program is
launched, it will begin in a winning state.
Nick Bowler [Thu, 10 Mar 2022 04:18:18 +0000 (23:18 -0500)]
Add a more direct way to specify the game background.
Rather than the user needing to know any details of the widget
hierarchy, add an application resource to set the game background
too (along with the tile colours).
We can also leverage Xt to allocate colours for us, which simplifies
things a bit.
Nick Bowler [Thu, 10 Mar 2022 03:53:18 +0000 (22:53 -0500)]
Avoid uninitialized value error in help output.
Technically simply passing an unitialized (indeterminate) arg value
to the help_print_option function has undefined behaviour even though
it is only unset in cases where it will not actually be used by the
function. But it is easy to just ensure it has a well-defined value.
Nick Bowler [Wed, 9 Mar 2022 02:03:48 +0000 (21:03 -0500)]
Generate and distribute some icon files.
Since we now have code that generates nifty icons in various sizes,
we can fairly easily make use of it to generate and install icon
files. These files need to be distributed because the application
cannot be run in the cross-compilation case, which will also avoid
the distribution depending on external image conversion utilities.
Nick Bowler [Tue, 8 Mar 2022 06:08:29 +0000 (01:08 -0500)]
Use XPM as icon test output format.
The output of this test program is very close to XPM format.
So why not make it actually produce XPM format. This gives
us a good way to have it output actual colour icons too.
Nick Bowler [Tue, 8 Mar 2022 04:35:22 +0000 (23:35 -0500)]
Allow compilation without X11.
At the moment this means nothing useful gets installed, but "make check"
is possible. The icon functions being tested don't _really_ depend on
X11, just the XColor structure for which we can supply a suitable
definition.
Nick Bowler [Sat, 5 Mar 2022 21:32:48 +0000 (16:32 -0500)]
Fix boardmove testcase typo.
Comparing "if (argv > 0)" is an obvious typo, totally invalid and bogus.
Weirdly GCC fails to complain without "-pedantic", but HP-UX cc is happy
to inform us about the error.