Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BasedOnStyle: Google
ColumnLimit: 100

SortIncludes: false

AllowShortFunctionsOnASingleLine: Empty
AllowShortBlocksOnASingleLine: Empty
ReflowComments: false

PenaltyBreakAssignment: 1000
PenaltyBreakBeforeFirstCallParameter: 1000
BinPackArguments: false
18 changes: 18 additions & 0 deletions .github/workflows/format-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Format Check

on:
pull_request:
push:
branches: [ main ]

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install clang-format
run: sudo apt install clang-format

- name: Check formatting
run: python3 format.py --check
11 changes: 6 additions & 5 deletions core/component/audio_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

namespace SpaceEngine {

//AudioSource::AudioSource() = default;
// AudioSource::AudioSource() = default;
//
//void AudioSource::setAudio(const std::string& path) {
// void AudioSource::setAudio(const std::string& path) {
// m_audioPath = path;
//// m_audio = ResourceManager::load<ResAudio>(path, std::dynamic_pointer_cast<IResourceUser>(shared_from_this()));
//// m_audio = ResourceManager::load<ResAudio>(path,
/// std::dynamic_pointer_cast<IResourceUser>(shared_from_this()));
//}
//
//void AudioSource::play() const {
// void AudioSource::play() const {
// if (m_audio) {
// // TODO: waiting for Audio system
// // Audio::playSound(m_audio->getData());
// }
//}

}
} // namespace SpaceEngine
16 changes: 8 additions & 8 deletions core/component/audio_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
namespace SpaceEngine {

struct AudioSource {
// explicit AudioSource();
//
// void setAudio(const std::string& path);
// void play() const;
//
// std::shared_ptr<ResAudio> m_audio;
// std::string m_audioPath;
// explicit AudioSource();
//
// void setAudio(const std::string& path);
// void play() const;
//
// std::shared_ptr<ResAudio> m_audio;
// std::string m_audioPath;
};

}
} // namespace SpaceEngine
36 changes: 20 additions & 16 deletions core/component/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,31 @@ glm::mat4 Camera::getViewMatrix(const World& world, Entity e) const {
}

glm::mat4 Camera::getProjectionMatrix() const {
if (projectionType == ProjectionType::PERSPECTIVE) {
glm::mat4 projection = glm::perspective(glm::radians(fieldOfView), aspectRatio, nearPlane, farPlane);
projection[1][1] *= -1;
return projection;
} else {
const float width = orthographicSize * aspectRatio;
const float height = orthographicSize;
glm::mat4 projection = glm::ortho(-width, width, -height, height, nearPlane, farPlane);
projection[1][1] *= -1;
return projection;
glm::mat4 projection;
switch (projectionType) {
case ProjectionType::PERSPECTIVE:
projection = glm::perspective(glm::radians(fieldOfView), aspectRatio, nearPlane, farPlane);
break;
case ProjectionType::ORTHOGRAPHIC:
projection = glm::ortho(-orthographicSize * aspectRatio,
orthographicSize * aspectRatio,
-orthographicSize,
orthographicSize,
nearPlane,
farPlane);
break;
}

projection[1][1] *= -1;
return projection;
}

void Camera::updateCameraVectors() {
front = glm::normalize(glm::vec3(
cos(glm::radians(yaw)) * cos(glm::radians(pitch)),
sin(glm::radians(pitch)),
sin(glm::radians(yaw)) * cos(glm::radians(pitch))
));
front = glm::normalize(glm::vec3(cos(glm::radians(yaw)) * cos(glm::radians(pitch)),
sin(glm::radians(pitch)),
sin(glm::radians(yaw)) * cos(glm::radians(pitch))));
right = glm::normalize(glm::cross(front, worldUp));
up = glm::normalize(glm::cross(right, front));
}

}
} // namespace SpaceEngine
19 changes: 7 additions & 12 deletions core/component/camera.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
#pragma once

#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"

#include "../imgui/imgui_impl_opengl3.h"

