From d585e2db6faeddc8474af0fa8fea7b03032782a2 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Tue, 27 Apr 2021 00:52:53 +0200 Subject: [PATCH] clang-format: break after top level definitions --- .clang-format | 1 + src/input/init.c | 3 ++- src/input/update.c | 3 ++- src/level/draw.c | 3 ++- src/level/get_tile.c | 3 ++- src/level/load.c | 12 ++++++++---- src/levelselection/draw.c | 3 ++- src/levelselection/init.c | 3 ++- src/levelselection/update.c | 4 ++-- src/main.c | 6 ++++-- src/mainmenu/draw.c | 3 ++- src/mainmenu/init.c | 6 +++++- src/mainmenu/update.c | 3 ++- src/particles/create.c | 10 ++++++---- src/particles/draw.c | 6 ++++-- src/particles/init.c | 3 ++- src/particles/update.c | 6 ++++-- src/player/collide.c | 20 +++++++++++++------- src/player/draw.c | 3 ++- src/player/init.c | 3 ++- src/player/update.c | 6 ++++-- src/titlescreen/draw.c | 3 ++- src/titlescreen/init.c | 6 +++++- src/titlescreen/update.c | 3 ++- src/transition/draw.c | 3 ++- src/transition/fade.c | 24 ++++++++++++++++++------ src/transition/init.c | 4 ++-- src/transition/update.c | 3 ++- 28 files changed, 106 insertions(+), 50 deletions(-) diff --git a/.clang-format b/.clang-format index ba4eed5..57fd90a 100644 --- a/.clang-format +++ b/.clang-format @@ -6,3 +6,4 @@ AllowShortIfStatementsOnASingleLine: false IndentCaseLabels: false ColumnLimit: 80 AlignConsecutiveMacros: true +AlwaysBreakAfterReturnType: TopLevelDefinitions diff --git a/src/input/init.c b/src/input/init.c index fae7c05..31dfe49 100644 --- a/src/input/init.c +++ b/src/input/init.c @@ -4,7 +4,8 @@ #include "input.h" #include -struct Input input_init(void) +struct Input +input_init(void) { struct Input input = { .keycodes = {KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_SHIFT}, diff --git a/src/input/update.c b/src/input/update.c index f4d7b61..98ae45b 100644 --- a/src/input/update.c +++ b/src/input/update.c @@ -4,7 +4,8 @@ #include "input.h" #include -void input_update(struct Input *input) +void +input_update(struct Input *input) { int i; diff --git a/src/level/draw.c b/src/level/draw.c index 2eb524b..6498946 100644 --- a/src/level/draw.c +++ b/src/level/draw.c @@ -9,7 +9,8 @@ extern struct Level level; extern const bopti_image_t bimg_tileset; -void level_draw(void) +void +level_draw(void) { int i; diff --git a/src/level/get_tile.c b/src/level/get_tile.c index 1b900f1..9bea1e9 100644 --- a/src/level/get_tile.c +++ b/src/level/get_tile.c @@ -6,7 +6,8 @@ extern struct Level level; -Tile level_get_tile(int x, int y) +Tile +level_get_tile(int x, int y) { if (x < 0 || y < 0 || x >= level.width || y >= level.height) return TILE_OOB; diff --git a/src/level/load.c b/src/level/load.c index e8ad697..7293978 100644 --- a/src/level/load.c +++ b/src/level/load.c @@ -28,7 +28,8 @@ static Tile read_merge_bytes(int file, int size); static int autotile_value(int x, int y); /* Load level from storage memory. */ -void level_load(void) +void +level_load(void) { int file; int tile_size; @@ -126,7 +127,8 @@ void level_load(void) } /* Read a single byte. Negative value is BFile error code. */ -static int read_byte(int file) +static int +read_byte(int file) { char byte; const int error = BFile_Read(file, &byte, sizeof(char), -1); @@ -138,7 +140,8 @@ static int read_byte(int file) /* Read multiple bytes and merge them as one integer. * Return -1 on failure. */ -static Tile read_merge_bytes(int file, int size) +static Tile +read_merge_bytes(int file, int size) { Tile merged = 0; int byte = 0; @@ -155,7 +158,8 @@ static Tile read_merge_bytes(int file, int size) return merged; } -static int autotile_value(int x, int y) +static int +autotile_value(int x, int y) { return ((level_get_tile(x - 1, y) == TILE_SOLID) | ((level_get_tile(x + 1, y) == TILE_SOLID) << 1) | diff --git a/src/levelselection/draw.c b/src/levelselection/draw.c index 8dd6c07..cd523a8 100644 --- a/src/levelselection/draw.c +++ b/src/levelselection/draw.c @@ -6,7 +6,8 @@ #include "zxcolors.h" #include -void levelselection_draw(struct LevelSelection levelselection) +void +levelselection_draw(struct LevelSelection levelselection) { dprint(0, 0, ZX_WHITE, ".pack_cursor=%d", levelselection.pack_cursor); } diff --git a/src/levelselection/init.c b/src/levelselection/init.c index 936f358..1719bda 100644 --- a/src/levelselection/init.c +++ b/src/levelselection/init.c @@ -3,7 +3,8 @@ #include "levelselection.h" -struct LevelSelection levelselection_init(void) +struct LevelSelection +levelselection_init(void) { return (struct LevelSelection){.pack_cursor = 0}; } diff --git a/src/levelselection/update.c b/src/levelselection/update.c index 533e374..61c95ad 100644 --- a/src/levelselection/update.c +++ b/src/levelselection/update.c @@ -7,8 +7,8 @@ #include /* Return 1 if game state should change. */ -int levelselection_update(struct LevelSelection *levelselection, - struct Input input) +int +levelselection_update(struct LevelSelection *levelselection, struct Input input) { /* decrease selected pack id */ if (input.keystates[K_LEFT] == KS_PRESS && diff --git a/src/main.c b/src/main.c index fde0b39..612e920 100644 --- a/src/main.c +++ b/src/main.c @@ -45,7 +45,8 @@ extern const font_t font_main; static int callback(volatile int *arg); -int main(void) +int +main(void) { int i; int timer; @@ -231,7 +232,8 @@ int main(void) return 1; } -static int callback(volatile int *arg) +static int +callback(volatile int *arg) { *arg += 1; return 0; diff --git a/src/mainmenu/draw.c b/src/mainmenu/draw.c index 803b27f..5739fee 100644 --- a/src/mainmenu/draw.c +++ b/src/mainmenu/draw.c @@ -6,7 +6,8 @@ #include "zxcolors.h" #include -void mainmenu_draw(struct MainMenu mainmenu) +void +mainmenu_draw(struct MainMenu mainmenu) { int i = MENU_ENTRIES; while (i-- > 0) { diff --git a/src/mainmenu/init.c b/src/mainmenu/init.c index 4f7b6e4..22d927b 100644 --- a/src/mainmenu/init.c +++ b/src/mainmenu/init.c @@ -3,4 +3,8 @@ #include "mainmenu.h" -struct MainMenu mainmenu_init(void) { return (struct MainMenu){.cursor = 0}; } +struct MainMenu +mainmenu_init(void) +{ + return (struct MainMenu){.cursor = 0}; +} diff --git a/src/mainmenu/update.c b/src/mainmenu/update.c index 6757432..ae799da 100644 --- a/src/mainmenu/update.c +++ b/src/mainmenu/update.c @@ -7,7 +7,8 @@ #include /* Return 1 if game state should change. */ -int mainmenu_update(struct MainMenu *mainmenu, struct Input input) +int +mainmenu_update(struct MainMenu *mainmenu, struct Input input) { /* decrease selected pack id */ if (input.keystates[K_UP] == KS_PRESS || diff --git a/src/particles/create.c b/src/particles/create.c index 7d1eb6b..28a4fb0 100644 --- a/src/particles/create.c +++ b/src/particles/create.c @@ -6,8 +6,9 @@ extern struct Particle particles[MAX_PARTICLES]; -void particle_create(img_t *texture, int x, int y, int frame_width, - int frame_duration, int looping, int flip_h) +void +particle_create(img_t *texture, int x, int y, int frame_width, + int frame_duration, int looping, int flip_h) { /* find unused slot */ int i = MAX_PARTICLES; @@ -18,8 +19,9 @@ void particle_create(img_t *texture, int x, int y, int frame_width, looping, flip_h); } -struct Particle particle_init(img_t *texture, int x, int y, int frame_width, - int frame_duration, int looping, int flip_h) +struct Particle +particle_init(img_t *texture, int x, int y, int frame_width, int frame_duration, + int looping, int flip_h) { struct Particle particle; diff --git a/src/particles/draw.c b/src/particles/draw.c index 17fd692..3d3d777 100644 --- a/src/particles/draw.c +++ b/src/particles/draw.c @@ -6,14 +6,16 @@ extern struct Particle particles[MAX_PARTICLES]; -void particles_draw(void) +void +particles_draw(void) { int i = MAX_PARTICLES; while (i-- > 0) particle_draw(particles[i]); } -void particle_draw(struct Particle particle) +void +particle_draw(struct Particle particle) { if (!particle.life) return; diff --git a/src/particles/init.c b/src/particles/init.c index 7cac43e..aac34d8 100644 --- a/src/particles/init.c +++ b/src/particles/init.c @@ -5,7 +5,8 @@ struct Particle particles[MAX_PARTICLES]; -void particles_init(void) +void +particles_init(void) { int i = MAX_PARTICLES; while (i-- > 0) { diff --git a/src/particles/update.c b/src/particles/update.c index 02845f1..e5f0511 100644 --- a/src/particles/update.c +++ b/src/particles/update.c @@ -5,14 +5,16 @@ extern struct Particle particles[MAX_PARTICLES]; -void particles_update(void) +void +particles_update(void) { int i = MAX_PARTICLES; while (i-- > 0) particle_update(&particles[i]); } -void particle_update(struct Particle *particle) +void +particle_update(struct Particle *particle) { if (!particle->life) return; diff --git a/src/player/collide.c b/src/player/collide.c index 4185d0a..58814fd 100644 --- a/src/player/collide.c +++ b/src/player/collide.c @@ -19,7 +19,8 @@ extern img_t img_exit_unlock_particle; static Tile collide_single(int x, int y); static int collide_sub_single(int x, int y, Tile sub, Tile rep); -void player_collide(Tile collisions[COLLIDE_POINTS], int x, int y, int margin) +void +player_collide(Tile collisions[COLLIDE_POINTS], int x, int y, int margin) { const int lx = x + margin; const int rx = x + PLAYER_WIDTH - 1 - margin; @@ -31,8 +32,9 @@ void player_collide(Tile collisions[COLLIDE_POINTS], int x, int y, int margin) collisions[DOWN_RIGHT] = collide_single(rx, dy); } -int player_collide_tile(Tile collisions[COLLIDE_POINTS], int x, int y, - Tile tile, int margin, int update) +int +player_collide_tile(Tile collisions[COLLIDE_POINTS], int x, int y, Tile tile, + int margin, int update) { if (update) player_collide(collisions, x, y, margin); @@ -45,7 +47,8 @@ int player_collide_tile(Tile collisions[COLLIDE_POINTS], int x, int y, } /* collide and replace tiles, return the number of tiles affecter */ -int player_collide_sub(int x, int y, Tile sub, Tile rep, int margin) +int +player_collide_sub(int x, int y, Tile sub, Tile rep, int margin) { const int lx = x + margin; const int rx = x + PLAYER_WIDTH - 1 - margin; @@ -57,13 +60,15 @@ int player_collide_sub(int x, int y, Tile sub, Tile rep, int margin) collide_sub_single(rx, dy, sub, rep); } -int player_collide_solid(int x, int y) +int +player_collide_solid(int x, int y) { Tile collisions[COLLIDE_POINTS]; return player_collide_tile(collisions, x, y, TILE_SOLID, 0, 1); } -static Tile collide_single(int x, int y) +static Tile +collide_single(int x, int y) { const int tx = x / TILE_WIDTH; const int ty = y / TILE_WIDTH; @@ -72,7 +77,8 @@ static Tile collide_single(int x, int y) /* try collide and replace tile at pixel position, return 1 if tile * replaced */ -static int collide_sub_single(int x, int y, Tile sub, Tile rep) +static int +collide_sub_single(int x, int y, Tile sub, Tile rep) { if (collide_single(x, y) == sub) { const int tile_index = diff --git a/src/player/draw.c b/src/player/draw.c index 85a2ab7..8fbde0a 100644 --- a/src/player/draw.c +++ b/src/player/draw.c @@ -13,7 +13,8 @@ extern struct Level level; extern bopti_image_t bimg_burst; -void player_draw(struct Player player) +void +player_draw(struct Player player) { /* set animation position */ struct Particle anim = player.anim; diff --git a/src/player/init.c b/src/player/init.c index a1820af..15a8afd 100644 --- a/src/player/init.c +++ b/src/player/init.c @@ -15,7 +15,8 @@ extern img_t img_player_idle; extern img_t img_player_jump; extern img_t img_player_walk; -struct Player player_init(void) +struct Player +player_init(void) { int x = 0; int y = 0; diff --git a/src/player/update.c b/src/player/update.c index 63cc77a..64a0899 100644 --- a/src/player/update.c +++ b/src/player/update.c @@ -15,7 +15,8 @@ extern struct Level level; /* return -1 on pause, return 1 if exit reached, 2 on death/reset and 0 * otherwise */ -int player_update(struct Player *player, struct Input input) +int +player_update(struct Player *player, struct Input input) { Tile collisions[COLLIDE_POINTS]; const int on_ground = player_collide_solid(player->x, player->y + 1); @@ -156,7 +157,8 @@ int player_update(struct Player *player, struct Input input) return 0; } -static void player_move(struct Player *player, int x, int y) +static void +player_move(struct Player *player, int x, int y) { const int sign_x = 1 * (x > 0) - 1 * (x < 0); const int sign_y = 1 * (y > 0) - 1 * (y < 0); diff --git a/src/titlescreen/draw.c b/src/titlescreen/draw.c index 25f37df..21dc404 100644 --- a/src/titlescreen/draw.c +++ b/src/titlescreen/draw.c @@ -6,7 +6,8 @@ #include "zxcolors.h" #include -void titlescreen_draw(struct TitleScreen titlescreen) +void +titlescreen_draw(struct TitleScreen titlescreen) { dprint_opt(DWIDTH / 2, DHEIGHT * 1 / 3, ZX_WHITE, C_NONE, DTEXT_CENTER, DTEXT_MIDDLE, GAME_NAME); diff --git a/src/titlescreen/init.c b/src/titlescreen/init.c index 8011ff4..90902b5 100644 --- a/src/titlescreen/init.c +++ b/src/titlescreen/init.c @@ -3,4 +3,8 @@ #include "titlescreen.h" -struct TitleScreen titlescreen_init(void) { return (struct TitleScreen){0}; } +struct TitleScreen +titlescreen_init(void) +{ + return (struct TitleScreen){0}; +} diff --git a/src/titlescreen/update.c b/src/titlescreen/update.c index 06210cf..22ece44 100644 --- a/src/titlescreen/update.c +++ b/src/titlescreen/update.c @@ -6,7 +6,8 @@ #include /* Return 1 if game state should change. */ -int titlescreen_update(struct TitleScreen *titlescreen, struct Input input) +int +titlescreen_update(struct TitleScreen *titlescreen, struct Input input) { if (input.keystates[K_A] == KS_PRESS) { return 1; diff --git a/src/transition/draw.c b/src/transition/draw.c index a9bff64..1ed2adb 100644 --- a/src/transition/draw.c +++ b/src/transition/draw.c @@ -3,7 +3,8 @@ #include "transition.h" -void transition_draw(struct Transition transition) +void +transition_draw(struct Transition transition) { switch (transition.mode) { case TransitionNone: diff --git a/src/transition/fade.c b/src/transition/fade.c index ac64a21..dd30ca0 100644 --- a/src/transition/fade.c +++ b/src/transition/fade.c @@ -8,7 +8,8 @@ static float square(float x); static float isquare(float x); -void hfade_in(float step, color_t color) +void +hfade_in(float step, color_t color) { int line = isquare(step) * DWIDTH; int x; @@ -18,7 +19,8 @@ void hfade_in(float step, color_t color) } } -void hfade_out(float step, color_t color) +void +hfade_out(float step, color_t color) { int line = square(step) * DWIDTH; int x; @@ -28,7 +30,8 @@ void hfade_out(float step, color_t color) } } -void vfade_in(float step, color_t color) +void +vfade_in(float step, color_t color) { int line = isquare(step) * DHEIGHT; int y; @@ -38,7 +41,8 @@ void vfade_in(float step, color_t color) } } -void vfade_out(float step, color_t color) +void +vfade_out(float step, color_t color) { int line = square(step) * DHEIGHT; int y; @@ -48,6 +52,14 @@ void vfade_out(float step, color_t color) } } -static float square(float x) { return x * x; } +static float +square(float x) +{ + return x * x; +} -static float isquare(float x) { return 1.0 - square(1.0 - x); } +static float +isquare(float x) +{ + return 1.0 - square(1.0 - x); +} diff --git a/src/transition/init.c b/src/transition/init.c index a2337d4..8fa826e 100644 --- a/src/transition/init.c +++ b/src/transition/init.c @@ -3,8 +3,8 @@ #include "transition.h" -struct Transition transition_init(float speed, color_t color, - enum TransitionMode mode) +struct Transition +transition_init(float speed, color_t color, enum TransitionMode mode) { return (struct Transition){ .step = 0.0, diff --git a/src/transition/update.c b/src/transition/update.c index f446fa5..62dfca2 100644 --- a/src/transition/update.c +++ b/src/transition/update.c @@ -3,7 +3,8 @@ #include "transition.h" -enum TransitionMode transition_update(struct Transition *transition) +enum TransitionMode +transition_update(struct Transition *transition) { enum TransitionMode previous_transition_mode = TransitionNone;