aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-06 13:45:05 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-06 13:45:05 +0200
commit509fb6ebdd27bc75375c1c51024ea906e25032c0 (patch)
tree89ef8b7e72b25c30e42d73de08769a4402ef0716
parent7c9d3452c99fcb89ea6df55755e90f741b23cf10 (diff)
WIP more code style enforcements
-rw-r--r--.clang-format2
-rw-r--r--.clang-tidy43
-rw-r--r--.editorconfig2
-rw-r--r--mwe/ecs-homemade/inc/ComponentManager.hpp3
-rw-r--r--mwe/ecs-homemade/inc/GameObjectMax.h3
-rw-r--r--src/crepe/ComponentManager.cpp5
-rw-r--r--src/crepe/ComponentManager.h27
-rw-r--r--src/crepe/ComponentManager.hpp38
-rw-r--r--src/crepe/Components.cpp9
-rw-r--r--src/crepe/Components.h18
-rw-r--r--src/crepe/GameObject.cpp2
-rw-r--r--src/crepe/GameObject.h16
-rw-r--r--src/crepe/GameObject.hpp6
-rw-r--r--src/crepe/api/AudioSource.h2
14 files changed, 104 insertions, 72 deletions
diff --git a/.clang-format b/.clang-format
index d2918db..3ae6c28 100644
--- a/.clang-format
+++ b/.clang-format
@@ -22,7 +22,7 @@ AlignTrailingComments:
ReflowComments: false
AlignEscapedNewlines: DontAlign
BreakBeforeBinaryOperators: All
-BreakTemplateDeclarations: Yes
+AlwaysBreakTemplateDeclarations: Yes
...
# vim: ft=yaml
diff --git a/.clang-tidy b/.clang-tidy
index b242e3f..0ec997d 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,18 +1,33 @@
Checks: '-*,readability-identifier-naming'
CheckOptions:
- - { key: readability-identifier-naming.EnumCase, value: lower_case }
- - { key: readability-identifier-naming.GlobalFunctionCase, value: lower_case }
- - { key: readability-identifier-naming.ClassCase, value: CamelCase }
- - { key: readability-identifier-naming.ClassMethodCase, value: lower_case }
- - { key: readability-identifier-naming.ClassMethodPrefix, value: '' }
- - { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
- - { key: readability-identifier-naming.ClassMemberPrefix, value: '' }
- - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
- - { key: readability-identifier-naming.GlobalConstantIgnoredRegexp, value: _.* }
- - { key: readability-identifier-naming.GlobalVariableCase, value: lower_case }
- - { key: readability-identifier-naming.GlobalVariableIgnoredRegexp, value: _.* }
- - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
- - { key: readability-identifier-naming.MacroDefinitionIgnoredRegexp, value: _.* }
- - { key: readability-identifier-naming.StructCase, value: lower_case }
+ - key: 'readability-identifier-naming.EnumCase'
+ value: 'lower_case'
+ - key: 'readability-identifier-naming.GlobalFunctionCase'
+ value: 'lower_case'
+ - key: 'readability-identifier-naming.ClassCase'
+ value: 'CamelCase'
+ - key: 'readability-identifier-naming.MethodCase'
+ value: 'lower_case'
+ - key: 'readability-identifier-naming.MethodPrefix'
+ value: ''
+ - key: 'readability-identifier-naming.MemberCase'
+ value: 'lower_case'
+ - key: 'readability-identifier-naming.MemberPrefix'
+ value: ''
+ - key: 'readability-identifier-naming.GlobalConstantCase'
+ value: 'UPPER_CASE'
+ - key: 'readability-identifier-naming.GlobalConstantIgnoredRegexp'
+ value: '_.*'
+ - key: 'readability-identifier-naming.GlobalVariableCase'
+ value: 'lower_case'
+ - key: 'readability-identifier-naming.GlobalVariableIgnoredRegexp'
+ value: '_.*'
+ - key: 'readability-identifier-naming.MacroDefinitionCase'
+ value: 'UPPER_CASE'
+ - key: 'readability-identifier-naming.MacroDefinitionIgnoredRegexp'
+ value: '_.*'
+ - key: 'readability-identifier-naming.StructCase'
+ value: 'lower_case'
# vim: ft=yaml
+
diff --git a/.editorconfig b/.editorconfig
index 1bd7da9..df2cf5e 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -5,7 +5,7 @@ indent_style = tab
end_of_line = lf
insert_final_newline = true
-[*.{md,yml}]
+[{*.{md,yml},.clang-*}]
indent_style = space
indent_size = 2
diff --git a/mwe/ecs-homemade/inc/ComponentManager.hpp b/mwe/ecs-homemade/inc/ComponentManager.hpp
index 161ce71..d6da8e8 100644
--- a/mwe/ecs-homemade/inc/ComponentManager.hpp
+++ b/mwe/ecs-homemade/inc/ComponentManager.hpp
@@ -42,7 +42,8 @@ void ComponentManager::DeleteComponentsById(std::uint32_t id) {
}
}
-template <typename T> void ComponentManager::DeleteComponents() {
+template <typename T>
+void ComponentManager::DeleteComponents() {
std::type_index type = typeid(
T); //Determine the type of T (this is used as the key of the unordered_map<>)
diff --git a/mwe/ecs-homemade/inc/GameObjectMax.h b/mwe/ecs-homemade/inc/GameObjectMax.h
index c88a834..3029053 100644
--- a/mwe/ecs-homemade/inc/GameObjectMax.h
+++ b/mwe/ecs-homemade/inc/GameObjectMax.h
@@ -7,7 +7,8 @@ class GameObject {
public:
GameObject(std::uint32_t id, std::string name, std::string tag, int layer);
- template <typename T, typename... Args> void AddComponent(Args &&... args);
+ template <typename T, typename... Args>
+ void AddComponent(Args &&... args);
std::uint32_t mId;
std::string mName;
diff --git a/src/crepe/ComponentManager.cpp b/src/crepe/ComponentManager.cpp
index b7a1bea..b080c9d 100644
--- a/src/crepe/ComponentManager.cpp
+++ b/src/crepe/ComponentManager.cpp
@@ -7,7 +7,7 @@ ComponentManager & ComponentManager::get_instance() {
return instance;
}
-void ComponentManager::DeleteAllComponentsOfId(std::uint32_t id) {
+void ComponentManager::delete_all_components_of_id(std::uint32_t id) {
// Loop through all the types (in the unordered_map<>)
for (auto & [type, componentArray] : components) {
// Make sure that the id (that we are looking for) is within the boundaries of the vector<>
@@ -18,8 +18,7 @@ void ComponentManager::DeleteAllComponentsOfId(std::uint32_t id) {
}
}
-void ComponentManager::DeleteAllComponents() {
+void ComponentManager::delete_all_components() {
// Clear the whole unordered_map<>
components.clear();
}
-
diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h
index 003cd0b..b88ad27 100644
--- a/src/crepe/ComponentManager.h
+++ b/src/crepe/ComponentManager.h
@@ -22,20 +22,26 @@ public:
public:
//! Add a component of a specific type
- template <typename T, typename... Args> void AddComponent(std::uint32_t id, Args &&... args);
+ template <typename T, typename... Args>
+ void add_component(std::uint32_t id, Args &&... args);
//! Deletes all components of a specific type and id
- template <typename T> void DeleteComponentsById(std::uint32_t id);
+ template <typename T>
+ void delete_components_by_id(std::uint32_t id);
//! Deletes all components of a specific type
- template <typename T> void DeleteComponents();
+ template <typename T>
+ void delete_components();
//! Deletes all components of a specific id
- void DeleteAllComponentsOfId(std::uint32_t id);
+ void delete_all_components_of_id(std::uint32_t id);
//! Deletes all components
- void DeleteAllComponents();
+ void delete_all_components();
//! Get a vector<> of all components at specific type and id
- template <typename T> std::vector<std::reference_wrapper<T>> GetComponentsByID(std::uint32_t id) const;
+ template <typename T>
+ std::vector<std::reference_wrapper<T>>
+ get_components_by_id(std::uint32_t id) const;
//! Get a vector<> of all components of a specific type
- template <typename T> std::vector<std::reference_wrapper<T>> GetComponentsByType() const;
+ template <typename T>
+ std::vector<std::reference_wrapper<T>> get_components_by_type() const;
private:
ComponentManager() = default;
@@ -46,10 +52,11 @@ private:
* The first std::vector<> stores another vector<>. This first vector<> is to bind the entity's id to a component.
* The second std::vector<> stores unique_ptrs. Each component can be gathered via an unique_ptr. This second vector<> allows multiple components of the same std::type_index for one entity (id).
*/
- std::unordered_map<std::type_index, std::vector<std::vector<std::unique_ptr<Component>>>> components;
+ std::unordered_map<std::type_index,
+ std::vector<std::vector<std::unique_ptr<Component>>>>
+ components;
};
-}
+} // namespace crepe
// #include "ComponentManager.hpp"
-
diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp
index 602490e..30b0e38 100644
--- a/src/crepe/ComponentManager.hpp
+++ b/src/crepe/ComponentManager.hpp
@@ -5,14 +5,15 @@
namespace crepe {
template <typename T, typename... Args>
-void ComponentManager::AddComponent(std::uint32_t id, Args &&... args) {
+void ComponentManager::add_component(std::uint32_t id, Args &&... args) {
// Determine the type of T (this is used as the key of the unordered_map<>)
std::type_index type = typeid(T);
// Check if this component type is already in the unordered_map<>
if (components.find(type) == components.end()) {
//If not, create a new (empty) vector<> of vector<unique_ptr<Component>>
- components[type] = std::vector<std::vector<std::unique_ptr<Component>>>();
+ components[type]
+ = std::vector<std::vector<std::unique_ptr<Component>>>();
}
// Resize the vector<> if the id is greater than the current size
@@ -23,18 +24,20 @@ void ComponentManager::AddComponent(std::uint32_t id, Args &&... args) {
// Create a new component of type T using perfect forwarding and store its
// unique_ptr in the vector<>
- components[type][id].push_back(std::make_unique<T>(std::forward<Args>(args)...));
+ components[type][id].push_back(
+ std::make_unique<T>(std::forward<Args>(args)...));
}
template <typename T>
-void ComponentManager::DeleteComponentsById(std::uint32_t id) {
+void ComponentManager::delete_components_by_id(std::uint32_t id) {
// Determine the type of T (this is used as the key of the unordered_map<>)
std::type_index type = typeid(T);
// Find the type (in the unordered_map<>)
if (components.find(type) != components.end()) {
// Get the correct vector<>
- std::vector<std::vector<std::unique_ptr<Component>>> & componentArray = components[type];
+ std::vector<std::vector<std::unique_ptr<Component>>> & componentArray
+ = components[type];
// Make sure that the id (that we are looking for) is within the boundaries of the vector<>
if (id < componentArray.size()) {
@@ -45,7 +48,7 @@ void ComponentManager::DeleteComponentsById(std::uint32_t id) {
}
template <typename T>
-void ComponentManager::DeleteComponents() {
+void ComponentManager::delete_components() {
// Determine the type of T (this is used as the key of the unordered_map<>)
std::type_index type = typeid(T);
@@ -58,7 +61,7 @@ void ComponentManager::DeleteComponents() {
template <typename T>
std::vector<std::reference_wrapper<T>>
-ComponentManager::GetComponentsByID(std::uint32_t id) const {
+ComponentManager::get_components_by_id(std::uint32_t id) const {
// Determine the type of T (this is used as the key of the unordered_map<>)
std::type_index type = typeid(T);
@@ -68,12 +71,15 @@ ComponentManager::GetComponentsByID(std::uint32_t id) const {
// Find the type (in the unordered_map<>)
if (components.find(type) != components.end()) {
// Get the correct vector<>
- const std::vector<std::vector<std::unique_ptr<Component>>> & componentArray = components.at(type);
+ const std::vector<std::vector<std::unique_ptr<Component>>> &
+ componentArray
+ = components.at(type);
// Make sure that the id (that we are looking for) is within the boundaries of the vector<>
- if (id < componentArray .size()) {
+ if (id < componentArray.size()) {
// Loop trough the whole vector<>
- for (const std::unique_ptr<Component> & componentPtr : componentArray[id]) {
+ for (const std::unique_ptr<Component> & componentPtr :
+ componentArray[id]) {
// Cast the unique_ptr to a raw pointer
T * castedComponent = static_cast<T *>(componentPtr.get());
@@ -92,7 +98,7 @@ ComponentManager::GetComponentsByID(std::uint32_t id) const {
template <typename T>
std::vector<std::reference_wrapper<T>>
-ComponentManager::GetComponentsByType() const {
+ComponentManager::get_components_by_type() const {
// Determine the type of T (this is used as the key of the unordered_map<>)
std::type_index type = typeid(T);
@@ -105,10 +111,13 @@ ComponentManager::GetComponentsByType() const {
if (components.find(type) != components.end()) {
// Get the correct vector<>
- const std::vector<std::vector<std::unique_ptr<Component>>> & componentArray = components.at(type);
+ const std::vector<std::vector<std::unique_ptr<Component>>> &
+ componentArray
+ = components.at(type);
// Loop through the whole vector<>
- for (const std::vector<std::unique_ptr<Component>> & component : componentArray) {
+ for (const std::vector<std::unique_ptr<Component>> & component :
+ componentArray) {
// Loop trough the whole vector<>
for (const std::unique_ptr<Component> & componentPtr : component) {
// Cast the unique_ptr to a raw pointer
@@ -130,5 +139,4 @@ ComponentManager::GetComponentsByType() const {
return componentVector;
}
-}
-
+} // namespace crepe
diff --git a/src/crepe/Components.cpp b/src/crepe/Components.cpp
index 9760daa..4a43692 100644
--- a/src/crepe/Components.cpp
+++ b/src/crepe/Components.cpp
@@ -3,11 +3,12 @@
using namespace crepe;
-Component::Component() : mActive(true) {}
+Component::Component() : m_active(true) {}
-Sprite::Sprite(std::string path) : mPath(path) {}
+Sprite::Sprite(std::string path) : m_path(path) {}
Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType)
- : mMass(mass), mGravityScale(gravityScale), mBodyType(bodyType) {}
+ : m_mass(mass), m_gravity_scale(gravityScale), m_body_type(bodyType) {}
+
+Collider::Collider(int size) : m_size(size) {}
-Colider::Colider(int size) : mSize(size) {}
diff --git a/src/crepe/Components.h b/src/crepe/Components.h
index 7cb6fbb..1ad9ef2 100644
--- a/src/crepe/Components.h
+++ b/src/crepe/Components.h
@@ -8,7 +8,7 @@ class Component {
public:
Component();
- bool mActive;
+ bool m_active;
};
// TODO: these should be in separate files
@@ -17,23 +17,23 @@ class Sprite : public Component {
public:
Sprite(std::string path);
- std::string mPath;
+ std::string m_path;
};
class Rigidbody : public Component {
public:
Rigidbody(int mass, int gravityScale, int bodyType);
- int mMass;
- int mGravityScale;
- int mBodyType;
+ int m_mass;
+ int m_gravity_scale;
+ int m_body_type;
};
-class Colider : public Component {
+class Collider : public Component {
public:
- Colider(int size);
+ Collider(int size);
- int mSize;
+ int m_size;
};
-}
+} // namespace crepe
diff --git a/src/crepe/GameObject.cpp b/src/crepe/GameObject.cpp
index 5ac9d7a..16dc62f 100644
--- a/src/crepe/GameObject.cpp
+++ b/src/crepe/GameObject.cpp
@@ -6,4 +6,4 @@ using namespace crepe;
GameObject::GameObject(std::uint32_t id, std::string name, std::string tag,
int layer)
- : mId(id), mName(name), mTag(tag), mActive(true), mLayer(layer) {}
+ : m_id(id), m_name(name), m_tag(tag), m_active(true), m_layer(layer) {}
diff --git a/src/crepe/GameObject.h b/src/crepe/GameObject.h
index 71ef60d..f0f5ea0 100644
--- a/src/crepe/GameObject.h
+++ b/src/crepe/GameObject.h
@@ -9,14 +9,14 @@ class GameObject {
public:
GameObject(std::uint32_t id, std::string name, std::string tag, int layer);
- template <typename T, typename... Args> void AddComponent(Args &&... args);
+ template <typename T, typename... Args>
+ void add_component(Args &&... args);
- std::uint32_t mId;
- std::string mName;
- std::string mTag;
- bool mActive;
- int mLayer;
+ std::uint32_t m_id;
+ std::string m_name;
+ std::string m_tag;
+ bool m_active;
+ int m_layer;
};
-}
-
+} // namespace crepe
diff --git a/src/crepe/GameObject.hpp b/src/crepe/GameObject.hpp
index 5a672cf..1152ddf 100644
--- a/src/crepe/GameObject.hpp
+++ b/src/crepe/GameObject.hpp
@@ -8,8 +8,8 @@ namespace crepe {
template <typename T, typename... Args>
void GameObject::AddComponent(Args &&... args) {
- ComponentManager::get_instance().AddComponent<T>(mId, std::forward<Args>(args)...);
-}
-
+ ComponentManager::get_instance().AddComponent<T>(
+ mId, std::forward<Args>(args)...);
}
+} // namespace crepe
diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h
index 2002d1a..2d26cda 100644
--- a/src/crepe/api/AudioSource.h
+++ b/src/crepe/api/AudioSource.h
@@ -35,7 +35,7 @@ public:
float volume;
private:
- std::unique_ptr<crepe::Sound> _sound;
+ std::unique_ptr<crepe::Sound> sound;
};
} // namespace crepe::api