diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-07 20:03:14 +0100 | 
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-07 20:03:14 +0100 | 
| commit | 3d2428af8e8d9d49b4ade52d4806a7dae4cf1ab8 (patch) | |
| tree | 30d908c427ff9b4ee53402fbf52cb15704e58623 | |
| parent | fde229c24dcbd1ed844880a35eabddb88279802b (diff) | |
merge #25 + nitpicking
| -rw-r--r-- | contributing.md | 17 | ||||
| -rw-r--r-- | src/crepe/api/Rigidbody.cpp | 2 | ||||
| -rw-r--r-- | src/crepe/api/Rigidbody.h | 13 | ||||
| -rw-r--r-- | src/crepe/api/Sprite.cpp | 4 | ||||
| -rw-r--r-- | src/crepe/api/Sprite.h | 7 | ||||
| -rw-r--r-- | src/crepe/api/Transform.cpp | 8 | ||||
| -rw-r--r-- | src/crepe/api/Transform.h | 4 | ||||
| -rw-r--r-- | src/crepe/system/PhysicsSystem.cpp | 2 | ||||
| -rw-r--r-- | src/crepe/types.h | 1 | ||||
| -rw-r--r-- | src/example/physics.cpp | 2 | ||||
| -rw-r--r-- | 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.    }    ```    </td></tr></table></details> +- <details><summary> +  Assigning booleans should be done with the +  <code>true</code>/<code>false</code> literals instead of +  <code>0</code>/<code>1</code> +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td> + +  ```cpp +  bool foo = true; +  bool bar = false; +  ``` +  </td><td> + +  ```cpp +  bool foo = 1; +  bool bar = 0; +  ``` +  </td></tr></table></details>  ## 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<Texture> image, const Color & color, -			   const FlipSettings & flip) +Sprite::Sprite(game_object_id_t id, shared_ptr<Texture> 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<Texture> image, const Color & color, const FlipSettings & flip); +	Sprite(game_object_id_t id, std::shared_ptr<Texture> image, +		   const Color & color, const FlipSettings & flip);  	~Sprite();  	std::shared_ptr<Texture> 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 <cstdint> -  #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>(Rigidbody::RigidbodyData{ +	game_object->add_component<Rigidbody>(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<Transform>(0);  		if (transforms.empty()) {  			game_object = new GameObject(0, "", "", Vector2{0, 0}, 0, 0); -			game_object->add_component<Rigidbody>(Rigidbody::RigidbodyData{ +			game_object->add_component<Rigidbody>(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<Transform>(0);  		Transform & transform = transforms.front().get(); |