mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 14:05:45 +01:00
fix pedantic warnings
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
#include "game.h"
|
||||
|
||||
#include <SDL_scancode.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../main.h"
|
||||
#include "../window/colour.h"
|
||||
#include "shapes.h"
|
||||
|
||||
|
||||
@@ -38,7 +40,7 @@ static void clear_rows(Row* row) {
|
||||
}
|
||||
|
||||
// sets a shape to the screen
|
||||
static void _set_shape(Row* row, const Shape shape, const Colour colour, const uint8_t pos_x) {
|
||||
static void set_shape_i(Row* row, const Shape shape, const Colour colour, const uint8_t pos_x) {
|
||||
for (uint8_t y = 0; y < SHAPE_HEIGHT; y++) {
|
||||
ShapeRow shape_row = shape_get_row(shape, y);
|
||||
|
||||
@@ -52,11 +54,11 @@ static void _set_shape(Row* row, const Shape shape, const Colour colour, const u
|
||||
}
|
||||
|
||||
static inline void set_shape(Row* row, const Shape shape, const Colour colour, const uint8_t pos_x, const uint8_t pos_y) {
|
||||
_set_shape(&row[pos_y], shape, colour, pos_x); // calls itself, but omitting the pos_y argument, instead opting for specifying the row
|
||||
set_shape_i(&row[pos_y], shape, colour, pos_x); // calls itself, but omitting the pos_y argument, instead opting for specifying the row
|
||||
}
|
||||
|
||||
// called every time the game's state is updated
|
||||
void game_update(GameData* game_data, const Uint8* keys) {
|
||||
void game_update(GameData* game_data, const uint8_t* keys) {
|
||||
if (keys[SDL_SCANCODE_ESCAPE]) {
|
||||
stop();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../window/colour.h"
|
||||
|
||||
@@ -7,7 +8,7 @@ typedef uint32_t PackedRow;
|
||||
|
||||
// stores the data used in the game
|
||||
#define COLUMNS ((uint8_t)(sizeof(PackedRow) * 8 / 3))
|
||||
#define ROWS ((uint8_t)(COLUMNS * 2))
|
||||
#define ROWS ((uint8_t)(COLUMNS * 2))
|
||||
|
||||
typedef struct {
|
||||
Colour columns[COLUMNS];
|
||||
@@ -18,4 +19,4 @@ typedef struct {
|
||||
} GameData;
|
||||
|
||||
// updates the game's state
|
||||
void game_update(GameData* game_data, const Uint8* keys);
|
||||
void game_update(GameData* game_data, const uint8_t* keys);
|
||||
|
||||
@@ -1,36 +1,40 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../util/typed_enums.h"
|
||||
|
||||
#define SHAPE_WIDTH 4
|
||||
#define SHAPE_HEIGHT 4
|
||||
|
||||
|
||||
typedef enum : uint16_t {
|
||||
typedef enum_t(uint16_t){
|
||||
// clang-format off
|
||||
/* 0 1 2 3 */
|
||||
TETROMINO_I = 0b1000100010001000, // 1000 1000 1000 1000 the I tetromino with no rotation
|
||||
TETROMINO_I_90 = 0b0000000000001111, // 0000 0000 0000 1111 the I tetromino with a no rotation
|
||||
TETROMINO_O = 0b1100110000000000, // 1100 1100 0000 0000 the O tetromino with no rotation
|
||||
TETROMINO_T = 0b1110010000000000, // 1110 0100 0000 0000 the T tetromino with no rotation
|
||||
TETROMINO_T_90 = 0b1100110010000000, // 1100 1100 1000 0000 the T tetromino with a no rotation
|
||||
TETROMINO_T_180 = 0b0100111000000000, // 0100 1110 0000 0000 the T tetromino with a 180° rotation
|
||||
TETROMINO_T_270 = 0b0010011000100000, // 0010 0110 0010 0000 the T tetromino with a 270° rotation
|
||||
TETROMINO_L = 0b1000100011000000, // 1000 1000 1100 0000 the L tetromino with no rotation
|
||||
TETROMINO_L_90 = 0b1110100000000000, // 1110 1000 0000 0000 the L tetromino with a no rotation
|
||||
TETROMINO_L_180 = 0b1100010001000000, // 1100 0100 0100 0000 the L tetromino with a 180° rotation
|
||||
TETROMINO_L_270 = 0b0000001011100000, // 0000 0010 1110 0000 the L tetromino with a 270° rotation
|
||||
TETROMINO_J = 0b0100010011000000, // 0100 0100 1100 0000 the J tetromino with no rotation
|
||||
TETROMINO_J_90 = 0b1000111000000000, // 1000 1110 0000 0000 the J tetromino with a no rotation
|
||||
TETROMINO_J_180 = 0b1100100010000000, // 1100 1000 1000 0000 the J tetromino with a 180° rotation
|
||||
TETROMINO_J_270 = 0b1110001000000000, // 1110 0010 0000 0000 the J tetromino with a 270° rotation
|
||||
TETROMINO_S = 0b0110110000000000, // 0110 1100 0000 0000 the S tetromino with no rotation
|
||||
TETROMINO_S_90 = 0b1000110001000000, // 1000 1100 0100 0000 the S tetromino with a no rotation
|
||||
TETROMINO_Z = 0b1100011000000000, // 1100 0110 0000 0000 the Z tetromino with no rotation
|
||||
TETROMINO_Z_90 = 0b0100110010000000, // 0100 1100 1000 0000 the Z tetromino with a no rotation
|
||||
/* 0 1 2 3 */
|
||||
TETROMINO_I = 0x8888, // 1000 1000 1000 1000 the I tetromino with no rotation
|
||||
TETROMINO_I_90 = 0x000F, // 0000 0000 0000 1111 the I tetromino with a no rotation
|
||||
TETROMINO_O = 0xCC00, // 1100 1100 0000 0000 the O tetromino with no rotation
|
||||
TETROMINO_T = 0xE400, // 1110 0100 0000 0000 the T tetromino with no rotation
|
||||
TETROMINO_T_90 = 0xCC80, // 1100 1100 1000 0000 the T tetromino with a no rotation
|
||||
TETROMINO_T_180 = 0x4E00, // 0100 1110 0000 0000 the T tetromino with a 180° rotation
|
||||
TETROMINO_T_270 = 0x2620, // 0010 0110 0010 0000 the T tetromino with a 270° rotation
|
||||
TETROMINO_L = 0x88C0, // 1000 1000 1100 0000 the L tetromino with no rotation
|
||||
TETROMINO_L_90 = 0xE800, // 1110 1000 0000 0000 the L tetromino with a no rotation
|
||||
TETROMINO_L_180 = 0xC440, // 1100 0100 0100 0000 the L tetromino with a 180° rotation
|
||||
TETROMINO_L_270 = 0x02E0, // 0000 0010 1110 0000 the L tetromino with a 270° rotation
|
||||
TETROMINO_J = 0x44C0, // 0100 0100 1100 0000 the J tetromino with no rotation
|
||||
TETROMINO_J_90 = 0x8E00, // 1000 1110 0000 0000 the J tetromino with a no rotation
|
||||
TETROMINO_J_180 = 0xC880, // 1100 1000 1000 0000 the J tetromino with a 180° rotation
|
||||
TETROMINO_J_270 = 0xC400, // 1110 0010 0000 0000 the J tetromino with a 270° rotation
|
||||
TETROMINO_S = 0x6C00, // 0110 1100 0000 0000 the S tetromino with no rotation
|
||||
TETROMINO_S_90 = 0x8C40, // 1000 1100 0100 0000 the S tetromino with a no rotation
|
||||
TETROMINO_Z = 0xC600, // 1100 0110 0000 0000 the Z tetromino with no rotation
|
||||
TETROMINO_Z_90 = 0x4C80, // 0100 1100 1000 0000 the Z tetromino with a no rotation
|
||||
// clang-format on
|
||||
} Shape;
|
||||
typedef uint8_t ShapeRow;
|
||||
|
||||
static inline ShapeRow shape_get_row(Shape shape, uint8_t index) {
|
||||
return shape >> (((SHAPE_HEIGHT - 1) - index) * 4) & 0b1111;
|
||||
return shape >> (((SHAPE_HEIGHT - 1) - index) * 4) & 0xF;
|
||||
}
|
||||
|
||||
static inline _Bool is_set(ShapeRow row, uint8_t index) {
|
||||
|
||||
Reference in New Issue
Block a user