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

@@ -85,9 +85,9 @@ BinPackArguments: true
# pointer alignment
# ---------------------------
DerivePointerAlignment: false
PointerAlignment: Left
PointerAlignment: Right
ReferenceAlignment: Pointer
QualifierAlignment: Right
QualifierAlignment: Left
# ---------------------------
# include settings and sorting

View File

@@ -21,13 +21,13 @@ static struct gamedata dat = {0};
/* shuffle an array using the FisherYates shuffle algorithm.
* `nmemb` is the number of members.
* `membs` is the byte size of each member */
static void shuffle(void* restrict ptr, size_t nmemb, size_t membs) {
static void shuffle(void *restrict ptr, size_t nmemb, size_t membs) {
u8 dat[membs];
for (size_t i = 0; i < nmemb; i++) {
size_t j = i + rand() % (nmemb - i);
void* ptri = (u8*)ptr + i * membs;
void* ptrj = (u8*)ptr + j * membs;
void *ptri = (u8 *)ptr + i * membs;
void *ptrj = (u8 *)ptr + j * membs;
memcpy(dat, ptri, membs);
memcpy(ptri, ptrj, membs);
memcpy(ptrj, dat, membs);
@@ -46,7 +46,7 @@ void next_shape(void) {
shuffle(dat.pdat.nxt, TETC, sizeof(u8));
}
struct gamedata* game_init(void) {
struct gamedata *game_init(void) {
srand(time(NULL));
// populate the data arrays

View File

@@ -30,7 +30,7 @@ struct pdat {
/* contains game data that's commonly shared */
struct gamedata {
struct pdat pdat;
colour8* rows[ROWS];
colour8 *rows[ROWS];
u16 pnts;
};
@@ -38,6 +38,6 @@ struct gamedata {
/* increments to the next shape, shuffling the next shapes, if there isn't a next shape immediately after the current one. */
void next_shape(void);
struct gamedata* game_init(void);
struct gamedata *game_init(void);
void game_update(int movdat, size_t time);
void game_free(void);

View File

@@ -12,9 +12,9 @@
#include "shapes.h"
static int clear_rows(u8* restrict* restrict rows) {
static int clear_rows(u8 *restrict *restrict rows) {
int count = 0;
u8* cache[4]; /* the maximum amount of rows the user can clear at once is four */
u8 *cache[4]; /* the maximum amount of rows the user can clear at once is four */
for (int y = ROWS - 1; y >= 0; y--) {
int x = 0;
@@ -33,7 +33,7 @@ static int clear_rows(u8* restrict* restrict rows) {
}
/* writes a shape to the screen */
static void plcmnt_place(u8* restrict const* restrict row, u8 id, i8vec2 pos) {
static void plcmnt_place(u8 *restrict const *restrict row, u8 id, i8vec2 pos) {
u8 colour = colour_from_id(id);
i8vec2 bpos[4];
@@ -49,13 +49,13 @@ static void plcmnt_place(u8* restrict const* restrict row, u8 id, i8vec2 pos) {
row[bpos[3][VY]][bpos[3][VX]] = colour;
}
static int plcmnt_valid(u8* restrict const* restrict const rows, i8vec2 pos) {
static int plcmnt_valid(u8 *restrict const *restrict const rows, i8vec2 pos) {
return pos[VX] >= 0 && pos[VX] < COLUMNS &&
pos[VY] >= 0 && pos[VY] < ROWS &&
!rows[pos[VY]][pos[VX]];
}
static int plcmnt_intersect(u8* restrict const* restrict const rows, u8 const id, i8vec2 pos) {
static int plcmnt_intersect(u8 *restrict const *restrict const rows, const u8 id, i8vec2 pos) {
i8vec2 bpos[4];
shape_getblocks(id, bpos);
return !(plcmnt_valid(rows, pos + bpos[0]) &&
@@ -64,7 +64,7 @@ static int plcmnt_intersect(u8* restrict const* restrict const rows, u8 const id
plcmnt_valid(rows, pos + bpos[3]));
}
int place_update(struct gamedata* gdat, int movdat) {
int place_update(struct gamedata *gdat, int movdat) {
// store the current index and ID, only changes when placed (which yields no movement) and rotation (which occurs last)
int tmp;
u8 id = gdat->pdat.cur;

View File

@@ -7,4 +7,4 @@
/* updates the movement of the `pdat` structure, updating the rows when colliding downwards.
* returns `0` if we successfully updated. Returns 1 if we couldn't update. (e.g. when a next block immediately collides) */
int place_update(struct gamedata* gdat, int movdat);
int place_update(struct gamedata *gdat, int movdat);

View File

@@ -5,7 +5,7 @@
#include "../../util/vec.h"
#include "../../error.h"
void shape_getblocks(u8 id, i8vec2* restrict out) {
void shape_getblocks(u8 id, i8vec2 *restrict out) {
struct blockdat {
u8 ax : 2, ay : 2;
u8 bx : 2, by : 2;

View File

@@ -24,5 +24,5 @@ enum tetromino {
#define SHAPE_HEIGHT 4
#define TETC 7
void shape_getblocks(u8 id, i8vec2* out);
void shape_getblocks(u8 id, i8vec2 *out);
colour8 colour_from_id(u8 id);

View File

@@ -8,14 +8,14 @@
#endif
#if __has_include(<features.h>) && _POSIX_C_SOURCE >= 199309L
#include <bits/time.h>
static void gettime(struct timespec* ts) {
static void gettime(struct timespec *ts) {
clock_gettime(CLOCK_MONOTONIC, ts);
}
#elif defined(_WIN32)
#include <profileapi.h>
#include <windows.h>
#include <winnt.h>
static void gettime(struct timespec* ts) {
static void gettime(struct timespec *ts) {
LARGE_INTEGER cnt, frq;
QueryPerformanceCounter(&cnt);
QueryPerformanceFrequency(&frq);
@@ -32,7 +32,7 @@ time_t time_pull(void) {
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}
int time_poll(time_t curr, time_t delta, time_t* restrict proj) {
int time_poll(time_t curr, time_t delta, time_t *restrict proj) {
bool tpass = curr >= *proj;
*proj += tpass * ((curr + delta) - *proj); // adds 0, or the difference to proj
return tpass;

View File

@@ -9,4 +9,4 @@ time_t time_pull(void);
/* Polls the time whether a given timeout has passed, comparing against `curr` as the current time.
* if `curr` ≥ `*proj`, `curr` + `delta` is written to `*proj`. `1` is returned.
* otherwise, we just return `0`. */
__nonnull((3)) int time_poll(time_t curr, time_t delta, time_t* restrict proj);
__nonnull((3)) int time_poll(time_t curr, time_t delta, time_t *restrict proj);

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);

View File

@@ -13,7 +13,7 @@ static void stop(void) {
}
// entry-point of the application
int main(int argc, char** argv) {
int main(int argc, char **argv) {
(void)argc, (void)argv;
// register stop as exit function
atexit(stop);

View File

@@ -46,7 +46,7 @@ enum faccess_perms {
/* tests a files access with F_OK, X_OK, R_OK, W_OK OR'd together
returns 0 upon success. -1 when errno is set and anything else when one or more of the permissions isn't set */
static inline int faccess(char const* restrict fname, int perms) {
static inline int faccess(const char *restrict fname, int perms) {
#if defined __unix__ && _POSIX_C_SOURCE >= 200809L
return access(fname, perms);
#elif defined _WIN32