Apply loop shorthand macros (#17159)

This commit is contained in:
Scott Lahteine
2020-03-13 23:18:16 -05:00
committed by GitHub
parent a96be32fae
commit 118bd2f8b2
93 changed files with 465 additions and 505 deletions

View File

@ -140,13 +140,13 @@ void BrickoutGame::game_screen() {
// Draw bricks
if (PAGE_CONTAINS(BRICK_TOP, BRICK_BOT)) {
for (uint8_t y = 0; y < BRICK_ROWS; ++y) {
LOOP_L_N(y, BRICK_ROWS) {
const uint8_t yy = y * BRICK_H + BRICK_TOP;
if (PAGE_CONTAINS(yy, yy + BRICK_H - 1)) {
for (uint8_t x = 0; x < BRICK_COLS; ++x) {
LOOP_L_N(x, BRICK_COLS) {
if (TEST(bdat.bricks[y], x)) {
const uint8_t xx = x * BRICK_W;
for (uint8_t v = 0; v < BRICK_H - 1; ++v)
LOOP_L_N(v, BRICK_H - 1)
if (PAGE_CONTAINS(yy + v, yy + v))
u8g.drawHLine(xx, yy + v, BRICK_W - 1);
}

View File

@ -170,7 +170,7 @@ inline void update_invader_data() {
uint8_t m = idat.bugs[y];
if (m) idat.botmost = y + 1;
inv_mask |= m;
for (uint8_t x = 0; x < INVADER_COLS; ++x)
LOOP_L_N(x, INVADER_COLS)
if (TEST(m, x)) idat.shooters[sc++] = (y << 4) | x;
}
idat.leftmost = 0;
@ -371,11 +371,11 @@ void InvadersGame::game_screen() {
// Draw invaders
if (PAGE_CONTAINS(idat.pos.y, idat.pos.y + idat.botmost * (INVADER_ROW_H) - 2 - 1)) {
int8_t yy = idat.pos.y;
for (uint8_t y = 0; y < INVADER_ROWS; ++y) {
LOOP_L_N(y, INVADER_ROWS) {
const uint8_t type = inv_type[y];
if (PAGE_CONTAINS(yy, yy + INVADER_H - 1)) {
int8_t xx = idat.pos.x;
for (uint8_t x = 0; x < INVADER_COLS; ++x) {
LOOP_L_N(x, INVADER_COLS) {
if (TEST(idat.bugs[y], x))
u8g.drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]);
xx += INVADER_COL_W;

View File

@ -83,7 +83,7 @@ void MazeGame::game_screen() {
if (PAGE_UNDER(HEADER_H)) lcd_put_int(0, HEADER_H - 1, score);
// Draw the maze
// for (uint8_t n = 0; n < head_ind; ++n) {
// LOOP_L_N(n, head_ind) {
// const pos_t &p = maze_walls[n], &q = maze_walls[n + 1];
// if (p.x == q.x) {
// const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));

View File

@ -84,14 +84,14 @@ void shorten_tail() {
}
if (shift) {
sdat.head_ind--;
for (uint8_t i = 0; i <= sdat.head_ind; ++i)
LOOP_LE_N(i, sdat.head_ind)
sdat.snake_tail[i] = sdat.snake_tail[i + 1];
}
}
// The food is on a line
inline bool food_on_line() {
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
if ((sdat.foodx == p.x - 1 || sdat.foodx == p.x) && WITHIN(sdat.foody, _MIN(p.y, q.y), _MAX(p.y, q.y)))
@ -151,7 +151,7 @@ bool snake_overlap() {
// VERTICAL head segment?
if (h1.x == h2.x) {
// Loop from oldest to segment two away from head
for (uint8_t n = 0; n < sdat.head_ind - 2; ++n) {
LOOP_L_N(n, sdat.head_ind - 2) {
// Segment p to q
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x != q.x) {
@ -163,7 +163,7 @@ bool snake_overlap() {
}
else {
// Loop from oldest to segment two away from head
for (uint8_t n = 0; n < sdat.head_ind - 2; ++n) {
LOOP_L_N(n, sdat.head_ind - 2) {
// Segment p to q
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.y != q.y) {
@ -240,7 +240,7 @@ void SnakeGame::game_screen() {
#if SNAKE_WH < 2
// At this scale just draw a line
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));
@ -256,7 +256,7 @@ void SnakeGame::game_screen() {
#elif SNAKE_WH == 2
// At this scale draw two lines
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));
@ -275,7 +275,7 @@ void SnakeGame::game_screen() {
#else
// Draw a series of boxes
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
const int8_t y1 = _MIN(p.y, q.y), y2 = _MAX(p.y, q.y);