Skip to content

Commit a0a606d

Browse files
committed
Merge branch 'main' into root
# Conflicts: # src/Giraffe.cpp
2 parents 90f8e10 + 4674a7e commit a0a606d

File tree

7 files changed

+153
-5
lines changed

7 files changed

+153
-5
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Checks: '-*,
1+
WarningsAsErrors: '-*,
22
bugprone-*,-bugprone-easily-swappable-parameters,
33
readability-*,-readability-convert-member-functions-to-static,-readability-redundant-access-specifiers,-readability-magic-numbers,
44
modernize-*,-modernize-use-trailing-return-type,-modernize-use-nodiscard'
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Code Styles and Guidelines
2+
3+
## General
4+
5+
* Use UTF-8 encoding
6+
* Windows should use CRLF line breaks, MacOS and Linux(Unix-like OSes) should use LF line breaks
7+
* Use `enum class` over `enum`
8+
https://stackoverflow.com/questions/18335861/why-is-enum-class-preferred-over-plain-enum
9+
https://www.geeksforgeeks.org/enum-classes-in-c-and-their-advantage-over-enum-datatype/
10+
* Line break at EOF
11+
https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline
12+
Force it in VSCode
13+
https://stackoverflow.com/questions/44704968/visual-studio-code-insert-newline-at-the-end-of-files
14+
* Write portable code by following C++ standards and avoid using `#pragma` directives
15+
* Add line breaks wherever it makes sense
16+
* Use primary operators instead of alternative ones([ref](https://en.cppreference.com/w/cpp/language/operator_alternative))
17+
18+
## Includes
19+
20+
Use `#ifndef` for include guards instead of `#pragma once`
21+
22+
Include guard format: `<NAMESPACE>_<FILENAME>_<FILE_EXTENSION>`
23+
24+
E.g.: Include guard for `GameObject.hpp` should be `GAME_OBJECT_HPP`
25+
26+
Internal header should use `""` and external headers should use `<>`
27+
28+
Unless specified, included headers should be the following order:
29+
30+
1. definition header(if needed)
31+
2. system header
32+
3. external header
33+
4. internal header
34+
35+
Different categories are separated with line breaks. If headers are in the same category, headers for the same libraries should be grouped together and be in alphabetical order
36+
37+
E.g. includes for `Player.cpp` should be
38+
39+
```cpp=
40+
#include "Player.hpp"
41+
42+
#include <string>
43+
#include <vector>
44+
45+
#include <spdlog/spdlog.h>
46+
47+
#include "Math/Vector2.hpp"
48+
49+
// ...
50+
```
51+
52+
See also: https://clangd.llvm.org/guides/include-cleaner
53+
54+
## Class
55+
56+
Member functions and variables declaration should be in the following order, access specifiers should be in the order of `public` -> `protected` -> `private`. Static members should be declared above normal members.
57+
58+
1. Functions
59+
1. Constructor
60+
1. Default
61+
2. Parameterized
62+
3. Copy
63+
4. Move
64+
2. Destructor
65+
3. Operator overload
66+
1. Copy assignment
67+
2. Move assignment
68+
4. Getter
69+
5. Setter
70+
6. Other
71+
2. Variables
72+
73+
Follow C++ rule of three/five/zero
74+
https://en.cppreference.com/w/cpp/language/rule_of_three
75+
76+
## File Types
77+
78+
C source file: `.c`
79+
C header file: `.h`
80+
C++ source file: `.cpp`
81+
C++ header file: `.hpp`
82+
83+
Vertex Shader: `.vert`
84+
Fragment Shader: `.frag`
85+
86+
## File and Folder Naming
87+
88+
Source and header files should be `PascalCase` if it defines a class or struct, otherwise it should be `snake_case`
89+
90+
Top level folders should only consist of a single word and be `lowercase` (e.g. `src/`, `include/`, `lib/`)
91+
92+
Source and header file folders should be `PascalCase` and be the same name as its namespace
93+
94+
E.g.: `include/Math/Vector2.hpp` should be:
95+
96+
```cpp=
97+
#ifndef MATH_VECTOR2_HPP
98+
#define MATH_VECTOR2_HPP
99+
100+
namespace Math {
101+
class Vector2 {
102+
public:
103+
Vector2();
104+
105+
}
106+
}
107+
108+
#endif
109+
110+
```
111+
112+
## Variable Naming Convention
113+
114+
Lower items override higher items if rules collide
115+
116+
| | Case | Prefix | Suffix |
117+
| ------------------- | ------------ | ------ | ------ |
118+
| Namespace | `PascalCase` | | |
119+
| Class | `PascalCase` | | |
120+
| Class member | `PascalCase` | `m_` | |
121+
| Static class member | `PascalCase` | `s_` | |
122+
| Struct | `PascalCase` | | |
123+
| Struct member | `camelCase` | | |
124+
| Enum | `PascalCase` | | |
125+
| Enum element | `UPPER_CASE` | | |
126+
| Function/Method | `camelCase` | | |
127+
| Parameter | `camelCase` | | |
128+
| Variable | `camelCase` | | |
129+
| Type Alias/Typedef | `PascalCase` | | |
130+
| Global constant | `UPPER_CASE` | | |
131+
| Macro | `UPPER_CASE` | | |
132+
| Template parameter | `UPPER_CASE` | | |

.github/workflows/build.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ jobs:
3333
with:
3434
submodules: recursive
3535

36+
- name: Check Format
37+
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang'
38+
run: |
39+
find src/ include/ test/ assets/shaders/ -name "*.*" -print0 | \
40+
xargs -0 clang-format --dry-run --Werror --ferror-limit=15
41+
3642
- name: Building Project
3743
if: matrix.os == 'ubuntu-latest'
3844
env:
@@ -42,6 +48,12 @@ jobs:
4248
cmake -B build -G "Ninja" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
4349
cmake --build build
4450
51+
- name: Run Linter
52+
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang'
53+
run: |
54+
find src/ include/ test/ -name "*.*" -print0 | \
55+
xargs -0 run-clang-tidy true -p build
56+
4557
- name: Building Project
4658
if: matrix.os == 'windows-latest'
4759
run: |

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [Code Styles and Guidelines](./.github/docs/Code-Styles-and-Guidelines.md)

src/App.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ void App::Start() {
2323
}
2424

2525
void App::Update() {
26-
auto cursorPos = Util::Input::GetCursorPosition();
2726
if (Util::Input::IsLButtonPressed()) {
2827
LOG_DEBUG("Left button pressed");
2928
}

src/Giraffe.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void GiraffeText::Start() {
3131

3232
void Giraffe::Start() {}
3333

34-
void Giraffe::Update(const Util::Transform &transform) {
34+
void Giraffe::Update([[maybe_unused]] const Util::Transform &transform) {
3535
static glm::vec2 dir = {1, 0.5};
3636

3737
auto &pos = m_Transform.translation;
@@ -53,8 +53,8 @@ void Giraffe::Update(const Util::Transform &transform) {
5353
glm::vec2(1, 1) * (std::sin(rotation / 2) + 1.0F) * 100.0F};
5454

5555
pos += deltaTransform.translation;
56-
rotation = std::fmod(rotation + deltaTransform.rotation, 360.0F);
57-
// scale = deltaTransform.scale;
56+
rotation += deltaTransform.rotation;
57+
scale = deltaTransform.scale;
5858

5959
m_Drawable->Draw(m_Transform, m_ZIndex);
6060
for (auto &child : m_Children) {

src/Util/Input.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Util/Input.hpp"
22

33
#include <SDL_events.h> // for SDL_Event
4+
#include "config.hpp"
45

56
namespace Util {
67

@@ -52,6 +53,9 @@ void Input::Update() {
5253
s_CursorPosition.x = static_cast<float>(x);
5354
s_CursorPosition.y = static_cast<float>(y);
5455

56+
s_CursorPosition.x -= static_cast<float>(WINDOW_WIDTH) / 2;
57+
s_CursorPosition.y = -(s_CursorPosition.y - static_cast<float>(WINDOW_HEIGHT) / 2);
58+
5559
s_LBPressed = s_RBPressed = s_MBPressed = s_Scroll = s_MouseMoving = false;
5660

5761
while (SDL_PollEvent(&s_Event) != 0) {

0 commit comments

Comments
 (0)