mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
add a tad more documentation about how we encode our data.
This commit is contained in:
@@ -75,7 +75,7 @@ void tetris_place(u8 *restrict *restrict rows, u8 tetromino, uint x, uint y) {
|
|||||||
uint *end = pos + 8;
|
uint *end = pos + 8;
|
||||||
tetris_get_blocks(tetromino, pos);
|
tetris_get_blocks(tetromino, pos);
|
||||||
tetromino &= 7; /* strip rotation data */
|
tetromino &= 7; /* strip rotation data */
|
||||||
tetromino |= 0x80; /* set an undefined bit, to signify there is data here. */
|
tetromino |= TET_NON_EMPTY;
|
||||||
for (; pos < end; pos += 2)
|
for (; pos < end; pos += 2)
|
||||||
rows[*(pos + 1)][*pos] = tetromino;
|
rows[*(pos + 1)][*pos] = tetromino;
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/tetris.h
11
src/tetris.h
@@ -6,9 +6,11 @@
|
|||||||
#define TET_WIDTH 10
|
#define TET_WIDTH 10
|
||||||
#define TET_HEIGHT 24 /* height may be 16—24 */
|
#define TET_HEIGHT 24 /* height may be 16—24 */
|
||||||
|
|
||||||
/* Defines tetromino id.
|
/* Defines tetromino indices.
|
||||||
* The `TET_R*` definitions specify various rotations.
|
* The `TET_R*` definitions specify various rotations.
|
||||||
* This is designed to be OR'd with the tetromino shape index. */
|
* This is designed to be OR'd with the tetromino shape index.
|
||||||
|
* Shape index can be obtained via `val & 7`, and rotation index is
|
||||||
|
* obtained via `val >> 3`. */
|
||||||
enum tetromino {
|
enum tetromino {
|
||||||
TET_I = 0x00,
|
TET_I = 0x00,
|
||||||
TET_O = 0x01,
|
TET_O = 0x01,
|
||||||
@@ -21,6 +23,11 @@ enum tetromino {
|
|||||||
TET_R90 = 0x08,
|
TET_R90 = 0x08,
|
||||||
TET_R180 = 0x10,
|
TET_R180 = 0x10,
|
||||||
TET_R270 = 0x18,
|
TET_R270 = 0x18,
|
||||||
|
|
||||||
|
/* Used when storing blocks to the board;
|
||||||
|
* allows to identify non-empty indices from empty ones.
|
||||||
|
* This value should not be used during general computation. */
|
||||||
|
TET_NON_EMPTY = 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Stores the co-ordinates of the four blocks in a 4x4 plane.
|
/* Stores the co-ordinates of the four blocks in a 4x4 plane.
|
||||||
|
|||||||
Reference in New Issue
Block a user