differentiate between out-of-bounds intersection and regular intersection.

This commit is contained in:
2025-09-10 09:56:37 +02:00
parent a827c84223
commit baf680ee3c
2 changed files with 4 additions and 3 deletions

View File

@@ -63,8 +63,8 @@ int tetris_intersect(const u8 *restrict const *restrict rows, u8 tetromino, uint
uint *end = pos + 8; uint *end = pos + 8;
tetris_get_blocks(tetromino, pos); tetris_get_blocks(tetromino, pos);
for (; pos < end; pos += 2) { for (; pos < end; pos += 2) {
if (*(pos + 0) >= TET_WIDTH) break; if (*(pos + 0) >= TET_WIDTH) return 2;
if (*(pos + 1) >= TET_HEIGHT) break; if (*(pos + 1) >= TET_HEIGHT) return 2;
if (rows[*(pos + 1)][*pos]) break; if (rows[*(pos + 1)][*pos]) break;
} }
return pos < end; return pos < end;

View File

@@ -50,7 +50,8 @@ void tetris_init_rows(const u8 *restrict data, const u8 *restrict *restrict out)
* Returns the amount of rows cleared. */ * Returns the amount of rows cleared. */
int tetris_clear_rows(u8 *restrict *restrict rows) NONNULL((1)); int tetris_clear_rows(u8 *restrict *restrict rows) NONNULL((1));
/* Checks if `tetromino` intersects at (`x`, `y`) in `rows`, returns `1` if so, `0` if not. */ /* Checks if `tetromino` intersects at (`x`, `y`) in the data within `rows` or is out-of-bounds,
* returns `1` if it overlaps within `rows`, `2` if it is out-of-bounds, `0` if no intersection is found. */
int tetris_intersect(const u8 *restrict const *restrict rows, u8 tetromino, uint x, uint y) NONNULL((1)); int tetris_intersect(const u8 *restrict const *restrict rows, u8 tetromino, uint x, uint y) NONNULL((1));
/* Writes the blocks of `tetromino` to `rows` at position `x` and `y`. */ /* Writes the blocks of `tetromino` to `rows` at position `x` and `y`. */