From 3d2428af8e8d9d49b4ade52d4806a7dae4cf1ab8 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 7 Nov 2024 20:03:14 +0100 Subject: merge #25 + nitpicking --- contributing.md | 17 +++++++++++++++++ src/crepe/api/Rigidbody.cpp | 2 +- src/crepe/api/Rigidbody.h | 13 ++++++------- src/crepe/api/Sprite.cpp | 4 ++-- src/crepe/api/Sprite.h | 7 ++++--- src/crepe/api/Transform.cpp | 8 +++----- src/crepe/api/Transform.h | 4 ++-- src/crepe/system/PhysicsSystem.cpp | 2 +- src/crepe/types.h | 1 - src/example/physics.cpp | 2 +- src/test/PhysicsTest.cpp | 5 +++-- 11 files changed, 40 insertions(+), 25 deletions(-) diff --git a/contributing.md b/contributing.md index ba8ad68..8799057 100644 --- a/contributing.md +++ b/contributing.md @@ -635,6 +635,23 @@ that you can click on to open them. } ``` +-
+ Assigning booleans should be done with the + true/false literals instead of + 0/1 +
GoodBad
+ + ```cpp + bool foo = true; + bool bar = false; + ``` + + + ```cpp + bool foo = 1; + bool bar = 0; + ``` +
## CMakeLists-specific diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp index 0de9846..cbf1325 100644 --- a/src/crepe/api/Rigidbody.cpp +++ b/src/crepe/api/Rigidbody.cpp @@ -2,7 +2,7 @@ using namespace crepe; -crepe::Rigidbody::Rigidbody(uint32_t game_object_id, const RigidbodyData & data) +crepe::Rigidbody::Rigidbody(uint32_t game_object_id, const Data & data) : Component(game_object_id), data(data) {} void crepe::Rigidbody::add_force_linear(const Vector2 & force) { diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index b12cf1d..68481f4 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -37,21 +37,20 @@ public: */ struct PhysicsConstraints { //! X constraint - bool x = 0; + bool x = false; //! Y constraint - bool y = 0; + bool y = false; //! rotation constraint - bool rotation = 0; + bool rotation = false; }; public: /** - * * \brief struct for Rigidbody data * * This struct holds the data for the Rigidbody. */ - struct RigidbodyData { + struct Data { //! objects mass double mass = 0.0; //! gravtiy scale @@ -83,9 +82,9 @@ public: * \param game_object_id id of the gameobject the rigibody is added to. * \param data struct to configure the rigidbody. */ - Rigidbody(uint32_t game_object_id, const RigidbodyData & data); + Rigidbody(uint32_t game_object_id, const Data & data); //! struct to hold data of rigidbody - RigidbodyData data; + Data data; public: /** diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index 7e810b5..d3465c7 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -10,8 +10,8 @@ using namespace std; using namespace crepe; -Sprite::Sprite(game_object_id_t id, shared_ptr image, const Color & color, - const FlipSettings & flip) +Sprite::Sprite(game_object_id_t id, shared_ptr image, + const Color & color, const FlipSettings & flip) : Component(id), color(color), flip(flip), sprite_image(image) { dbg_trace(); } diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index 28078cd..00dcb27 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -12,14 +12,15 @@ namespace crepe { struct FlipSettings { - bool flip_x = 1; - bool flip_y = 1; + bool flip_x = true; + bool flip_y = true; }; class Sprite : public Component { public: - Sprite(game_object_id_t id, std::shared_ptr image, const Color & color, const FlipSettings & flip); + Sprite(game_object_id_t id, std::shared_ptr image, + const Color & color, const FlipSettings & flip); ~Sprite(); std::shared_ptr sprite_image; Color color; diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index a5f29ea..a244bc5 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -1,13 +1,11 @@ -#include - #include "util/log.h" #include "Transform.h" using namespace crepe; -Transform::Transform(game_object_id_t id, const Vector2 & point, double rot, - double scale) - : Component(id), position(point), rotation(rot), scale(scale) { +Transform::Transform(game_object_id_t id, const Vector2 & point, + double rotation, double scale) + : Component(id), position(point), rotation(rotation), scale(scale) { dbg_trace(); } diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h index 805553e..d7a5b8a 100644 --- a/src/crepe/api/Transform.h +++ b/src/crepe/api/Transform.h @@ -17,10 +17,10 @@ public: /** * \param id The id of the GameObject this component belongs to * \param point The position of the GameObject - * \param rot The rotation of the GameObject + * \param rotation The rotation of the GameObject * \param scale The scale of the GameObject */ - Transform(game_object_id_t id, const Vector2 & point, double rot, + Transform(game_object_id_t id, const Vector2 & point, double rotation, double scale); /** * \brief Get the maximum number of instances for this component diff --git a/src/crepe/system/PhysicsSystem.cpp b/src/crepe/system/PhysicsSystem.cpp index 1bd2171..eb54ad3 100644 --- a/src/crepe/system/PhysicsSystem.cpp +++ b/src/crepe/system/PhysicsSystem.cpp @@ -20,7 +20,7 @@ void PhysicsSystem::update() { double gravity = Config::get_instance().physics.gravity; for (Rigidbody & rigidbody : rigidbodies) { if (!rigidbody.active) continue; - + switch (rigidbody.data.body_type) { case Rigidbody::BodyType::DYNAMIC: for (Transform & transform : transforms) { diff --git a/src/crepe/types.h b/src/crepe/types.h index 5ae2c81..0d459e8 100644 --- a/src/crepe/types.h +++ b/src/crepe/types.h @@ -7,4 +7,3 @@ namespace crepe { typedef uint32_t game_object_id_t; } - diff --git a/src/example/physics.cpp b/src/example/physics.cpp index a7e94f6..848f857 100644 --- a/src/example/physics.cpp +++ b/src/example/physics.cpp @@ -11,7 +11,7 @@ using namespace std; int main(int argc, char * argv[]) { GameObject * game_object; game_object = new GameObject(0, "Name", "Tag", Vector2{0, 0}, 0, 0); - game_object->add_component(Rigidbody::RigidbodyData{ + game_object->add_component(Rigidbody::Data{ .mass = 1, .gravity_scale = 1, .body_type = Rigidbody::BodyType::DYNAMIC, diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp index 6b8c4d8..5385962 100644 --- a/src/test/PhysicsTest.cpp +++ b/src/test/PhysicsTest.cpp @@ -20,7 +20,7 @@ protected: = mgr.get_components_by_id(0); if (transforms.empty()) { game_object = new GameObject(0, "", "", Vector2{0, 0}, 0, 0); - game_object->add_component(Rigidbody::RigidbodyData{ + game_object->add_component(Rigidbody::Data{ .mass = 1, .gravity_scale = 1, .body_type = Rigidbody::BodyType::DYNAMIC, @@ -28,7 +28,8 @@ protected: .max_angular_velocity = 10, .constraints = {0, 0}, .use_gravity = true, - .bounce = false}); + .bounce = false, + }); } transforms = mgr.get_components_by_id(0); Transform & transform = transforms.front().get(); -- cgit v1.2.3