Skip to content

Commit 4cb8140

Browse files
committed
Merge remote-tracking branch 'upstream/main' into makeStub
2 parents 8ac5fa0 + f74285d commit 4cb8140

File tree

14 files changed

+250
-112
lines changed

14 files changed

+250
-112
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: |

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ set(SRC_FILES
4242
${SRC_DIR}/Util/Text.cpp
4343
${SRC_DIR}/Util/TransformUtils.cpp
4444
${SRC_DIR}/Util/GameObject.cpp
45+
${SRC_DIR}/Util/Root.cpp
4546

4647
${SRC_DIR}/App.cpp
47-
${SRC_DIR}/Triangle.cpp
4848
${SRC_DIR}/Giraffe.cpp
4949
)
5050
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
@@ -72,10 +72,10 @@ set(INCLUDE_FILES
7272
${INCLUDE_DIR}/Util/Text.hpp
7373
${INCLUDE_DIR}/Util/Transform.hpp
7474
${INCLUDE_DIR}/Util/TransformUtils.hpp
75-
${INCLUDE_DIR}Util/GameObject.hpp
75+
${INCLUDE_DIR}/Util/GameObject.hpp
76+
${INCLUDE_DIR}/Util/Root.hpp
7677

7778
${INCLUDE_DIR}/App.hpp
78-
${INCLUDE_DIR}/Triangle.hpp
7979
${INCLUDE_DIR}/Giraffe.hpp
8080
${INCLUDE_DIR}/config.hpp
8181
)

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)

include/App.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "pch.hpp" // IWYU pragma: export
55

66
#include "Giraffe.hpp"
7-
#include "Triangle.hpp"
87

98
class App {
109
public:
@@ -23,8 +22,7 @@ class App {
2322
private:
2423
State m_CurrentState = State::START;
2524

26-
Triangle m_Triangle;
27-
std::shared_ptr<Giraffe> m_Giraffe= std::make_shared<Giraffe>();
25+
std::shared_ptr<Giraffe> m_Giraffe = std::make_shared<Giraffe>();
2826
};
2927

3028
#endif

include/Triangle.hpp

Lines changed: 0 additions & 34 deletions
This file was deleted.

include/Util/GameObject.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ class GameObject {
1313
GameObject() = default;
1414

1515
GameObject(std::unique_ptr<Core::Drawable> drawable, const float zIndex,
16+
const bool visible = true,
1617
const std::vector<std::shared_ptr<GameObject>> &children =
1718
std::vector<std::shared_ptr<GameObject>>())
1819
: m_Drawable(std::move(drawable)),
1920
m_Children(children),
20-
m_ZIndex(zIndex) {}
21+
m_ZIndex(zIndex),
22+
m_Visible(visible) {}
2123

2224
GameObject(const GameObject &other) = delete;
2325

@@ -33,17 +35,19 @@ class GameObject {
3335
return m_Drawable->GetSize() * m_Transform.scale;
3436
};
3537

36-
std::vector<std::shared_ptr<GameObject>> &GetChildren() {
38+
Transform GetTransform() const { return m_Transform; }
39+
const std::vector<std::shared_ptr<GameObject>> &GetChildren() const {
3740
return m_Children;
3841
}
3942

4043
void SetZIndex(float index) { m_ZIndex = index; }
41-
4244
void SetDrawable(std::unique_ptr<Core::Drawable> drawable) {
4345
m_Drawable = std::move(drawable);
4446
}
4547

46-
void AppendChild(std::shared_ptr<GameObject> child) {
48+
void SetVisible(bool visible) { m_Visible = visible; }
49+
50+
void AddChild(std::shared_ptr<GameObject> child) {
4751
m_Children.push_back(std::move(child));
4852
}
4953

@@ -61,6 +65,7 @@ class GameObject {
6165
std::vector<std::shared_ptr<GameObject>> m_Children;
6266

6367
float m_ZIndex;
68+
bool m_Visible = true;
6469
};
6570
} // namespace Util
6671
#endif

include/Util/Root.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef UTIL_ROOT_HPP
2+
#define UTIL_ROOT_HPP
3+
4+
#include <memory>
5+
#include <vector>
6+
7+
#include "Util/GameObject.hpp"
8+
9+
class App;
10+
11+
namespace Util {
12+
class Root final {
13+
public:
14+
Root(const std::vector<std::shared_ptr<GameObject>> &children = {});
15+
16+
void AddChild(std::shared_ptr<GameObject> child);
17+
void AddChildren(const std::vector<std::shared_ptr<GameObject>> &children);
18+
19+
void Update();
20+
21+
private:
22+
std::vector<std::shared_ptr<GameObject>> m_Children;
23+
};
24+
} // namespace Util
25+
26+
#endif

src/App.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ void App::Start() {
1717
"Giraffe");
1818
gf->SetZIndex(m_Giraffe->GetZIndex() - 1);
1919
gf->Start();
20-
m_Giraffe->AppendChild(gf);
20+
m_Giraffe->AddChild(gf);
2121

2222
m_CurrentState = State::UPDATE;
2323
}
2424

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

0 commit comments

Comments
 (0)