<feed xmlns='http://www.w3.org/2005/Atom'>
<title>puzzles/midend.c, branch master</title>
<subtitle>My sgt-puzzles tree</subtitle>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/'/>
<entry>
<title>Refactor `button &amp; ~MOD_MASK' as `STRIP_BUTTON_MODIFIERS(button)'.</title>
<updated>2024-07-31T22:29:00+00:00</updated>
<author>
<name>Franklin Wei</name>
<email>franklin@rockbox.org</email>
</author>
<published>2024-07-21T22:06:37+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=5de69c22b0ff037f648a740a7c01869e78587df2'/>
<id>5de69c22b0ff037f648a740a7c01869e78587df2</id>
<content type='text'>
This refactors all instances of bitwise-ANDs with `~MOD_MASK'. There is
a handful of more complex instances I left unchanged (in cube.c, midend.c,
and twiddle.c), since those AND with `~MOD_MASK | MOD_NUM_KEYPAD' or
similar. I don't think it's worth writing a macro for those cases.

Also document this new macro's usage in devel.but.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This refactors all instances of bitwise-ANDs with `~MOD_MASK'. There is
a handful of more complex instances I left unchanged (in cube.c, midend.c,
and twiddle.c), since those AND with `~MOD_MASK | MOD_NUM_KEYPAD' or
similar. I don't think it's worth writing a macro for those cases.

Also document this new macro's usage in devel.but.
</pre>
</div>
</content>
</entry>
<entry>
<title>midend_process_key: allow Shift+Tab to pass through to the backend.</title>
<updated>2024-07-31T22:29:00+00:00</updated>
<author>
<name>Franklin Wei</name>
<email>franklin@rockbox.org</email>
</author>
<published>2024-07-21T08:49:06+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=3f8ef290786fbaf7b9ec200a2fd598eb324c6b0c'/>
<id>3f8ef290786fbaf7b9ec200a2fd598eb324c6b0c</id>
<content type='text'>
Previously, a button code of ('\t' | MOD_SHFT) from a frontend would have
the MOD_SHFT flag stripped by midend_process_key, resulting in a bare '\t'
passed to the backend. Now, this combination is allowed to pass through to
the backend. This will be used in the keyboard interface to Untangle, which
I'm about to add.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Previously, a button code of ('\t' | MOD_SHFT) from a frontend would have
the MOD_SHFT flag stripped by midend_process_key, resulting in a bare '\t'
passed to the backend. Now, this combination is allowed to pass through to
the backend. This will be used in the keyboard interface to Untangle, which
I'm about to add.
</pre>
</div>
</content>
</entry>
<entry>
<title>midend_request_keys: fix memory leak of a game_params.</title>
<updated>2023-08-24T11:46:38+00:00</updated>
<author>
<name>Simon Tatham</name>
<email>anakin@pobox.com</email>
</author>
<published>2023-08-24T11:40:51+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=f279c5eba035d018a8805a65a8a245b8b8d2ea2e'/>
<id>f279c5eba035d018a8805a65a8a245b8b8d2ea2e</id>
<content type='text'>
Thanks to Steffen Bauer for spotting this. The call to
midend_get_params(me) was making a duplicate of me-&gt;params, and
nothing was freeing it.

Since the game_params is passed to request_keys as a const pointer, it
should be safe to pass me-&gt;params itself, so that instead of adding a
free, we can remove the unnecessary allocation.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Thanks to Steffen Bauer for spotting this. The call to
midend_get_params(me) was making a duplicate of me-&gt;params, and
nothing was freeing it.

Since the game_params is passed to request_keys as a const pointer, it
should be safe to pass me-&gt;params itself, so that instead of adding a
free, we can remove the unnecessary allocation.
</pre>
</div>
</content>
</entry>
<entry>
<title>midend_get_prefs: Don't free memory that we just copied elsewhere.</title>
<updated>2023-07-29T21:09:52+00:00</updated>
<author>
<name>Asher Gordon</name>
<email>AsDaGo@posteo.net</email>
</author>
<published>2023-07-29T19:27:46+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=3e7a6adce5887db04d26438da64fdc4de308f4da'/>
<id>3e7a6adce5887db04d26438da64fdc4de308f4da</id>
<content type='text'>
We were using free_cfg(be_prefs) after we copied be_prefs to
all_prefs, but we actually want to use sfree(be_prefs) since we don't
want to free each element that has been copied. None of the games so
far use string preferences, which is why they haven't been affected by
this bug.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We were using free_cfg(be_prefs) after we copied be_prefs to
all_prefs, but we actually want to use sfree(be_prefs) since we don't
want to free each element that has been copied. None of the games so
far use string preferences, which is why they haven't been affected by
this bug.
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix control-character generation fix</title>
<updated>2023-06-26T08:17:01+00:00</updated>
<author>
<name>Ben Harris</name>
<email>bjh21@bjh21.me.uk</email>
</author>
<published>2023-06-26T08:10:28+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=8b8a277a7aa9146b0825398f9e81ddccb81ee2dd'/>
<id>8b8a277a7aa9146b0825398f9e81ddccb81ee2dd</id>
<content type='text'>
The change I made in c224416c76e41f284b318adc51f08c3ed11de8e2 was
incorrect: I accidentally removed a "return" statement and left in a
debugging printf() when I meant to keep the return and drop the
printf().
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The change I made in c224416c76e41f284b318adc51f08c3ed11de8e2 was
incorrect: I accidentally removed a "return" statement and left in a
debugging printf() when I meant to keep the return and drop the
printf().
</pre>
</div>
</content>
</entry>
<entry>
<title>Reduce the set of keys from which we generate control characters</title>
<updated>2023-06-25T12:54:21+00:00</updated>
<author>
<name>Ben Harris</name>
<email>bjh21@bjh21.me.uk</email>
</author>
<published>2023-06-25T12:54:21+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=c224416c76e41f284b318adc51f08c3ed11de8e2'/>
<id>c224416c76e41f284b318adc51f08c3ed11de8e2</id>
<content type='text'>
midend_process_key() has some generic code for converting MOD_CTRL along
with a printing character into a control character.  This is derived
from the Emscripten front-end because browsers don't do this themselves.
Most other front ends seem to depend on the platform for this mapping.

The mapping was applied to all printable ASCII characters, but this
meant that Ctrl+-, which is commonly used by browsers to mean "zoom out"
got converted into CR and then CURSOR_SELECT.  That was confusing to say
the least.

So now, the CTRL mapping is only applied to characters in the roughly
alphabetic range (0x40 to 0x7f), and MOD_CTRL applied to a character in
the range 0x20 to 0x3f gets a return of PKR_UNUSED instead.  That means
that Ctrl+- in browsers now works properly.

I don't think this will affect other front-ends because they're
generally a lot less generous about passing MOD_CTRL to the mid-end.
I've tested the GTK port nonetheless and not found any problems.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
midend_process_key() has some generic code for converting MOD_CTRL along
with a printing character into a control character.  This is derived
from the Emscripten front-end because browsers don't do this themselves.
Most other front ends seem to depend on the platform for this mapping.

The mapping was applied to all printable ASCII characters, but this
meant that Ctrl+-, which is commonly used by browsers to mean "zoom out"
got converted into CR and then CURSOR_SELECT.  That was confusing to say
the least.

So now, the CTRL mapping is only applied to characters in the roughly
alphabetic range (0x40 to 0x7f), and MOD_CTRL applied to a character in
the range 0x20 to 0x3f gets a return of PKR_UNUSED instead.  That means
that Ctrl+- in browsers now works properly.

I don't think this will affect other front-ends because they're
generally a lot less generous about passing MOD_CTRL to the mid-end.
I've tested the GTK port nonetheless and not found any problems.
</pre>
</div>
</content>
</entry>
<entry>
<title>Expose the NO_EFFECT/UNUSED distinction through midend_process_key()</title>
<updated>2023-06-10T23:33:28+00:00</updated>
<author>
<name>Ben Harris</name>
<email>bjh21@bjh21.me.uk</email>
</author>
<published>2023-06-07T22:03:30+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=1547154efbfcf0bd8f6fc4f91fe99c26371fe0ee'/>
<id>1547154efbfcf0bd8f6fc4f91fe99c26371fe0ee</id>
<content type='text'>
This removed the "handled" pointer and instead extends the existing
boolean return value (quit or don't quit) into an enumeration.  One of
the values still quits the program, but now there are different values
for keys that had an effect, had no effect, and are not used by the
puzzle at all.  The mapping from interpret_move results to process_key
results is roughly:

move string    -&gt; PKR_SOME_EFFECT
MOVE_UI_UPDATE -&gt; PKR_SOME_EFFECT
MOVE_NO_EFFECT -&gt; PKR_NO_EFFECT
MOVE_UNUSED    -&gt; PKR_UNUSED

The mid-end can also generate results internally, and is the only place
that PKR_QUIT can arise.

For compatibility, PKR_QUIT is zero, so anything expecting a false
return value to mean quit will be unsurprised.  The other values are
ordered so that lower values indicate a greater amount of handling of
the key.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This removed the "handled" pointer and instead extends the existing
boolean return value (quit or don't quit) into an enumeration.  One of
the values still quits the program, but now there are different values
for keys that had an effect, had no effect, and are not used by the
puzzle at all.  The mapping from interpret_move results to process_key
results is roughly:

move string    -&gt; PKR_SOME_EFFECT
MOVE_UI_UPDATE -&gt; PKR_SOME_EFFECT
MOVE_NO_EFFECT -&gt; PKR_NO_EFFECT
MOVE_UNUSED    -&gt; PKR_UNUSED

The mid-end can also generate results internally, and is the only place
that PKR_QUIT can arise.

For compatibility, PKR_QUIT is zero, so anything expecting a false
return value to mean quit will be unsurprised.  The other values are
ordered so that lower values indicate a greater amount of handling of
the key.
</pre>
</div>
</content>
</entry>
<entry>
<title>Add MOVE_NO_EFFECT and MOVE_UNUSED return values from interpret_move()</title>
<updated>2023-06-10T23:33:27+00:00</updated>
<author>
<name>Ben Harris</name>
<email>bjh21@bjh21.me.uk</email>
</author>
<published>2023-06-04T18:02:21+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=a943f3177f4adc591a282bdc62eef80675dc2a67'/>
<id>a943f3177f4adc591a282bdc62eef80675dc2a67</id>
<content type='text'>
These allow for distinguishing the case where a puzzle doesn't have a
use for a key from the case where it just happens to have no effect in
the current state of the puzzle.  These were both represented by NULL,
but that now represents the case where a puzzle hasn't been updated to
make the distinction yet.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
These allow for distinguishing the case where a puzzle doesn't have a
use for a key from the case where it just happens to have no effect in
the current state of the puzzle.  These were both represented by NULL,
but that now represents the case where a puzzle hasn't been updated to
make the distinction yet.
</pre>
</div>
</content>
</entry>
<entry>
<title>Rename UI_UPDATE as MOVE_UI_UPDATE</title>
<updated>2023-06-10T23:33:27+00:00</updated>
<author>
<name>Ben Harris</name>
<email>bjh21@bjh21.me.uk</email>
</author>
<published>2023-06-04T17:42:58+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=a9af3fda1d784c42d486a019a0a4e947f762af70'/>
<id>a9af3fda1d784c42d486a019a0a4e947f762af70</id>
<content type='text'>
All the other constants named UI_* are special key names that can be
passed to midend_process_key(), but UI_UPDATE is a special return value
from the back-end interpret_move() function instead.  This renaming
makes the distinction clear and provides a naming convention for future
special return values from interpret_move().
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
All the other constants named UI_* are special key names that can be
passed to midend_process_key(), but UI_UPDATE is a special return value
from the back-end interpret_move() function instead.  This renaming
makes the distinction clear and provides a naming convention for future
special return values from interpret_move().
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix a few minor memory leaks.</title>
<updated>2023-06-06T18:54:40+00:00</updated>
<author>
<name>Simon Tatham</name>
<email>anakin@pobox.com</email>
</author>
<published>2023-06-06T17:50:38+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=7333d27b0c9d85d7fec41c2ca60dbea740767451'/>
<id>7333d27b0c9d85d7fec41c2ca60dbea740767451</id>
<content type='text'>
Thanks to Jeremy Stephens for reporting them.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Thanks to Jeremy Stephens for reporting them.
</pre>
</div>
</content>
</entry>
</feed>
