mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
remove the lookup table / binary-encoded logic.
This commit is contained in:
@@ -4,39 +4,6 @@
|
|||||||
#include "../../util/types.h"
|
#include "../../util/types.h"
|
||||||
#include "../../util/vec.h"
|
#include "../../util/vec.h"
|
||||||
|
|
||||||
/* 0 1 2 3 */
|
|
||||||
#define SHAPE_O ((u16)0x0660) // 0000 0110 0110 0000 the O tetromino with no rotation
|
|
||||||
|
|
||||||
#define SHAPE_I ((u16)0x0F00) // 0000 1111 0000 0000 the I tetromino with no rotation
|
|
||||||
#define SHAPE_I_90 ((u16)0x2222) // 0010 0010 0010 0010 the I tetromino with a 90° rotation
|
|
||||||
#define SHAPE_I_180 ((u16)0x00F0) // 0000 0000 1111 0000 the I tetromino with a 180° rotation
|
|
||||||
#define SHAPE_I_270 ((u16)0x4444) // 0100 0100 0100 0100 the I tetromino with a 270° rotation
|
|
||||||
|
|
||||||
#define SHAPE_S ((u16)0x6C00) // 0110 1100 0000 0000 the S tetromino with no rotation
|
|
||||||
#define SHAPE_S_90 ((u16)0x4620) // 0100 0110 0010 0000 the S tetromino with a 90° rotation
|
|
||||||
#define SHAPE_S_180 ((u16)0x06C0) // 0000 0110 1100 0000 the S tetromino with a 180° rotation
|
|
||||||
#define SHAPE_S_270 ((u16)0x8C40) // 1000 1100 0100 0000 the S tetromino with a 270° rotation
|
|
||||||
|
|
||||||
#define SHAPE_Z ((u16)0xC600) // 1100 0110 0000 0000 the Z tetromino with no rotation
|
|
||||||
#define SHAPE_Z_90 ((u16)0x2640) // 0010 0110 0100 0000 the Z tetromino with a 90° rotation
|
|
||||||
#define SHAPE_Z_180 ((u16)0x0C60) // 0000 1100 0110 0000 the Z tetromino with a 180° rotation
|
|
||||||
#define SHAPE_Z_270 ((u16)0x4C80) // 0100 1100 1000 0000 the Z tetromino with a 270° rotation
|
|
||||||
|
|
||||||
#define SHAPE_T ((u16)0x0E40) // 0000 1110 0100 0000 the T tetromino with no rotation
|
|
||||||
#define SHAPE_T_90 ((u16)0x4C40) // 0100 1100 0100 0000 the T tetromino with a 90° rotation
|
|
||||||
#define SHAPE_T_180 ((u16)0x4E00) // 0100 1110 0000 0000 the T tetromino with a 180° rotation
|
|
||||||
#define SHAPE_T_270 ((u16)0x4640) // 0100 0110 0100 0000 the T tetromino with a 270° rotation
|
|
||||||
|
|
||||||
#define SHAPE_L ((u16)0x4460) // 0100 0100 0110 0000 the L tetromino with no rotation
|
|
||||||
#define SHAPE_L_90 ((u16)0x0E80) // 0000 1110 1000 0000 the L tetromino with a 90° rotation
|
|
||||||
#define SHAPE_L_180 ((u16)0xC440) // 1100 0100 0100 0000 the L tetromino with a 180° rotation
|
|
||||||
#define SHAPE_L_270 ((u16)0x2E00) // 0010 1110 0000 0000 the L tetromino with a 270° rotation
|
|
||||||
|
|
||||||
#define SHAPE_J ((u16)0x44C0) // 0100 0100 1100 0000 the J tetromino with no rotation
|
|
||||||
#define SHAPE_J_90 ((u16)0x8E00) // 1000 1110 0000 0000 the J tetromino with a 90° rotation
|
|
||||||
#define SHAPE_J_180 ((u16)0x6440) // 0110 0100 0100 0000 the J tetromino with a 180° rotation
|
|
||||||
#define SHAPE_J_270 ((u16)0x0E20) // 0000 1110 0010 0000 the J tetromino with a 270° rotation
|
|
||||||
|
|
||||||
void shape_getblocks(u8 id, i8vec2* restrict out) {
|
void shape_getblocks(u8 id, i8vec2* restrict out) {
|
||||||
struct blockdat {
|
struct blockdat {
|
||||||
u8 ax : 2, ay : 2;
|
u8 ax : 2, ay : 2;
|
||||||
@@ -95,22 +62,6 @@ void shape_getblocks(u8 id, i8vec2* restrict out) {
|
|||||||
out[3] = (i8vec2){dat.dx, dat.dy};
|
out[3] = (i8vec2){dat.dx, dat.dy};
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 shape_from_id(u8 id) {
|
|
||||||
static u16 const shapes[TETROMINO_COUNT][4] = {
|
|
||||||
// 0° 90° 180° 170°
|
|
||||||
{SHAPE_O, SHAPE_O, SHAPE_O, SHAPE_O},
|
|
||||||
{SHAPE_I, SHAPE_I_90, SHAPE_I_180, SHAPE_I_270},
|
|
||||||
{SHAPE_S, SHAPE_S_90, SHAPE_S_180, SHAPE_S_270},
|
|
||||||
{SHAPE_Z, SHAPE_Z_90, SHAPE_Z_180, SHAPE_Z_270},
|
|
||||||
{SHAPE_T, SHAPE_T_90, SHAPE_T_180, SHAPE_T_270},
|
|
||||||
{SHAPE_L, SHAPE_L_90, SHAPE_L_180, SHAPE_L_270},
|
|
||||||
{SHAPE_J, SHAPE_J_90, SHAPE_J_180, SHAPE_J_270},
|
|
||||||
};
|
|
||||||
|
|
||||||
// first 3 least significant bits is the shape type, the rest is rotation data
|
|
||||||
return shapes[id & 7][id >> 3];
|
|
||||||
}
|
|
||||||
|
|
||||||
colour8 colour_from_id(u8 id) {
|
colour8 colour_from_id(u8 id) {
|
||||||
switch (id & 7) {
|
switch (id & 7) {
|
||||||
case TETROMINO_O: return COLOUR8_YELLOW;
|
case TETROMINO_O: return COLOUR8_YELLOW;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/cdefs.h>
|
|
||||||
|
|
||||||
#include "../../io/colour/colour8.h"
|
#include "../../io/colour/colour8.h"
|
||||||
#include "../../util/types.h"
|
#include "../../util/types.h"
|
||||||
@@ -25,14 +24,5 @@ enum {
|
|||||||
#define SHAPE_HEIGHT 4
|
#define SHAPE_HEIGHT 4
|
||||||
#define TETROMINO_COUNT 7
|
#define TETROMINO_COUNT 7
|
||||||
|
|
||||||
static inline u8 shape_get_row(u16 shape, u8 index) __attribute_deprecated_msg__("switching to a logic-based tetromino storage") {
|
|
||||||
return shape >> (((SHAPE_HEIGHT - 1) - index) * SHAPE_WIDTH) & 0xF;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool shape_is_set(u8 row, u8 index) __attribute_deprecated_msg__("switching to a logic-based tetromino storage") {
|
|
||||||
return (row >> ((SHAPE_WIDTH - 1) - index) & 1) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void shape_getblocks(u8 id, i8vec2* out);
|
void shape_getblocks(u8 id, i8vec2* out);
|
||||||
u16 shape_from_id(u8 id) __attribute_deprecated_msg__("switching to a logic-based tetromino storage");
|
|
||||||
colour8 colour_from_id(u8 id);
|
colour8 colour_from_id(u8 id);
|
||||||
|
|||||||
Reference in New Issue
Block a user