diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/action_list.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/include/action_list.c b/include/action_list.c index fd45afd..10bbdcf 100644 --- a/include/action_list.c +++ b/include/action_list.c @@ -4,6 +4,8 @@ // Helper method declarations // =================================================================== +#define CLR_STONE NUM_MASK + static inline action_list_t * action_list_prepend(action_list_t *list, const enum A_TYPE type, const int8_t loc, const uint8_t data0, @@ -178,13 +180,13 @@ void action_take(action_list_t *action) { int8_t delta = deltas[dir]; // Use the Kernighan method to count the set bits - uint8_t steps = 1; + int8_t steps = 1; for (uint8_t _gaps = gaps; _gaps > 0; steps++) _gaps &= _gaps - 1; // Move top stone type to destination - celldat[loc+steps*delta] &= NUM_MASK; // necessary for crushing + celldat[loc+steps*delta] &= CLR_STONE; // necessary for crushing celldat[loc+steps*delta] |= STONE_AT(loc); - celldat[loc] &= NUM_MASK; + celldat[loc] &= CLR_STONE; celldat[loc] |= STONE_FLAT; // should be optimised out uint8_t gap_bit = 0, total = 0; @@ -253,32 +255,30 @@ void action_undo(action_list_t *action) { dir = action->data1 >> 4; const int8_t delta = deltas[dir]; - uint8_t gap_bit = 1, total = (num > 1) ? 1 : 0, steps = 1; + int8_t steps = 1; + uint8_t gap_bit = 1, total = (num > 1) ? 1 : 0; for (uint8_t d = 0; d + 1 < num; d++, total++, gap_bit <<= 1) { - // We took a step, move everything over so far if (gaps & gap_bit) { colours[loc] <<= total; colours[loc] |= colours[loc+steps*delta] & ((1 << total) - 1); colours[loc+steps*delta] >>= total; celldat[loc] += total*NUM_INC; celldat[loc+steps*delta] -= total*NUM_INC; - // Reset for next step total = 0; steps++; } } total++; - // Move what remains colours[loc] <<= total; colours[loc] |= colours[loc+steps*delta] & ((1 << total) - 1); colours[loc+steps*delta] >>= total; - // celldat[loc] &= NUM_MASK; // not necessary, assumed STONE_FLAT + // celldat[loc] &= CLR_STONE; is not necessary, as STONE_FLAT == 0 celldat[loc] += total*NUM_INC; celldat[loc+steps*delta] -= total*NUM_INC; // Top stone type celldat[loc] |= STONE_AT(loc+steps*delta); - celldat[loc+steps*delta] &= NUM_MASK; - celldat[loc+steps*delta] |= STONE_STANDING; // optimised + celldat[loc+steps*delta] &= CLR_STONE; + celldat[loc+steps*delta] |= STONE_FLAT; // should be optimised out } } |
