Skip to content

Commit

Permalink
Merge pull request #60 from boingoing/macro_moves
Browse files Browse the repository at this point in the history
Change the flood fill move functions into macros
  • Loading branch information
boingoing authored Jun 23, 2023
2 parents b061cb1 + b35e059 commit b11c89a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 89 deletions.
86 changes: 0 additions & 86 deletions src/flood_fill.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,92 +14,6 @@
#include "types.h"
#include "zeropage.h"

unsigned int get_front() {
switch (get_cur_dir()) {
case MOVE_DIRECTION_RIGHT:
return playfield_index_move_right(get_current_position());
case MOVE_DIRECTION_LEFT:
return playfield_index_move_left(get_current_position());
case MOVE_DIRECTION_DOWN:
return playfield_index_move_down(get_current_position());
case MOVE_DIRECTION_UP:
return playfield_index_move_up(get_current_position());
}
}

unsigned int get_back() {
switch (get_cur_dir()) {
case MOVE_DIRECTION_RIGHT:
return playfield_index_move_left(get_current_position());
case MOVE_DIRECTION_LEFT:
return playfield_index_move_right(get_current_position());
case MOVE_DIRECTION_DOWN:
return playfield_index_move_up(get_current_position());
case MOVE_DIRECTION_UP:
return playfield_index_move_down(get_current_position());
}
}

unsigned int get_right() {
switch (get_cur_dir()) {
case MOVE_DIRECTION_RIGHT:
return playfield_index_move_down(get_current_position());
case MOVE_DIRECTION_LEFT:
return playfield_index_move_up(get_current_position());
case MOVE_DIRECTION_DOWN:
return playfield_index_move_left(get_current_position());
case MOVE_DIRECTION_UP:
return playfield_index_move_right(get_current_position());
}
}

unsigned int get_left() {
switch (get_cur_dir()) {
case MOVE_DIRECTION_RIGHT:
return playfield_index_move_up(get_current_position());
case MOVE_DIRECTION_LEFT:
return playfield_index_move_down(get_current_position());
case MOVE_DIRECTION_DOWN:
return playfield_index_move_right(get_current_position());
case MOVE_DIRECTION_UP:
return playfield_index_move_left(get_current_position());
}
}

unsigned int get_front_left() {
switch (get_cur_dir()) {
case MOVE_DIRECTION_RIGHT:
return playfield_index_move_right(
playfield_index_move_up(get_current_position()));
case MOVE_DIRECTION_LEFT:
return playfield_index_move_left(
playfield_index_move_down(get_current_position()));
case MOVE_DIRECTION_DOWN:
return playfield_index_move_down(
playfield_index_move_right(get_current_position()));
case MOVE_DIRECTION_UP:
return playfield_index_move_up(
playfield_index_move_left(get_current_position()));
}
}

unsigned int get_back_left() {
switch (get_cur_dir()) {
case MOVE_DIRECTION_RIGHT:
return playfield_index_move_left(
playfield_index_move_up(get_current_position()));
case MOVE_DIRECTION_LEFT:
return playfield_index_move_right(
playfield_index_move_down(get_current_position()));
case MOVE_DIRECTION_DOWN:
return playfield_index_move_up(
playfield_index_move_right(get_current_position()));
case MOVE_DIRECTION_UP:
return playfield_index_move_down(
playfield_index_move_left(get_current_position()));
}
}

void compute_playfield_mark_bit_one_ball(unsigned char ball_index) {
// Set cur to starting playfield tile
set_current_position(balls[ball_index].nearest_playfield_tile);
Expand Down
65 changes: 62 additions & 3 deletions src/flood_fill.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#define playfield_index_move_left(i) ((i)-1)
#define playfield_index_move_right(i) ((i) + 1)

#define playfield_index_move_right_up(i) ((i)-31)
#define playfield_index_move_left_down(i) ((i) + 31)
#define playfield_index_move_left_up(i) ((i)-33)
#define playfield_index_move_right_down(i) ((i) + 33)

#define inside(i) \
((playfield[(i)] & (PLAYFIELD_WALL | PLAYFIELD_BITMASK_MARK)) == 0)

Expand All @@ -23,21 +28,21 @@ enum {
MOVE_DIRECTION_DEFAULT = MOVE_DIRECTION_RIGHT
};

unsigned char reverse_direction_table[] = {
const unsigned char reverse_direction_table[] = {
MOVE_DIRECTION_LEFT,
MOVE_DIRECTION_UP,
MOVE_DIRECTION_RIGHT,
MOVE_DIRECTION_DOWN,
};

unsigned char turn_right_table[] = {
const unsigned char turn_right_table[] = {
MOVE_DIRECTION_DOWN,
MOVE_DIRECTION_LEFT,
MOVE_DIRECTION_UP,
MOVE_DIRECTION_RIGHT,
};

unsigned char turn_left_table[] = {
const unsigned char turn_left_table[] = {
MOVE_DIRECTION_UP,
MOVE_DIRECTION_RIGHT,
MOVE_DIRECTION_DOWN,
Expand Down Expand Up @@ -78,6 +83,60 @@ unsigned char turn_left_table[] = {
#define turn_left() (set_cur_dir(turn_left_table[get_cur_dir()]))
#define move_forward() (set_current_position(get_front()))

#define get_front() \
(get_cur_dir() == MOVE_DIRECTION_RIGHT \
? playfield_index_move_right(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_LEFT \
? playfield_index_move_left(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_DOWN \
? playfield_index_move_down(get_current_position()) \
: playfield_index_move_up(get_current_position()))

#define get_back() \
(get_cur_dir() == MOVE_DIRECTION_RIGHT \
? playfield_index_move_left(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_LEFT \
? playfield_index_move_right(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_DOWN \
? playfield_index_move_up(get_current_position()) \
: playfield_index_move_down(get_current_position()))

#define get_right() \
(get_cur_dir() == MOVE_DIRECTION_RIGHT \
? playfield_index_move_down(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_LEFT \
? playfield_index_move_up(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_DOWN \
? playfield_index_move_left(get_current_position()) \
: playfield_index_move_right(get_current_position()))

#define get_left() \
(get_cur_dir() == MOVE_DIRECTION_RIGHT \
? playfield_index_move_up(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_LEFT \
? playfield_index_move_down(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_DOWN \
? playfield_index_move_right(get_current_position()) \
: playfield_index_move_left(get_current_position()))

#define get_front_left() \
(get_cur_dir() == MOVE_DIRECTION_RIGHT \
? playfield_index_move_right_up(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_LEFT \
? playfield_index_move_left_down(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_DOWN \
? playfield_index_move_right_down(get_current_position()) \
: playfield_index_move_left_up(get_current_position()))

#define get_back_left() \
(get_cur_dir() == MOVE_DIRECTION_RIGHT \
? playfield_index_move_left_up(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_LEFT \
? playfield_index_move_right_down(get_current_position()) \
: get_cur_dir() == MOVE_DIRECTION_DOWN \
? playfield_index_move_right_up(get_current_position()) \
: playfield_index_move_left_down(get_current_position()))

// Uses a constant-memory usage implementation of the painters algorithm to
// walk the playfield starting at the playfield tile where |ball_index| is
// currently located. Each reachable playfield tile is marked until we run
Expand Down

0 comments on commit b11c89a

Please sign in to comment.