Skip to content

Commit d2e0768

Browse files
authored
Merge pull request #21 from PottierLoic/format
Format whole project
2 parents be9334a + b932d79 commit d2e0768

Some content is hidden

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

63 files changed

+1239
-1346
lines changed

.clang-format

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BasedOnStyle: Google
2+
ColumnLimit: 100
3+
4+
SortIncludes: false
5+
6+
AllowShortFunctionsOnASingleLine: Empty
7+
AllowShortBlocksOnASingleLine: Empty
8+
ReflowComments: false
9+
10+
PenaltyBreakAssignment: 1000
11+
PenaltyBreakBeforeFirstCallParameter: 1000
12+
BinPackArguments: false

.github/workflows/format-ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Format Check
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
format:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Install clang-format
15+
run: sudo apt install clang-format
16+
17+
- name: Check formatting
18+
run: python3 format.py --check

core/component/audio_source.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
namespace SpaceEngine {
44

5-
//AudioSource::AudioSource() = default;
5+
// AudioSource::AudioSource() = default;
66
//
7-
//void AudioSource::setAudio(const std::string& path) {
7+
// void AudioSource::setAudio(const std::string& path) {
88
// m_audioPath = path;
9-
//// m_audio = ResourceManager::load<ResAudio>(path, std::dynamic_pointer_cast<IResourceUser>(shared_from_this()));
9+
//// m_audio = ResourceManager::load<ResAudio>(path,
10+
/// std::dynamic_pointer_cast<IResourceUser>(shared_from_this()));
1011
//}
1112
//
12-
//void AudioSource::play() const {
13+
// void AudioSource::play() const {
1314
// if (m_audio) {
1415
// // TODO: waiting for Audio system
1516
// // Audio::playSound(m_audio->getData());
1617
// }
1718
//}
1819

19-
}
20+
} // namespace SpaceEngine

core/component/audio_source.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
namespace SpaceEngine {
99

1010
struct AudioSource {
11-
// explicit AudioSource();
12-
//
13-
// void setAudio(const std::string& path);
14-
// void play() const;
15-
//
16-
// std::shared_ptr<ResAudio> m_audio;
17-
// std::string m_audioPath;
11+
// explicit AudioSource();
12+
//
13+
// void setAudio(const std::string& path);
14+
// void play() const;
15+
//
16+
// std::shared_ptr<ResAudio> m_audio;
17+
// std::string m_audioPath;
1818
};
1919

20-
}
20+
} // namespace SpaceEngine

core/component/camera.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,31 @@ glm::mat4 Camera::getViewMatrix(const World& world, Entity e) const {
1919
}
2020

2121
glm::mat4 Camera::getProjectionMatrix() const {
22-
if (projectionType == ProjectionType::PERSPECTIVE) {
23-
glm::mat4 projection = glm::perspective(glm::radians(fieldOfView), aspectRatio, nearPlane, farPlane);
24-
projection[1][1] *= -1;
25-
return projection;
26-
} else {
27-
const float width = orthographicSize * aspectRatio;
28-
const float height = orthographicSize;
29-
glm::mat4 projection = glm::ortho(-width, width, -height, height, nearPlane, farPlane);
30-
projection[1][1] *= -1;
31-
return projection;
22+
glm::mat4 projection;
23+
switch (projectionType) {
24+
case ProjectionType::PERSPECTIVE:
25+
projection = glm::perspective(glm::radians(fieldOfView), aspectRatio, nearPlane, farPlane);
26+
break;
27+
case ProjectionType::ORTHOGRAPHIC:
28+
projection = glm::ortho(-orthographicSize * aspectRatio,
29+
orthographicSize * aspectRatio,
30+
-orthographicSize,
31+
orthographicSize,
32+
nearPlane,
33+
farPlane);
34+
break;
3235
}
36+
37+
projection[1][1] *= -1;
38+
return projection;
3339
}
3440

3541
void Camera::updateCameraVectors() {
36-
front = glm::normalize(glm::vec3(
37-
cos(glm::radians(yaw)) * cos(glm::radians(pitch)),
38-
sin(glm::radians(pitch)),
39-
sin(glm::radians(yaw)) * cos(glm::radians(pitch))
40-
));
42+
front = glm::normalize(glm::vec3(cos(glm::radians(yaw)) * cos(glm::radians(pitch)),
43+
sin(glm::radians(pitch)),
44+
sin(glm::radians(yaw)) * cos(glm::radians(pitch))));
4145
right = glm::normalize(glm::cross(front, worldUp));
4246
up = glm::normalize(glm::cross(right, front));
4347
}
4448

45-
}
49+
} // namespace SpaceEngine

core/component/camera.hpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
#pragma once
22

3-
#include "glm/glm.hpp"
4-
#include "glm/gtc/matrix_transform.hpp"
5-
63
#include "../imgui/imgui_impl_opengl3.h"
7-
8-
#include "ecs/world.hpp"
9-
#include "ecs/entity.hpp"
104
#include "component/transform.hpp"
5+
#include "ecs/entity.hpp"
6+
#include "ecs/world.hpp"
7+
#include "glm/glm.hpp"
8+
#include "glm/gtc/matrix_transform.hpp"
119

1210
namespace SpaceEngine {
1311

1412
struct Camera {
15-
enum class ProjectionType {
16-
PERSPECTIVE,
17-
ORTHOGRAPHIC
18-
};
13+
enum class ProjectionType { PERSPECTIVE, ORTHOGRAPHIC };
1914

2015
glm::vec3 front{};
2116
glm::vec3 up{};
@@ -26,7 +21,7 @@ struct Camera {
2621

2722
ProjectionType projectionType = ProjectionType::PERSPECTIVE;
2823
float fieldOfView = 45.0f;
29-
float aspectRatio = 16.0f/9.0f;
24+
float aspectRatio = 16.0f / 9.0f;
3025
float nearPlane = 0.1f;
3126
float farPlane = 100.0f;
3227

@@ -40,4 +35,4 @@ struct Camera {
4035
void updateCameraVectors();
4136
};
4237

43-
}
38+
} // namespace SpaceEngine

core/component/light.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace SpaceEngine {
44

5-
Light::Light() {
5+
Light::Light() {}
66

7-
}
8-
9-
}
7+
} // namespace SpaceEngine

core/component/light.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
namespace SpaceEngine {
66

7-
enum LightType {
8-
POINT,
9-
DIRECTIONAL,
10-
SPOT
11-
};
7+
enum LightType { POINT, DIRECTIONAL, SPOT };
128

139
struct Light {
1410
float intensity = 1.0f;
@@ -22,4 +18,4 @@ struct Light {
2218
Light();
2319
};
2420

25-
}
21+
} // namespace SpaceEngine

core/component/model_renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ void ModelRenderer::setModel() {
1111
model = std::make_shared<Model>(path.c_str());
1212
}
1313

14-
}
14+
} // namespace SpaceEngine

core/component/model_renderer.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#pragma once
22

3-
#include "model/model.hpp"
43
#include <memory>
54

5+
#include "model/model.hpp"
6+
67
namespace SpaceEngine {
78

89
struct ModelRenderer {
910
std::shared_ptr<Model> model;
10-
std::string path; // TODO this should not be a path
11+
std::string path; // TODO this should not be a path
1112

1213
ModelRenderer();
13-
void setModel(); // TODO can't remember why I did it like this, should be refactored
14+
void setModel(); // TODO can't remember why I did it like this, should be
15+
// refactored
1416
};
1517

16-
}
18+
} // namespace SpaceEngine

0 commit comments

Comments
 (0)