#include "ecs/world.hpp"
#include "ecs/entity.hpp"
#include "component/transform.hpp"
#include "ecs/entity.hpp"
#include "ecs/world.hpp"
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"

namespace SpaceEngine {

struct Camera {
enum class ProjectionType {
PERSPECTIVE,
ORTHOGRAPHIC
};
enum class ProjectionType { PERSPECTIVE, ORTHOGRAPHIC };

glm::vec3 front{};
glm::vec3 up{};
Expand All @@ -26,7 +21,7 @@ struct Camera {

ProjectionType projectionType = ProjectionType::PERSPECTIVE;
float fieldOfView = 45.0f;
float aspectRatio = 16.0f/9.0f;
float aspectRatio = 16.0f / 9.0f;
float nearPlane = 0.1f;
float farPlane = 100.0f;

Expand All @@ -40,4 +35,4 @@ struct Camera {
void updateCameraVectors();
};

}
} // namespace SpaceEngine
6 changes: 2 additions & 4 deletions core/component/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace SpaceEngine {

Light::Light() {
Light::Light() {}

}

}
} // namespace SpaceEngine
8 changes: 2 additions & 6 deletions core/component/light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

namespace SpaceEngine {

enum LightType {
POINT,
DIRECTIONAL,
SPOT
};
enum LightType { POINT, DIRECTIONAL, SPOT };

struct Light {
float intensity = 1.0f;
Expand All @@ -22,4 +18,4 @@ struct Light {
Light();
};

}
} // namespace SpaceEngine
2 changes: 1 addition & 1 deletion core/component/model_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ void ModelRenderer::setModel() {
model = std::make_shared<Model>(path.c_str());
}

}
} // namespace SpaceEngine
10 changes: 6 additions & 4 deletions core/component/model_renderer.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#pragma once

#include "model/model.hpp"
#include <memory>

#include "model/model.hpp"

namespace SpaceEngine {

struct ModelRenderer {
std::shared_ptr<Model> model;
std::string path; // TODO this should not be a path
std::string path; // TODO this should not be a path

ModelRenderer();
void setModel(); // TODO can't remember why I did it like this, should be refactored
void setModel(); // TODO can't remember why I did it like this, should be
// refactored
};

}
} // namespace SpaceEngine
2 changes: 1 addition & 1 deletion core/component/physic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Physic::Physic() {
this->gravity = false;
}

}
} // namespace SpaceEngine
2 changes: 1 addition & 1 deletion core/component/physic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ struct Physic {
Physic();
};

}
} // namespace SpaceEngine
2 changes: 1 addition & 1 deletion core/component/script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ struct Script {
virtual void onEnable();
};

}
} // namespace SpaceEngine
4 changes: 2 additions & 2 deletions core/component/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace SpaceEngine {

Transform::Transform(const std::string &name) {
Transform::Transform(const std::string& name) {
this->name = name;
this->position = Vec3f();
this->rotation = Vec3f();
this->scale = Vec3f(1.0f, 1.0f, 1.0f);
}

}
} // namespace SpaceEngine
9 changes: 5 additions & 4 deletions core/component/transform.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#pragma once

#include <string>

#include "maths/vector.hpp"

namespace SpaceEngine {

struct Transform {
public:
std::string name; // TODO stay for now but will be in its own component soon
public:
std::string name; // TODO stay for now but will be in its own component soon
Vec3f position;
Vec3f rotation;
Vec3f scale;

explicit Transform(const std::string &name);
explicit Transform(const std::string& name);
};

}
} // namespace SpaceEngine
17 changes: 8 additions & 9 deletions core/ecs/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
namespace SpaceEngine {

struct Entity {
u32 id{};
u32 id{};

bool operator==(const Entity& other) const {
return id == other.id;
}

bool operator!=(const Entity& other) const {
return id != other.id;
}
bool operator==(const Entity& other) const {
return id == other.id;
}
bool operator!=(const Entity& other) const {
return id != other.id;
}
};

}
} // namespace SpaceEngine
Loading