Skip to content

Commit 48d0e5e

Browse files
authored
Introduces .clang-format (#155)
* Introduces .clang-format Formats all files and adds a validation job to github actions. * Fix clang format ci version * 8 space tabs * Don't format help content.
1 parent 5802db7 commit 48d0e5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+2070
-2922
lines changed

.clang-format

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
BasedOnStyle: LLVM
3+
IndentWidth: 8
4+
TabWidth: 8
5+
UseTab: ForIndentation
6+
BreakBeforeBraces: Linux
7+
ColumnLimit: 120
8+
PointerAlignment: Right
9+
IndentCaseLabels: true
10+
SpaceBeforeParens: ControlStatements
11+
AlignAfterOpenBracket: Align
12+
AllowShortFunctionsOnASingleLine: None
13+
AllowShortIfStatementsOnASingleLine: Never
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterReturnType: AllDefinitions
16+
SortIncludes: Never
17+
IndentPPDirectives: None
18+
SpaceAfterCStyleCast: false
19+
SpacesInParentheses: false
20+
SpacesInContainerLiterals: false
21+
BreakBeforeBinaryOperators: NonAssignment

.github/workflows/clang-format.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: clang-format
2+
3+
on:
4+
push:
5+
branches: [ "dev", "feature/*" ]
6+
pull_request:
7+
branches: [ "dev" ]
8+
9+
jobs:
10+
clang-format:
11+
name: Check formatting
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Install clang-format
18+
run: pip install clang-format==21.1.8
19+
20+
- name: Check formatting
21+
run: |
22+
find src -name '*.c' -o -name '*.h' \
23+
| xargs clang-format --dry-run --Werror

src/actiontext.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@
2121
#include "util.h"
2222
#include "update_data.h"
2323

24-
ActionText*
24+
ActionText *
2525
actiontext_create(Sprite *sprite)
2626
{
2727
ActionText *t = ec_malloc(sizeof(ActionText));
28-
t->pos = (Position) { 0, 0 };
28+
t->pos = (Position){0, 0};
2929
t->sprite = sprite;
3030
t->timer = _timer_create();
3131
t->dead = false;
32-
t->velocity = (Vector2d) { 0, -100 };
32+
t->velocity = (Vector2d){0, -100};
3333
t->color = C_WHITE;
3434
return t;
3535
}
3636

3737
void
3838
actiontext_update(ActionText *t, UpdateData *data)
3939
{
40-
t->sprite->pos.x += (int) (t->velocity.x * data->deltatime);
41-
t->sprite->pos.y += (int) (t->velocity.y * data->deltatime);
40+
t->sprite->pos.x += (int)(t->velocity.x * data->deltatime);
41+
t->sprite->pos.y += (int)(t->velocity.y * data->deltatime);
4242
}
4343

4444
void

src/actiontext.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
#ifndef ACTIONTEXT_H_
20-
#define ACTIONTEXT_H_
20+
#define ACTIONTEXT_H_
2121

2222
#include <SDL3/SDL.h>
2323
#include <stdbool.h>
@@ -38,12 +38,12 @@ typedef struct {
3838
SDL_Color color;
3939
} ActionText;
4040

41-
ActionText* actiontext_create(Sprite*);
41+
ActionText *actiontext_create(Sprite *);
4242

43-
void actiontext_update(ActionText*, struct UpdateData*);
43+
void actiontext_update(ActionText *, struct UpdateData *);
4444

45-
void actiontext_render(ActionText*, Camera*);
45+
void actiontext_render(ActionText *, Camera *);
4646

47-
void actiontext_destroy(ActionText*);
47+
void actiontext_destroy(ActionText *);
4848

4949
#endif // ACTIONTEXT_H_

src/actiontextbuilder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ actiontextbuilder_init(SDL_Renderer *renderer)
3434
void
3535
actiontextbuilder_create_text(const char *msg, SDL_Color color, const Position *p)
3636
{
37-
assert (gRenderer != NULL);
37+
assert(gRenderer != NULL);
3838
Sprite *sprite = sprite_create();
3939
sprite->pos = *p;
4040
sprite_load_text_texture(sprite, "GUI/SDS_8x8.ttf", 0, 11, 1);

src/actiontextbuilder.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,21 @@
1717
*/
1818

1919
#ifndef ACTIONTEXTBUILDER_H_
20-
#define ACTIONTEXTBUILDER_H_
20+
#define ACTIONTEXTBUILDER_H_
2121

2222
#include <SDL3/SDL.h>
2323
#include "actiontext.h"
2424
#include "camera.h"
2525
#include "update_data.h"
2626

27-
void
28-
actiontextbuilder_init(SDL_Renderer*);
27+
void actiontextbuilder_init(SDL_Renderer *);
2928

30-
void
31-
actiontextbuilder_update(UpdateData*);
29+
void actiontextbuilder_update(UpdateData *);
3230

33-
void
34-
actiontextbuilder_render(Camera*);
31+
void actiontextbuilder_render(Camera *);
3532

36-
void
37-
actiontextbuilder_create_text(const char *msg, SDL_Color, const Position*);
33+
void actiontextbuilder_create_text(const char *msg, SDL_Color, const Position *);
3834

39-
void
40-
actiontextbuilder_close(void);
35+
void actiontextbuilder_close(void);
4136

4237
#endif // ACTIONTEXTBUILDER_H_
43-

src/animation.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
Animation *
2626
animation_create(unsigned int clipCount)
2727
{
28-
Animation *animation = ec_malloc(sizeof(Animation)
29-
+ clipCount * sizeof(AnimationClip));
28+
Animation *animation = ec_malloc(sizeof(Animation) + clipCount * sizeof(AnimationClip));
3029
animation->clipTimer = _timer_create();
3130
animation->clipCount = clipCount;
3231
animation->currentClip = 0;
@@ -53,9 +52,7 @@ animation_update(Animation *animation)
5352
timer_start(animation->clipTimer);
5453
}
5554

56-
if (timer_get_ticks(animation->clipTimer)
57-
>= animation->clips[animation->currentClip].renderTime)
58-
{
55+
if (timer_get_ticks(animation->clipTimer) >= animation->clips[animation->currentClip].renderTime) {
5956
animation->currentClip++;
6057
if (animation->currentClip >= animation->clipCount) {
6158
animation->currentClip = 0;
@@ -67,12 +64,9 @@ animation_update(Animation *animation)
6764
}
6865
}
6966

70-
animation->sprite->clip = (SDL_Rect) {
71-
animation->clips[animation->currentClip].x,
72-
animation->clips[animation->currentClip].y,
73-
animation->clips[animation->currentClip].w,
74-
animation->clips[animation->currentClip].h
75-
};
67+
animation->sprite->clip =
68+
(SDL_Rect){animation->clips[animation->currentClip].x, animation->clips[animation->currentClip].y,
69+
animation->clips[animation->currentClip].w, animation->clips[animation->currentClip].h};
7670
}
7771

7872
void
@@ -114,4 +108,3 @@ animation_destroy(Animation *animation)
114108
sprite_destroy(animation->sprite);
115109
free(animation);
116110
}
117-

src/animation.h

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
#ifndef _ANIMATION_H
20-
#define _ANIMATION_H
20+
#define _ANIMATION_H
2121

2222
#include <SDL3/SDL.h>
2323
#include <stdbool.h>
@@ -26,17 +26,15 @@ typedef struct Timer Timer;
2626
typedef struct Camera Camera;
2727
typedef struct Sprite Sprite;
2828

29-
typedef struct AnimationClip
30-
{
29+
typedef struct AnimationClip {
3130
unsigned int x;
3231
unsigned int y;
3332
unsigned int w;
3433
unsigned int h;
3534
unsigned int renderTime;
3635
} AnimationClip;
3736

38-
typedef struct Animation
39-
{
37+
typedef struct Animation {
4038
Sprite *sprite;
4139
Timer *clipTimer;
4240
unsigned int currentClip;
@@ -46,30 +44,20 @@ typedef struct Animation
4644
AnimationClip clips[];
4745
} Animation;
4846

49-
Animation*
50-
animation_create(unsigned int clipCount);
47+
Animation *animation_create(unsigned int clipCount);
5148

52-
void
53-
animation_load_texture(Animation *, const char *path, SDL_Renderer*);
49+
void animation_load_texture(Animation *, const char *path, SDL_Renderer *);
5450

55-
void
56-
animation_set_frames(Animation*, const AnimationClip clips[]);
51+
void animation_set_frames(Animation *, const AnimationClip clips[]);
5752

58-
void
59-
animation_run(Animation*);
53+
void animation_run(Animation *);
6054

61-
void
62-
animation_update(Animation*);
55+
void animation_update(Animation *);
6356

64-
void
65-
animation_render(Animation*, Camera*);
57+
void animation_render(Animation *, Camera *);
6658

67-
void
68-
animation_stop(Animation*);
59+
void animation_stop(Animation *);
6960

70-
void
71-
animation_destroy(Animation*);
61+
void animation_destroy(Animation *);
7262

7363
#endif // _ANIMATION_H
74-
75-

src/animation_controller.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,20 @@ create_explosion(Position pos)
2121
sprite_set_texture(a->sprite, t, 0);
2222
a->sprite->pos.x = pos.x - 16;
2323
a->sprite->pos.y = pos.y - 16;
24-
a->sprite->dim = (Dimension) { 64, 64 };
25-
a->sprite->clip = (SDL_Rect) { 0, 0, 32, 32 };
26-
a->sprite->rotationPoint = (SDL_Point) { 32, 32 };
24+
a->sprite->dim = (Dimension){64, 64};
25+
a->sprite->clip = (SDL_Rect){0, 0, 32, 32};
26+
a->sprite->rotationPoint = (SDL_Point){32, 32};
2727

2828
a->loop = false;
2929
a->running = true;
30-
animation_set_frames(a, (AnimationClip[]) {
31-
{ 0, 0, 32, 32, 100 },
32-
{ 32, 0, 32, 32, 100 },
33-
{ 64, 0, 32, 32, 100 },
34-
{ 96, 0, 32, 32, 100 },
35-
{ 128, 0, 32, 32, 100 },
36-
{ 160, 0, 32, 32, 100 },
37-
{ 192, 0, 32, 32, 300 },
38-
{ 224, 0, 32, 32, 300 }
39-
});
30+
animation_set_frames(a, (AnimationClip[]){{0, 0, 32, 32, 100},
31+
{32, 0, 32, 32, 100},
32+
{64, 0, 32, 32, 100},
33+
{96, 0, 32, 32, 100},
34+
{128, 0, 32, 32, 100},
35+
{160, 0, 32, 32, 100},
36+
{192, 0, 32, 32, 300},
37+
{224, 0, 32, 32, 300}});
4038
}
4139

4240
void

src/animation_controller.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,14 @@ enum AnimationType {
77
EXPLOSION_ANIMATION,
88
};
99

10-
void
11-
animation_controller_create(enum AnimationType type, Position pos);
10+
void animation_controller_create(enum AnimationType type, Position pos);
1211

13-
void
14-
animation_controller_init(void);
12+
void animation_controller_init(void);
1513

16-
void
17-
animation_controller_update(void);
14+
void animation_controller_update(void);
1815

19-
void
20-
animation_controller_render(Camera *cam);
16+
void animation_controller_render(Camera *cam);
2117

22-
void
23-
animation_controller_close(void);
24-
25-
#endif // ANIMATION_CONTROLLER_H_
18+
void animation_controller_close(void);
2619

20+
#endif // ANIMATION_CONTROLLER_H_

0 commit comments

Comments
 (0)