update pointer alignment rule

This commit is contained in:
2025-09-09 16:17:02 +02:00
parent c339accedc
commit cfad7f6fdc
19 changed files with 50 additions and 50 deletions

View File

@@ -13,7 +13,7 @@
#include "../util/types.h"
struct audioplayer {
u8 const* buf;
const u8 *buf;
int len;
};
@@ -25,13 +25,13 @@ static struct audiodevice {
struct audiodata audio_dat[AUDIO_ID_COUNT] = {0}; // contains pointers to audio buffers.
static char const* const audio_path[AUDIO_ID_COUNT] = {
static const char *const audio_path[AUDIO_ID_COUNT] = {
"korobeiniki.wav",
"place.wav",
};
/* mixes the audio output stream, using the different audio as sources */
static void audiomixer(void* const userdata, u8* const stream, int const len) {
static void audiomixer(void *const userdata, u8 *const stream, const int len) {
(void)userdata;
memset(stream, 0, len); // clear the playing audio
@@ -50,7 +50,7 @@ static void audiomixer(void* const userdata, u8* const stream, int const len) {
* `len` is a pointer to the current size, the new size will be written to this location.
* returns the pointer to the audio buffer to use, or NULL, when something went wrong.
* NULL will never be returned after the conversion */
static u8* audio_cvt(SDL_AudioSpec const* spec, u8* bufptr, unsigned* len) {
static u8 *audio_cvt(const SDL_AudioSpec *spec, u8 *bufptr, unsigned *len) {
if (!bufptr) return NULL;
// init the converter
@@ -91,7 +91,7 @@ static inline u32 audio_btoms(u32 len) {
}
/* loads a `struct audiodata` from `fpat` to `out`. */
static void audio_wav_load(char const* restrict fpat, struct audiodata* restrict out) {
static void audio_wav_load(const char *restrict fpat, struct audiodata *restrict out) {
debug("loading audio file '%s'...", fpat);
if (faccess(fpat, FA_R)) {
error("audio file either isn't readable or doesn't exist. path: '%s'!", fpat);
@@ -146,5 +146,5 @@ void audio_free(void) {
dev = (struct audiodevice){0};
for (size_t i = 0; i < AUDIO_ID_COUNT; i++)
free((void*)audio_dat[i].buf);
free((void *)audio_dat[i].buf);
}

View File

@@ -8,7 +8,7 @@
#define AUDIO_MAX 4 // maximum number of sound effects that are allowed to play at once
struct audiodata {
u8 const* buf; // pointer to the audio buffer
const u8 *buf; // pointer to the audio buffer
u32 len; // length in bytes of the audio buffer
u32 ms; // length in miliseconds of the audio buffer
};

View File

@@ -25,7 +25,7 @@ typedef union {
#define COLOUR32_WHITE ((colour32){0xFFFFFFFF})
// sets the render colour to a colour32 value
static inline void set_colour32(SDL_Renderer* const renderer, colour32 const c) {
static inline void set_colour32(SDL_Renderer *const renderer, const colour32 c) {
(void)SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, c.a);
}

View File

@@ -18,22 +18,22 @@ typedef uint8_t colour8;
#define COLOUR8_WHITE ((colour8)0xFF) // 1111 1111
// gets the red channel in 32 bit colour space
static inline uint8_t colour8_red32(colour8 const colour) {
static inline uint8_t colour8_red32(const colour8 colour) {
return (colour >> 5) * (255 / 7);
}
// gets the green channel in 32 bit colour space
static inline uint8_t colour8_green32(colour8 const colour) {
static inline uint8_t colour8_green32(const colour8 colour) {
return ((colour >> 2) & 7) * (255 / 7);
}
// gets the blue channel in 32 bit colour space
static inline uint8_t colour8_blue32(colour8 const colour) {
static inline uint8_t colour8_blue32(const colour8 colour) {
return (colour & 3) * (255 / 3);
}
// sets the render colour to a colour8 value
static inline void set_colour8(SDL_Renderer* const renderer, colour8 const c) {
static inline void set_colour8(SDL_Renderer *const renderer, const colour8 c) {
(void)SDL_SetRenderDrawColor(renderer, colour8_red32(c), colour8_green32(c), colour8_blue32(c), 0xFF);
}

View File

@@ -22,12 +22,12 @@
#define COLOUR_SCORE COLOUR32_YELLOW
SDL_Renderer* rend = NULL;
TTF_Font* font = NULL;
struct gamedata const* gdat = NULL;
SDL_Renderer *rend = NULL;
TTF_Font *font = NULL;
struct gamedata const *gdat = NULL;
static SDL_Surface* score_surface = NULL;
static SDL_Texture* score_texture = NULL;
static SDL_Surface *score_surface = NULL;
static SDL_Texture *score_texture = NULL;
static inline i32 colpos(uint column) {
return column * BLOCK_WIDTH + 1 + TET_PADDING;
@@ -56,12 +56,12 @@ static void draw_score_text(void) {
SDL_RenderCopy(rend, score_texture, NULL, &text_rect);
}
static inline int draw_block(SDL_Renderer* const renderer, i8vec2 pos) {
SDL_Rect const block = {colpos(pos[VX]), rowpos(pos[VY]), BLOCK_WIDTH - 1, BLOCK_HEIGHT - 1};
static inline int draw_block(SDL_Renderer *const renderer, i8vec2 pos) {
const SDL_Rect block = {colpos(pos[VX]), rowpos(pos[VY]), BLOCK_WIDTH - 1, BLOCK_HEIGHT - 1};
return SDL_RenderFillRect(renderer, &block);
}
static void draw_shape(u8 const id, i8vec2 pos) {
static void draw_shape(const u8 id, i8vec2 pos) {
set_colour8(rend, colour_from_id(id));
i8vec2 bpos[4];
shape_getblocks(id, bpos);
@@ -73,7 +73,7 @@ static void draw_shape(u8 const id, i8vec2 pos) {
static void render_level(void) {
for (int y = 0; y < ROWS; y++) {
u8 const* row = gdat->rows[y];
const u8 *row = gdat->rows[y];
for (int x = 0; x < COLUMNS; x++) {
if (row[x] != 0) {
@@ -84,7 +84,7 @@ static void render_level(void) {
}
}
void render_init(SDL_Window* win, struct gamedata const* game_data) {
void render_init(SDL_Window *win, struct gamedata const *game_data) {
rend = SDL_CreateRenderer(win, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
if (rend == NULL) fatal(ERROR_SDL_RENDERING_INIT, "Renderer failed to be created! SDL Error: %s", SDL_GetError());
@@ -99,7 +99,7 @@ void render_update(void) {
SDL_RenderClear(rend);
set_colour32(rend, COLOUR32_WHITE);
static SDL_Rect const field_size = {TET_PADDING, TET_PADDING, TET_WIDTH + 1, TET_HEIGHT + 1};
static const SDL_Rect field_size = {TET_PADDING, TET_PADDING, TET_WIDTH + 1, TET_HEIGHT + 1};
SDL_RenderDrawRect(rend, &field_size);
if (font) draw_score_text();

View File

@@ -15,6 +15,6 @@
#define BLOCK_WIDTH (TET_WIDTH / COLUMNS) // width of a block
#define BLOCK_HEIGHT (TET_HEIGHT / ROWS) // height of a block
__nonnull((1, 2)) void render_init(SDL_Window*, struct gamedata const*);
__nonnull((1, 2)) void render_init(SDL_Window *, struct gamedata const *);
void render_update(void); // causes a draw to occur, will also determine update rate
void render_free(void); // frees the memory allocated to the renderer in render_data

View File

@@ -15,10 +15,10 @@
#include "input.h"
#include "render.h"
static SDL_Window* win = NULL;
static SDL_Window *win = NULL;
static bool close = false;
void window_init(struct gamedata const* gdat) {
void window_init(struct gamedata const *gdat) {
assert(!win && !close);
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
fatal(ERROR_SDL_INIT, "SDL could not initialize! SDL Error: %s", SDL_GetError());

View File

@@ -6,7 +6,7 @@
#define SCREEN_WIDTH ((COLUMNS + 6) * PX_DENS) // window width
#define SCREEN_HEIGHT ((COLUMNS) * PX_DENS / COLUMNS * ROWS) // window height
void window_init(struct gamedata const*);
void window_init(struct gamedata const *);
void window_open(void);
void window_close(void);
void window_free(void);