Skip to content

Conversation

@entrez
Copy link
Contributor

@entrez entrez commented Jun 8, 2022

Mentioned in 1654735 and a comment in do_play_instrument(music.c) as
something which would be a nice future improvement if there were more
bits available in flags/drawbridgemask. Turns out the DB_UNDER states
are all mutually exclusive and never overlap, so a bit for the jam can
be saved by rearranging those. An attempt at implementing this.

Mentioned in 1654735 and a comment in do_play_instrument(music.c) as
something which would be a nice future improvement if there were more
bits available in flags/drawbridgemask.  Turns out the DB_UNDER states
are all mutually exclusive and never overlap, so a bit for the jam can
be saved by rearranging those.
When a drawbridge becomes jammed, it can be unjammed with the #untrap
command, on either the drawbridge itself or the portcullis.
Comment on lines +204 to +208
#define DB_MOAT 0x0
#define DB_LAVA 0x4
#define DB_ICE 0x8
#define DB_FLOOR 0xc
#define DB_UNDER 0xc /* mask for underneath */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, DB_UNDER = DB_LAVA | DB_ICE | DB_FLOOR. In this change, DB_UNDER = DB_FLOOR. Does this not introduce bugs in code that uses DB_UNDER?

Copy link
Contributor Author

@entrez entrez Dec 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still DB_MOAT | DB_LAVA | DB_ICE | DB_FLOOR (0x0 | 0x4 | 0x8 | 0xc is 0xc), it's just that because they are mutually exclusive states, there can be overlap -- in other words, the checks are always (flags & DB_UNDER) == DB_MOAT, never (flags & DB_MOAT) != 0 (which would be impossible even in the current arrangement, since one of them is 0). So it's not necessary to give each one a unique bit; as long as the values themselves are unique and distinguishable all the existing code works fine.

But this hack to save a bit is also not really necessary if you've expanded flags.

@entrez entrez marked this pull request as draft June 9, 2023 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants