rename Colour8 to colour8

This commit is contained in:
2025-02-10 11:58:00 +01:00
parent 94ff2d200a
commit 94ca7e3d08
7 changed files with 20 additions and 20 deletions

View File

@@ -48,7 +48,7 @@ void game_init(GameData* const game_data) {
// allocate size for each row // allocate size for each row
for (int8_t i = 0; i < ROWS; i++) { for (int8_t i = 0; i < ROWS; i++) {
game_data->rows[i] = calloc(COLUMNS, sizeof(Colour8)); game_data->rows[i] = calloc(COLUMNS, sizeof(colour8));
// game_data->rows[i][0] = (colour8){(uint8_t)((((i + 1) ^ ((i + 1) >> 3)) * 0x27) & 0xFF)}; // for debugging rows // game_data->rows[i][0] = (colour8){(uint8_t)((((i + 1) ^ ((i + 1) >> 3)) * 0x27) & 0xFF)}; // for debugging rows
} }

View File

@@ -10,8 +10,8 @@
#define COLUMNS ((int8_t)10) #define COLUMNS ((int8_t)10)
#define ROWS ((int8_t)24) #define ROWS ((int8_t)24)
typedef const Colour8* const CRow; typedef const colour8* const CRow;
typedef Colour8* Row; typedef colour8* Row;
typedef struct { typedef struct {
Row rows[ROWS]; Row rows[ROWS];

View File

@@ -59,7 +59,7 @@ static void clear_rows(Row* const rows, uint16_t* const score) {
// sets a shape to the screen // sets a shape to the screen
static void set_shape_i(Row const* const row, ShapeId const id, int8_t const pos_x) { static void set_shape_i(Row const* const row, ShapeId const id, int8_t const pos_x) {
Shape const shape = shape_from_id(id); Shape const shape = shape_from_id(id);
Colour8 const colour = colour_from_id(id); colour8 const colour = colour_from_id(id);
for (int8_t y = 0; y < SHAPE_HEIGHT; y++) { for (int8_t y = 0; y < SHAPE_HEIGHT; y++) {
ShapeRow const shape_row = shape_get_row(shape, y); ShapeRow const shape_row = shape_get_row(shape, y);

View File

@@ -53,7 +53,7 @@ Shape shape_from_id(ShapeId const id) {
return shapes[id & 7][id >> 3]; return shapes[id & 7][id >> 3];
} }
Colour8 colour_from_id(ShapeId const id) { colour8 colour_from_id(ShapeId const id) {
switch (id & 7) { switch (id & 7) {
case TETROMINO_O: return COLOUR_YELLOW; case TETROMINO_O: return COLOUR_YELLOW;
case TETROMINO_I: return COLOUR_CYAN; case TETROMINO_I: return COLOUR_CYAN;

View File

@@ -36,4 +36,4 @@ static inline bool is_set(ShapeRow const row, uint8_t const index) {
} }
Shape shape_from_id(ShapeId id); Shape shape_from_id(ShapeId id);
Colour8 colour_from_id(ShapeId id); colour8 colour_from_id(ShapeId id);

View File

@@ -9,30 +9,30 @@ typedef union {
uint8_t g : 3; uint8_t g : 3;
uint8_t r : 3; uint8_t r : 3;
}; };
} Colour8; } colour8;
/* rrrg ggbb */ /* rrrg ggbb */
#define COLOUR_BLACK ((Colour8){0x00}) // 0000 0000 #define COLOUR_BLACK ((colour8){0x00}) // 0000 0000
#define COLOUR_RED ((Colour8){0xE0}) // 1110 0000 #define COLOUR_RED ((colour8){0xE0}) // 1110 0000
#define COLOUR_YELLOW ((Colour8){0xFC}) // 1111 1100 #define COLOUR_YELLOW ((colour8){0xFC}) // 1111 1100
#define COLOUR_ORANGE ((Colour8){0xEC}) // 1111 1100 #define COLOUR_ORANGE ((colour8){0xEC}) // 1111 1100
#define COLOUR_GREEN ((Colour8){0x1C}) // 0001 1100 #define COLOUR_GREEN ((colour8){0x1C}) // 0001 1100
#define COLOUR_CYAN ((Colour8){0x1F}) // 0001 1111 #define COLOUR_CYAN ((colour8){0x1F}) // 0001 1111
#define COLOUR_BLUE ((Colour8){0x03}) // 0000 0011 #define COLOUR_BLUE ((colour8){0x03}) // 0000 0011
#define COLOUR_MAGENTA ((Colour8){0xE3}) // 1110 0011 #define COLOUR_MAGENTA ((colour8){0xE3}) // 1110 0011
#define COLOUR_WHITE ((Colour8){0xFF}) // 1111 1111 #define COLOUR_WHITE ((colour8){0xFF}) // 1111 1111
// gets the red channel in 32 bit colour space // gets the red channel in 32 bit colour space
static inline uint8_t colour8_red32(Colour8 const colour) { static inline uint8_t colour8_red32(colour8 const colour) {
return colour.r * (255 / 7); return colour.r * (255 / 7);
} }
// gets the green channel in 32 bit colour space // gets the green channel in 32 bit colour space
static inline uint8_t colour8_green32(Colour8 const colour) { static inline uint8_t colour8_green32(colour8 const colour) {
return colour.g * (255 / 7); return colour.g * (255 / 7);
} }
// gets the blue channel in 32 bit colour space // gets the blue channel in 32 bit colour space
static inline uint8_t colour8_blue32(Colour8 const colour) { static inline uint8_t colour8_blue32(colour8 const colour) {
return colour.b * (255 / 3); return colour.b * (255 / 3);
} }

View File

@@ -69,7 +69,7 @@ static inline int draw_block(SDL_Renderer* const renderer, int8_t const x, int8_
} }
// sets the colour32 from the colour8 // sets the colour32 from the colour8
static inline void set_colour(SDL_Renderer* const renderer, Colour8 const c) { static inline void set_colour(SDL_Renderer* const renderer, colour8 const c) {
(void)SDL_SetRenderDrawColor(renderer, colour8_red32(c), colour8_green32(c), colour8_blue32(c), 0xFF); (void)SDL_SetRenderDrawColor(renderer, colour8_red32(c), colour8_green32(c), colour8_blue32(c), 0xFF);
} }