write constants VX, VY, to make vector component selection more readable

This commit is contained in:
2025-06-26 11:48:15 +02:00
parent 390ca02172
commit 0f4c9411b0
3 changed files with 11 additions and 8 deletions

View File

@@ -78,8 +78,8 @@ static int shape_intersects(u8* restrict const* restrict const rows, u8 const id
for (int x0 = 0; x0 < SHAPE_WIDTH; x0++) { for (int x0 = 0; x0 < SHAPE_WIDTH; x0++) {
if (shape_is_set(shape_row, x0) == false) continue; // if the bit isn't set at this index; continue if (shape_is_set(shape_row, x0) == false) continue; // if the bit isn't set at this index; continue
int x1 = pos[0] + x0; int x1 = pos[VX] + x0;
int y1 = pos[1] + y0; int y1 = pos[VY] + y0;
if (x1 < 0 || x1 >= COLUMNS) return 1; // if X is out of bounds if (x1 < 0 || x1 >= COLUMNS) return 1; // if X is out of bounds
if (y1 < 0 || y1 >= ROWS) return 1; // if Y is out of bounds if (y1 < 0 || y1 >= ROWS) return 1; // if Y is out of bounds
@@ -97,9 +97,9 @@ void place_update(struct gamedata* gdat, int movdat) {
// set the shape if we moved vertically and intersected // set the shape if we moved vertically and intersected
if (movdat & MOVD) { if (movdat & MOVD) {
i8 y = gdat->pdat.sel[1] + 1; i8 y = gdat->pdat.sel[VY] + 1;
if (shape_intersects(gdat->rows, id, gdat->pdat.sel)) { if (shape_intersects(gdat->rows, id, gdat->pdat.sel)) {
set_shape(gdat->rows + gdat->pdat.sel[1], id, gdat->pdat.sel[0]); // if the shape intersects vertically, write the shape at the current position and return set_shape(gdat->rows + gdat->pdat.sel[VY], id, gdat->pdat.sel[VX]); // if the shape intersects vertically, write the shape at the current position and return
clear_rows(gdat->rows, &gdat->pnts); // clear the rows that have been completed clear_rows(gdat->rows, &gdat->pnts); // clear the rows that have been completed
// TODO: play place_sfx // TODO: play place_sfx
@@ -111,13 +111,13 @@ void place_update(struct gamedata* gdat, int movdat) {
} }
// otherwise, just set Y // otherwise, just set Y
gdat->pdat.sel[1] = y; gdat->pdat.sel[VY] = y;
} }
} }
// update X axis // update X axis
tmp = !!(movdat & MOVR) - !!(movdat & MOVL); tmp = !!(movdat & MOVR) - !!(movdat & MOVL);
gdat->pdat.sel[0] += (tmp && !shape_intersects(gdat->rows, id, gdat->pdat.sel + (i8vec2){tmp, 0})) * tmp; gdat->pdat.sel[VX] += (tmp && !shape_intersects(gdat->rows, id, gdat->pdat.sel + (i8vec2){tmp, 0})) * tmp;
// update roll // update roll
tmp = id ^ (((!!(movdat & MOVRR) - !!(movdat & MOVRL)) * 8 + id) & 31); tmp = id ^ (((!!(movdat & MOVRR) - !!(movdat & MOVRL)) * 8 + id) & 31);

View File

@@ -85,7 +85,7 @@ static void draw_shape(u8 const id, i8vec2 pos) {
for (int8_t x = 0; x < SHAPE_WIDTH; x++) for (int8_t x = 0; x < SHAPE_WIDTH; x++)
if (shape_is_set(shape_row, x)) if (shape_is_set(shape_row, x))
draw_block(rend, pos[0] + x, pos[1] + y); draw_block(rend, pos[VX] + x, pos[VY] + y);
} }
} }

View File

@@ -2,4 +2,7 @@
#include <stdint.h> #include <stdint.h>
#define VX 0
#define VY 1
typedef int8_t i8vec2 __attribute__((vector_size(4))); typedef int8_t i8vec2 __attribute__((vector_size(4)));