From b019b401c3a1de0ffea7e6776242ae73599651ef Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 15 Nov 2024 16:10:45 +0100 Subject: collision handeling example --- src/crepe/api/Script.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/crepe/api/Script.h') diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 49e625f..0a10848 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -28,7 +28,7 @@ protected: template std::vector> get_components(); -private: +public: friend class crepe::BehaviorScript; BehaviorScript * parent = nullptr; }; -- cgit v1.2.3 From 690471c7c4536c074a4dca5aab7cc618d47bfb5f Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 20 Nov 2024 10:43:32 +0100 Subject: merge with maser --- src/crepe/api/LoopManager.cpp | 6 +- src/crepe/api/LoopManager.h | 5 +- src/crepe/api/Script.h | 9 ++- src/crepe/system/CollisionSystem.cpp | 6 +- src/crepe/system/CollisionSystem.h | 2 - src/example/CMakeLists.txt | 2 +- src/example/collision.cpp | 123 ----------------------------------- src/example/game.cpp | 89 +++++++++++++++++++++++++ src/example/particles.cpp | 43 ------------ src/example/physics.cpp | 24 ------- src/example/rendering.cpp | 4 +- src/test/CMakeLists.txt | 2 - src/test/CollisionTest.cpp | 121 ++++++++++++++++------------------ 13 files changed, 165 insertions(+), 271 deletions(-) delete mode 100644 src/example/collision.cpp create mode 100644 src/example/game.cpp delete mode 100644 src/example/particles.cpp delete mode 100644 src/example/physics.cpp (limited to 'src/crepe/api/Script.h') diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index a4bc101..586919d 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -35,10 +35,8 @@ void LoopManager::start() { void LoopManager::set_running(bool running) { this->game_running = running; } void LoopManager::fixed_update() { - PhysicsSystem phys; - phys.update(); - CollisionSystem col; - col.update(); + this->get_system().update(); + this->get_system().update(); } void LoopManager::loop() { diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h index f6904be..37f13ac 100644 --- a/src/crepe/api/LoopManager.h +++ b/src/crepe/api/LoopManager.h @@ -4,6 +4,7 @@ #include "../ComponentManager.h" #include "../system/System.h" +#include "api/SceneManager.h" namespace crepe { @@ -71,7 +72,9 @@ private: private: //! Component manager instance ComponentManager component_manager{}; - +public: + //! Scene manager instance + SceneManager scene_manager{component_manager}; private: /** * \brief Collection of System instances diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 2b70379..939d142 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -63,7 +63,14 @@ protected: */ template std::vector> get_components() const; - + + /** + * \brief Gets game object id this script is attached to + * + * \returns game object id + */ + game_object_id_t get_game_object_id() const {return this->game_object_id;}; + protected: // NOTE: Script must have a constructor without arguments so the game programmer doesn't need // to manually add `using Script::Script` to their concrete script class. diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index df0ee41..3e73b44 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -18,11 +18,9 @@ using namespace crepe; -CollisionSystem::CollisionSystem() {} - void CollisionSystem::update() { // Get collider components and keep them seperate - ComponentManager & mgr = ComponentManager::get_instance(); + ComponentManager & mgr = this->component_manager; std::vector> boxcolliders = mgr.get_components_by_type(); std::vector> circlecolliders = mgr.get_components_by_type(); @@ -185,7 +183,7 @@ void CollisionSystem::static_collision_handler(CollisionInfo& info){ } std::vector> CollisionSystem::check_collisions(const std::vector>& boxcolliders, const std::vector>& circlecolliders) { - ComponentManager & mgr = ComponentManager::get_instance(); + ComponentManager & mgr = this->component_manager; std::vector> collisions_ret; // TODO: diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 0518b34..d94f6bc 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -70,8 +70,6 @@ public: public: - CollisionSystem(); - //! Updates the collision system by checking for collisions between colliders and handling them. void update() override; diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index d2ea926..2facc4d 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -28,7 +28,7 @@ add_example(proxy) add_example(db) add_example(ecs) add_example(scene_manager) -add_example(collision) +add_example(game) add_example(events) add_example(particles) add_example(gameloop) diff --git a/src/example/collision.cpp b/src/example/collision.cpp deleted file mode 100644 index f51380e..0000000 --- a/src/example/collision.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "api/BoxCollider.h" -#include "system/CollisionSystem.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using namespace crepe; -using namespace std; - -class MyScript : public Script { - static bool oncollision(const CollisionEvent& test) { - std::cout << "test collision: " << test.info.first.collider.game_object_id << std::endl; - return true; - } - void init() { - EventManager::get_instance().subscribe(oncollision, this->parent->game_object_id); - } - void update() { - // Retrieve component from the same GameObject this script is on - - } - - -}; - -int main(int argc, char * argv[]) { - //setup - LoopManager gameloop; - Color color(0, 0, 0, 0); - - double screen_size_width = 640; - double screen_size_height = 480; - double world_collider = 1000; - //define playable world - GameObject World(0, "Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1); - World.add_component(Rigidbody::Data{ - .mass = 0, - .gravity_scale = 0, - .body_type = Rigidbody::BodyType::STATIC, - .constraints = {0, 0, 0}, - .use_gravity = false, - .bounce = false, - .offset = {0,0} - }); - World.add_component(Vector2{0, 0-(screen_size_height/2+world_collider/2)}, world_collider, world_collider);; // Top - World.add_component(Vector2{0, screen_size_height/2+world_collider/2}, world_collider, world_collider); // Bottom - World.add_component(Vector2{0-(screen_size_width/2+world_collider/2), 0}, world_collider, world_collider); // Left - World.add_component(Vector2{screen_size_width/2+world_collider/2, 0}, world_collider, world_collider); // right - - - GameObject game_object1(1, "Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1); - game_object1.add_component(Rigidbody::Data{ - .mass = 1, - .gravity_scale = 0.01, - .body_type = Rigidbody::BodyType::DYNAMIC, - .linear_velocity = {1,0}, - .constraints = {0, 0, 0}, - .use_gravity = true, - .bounce = true, - .elastisity = 1, - .offset = {0,0}, - }); - game_object1.add_component(Vector2{0, 0}, 20, 20); - game_object1.add_component().set_script(); - game_object1.add_component( - make_shared("/home/jaro/crepe/asset/texture/green_square.png"), color, - FlipSettings{true, true}); - game_object1.add_component(Color::get_white()); - - - // GameObject game_object2(2, "Name", "Tag", Vector2{20, 470}, 0, 1); - // game_object2.add_component(Rigidbody::Data{ - // .mass = 1, - // .gravity_scale = 1, - // .body_type = Rigidbody::BodyType::DYNAMIC, - // .linear_velocity = {0,0}, - // .constraints = {0, 0, 0}, - // .use_gravity = false, - // .bounce = false, - // .offset = {0,0}, - // }); - // game_object2.add_component(Vector2{0, 0}, 0, 0); - // game_object2.add_component().set_script(); - // game_object2.add_component( - // make_shared("/home/jaro/crepe/asset/texture/red_square.png"), color, - // FlipSettings{true, true}); - - - crepe::ScriptSystem sys; - // Update all scripts. This should result in MyScript::update being called - sys.update(); - - gameloop.start(); - // auto & render = crepe::RenderSystem::get_instance(); - // auto start = std::chrono::steady_clock::now(); - // while (std::chrono::steady_clock::now() - start < std::chrono::seconds(5)) { - // render.update(); - // } - - - return 0; -} diff --git a/src/example/game.cpp b/src/example/game.cpp new file mode 100644 index 0000000..a9f6103 --- /dev/null +++ b/src/example/game.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace crepe; + +using namespace std; + +class MyScript : public Script { + static bool oncollision(const CollisionEvent& test) { + std::cout << "test collision: " << test.info.first.collider.game_object_id << std::endl; + return true; + } + void init() { + EventManager::get_instance().subscribe(oncollision, this->get_game_object_id()); + } + void update() { + // Retrieve component from the same GameObject this script is on + + } +}; + +class ConcreteScene1 : public Scene { +public: + using Scene::Scene; + + void load_scene() { + ComponentManager & mgr = this->component_manager; + Color color(0, 0, 0, 0); + + double screen_size_width = 640; + double screen_size_height = 480; + double world_collider = 1000; + //define playable world + GameObject world = mgr.new_object("Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1); + world.add_component(Rigidbody::Data{ + .mass = 0, + .gravity_scale = 0, + .body_type = Rigidbody::BodyType::STATIC, + .constraints = {0, 0, 0}, + .use_gravity = false, + .bounce = false, + .offset = {0,0} + }); + world.add_component(Vector2{0, 0-(screen_size_height/2+world_collider/2)}, world_collider, world_collider);; // Top + world.add_component(Vector2{0, screen_size_height/2+world_collider/2}, world_collider, world_collider); // Bottom + world.add_component(Vector2{0-(screen_size_width/2+world_collider/2), 0}, world_collider, world_collider); // Left + world.add_component(Vector2{screen_size_width/2+world_collider/2, 0}, world_collider, world_collider); // right + + + GameObject game_object1 = mgr.new_object("Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1); + game_object1.add_component(Rigidbody::Data{ + .mass = 1, + .gravity_scale = 0.01, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = {1,0}, + .constraints = {0, 0, 0}, + .use_gravity = true, + .bounce = true, + .elastisity = 1, + .offset = {0,0}, + }); + game_object1.add_component(Vector2{0, 0}, 20, 20); + game_object1.add_component().set_script(); + game_object1.add_component( + make_shared("/home/jaro/crepe/asset/texture/green_square.png"), color, + FlipSettings{true, true}); + game_object1.add_component(Color::get_white()); + } +}; + +int main(int argc, char * argv[]) { + + LoopManager gameloop; + gameloop.scene_manager.add_scene("scene1"); + gameloop.scene_manager.load_next_scene(); + gameloop.start(); + return 0; +} diff --git a/src/example/particles.cpp b/src/example/particles.cpp deleted file mode 100644 index 3d5f676..0000000 --- a/src/example/particles.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -int main(int argc, char * argv[]) { - ComponentManager mgr{}; - GameObject game_object = mgr.new_object("", "", Vector2{0, 0}, 0, 0); - Color color(0, 0, 0, 0); - Sprite test_sprite = game_object.add_component( - make_shared("../asset/texture/img.png"), color, FlipSettings{true, true}); - game_object.add_component(ParticleEmitter::Data{ - .position = {0, 0}, - .max_particles = 100, - .emission_rate = 0, - .min_speed = 0, - .max_speed = 0, - .min_angle = 0, - .max_angle = 0, - .begin_lifespan = 0, - .end_lifespan = 0, - .force_over_time = Vector2{0, 0}, - .boundary{ - .width = 0, - .height = 0, - .offset = Vector2{0, 0}, - .reset_on_exit = false, - }, - .sprite = test_sprite, - }); - - return 0; -} diff --git a/src/example/physics.cpp b/src/example/physics.cpp deleted file mode 100644 index ad663a0..0000000 --- a/src/example/physics.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -int main(int argc, char * argv[]) { - ComponentManager mgr{}; - - GameObject game_object = mgr.new_object("Name", "Tag", Vector2{0, 0}, 0, 0); - game_object.add_component(Rigidbody::Data{ - .mass = 1, - .gravity_scale = 1, - .body_type = Rigidbody::BodyType::DYNAMIC, - .constraints = {0, 0, 0}, - .use_gravity = true, - .bounce = false, - }); - return 0; -} diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp index c9e62f1..14ecaa9 100644 --- a/src/example/rendering.cpp +++ b/src/example/rendering.cpp @@ -30,13 +30,13 @@ int main() { // Normal adding components { Color color(0, 0, 0, 0); - obj.add_component(make_shared("../asset/texture/img.png"), color, + obj.add_component(make_shared("/home/jaro/crepe/asset/texture/green_square.png"), color, FlipSettings{false, false}); obj.add_component(Color::get_red()); } { Color color(0, 0, 0, 0); - obj1.add_component(make_shared("../asset/texture/second.png"), color, + obj1.add_component(make_shared("/home/jaro/crepe/asset/texture/green_square.png"), color, FlipSettings{true, true}); } diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index a41d097..f830165 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,6 +1,4 @@ target_sources(test_main PUBLIC - dummy.cpp - # audio.cpp CollisionTest.cpp main.cpp PhysicsTest.cpp diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp index 3e43479..83564e1 100644 --- a/src/test/CollisionTest.cpp +++ b/src/test/CollisionTest.cpp @@ -1,83 +1,76 @@ -#include "api/BoxCollider.h" -#include "api/CircleCollider.h" -#include "api/Vector2.h" #include #include #include #include #include -#include +#include #include using namespace std; using namespace std::chrono_literals; using namespace crepe; -class CollisionTest : public ::testing::Test { -protected: - GameObject * game_object1; - GameObject * game_object2; - CollisionSystem collision_system; - void SetUp() override { - ComponentManager & mgr = ComponentManager::get_instance(); - mgr.delete_all_components(); - std::vector> transforms - = mgr.get_components_by_id(0); - - // ob 1 - game_object1 = new GameObject(0, "", "", Vector2{0, 0}, 0, 0); - game_object1->add_component(Rigidbody::Data{ - .mass = 1, - .gravity_scale = 1, - .body_type = Rigidbody::BodyType::DYNAMIC, - .max_linear_velocity = Vector2{10, 10}, - .max_angular_velocity = 10, - .constraints = {0, 0, 0}, - .use_gravity = false, - .bounce = false, - }); - - game_object1->add_component(Vector2{0,0},10,10); +class MyScript : public Script { + static bool oncollision(const CollisionEvent& test) { + std::cout << "test collision: " << test.info.first.collider.game_object_id << std::endl; + return true; + } + void init() { + EventManager::get_instance().subscribe(oncollision, this->get_game_object_id()); + } + void update() { + // Retrieve component from the same GameObject this script is on + } +}; + +class PhysicsTest : public ::testing::Test { +public: + ComponentManager component_manager; + PhysicsSystem system{component_manager}; - //ob 2 - game_object2 = new GameObject(1, "", "", Vector2{50, 50}, 0, 0); - game_object2->add_component(Rigidbody::Data{ - .mass = 1, - .gravity_scale = 1, - .body_type = Rigidbody::BodyType::DYNAMIC, - .max_linear_velocity = Vector2{10, 10}, - .max_angular_velocity = 10, - .constraints = {0, 0, 0}, - .use_gravity = false, - .bounce = false, - }); - game_object2->add_component(Vector2{0,0},5); + void SetUp() override { + ComponentManager & mgr = this->component_manager; + vector> transforms + = mgr.get_components_by_id(0); + if (transforms.empty()) { + auto entity = mgr.new_object("", "", Vector2{0, 0}, 0, 0); + entity.add_component(Rigidbody::Data{ + .mass = 1, + .gravity_scale = 1, + .body_type = Rigidbody::BodyType::DYNAMIC, + .max_linear_velocity = Vector2{10, 10}, + .max_angular_velocity = 10, + .constraints = {0, 0}, + .use_gravity = true, + .bounce = false, + }); + } + transforms = mgr.get_components_by_id(0); + Transform & transform = transforms.front().get(); + transform.position.x = 0.0; + transform.position.y = 0.0; + transform.rotation = 0.0; + vector> rigidbodies + = mgr.get_components_by_id(0); + Rigidbody & rigidbody = rigidbodies.front().get(); + rigidbody.data.angular_velocity = 0; + rigidbody.data.linear_velocity.x = 0; + rigidbody.data.linear_velocity.y = 0; } }; -TEST_F(CollisionTest, box_box_collision) { +TEST_F(PhysicsTest, gravity) { Config::get_instance().physics.gravity = 1; - ComponentManager & mgr = ComponentManager::get_instance(); - std::vector> transforms - = mgr.get_components_by_id(0); - Transform & transform = transforms.front().get(); + ComponentManager & mgr = this->component_manager; + vector> transforms = mgr.get_components_by_id(0); + const Transform & transform = transforms.front().get(); ASSERT_FALSE(transforms.empty()); - transform.position = {39,50}; - collision_system.update(); - transform.position = {40,50}; - collision_system.update(); - transform.position = {50,39}; - collision_system.update(); - transform.position = {50,40}; - collision_system.update(); - transform.position = {50,60}; - collision_system.update(); - transform.position = {50,61}; - collision_system.update(); - transform.position = {60,50}; - collision_system.update(); - transform.position = {61,50}; - collision_system.update(); -} + EXPECT_EQ(transform.position.y, 0); + + system.update(); + EXPECT_EQ(transform.position.y, 1); + system.update(); + EXPECT_EQ(transform.position.y, 3); +} -- cgit v1.2.3 From 27a5332ee8e905d346a088ac7f4d1d1bb30025c4 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 6 Dec 2024 15:32:31 +0100 Subject: review feedback --- src/crepe/api/LoopManager.cpp | 1 + src/crepe/api/Rigidbody.h | 4 ++-- src/crepe/api/Script.h | 2 +- src/crepe/system/CollisionSystem.cpp | 10 +++++----- src/crepe/system/CollisionSystem.h | 12 ++++++------ src/test/Profiling.cpp | 4 ++-- 6 files changed, 17 insertions(+), 16 deletions(-) (limited to 'src/crepe/api/Script.h') diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index b9e91dd..2c12895 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -34,6 +34,7 @@ void LoopManager::start() { void LoopManager::set_running(bool running) { this->game_running = running; } void LoopManager::fixed_update() { + // TODO: retrieve EventManager from direct member after singleton refactor EventManager & ev = this->mediator.event_manager; ev.dispatch_events(); this->get_system().update(); diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index b0a24f7..a6aab26 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -136,8 +136,8 @@ public: /** * \brief Defines the collision layers of a GameObject. * - * The `collision_layers` vector specifies the layers that the GameObject will collide with. - * Each element in the vector represents a layer ID, and the GameObject will only detect + * The `collision_layers` specifies the layers that the GameObject will collide with. + * Each element represents a layer ID, and the GameObject will only detect * collisions with other GameObjects that belong to these layers. */ std::set collision_layers; diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 1474a09..3d416a1 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -3,7 +3,7 @@ #include #include "../manager/EventManager.h" -#include "system/CollisionSystem.h" +#include "../system/CollisionSystem.h" #include "../manager/Mediator.h" #include "../types.h" #include "../util/OptionalRef.h" diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 44ea7ee..e196e10 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -158,8 +158,8 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal data1.rigidbody); vec2 collider_pos2 = this->get_current_position(collider2.offset, data2.transform, data2.rigidbody); - resolution = this->get_circle_box_resolution(collider2, collider1, collider_pos2, - collider_pos1,true); + resolution = -this->get_circle_box_resolution(collider2, collider1, collider_pos2, + collider_pos1); break; } case CollisionInternalType::CIRCLE_CIRCLE: { @@ -185,7 +185,7 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal vec2 collider_pos2 = this->get_current_position(collider2.offset, data2.transform, data2.rigidbody); resolution = this->get_circle_box_resolution(collider1, collider2, collider_pos1, - collider_pos2,false); + collider_pos2); break; } } @@ -272,7 +272,7 @@ vec2 CollisionSystem::get_circle_circle_resolution(const CircleCollider & circle vec2 CollisionSystem::get_circle_box_resolution(const CircleCollider & circle_collider, const BoxCollider & box_collider, const vec2 & circle_position, - const vec2 & box_position,bool inverse) const { + const vec2 & box_position) const { vec2 delta = circle_position - box_position; // Compute half-dimensions of the box @@ -294,7 +294,7 @@ vec2 CollisionSystem::get_circle_box_resolution(const CircleCollider & circle_co // Compute penetration depth float penetration_depth = circle_collider.radius - distance; - if(inverse) collision_normal = -collision_normal; + // Compute the resolution vector vec2 resolution = collision_normal * penetration_depth; diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index b978dbb..6216af9 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -184,7 +184,7 @@ private: vec2 get_circle_box_resolution(const CircleCollider & circle_collider, const BoxCollider & box_collider, const vec2 & circle_position, - const vec2 & box_position,bool inverse) const; + const vec2 & box_position) const; /** * \brief Determines the appropriate collision handler for a collision. @@ -219,14 +219,14 @@ private: /** * \brief Checks if two collision layers have at least one common layer. * - * This function checks if there is any overlapping layer between the two input - * collision layer vectors. It compares each layer from the first vector to see - * if it exists in the second vector. If at least one common layer is found, + * This function checks if there is any overlapping layer between the two inputs. + * It compares each layer from the first input to see + * if it exists in the second input. If at least one common layer is found, * the function returns true, indicating that the two colliders share a common * collision layer. * - * \param layers1 A vector of collision layers for the first collider. - * \param layers2 A vector of collision layers for the second collider. + * \param layers1 all collision layers for the first collider. + * \param layers2 all collision layers for the second collider. * \return Returns true if there is at least one common layer, false otherwise. */ diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp index 91be769..6a6c29f 100644 --- a/src/test/Profiling.cpp +++ b/src/test/Profiling.cpp @@ -165,7 +165,7 @@ TEST_F(Profiling, Profiling_2) { gameobject.add_component().set_script(); Color color(0, 0, 0, 0); - auto img = Texture("asset/texture/green_square.png"); + auto img = Texture("asset/texture/square.png"); Sprite & test_sprite = gameobject.add_component( img, color, Sprite::FlipSettings{false, false}, 1, 1, 500); } @@ -198,7 +198,7 @@ TEST_F(Profiling, Profiling_3) { gameobject.add_component(vec2{0, 0}, vec2{1, 1}); gameobject.add_component().set_script(); Color color(0, 0, 0, 0); - auto img = Texture("asset/texture/green_square.png"); + auto img = Texture("asset/texture/square.png"); Sprite & test_sprite = gameobject.add_component( img, color, Sprite::FlipSettings{false, false}, 1, 1, 500); auto & test = gameobject.add_component(ParticleEmitter::Data{ -- cgit v1.2.3 From 70c1cd14ec4c4aca185d5a7e4a3749169f6425f4 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 6 Dec 2024 15:42:52 +0100 Subject: make format --- src/crepe/api/LoopManager.cpp | 4 +- src/crepe/api/Rigidbody.h | 1 - src/crepe/api/Script.h | 2 +- src/crepe/system/CollisionSystem.cpp | 33 +++++-------- src/crepe/system/CollisionSystem.h | 2 +- src/example/game.cpp | 94 +++++++++++++++++------------------- src/test/CollisionTest.cpp | 6 +-- src/test/Profiling.cpp | 6 +-- 8 files changed, 66 insertions(+), 82 deletions(-) (limited to 'src/crepe/api/Script.h') diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index 2c12895..a76c167 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -48,13 +48,13 @@ void LoopManager::loop() { while (game_running) { timer.update(); - + while (timer.get_lag() >= timer.get_fixed_delta_time()) { this->process_input(); this->fixed_update(); timer.advance_fixed_update(); } - + this->update(); this->render(); diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index a6aab26..8265ba5 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -7,7 +7,6 @@ #include "types.h" - namespace crepe { /** diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 3d416a1..d1be1dc 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -3,8 +3,8 @@ #include #include "../manager/EventManager.h" -#include "../system/CollisionSystem.h" #include "../manager/Mediator.h" +#include "../system/CollisionSystem.h" #include "../types.h" #include "../util/OptionalRef.h" diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index e196e10..44a0431 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -6,6 +6,8 @@ #include #include +#include "../manager/ComponentManager.h" +#include "../manager/EventManager.h" #include "api/BoxCollider.h" #include "api/CircleCollider.h" #include "api/Event.h" @@ -13,8 +15,6 @@ #include "api/Rigidbody.h" #include "api/Transform.h" #include "api/Vector2.h" -#include "../manager/ComponentManager.h" -#include "../manager/EventManager.h" #include "Collider.h" #include "CollisionSystem.h" @@ -27,17 +27,14 @@ void CollisionSystem::update() { std::vector all_colliders; game_object_id_t id = 0; ComponentManager & mgr = this->mediator.component_manager; - RefVector rigidbodies - = mgr.get_components_by_type(); + RefVector rigidbodies = mgr.get_components_by_type(); // Collisions can only happen on object with a rigidbody for (Rigidbody & rigidbody : rigidbodies) { if (!rigidbody.active) continue; id = rigidbody.game_object_id; - Transform & transform - = mgr.get_components_by_id(id).front().get(); + Transform & transform = mgr.get_components_by_id(id).front().get(); // Check if the boxcollider is active and has the same id as the rigidbody. - RefVector boxcolliders - = mgr.get_components_by_type(); + RefVector boxcolliders = mgr.get_components_by_type(); for (BoxCollider & boxcollider : boxcolliders) { if (boxcollider.game_object_id != id) continue; if (!boxcollider.active) continue; @@ -159,7 +156,7 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal vec2 collider_pos2 = this->get_current_position(collider2.offset, data2.transform, data2.rigidbody); resolution = -this->get_circle_box_resolution(collider2, collider1, collider_pos2, - collider_pos1); + collider_pos1); break; } case CollisionInternalType::CIRCLE_CIRCLE: { @@ -261,7 +258,6 @@ vec2 CollisionSystem::get_circle_circle_resolution(const CircleCollider & circle // Normalize the delta vector to get the collision direction vec2 collision_normal = delta / distance; - // Compute the resolution vector vec2 resolution = -collision_normal * penetration_depth; @@ -311,8 +307,7 @@ void CollisionSystem::determine_collision_handler(CollisionInfo & info) { // Call collision event for user CollisionEvent data(info); EventManager & emgr = this->mediator.event_manager; - emgr.trigger_event( - data, info.this_collider.game_object_id); + emgr.trigger_event(data, info.this_collider.game_object_id); } void CollisionSystem::static_collision_handler(CollisionInfo & info) { @@ -389,14 +384,14 @@ CollisionSystem::gather_collisions(std::vector & colliders) { bool CollisionSystem::have_common_layer(const std::set & layers1, const std::set & layers2) { - + // Check if any number is equal in the layers for (int num : layers1) { - if (layers2.contains(num)) { - // Common layer found - return true; - break; - } + if (layers2.contains(num)) { + // Common layer found + return true; + break; + } } // No common layer found return false; @@ -554,5 +549,3 @@ vec2 CollisionSystem::get_current_position(const vec2 & collider_offset, // Final positions considering scaling and rotation return (transform.position + vec2(rotated_total_offset_x1, rotated_total_offset_y1)); } - - diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 6216af9..7e893c8 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -6,11 +6,11 @@ #include "api/BoxCollider.h" #include "api/CircleCollider.h" +#include "api/Event.h" #include "api/Metadata.h" #include "api/Rigidbody.h" #include "api/Transform.h" #include "api/Vector2.h" -#include "api/Event.h" #include "Collider.h" #include "System.h" diff --git a/src/example/game.cpp b/src/example/game.cpp index be756bd..4239c15 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -1,6 +1,6 @@ #include "api/CircleCollider.h" -#include "manager/ComponentManager.h" #include "api/Scene.h" +#include "manager/ComponentManager.h" #include "manager/Mediator.h" #include #include @@ -28,66 +28,60 @@ class MyScript1 : public Script { bool keypressed(const KeyPressEvent & test) { Log::logf("Box script keypressed()"); switch (test.key) { - case Keycode::A: - { + case Keycode::A: { Transform & tf = this->get_component(); tf.position.x -= 1; break; } - case Keycode::W: - { + case Keycode::W: { Transform & tf = this->get_component(); tf.position.y -= 1; break; } - case Keycode::S: - { + case Keycode::S: { Transform & tf = this->get_component(); tf.position.y += 1; break; } - case Keycode::D: - { + case Keycode::D: { Transform & tf = this->get_component(); tf.position.x += 1; break; } - case Keycode::E: - { - if(flip){ + case Keycode::E: { + if (flip) { flip = false; this->get_component().active = true; this->get_components()[0].get().active = true; this->get_component().active = false; this->get_components()[1].get().active = false; - } - else { + } else { flip = true; this->get_component().active = false; this->get_components()[0].get().active = false; this->get_component().active = true; this->get_components()[1].get().active = true; } - - + //add collider switch break; } default: - break; + break; } return false; - } + } void init() { Log::logf("init"); - subscribe([this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); - subscribe([this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); + subscribe( + [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); + subscribe( + [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); } void update() { // Retrieve component from the same GameObject this script is on } - }; class MyScript2 : public Script { @@ -99,74 +93,68 @@ class MyScript2 : public Script { bool keypressed(const KeyPressEvent & test) { Log::logf("Box script keypressed()"); switch (test.key) { - case Keycode::LEFT: - { + case Keycode::LEFT: { Transform & tf = this->get_component(); tf.position.x -= 1; break; } - case Keycode::UP: - { + case Keycode::UP: { Transform & tf = this->get_component(); tf.position.y -= 1; break; } - case Keycode::DOWN: - { + case Keycode::DOWN: { Transform & tf = this->get_component(); tf.position.y += 1; break; } - case Keycode::RIGHT: - { + case Keycode::RIGHT: { Transform & tf = this->get_component(); tf.position.x += 1; break; } - case Keycode::PAUSE: - { - if(flip){ + case Keycode::PAUSE: { + if (flip) { flip = false; this->get_component().active = true; this->get_components()[0].get().active = true; this->get_component().active = false; this->get_components()[1].get().active = false; - } - else { + } else { flip = true; this->get_component().active = false; this->get_components()[0].get().active = false; this->get_component().active = true; this->get_components()[1].get().active = true; } - - + //add collider switch break; } default: - break; + break; } return false; - } + } void init() { Log::logf("init"); - subscribe([this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); - subscribe([this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); + subscribe( + [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); + subscribe( + [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); } void update() { // Retrieve component from the same GameObject this script is on } - }; class ConcreteScene1 : public Scene { public: using Scene::Scene; - + void load_scene() { - + Mediator & m = this->mediator; ComponentManager & mgr = m.component_manager; Color color(0, 0, 0, 255); @@ -195,7 +183,10 @@ public: vec2{world_collider, world_collider}); // Left world.add_component(vec2{screen_size_width / 2 + world_collider / 2, 0}, vec2{world_collider, world_collider}); // right - world.add_component(Color::WHITE, ivec2{static_cast(screen_size_width), static_cast(screen_size_height)}, vec2{screen_size_width, screen_size_height}, 1.0f); + world.add_component( + Color::WHITE, + ivec2{static_cast(screen_size_width), static_cast(screen_size_height)}, + vec2{screen_size_width, screen_size_height}, 1.0f); GameObject game_object1 = mgr.new_object( "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); @@ -219,10 +210,10 @@ public: //add circle with cirlcecollider deactiveated game_object1.add_component(vec2{0, 0}, 10).active = false; auto img2 = Texture("asset/texture/circle.png"); - game_object1.add_component(img2, color, Sprite::FlipSettings{false, false}, 1, - 1, 20).active = false; - - + game_object1 + .add_component(img2, color, Sprite::FlipSettings{false, false}, 1, 1, 20) + .active + = false; GameObject game_object2 = mgr.new_object( "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); @@ -246,9 +237,10 @@ public: //add circle with cirlcecollider deactiveated game_object2.add_component(vec2{0, 0}, 10).active = false; auto img4 = Texture("asset/texture/circle.png"); - game_object2.add_component(img4, color, Sprite::FlipSettings{false, false}, 1, - 1, 20).active = false; - + game_object2 + .add_component(img4, color, Sprite::FlipSettings{false, false}, 1, 1, 20) + .active + = false; } string get_name() const { return "scene1"; } diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp index a683b1f..dd45eb6 100644 --- a/src/test/CollisionTest.cpp +++ b/src/test/CollisionTest.cpp @@ -7,14 +7,14 @@ #define private public #define protected public -#include -#include #include -#include #include #include #include #include +#include +#include +#include #include #include #include diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp index 6a6c29f..24ac494 100644 --- a/src/test/Profiling.cpp +++ b/src/test/Profiling.cpp @@ -9,14 +9,14 @@ #define private public #define protected public -#include #include -#include #include #include #include #include #include +#include +#include #include #include #include @@ -162,7 +162,7 @@ TEST_F(Profiling, Profiling_2) { .body_type = Rigidbody::BodyType::STATIC, }); gameobject.add_component(vec2{0, 0}, vec2{1, 1}); - + gameobject.add_component().set_script(); Color color(0, 0, 0, 0); auto img = Texture("asset/texture/square.png"); -- cgit v1.2.3 From fdb4c99e139a264d4e15e6913a3756fc6cccb2f2 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 6 Dec 2024 20:07:24 +0100 Subject: nitpick #59 --- src/crepe/Collider.h | 2 +- src/crepe/Component.h | 2 +- src/crepe/api/Animator.cpp | 6 ++-- src/crepe/api/Animator.h | 58 ++++++++------------------------ src/crepe/api/AssetManager.h | 6 ++-- src/crepe/api/BoxCollider.h | 2 +- src/crepe/api/Button.h | 6 ++-- src/crepe/api/CMakeLists.txt | 4 +-- src/crepe/api/CircleCollider.h | 2 +- src/crepe/api/Config.h | 5 +-- src/crepe/api/EventHandler.h | 34 +++++++++---------- src/crepe/api/GameObject.h | 12 +++---- src/crepe/api/Metadata.h | 2 +- src/crepe/api/Rigidbody.h | 28 ++++++++-------- src/crepe/api/Scene.h | 4 +-- src/crepe/api/Script.h | 2 +- src/crepe/api/Sprite.h | 38 ++++++++++----------- src/crepe/api/Transform.h | 2 +- src/crepe/facade/SDLContext.h | 28 ++++++++-------- src/crepe/facade/Sound.h | 2 +- src/crepe/manager/ComponentManager.h | 30 ++++++++--------- src/crepe/manager/EventManager.h | 28 ++++++++-------- src/crepe/system/CollisionSystem.h | 65 ++++++++++++++++++------------------ src/crepe/system/ParticleSystem.h | 10 +++--- src/crepe/system/PhysicsSystem.h | 4 +-- src/crepe/system/RenderSystem.cpp | 3 +- src/crepe/system/RenderSystem.h | 8 ++--- src/crepe/system/ScriptSystem.h | 2 +- src/test/Profiling.cpp | 25 ++++++++++---- 29 files changed, 200 insertions(+), 220 deletions(-) (limited to 'src/crepe/api/Script.h') diff --git a/src/crepe/Collider.h b/src/crepe/Collider.h index a08a68e..42ccfd4 100644 --- a/src/crepe/Collider.h +++ b/src/crepe/Collider.h @@ -15,7 +15,7 @@ public: * * The `offset` defines the positional shift applied to the collider relative to the position of the rigidbody it is attached to. * This allows the collider to be placed at a different position than the rigidbody. - * + * */ vec2 offset; }; diff --git a/src/crepe/Component.h b/src/crepe/Component.h index dc17721..c30419d 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -8,7 +8,7 @@ class ComponentManager; /** * \brief Base class for all components - * + * * This class is the base class for all components. It provides a common interface for all * components. */ diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 154135f..b8a91dc 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -7,10 +7,10 @@ using namespace crepe; -Animator::Animator(uint32_t id, Sprite & ss, unsigned int max_row, unsigned int max_col, - const Animator::Data & data) +Animator::Animator(game_object_id_t id, Sprite & spritesheet, unsigned int max_row, + unsigned int max_col, const Animator::Data & data) : Component(id), - spritesheet(ss), + spritesheet(spritesheet), max_rows(max_row), max_columns(max_col), data(data) { diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 23d29f6..7c850b8 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -1,10 +1,9 @@ #pragma once -#include +#include "../types.h" #include "Component.h" #include "Sprite.h" -#include "types.h" namespace crepe { @@ -21,55 +20,31 @@ class SDLContext; class Animator : public Component { public: struct Data { - //! frames per second for animation unsigned int fps = 1; - //! The current col being animated. unsigned int col = 0; - //! The current row being animated. unsigned int row = 0; - //! should the animation loop bool looping = false; - //! starting frame for cycling unsigned int cycle_start = 0; - - //! end frame for cycling (-1 --> use last frame) + //! end frame for cycling (-1 = use last frame) int cycle_end = -1; - - //! offset in pixels. - // TODO implement - unsigned int white_space = 0; }; public: - /** - * \brief Animator will repeat the animation - * - */ + //! Animator will repeat the animation void loop(); - - /** - * \brief starts the animation - * - */ + //! starts the animation void play(); - /** - * \brief pauses the animation - * - * sets the active false - * - */ + //! pauses the animation void pause(); - /** * \brief stops the animation * * sets the active on false and resets all the current rows and columns - * */ void stop(); /** @@ -81,8 +56,8 @@ public: /** * \brief set the range in the row * - * \param start of row animation - * \param end of row animation + * \param start of row animation + * \param end of row animation */ void set_cycle_range(int start, int end); /** @@ -91,11 +66,7 @@ public: * \param col animation column */ void set_anim(int col); - - /** - * \brief will go to the next animaiton of current row - * - */ + //! will go to the next animaiton of current row void next_anim(); public: @@ -103,7 +74,7 @@ public: * \brief Constructs an Animator object that will control animations for a sprite sheet. * * \param id The unique identifier for the component, typically assigned automatically. - * \param ss the reference to the spritesheet + * \param spritesheet the reference to the spritesheet * \param max_row maximum of rows inside the given spritesheet * \param max_col maximum of columns inside the given spritesheet * \param data extra animation data for more control @@ -111,25 +82,22 @@ public: * This constructor sets up the Animator with the given parameters, and initializes the * animation system. */ - Animator(game_object_id_t id, Sprite & ss, unsigned int max_row, unsigned int max_col, - const Animator::Data & data); + Animator(game_object_id_t id, Sprite & spritesheet, unsigned int max_row, + unsigned int max_col, const Animator::Data & data); ~Animator(); // dbg_trace public: //! The maximum number of columns in the sprite sheet. const unsigned int max_columns; - //! The maximum number of rows in the sprite sheet. const unsigned int max_rows; - Animator::Data data; private: //! A reference to the Sprite sheet containing. Sprite & spritesheet; - - // uses the spritesheet + //! Uses the spritesheet friend AnimatorSystem; }; + } // namespace crepe -// diff --git a/src/crepe/api/AssetManager.h b/src/crepe/api/AssetManager.h index fee6780..3b1cc4b 100644 --- a/src/crepe/api/AssetManager.h +++ b/src/crepe/api/AssetManager.h @@ -9,7 +9,7 @@ namespace crepe { /** * \brief The AssetManager is responsible for storing and managing assets over multiple scenes. - * + * * The AssetManager ensures that assets are loaded once and can be accessed across different * scenes. It caches assets to avoid reloading them every time a scene is loaded. Assets are * retained in memory until the AssetManager is destroyed, at which point the cached assets are @@ -46,9 +46,9 @@ public: * \param reload If true, the asset will be reloaded from the file, even if it is already * cached. * \tparam T The type of asset to cache (e.g., texture, sound, etc.). - * + * * \return A shared pointer to the cached asset. - * + * * This template function caches the asset at the given file path. If the asset is already * cached and `reload` is false, the existing cached version will be returned. Otherwise, the * asset will be reloaded and added to the cache. diff --git a/src/crepe/api/BoxCollider.h b/src/crepe/api/BoxCollider.h index 89e43d8..1ac4d46 100644 --- a/src/crepe/api/BoxCollider.h +++ b/src/crepe/api/BoxCollider.h @@ -8,7 +8,7 @@ namespace crepe { /** * \brief A class representing a box-shaped collider. - * + * * This class is used for collision detection with other colliders (e.g., CircleCollider). */ class BoxCollider : public Collider { diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h index 26e7526..61b18d7 100644 --- a/src/crepe/api/Button.h +++ b/src/crepe/api/Button.h @@ -11,7 +11,7 @@ class Button : public UIObject { public: /** * \brief Constructs a Button with the specified game object ID and dimensions. - * + * * \param id The unique ID of the game object associated with this button. * \param dimensions The width and height of the UIObject * \param offset The offset relative this GameObjects Transform @@ -23,7 +23,7 @@ public: /** * \brief Indicates if the button is a toggle button (can be pressed and released). - * + * * A toggle button allows for a pressed/released state, whereas a regular button * typically only has an on-click state. */ @@ -31,7 +31,7 @@ public: // TODO: create separate toggle button class /** * \brief The callback function to be executed when the button is clicked. - * + * * This function is invoked whenever the button is clicked. It can be set to any * function that matches the signature `void()`. */ diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index b2e3df8..593c4e6 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -39,8 +39,8 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Vector2.h Vector2.hpp Color.h - Texture.h - AssetManager.h + Texture.h + AssetManager.h AssetManager.hpp Scene.h Metadata.h diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h index ebd1cb2..c7bf66e 100644 --- a/src/crepe/api/CircleCollider.h +++ b/src/crepe/api/CircleCollider.h @@ -8,7 +8,7 @@ namespace crepe { /** * \brief A class representing a circle-shaped collider. - * + * * This class is used for collision detection with other colliders (e.g., BoxCollider). */ class CircleCollider : public Collider { diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index f1bca62..a9745c3 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -1,8 +1,10 @@ #pragma once +#include + #include "../util/Log.h" + #include "types.h" -#include namespace crepe { @@ -69,7 +71,6 @@ public: //! default screen size in pixels ivec2 default_size = {1280, 720}; std::string window_title = "Jetpack joyride clone"; - } window_settings; //! Asset loading options diff --git a/src/crepe/api/EventHandler.h b/src/crepe/api/EventHandler.h index 7bdd9a3..7bb501b 100644 --- a/src/crepe/api/EventHandler.h +++ b/src/crepe/api/EventHandler.h @@ -8,12 +8,12 @@ namespace crepe { /** * \brief A type alias for an event handler function. - * - * The EventHandler is a std::function that takes an EventType reference and returns a boolean value + * + * The EventHandler is a std::function that takes an EventType reference and returns a boolean value * indicating whether the event is handled. - * + * * \tparam EventType The type of event this handler will handle. - * + * * Returning \c false from an event handler results in the event being propogated to other listeners for the same event type, while returning \c true stops propogation altogether. */ template @@ -22,7 +22,7 @@ using EventHandler = std::function; /** * \class IEventHandlerWrapper * \brief An abstract base class for event handler wrappers. - * + * * This class provides the interface for handling events. Derived classes must implement the * `call()` method to process events */ @@ -35,9 +35,9 @@ public: /** * \brief Executes the handler with the given event. - * + * * This method calls the `call()` method of the derived class, passing the event to the handler. - * + * * \param e The event to be processed. * \return A boolean value indicating whether the event is handled. */ @@ -46,9 +46,9 @@ public: private: /** * \brief The method responsible for handling the event. - * + * * This method is implemented by derived classes to process the event. - * + * * \param e The event to be processed. * \return A boolean value indicating whether the event is handled. */ @@ -58,11 +58,11 @@ private: /** * \class EventHandlerWrapper * \brief A wrapper for event handler functions. - * - * This class wraps an event handler function of a specific event type. It implements the - * `call()` and `get_type()` methods to allow the handler to be executed and its type to be + * + * This class wraps an event handler function of a specific event type. It implements the + * `call()` and `get_type()` methods to allow the handler to be executed and its type to be * queried. - * + * * \tparam EventType The type of event this handler will handle. */ template @@ -70,9 +70,9 @@ class EventHandlerWrapper : public IEventHandlerWrapper { public: /** * \brief Constructs an EventHandlerWrapper with a given handler. - * + * * The constructor takes an event handler function and stores it in the wrapper. - * + * * \param handler The event handler function. */ explicit EventHandlerWrapper(const EventHandler & handler); @@ -80,9 +80,9 @@ public: private: /** * \brief Calls the stored event handler with the event. - * + * * This method casts the event to the appropriate type and calls the handler. - * + * * \param e The event to be handled. * \return A boolean value indicating whether the event is handled. */ diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index 4cd2bc0..ff80f49 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -10,7 +10,7 @@ class ComponentManager; /** * \brief Represents a GameObject - * + * * This class represents a GameObject. The GameObject class is only used as an interface for * the game programmer. The actual implementation is done in the ComponentManager. */ @@ -19,7 +19,7 @@ private: /** * This constructor creates a new GameObject. It creates a new Transform and Metadata * component and adds them to the ComponentManager. - * + * * \param component_manager Reference to component_manager * \param id The id of the GameObject * \param name The name of the GameObject @@ -37,20 +37,20 @@ private: public: /** * \brief Set the parent of this GameObject - * + * * This method sets the parent of this GameObject. It sets the parent in the Metadata * component of this GameObject and adds this GameObject to the children list of the parent * GameObject. - * + * * \param parent The parent GameObject */ void set_parent(const GameObject & parent); /** * \brief Add a component to the GameObject - * + * * This method adds a component to the GameObject. It forwards the arguments to the * ComponentManager. - * + * * \tparam T The type of the component * \tparam Args The types of the arguments * \param args The arguments to create the component diff --git a/src/crepe/api/Metadata.h b/src/crepe/api/Metadata.h index 235d42f..f404703 100644 --- a/src/crepe/api/Metadata.h +++ b/src/crepe/api/Metadata.h @@ -9,7 +9,7 @@ namespace crepe { /** * \brief Metadata component - * + * * This class represents the Metadata component. It stores the name, tag, parent and children * of a GameObject. */ diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index 8265ba5..40c6bf1 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -11,7 +11,7 @@ namespace crepe { /** * \brief Rigidbody class - * + * * This class is used by the physics sytem and collision system. It configures how to system * interact with the gameobject for movement and collisions. */ @@ -19,7 +19,7 @@ class Rigidbody : public Component { public: /** * \brief BodyType enum - * + * * This enum provides three bodytypes the physics sytem and collision system use. */ enum class BodyType { @@ -32,7 +32,7 @@ public: }; /** * \brief PhysicsConstraints to constrain movement - * + * * This struct configures the movement constraint for this object. If a constraint is enabled * the systems will not move the object. */ @@ -46,9 +46,9 @@ public: }; public: - /** + /** * \brief struct for Rigidbody data - * + * * This struct holds the data for the Rigidbody. */ struct Data { @@ -59,7 +59,7 @@ public: * * The `gravity_scale` controls how much gravity affects the object. It is a multiplier applied to the default * gravity force, allowing for fine-grained control over how the object responds to gravity. - * + * */ float gravity_scale = 0; @@ -108,7 +108,7 @@ public: * The `PhysicsConstraints` struct defines the constraints that restrict an object's movement * in certain directions or prevent rotation. These constraints effect only the physics system * to prevent the object from moving or rotating in specified ways. - * + * */ PhysicsConstraints constraints; @@ -128,7 +128,7 @@ public: * The `offset` defines a positional shift applied to all colliders associated with the object, relative to the object's * transform position. This allows for the colliders to be placed at a different position than the object's actual * position, without modifying the object's transform itself. - * + * */ vec2 offset; @@ -136,14 +136,14 @@ public: * \brief Defines the collision layers of a GameObject. * * The `collision_layers` specifies the layers that the GameObject will collide with. - * Each element represents a layer ID, and the GameObject will only detect + * Each element represents a layer ID, and the GameObject will only detect * collisions with other GameObjects that belong to these layers. */ std::set collision_layers; }; public: - /** + /** * \param game_object_id id of the gameobject the rigibody is added to. * \param data struct to configure the rigidbody. */ @@ -152,15 +152,15 @@ public: Data data; public: - /** + /** * \brief add a linear force to the Rigidbody. - * + * * \param force Vector2 that is added to the linear force. */ void add_force_linear(const vec2 & force); - /** + /** * \brief add a angular force to the Rigidbody. - * + * * \param force Vector2 that is added to the angular force. */ void add_force_angular(float force); diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 9f1e8ce..ba9bb76 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -12,7 +12,7 @@ class ComponentManager; /** * \brief Represents a Scene - * + * * This class represents a Scene. The Scene class is only used as an interface for the game * programmer. */ @@ -41,7 +41,7 @@ public: protected: /** * \name Late references - * + * * These references are set by SceneManager immediately after calling the constructor of Scene. * * \note Scene must have a constructor without arguments so the game programmer doesn't need to diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index d1be1dc..d99ab0e 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -20,7 +20,7 @@ class ComponentManager; * This class is used as a base class for user-defined scripts that can be added to game * objects using the \c BehaviorScript component. * - * \info Additional *events* (like Unity's OnDisable and OnEnable) should be implemented as + * \note Additional *events* (like Unity's OnDisable and OnEnable) should be implemented as * member or lambda methods in derivative user script classes and registered in \c init(). * * \warning Concrete scripts are allowed do create a custom constructor, but the utility diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index ea8104c..dbf41e4 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -31,11 +31,10 @@ public: //! Sprite data that does not have to be set in the constructor struct Data { /** - * \color tint of the sprite + * \brief Sprite tint (multiplied) * - * the default value is white because of the color multiplier. - * this means that the orginal image will be shown. if color is BLACK for example - * then it turns the image black because of the Color channels being 0. + * The sprite texture's pixels are multiplied by this color before being displayed + * (including alpha channel for transparency). */ Color color = Color::WHITE; @@ -49,15 +48,15 @@ public: const int order_in_layer = 0; /** - * \size width and height of the sprite in game units - * - * - if height is filled in and not width it will multiply width by aspect_ratio. - * - if width is filled in and not height it will multiply height by aspect_ratio. - * - if neither is filled it will not show sprite because size will be zero - * - if both are filled will it use the width and height without making sure the aspect_ratio - * is correct - */ - vec2 size; + * \brief width and height of the sprite in game units + * + * - if exclusively width is specified, the height is calculated using the texture's aspect + * ratio + * - if exclusively height is specified, the width is calculated using the texture's aspect + * ratio + * - if both are specified the texture is streched to fit the specified size + */ + vec2 size = {0, 0}; //! independent sprite angle. rotating clockwise direction in degrees float angle_offset = 0; @@ -71,7 +70,6 @@ public: public: /** - * \brief Constructs a Sprite with specified parameters. * \param game_id Unique identifier for the game object this sprite belongs to. * \param texture asset of the image * \param ctx all the sprite data @@ -86,12 +84,12 @@ public: private: /** - * \aspect_ratio ratio of the img - * - * - This will multiply one of \c size variable if it is 0. - * - Will be adjusted if \c Animator component is added to an GameObject - * that is why this value cannot be const. - */ + * \brief ratio of the img + * + * - This will multiply one of \c size variable if it is 0. + * - Will be adjusted if \c Animator component is added to an GameObject that is why this + * value cannot be const. + */ float aspect_ratio; //! Reads the mask of sprite diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h index 3ef0fb5..7ee6d65 100644 --- a/src/crepe/api/Transform.h +++ b/src/crepe/api/Transform.h @@ -7,7 +7,7 @@ namespace crepe { /** * \brief Transform component - * + * * This class represents the Transform component. It stores the position, rotation and scale of * a GameObject. */ diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 81a8a34..e232511 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -25,7 +25,7 @@ class InputSystem; /** * \class SDLContext * \brief Facade for the SDL library - * + * * SDLContext is a singleton that handles the SDL window and renderer, provides methods for * event handling, and rendering to the screen. It is never used directly by the user */ @@ -38,16 +38,16 @@ public: vec2 zoomed_viewport; /** - * \render_scale scaling factor + * \brief scaling factor * * depending on the black bars type will the scaling be different. - * - lettorboxing --> scaling on the y-as - * - pillarboxing --> scaling on the x-as + * - letterboxing --> scaling on the y-as + * - pillarboxing --> scaling on the x-as */ vec2 render_scale; /** - * \bar_size size of calculated black bars + * \brief size of calculated black bars * * depending on the black bars type will the size be different * - lettorboxing --> {0, bar_height} @@ -108,21 +108,21 @@ private: friend class InputSystem; /** * \brief Retrieves a list of all events from the SDL context. - * + * * This method retrieves all the events from the SDL context that are currently * available. It is primarily used by the InputSystem to process various * input events such as mouse clicks, mouse movements, and keyboard presses. - * + * * \return Events that occurred since last call to `get_events()` */ std::vector get_events(); /** * \brief Converts an SDL key code to the custom Keycode type. - * + * * This method maps an SDL key code to the corresponding `Keycode` enum value, * which is used internally by the system to identify the keys. - * + * * \param sdl_key The SDL key code to convert. * \return The corresponding `Keycode` value or `Keycode::NONE` if the key is unrecognized. */ @@ -130,10 +130,10 @@ private: /** * \brief Converts an SDL mouse button code to the custom MouseButton type. - * - * This method maps an SDL mouse button code to the corresponding `MouseButton` + * + * This method maps an SDL mouse button code to the corresponding `MouseButton` * enum value, which is used internally by the system to identify mouse buttons. - * + * * \param sdl_button The SDL mouse button code to convert. * \return The corresponding `MouseButton` value or `MouseButton::NONE` if the key is unrecognized */ @@ -233,14 +233,14 @@ private: * \param pos the pos in world units * \param cam the camera of the current scene * \param cam_pos the current postion of the camera - * \param img_scale the image multiplier for increasing img size + * \param img_scale the image multiplier for increasing img size * \return sdl rectangle to draw a dst image to draw on the screen */ SDL_FRect get_dst_rect(const DestinationRectangleData & data) const; /** * \brief Set an additional color value multiplied into render copy operations. * - * \param texture the given texture to adjust + * \param texture the given texture to adjust * \param color the color data for the texture */ void set_color_texture(const Texture & texture, const Color & color); diff --git a/src/crepe/facade/Sound.h b/src/crepe/facade/Sound.h index 4c68f32..ee43d94 100644 --- a/src/crepe/facade/Sound.h +++ b/src/crepe/facade/Sound.h @@ -35,7 +35,7 @@ public: void play(); /** * \brief Reset playhead position - * + * * Resets the playhead position so that calling \c play() after this function makes it play * from the start of the sample. If the sound is not paused before calling this function, * this function will stop playback. diff --git a/src/crepe/manager/ComponentManager.h b/src/crepe/manager/ComponentManager.h index ad37586..44429d9 100644 --- a/src/crepe/manager/ComponentManager.h +++ b/src/crepe/manager/ComponentManager.h @@ -16,7 +16,7 @@ class GameObject; /** * \brief Manages all components - * + * * This class manages all components. It provides methods to add, delete and get components. */ class ComponentManager : public Manager { @@ -56,10 +56,10 @@ protected: friend class GameObject; /** * \brief Add a component to the ComponentManager - * + * * This method adds a component to the ComponentManager. The component is created with the * given arguments and added to the ComponentManager. - * + * * \tparam T The type of the component * \tparam Args The types of the arguments * \param id The id of the GameObject this component belongs to @@ -70,9 +70,9 @@ protected: T & add_component(game_object_id_t id, Args &&... args); /** * \brief Delete all components of a specific type and id - * + * * This method deletes all components of a specific type and id. - * + * * \tparam T The type of the component * \param id The id of the GameObject this component belongs to */ @@ -80,24 +80,24 @@ protected: void delete_components_by_id(game_object_id_t id); /** * \brief Delete all components of a specific type - * + * * This method deletes all components of a specific type. - * + * * \tparam T The type of the component */ template void delete_components(); /** * \brief Delete all components of a specific id - * + * * This method deletes all components of a specific id. - * + * * \param id The id of the GameObject this component belongs to */ void delete_all_components_of_id(game_object_id_t id); /** * \brief Delete all components - * + * * This method deletes all components. */ void delete_all_components(); @@ -115,9 +115,9 @@ protected: public: /** * \brief Get all components of a specific type and id - * + * * This method gets all components of a specific type and id. - * + * * \tparam T The type of the component * \param id The id of the GameObject this component belongs to * \return A vector of all components of the specific type and id @@ -126,9 +126,9 @@ public: RefVector get_components_by_id(game_object_id_t id) const; /** * \brief Get all components of a specific type - * + * * This method gets all components of a specific type. - * + * * \tparam T The type of the component * \return A vector of all components of the specific type */ @@ -138,7 +138,7 @@ public: private: /** * \brief The components - * + * * This unordered_map stores all components. The key is the type of the component and the * value is a vector of vectors of unique pointers to the components. * diff --git a/src/crepe/manager/EventManager.h b/src/crepe/manager/EventManager.h index d634f54..ba5e98b 100644 --- a/src/crepe/manager/EventManager.h +++ b/src/crepe/manager/EventManager.h @@ -24,7 +24,7 @@ typedef size_t event_channel_t; /** * \class EventManager * \brief Manages event subscriptions, triggers, and queues, enabling decoupled event handling. - * + * * The `EventManager` acts as a centralized event system. It allows for registering callbacks * for specific event types, triggering events synchronously, queueing events for later * processing, and managing subscriptions via unique identifiers. @@ -35,20 +35,20 @@ public: /** * \brief Get the singleton instance of the EventManager. - * + * * This method returns the unique instance of the EventManager, creating it if it * doesn't already exist. Ensures only one instance is active in the program. - * + * * \return Reference to the singleton instance of the EventManager. */ static EventManager & get_instance(); /** * \brief Subscribe to a specific event type. - * + * * Registers a callback for a given event type and optional channel. Each callback * is assigned a unique subscription ID that can be used for later unsubscription. - * + * * \tparam EventType The type of the event to subscribe to. * \param callback The callback function to be invoked when the event is triggered. * \param channel The channel number to subscribe to (default is CHANNEL_ALL, which listens to all channels). @@ -60,18 +60,18 @@ public: /** * \brief Unsubscribe a previously registered callback. - * + * * Removes a callback from the subscription list based on its unique subscription ID. - * + * * \param event_id The unique subscription ID of the callback to remove. */ void unsubscribe(subscription_t event_id); /** * \brief Trigger an event immediately. - * + * * Synchronously invokes all registered callbacks for the given event type on the specified channel. - * + * * \tparam EventType The type of the event to trigger. * \param event The event instance to pass to the callbacks. * \param channel The channel to trigger the event on (default is CHANNEL_ALL, which triggers on all channels). @@ -81,9 +81,9 @@ public: /** * \brief Queue an event for later processing. - * + * * Adds an event to the event queue to be processed during the next call to `dispatch_events`. - * + * * \tparam EventType The type of the event to queue. * \param event The event instance to queue. * \param channel The channel to associate with the event (default is CHANNEL_ALL). @@ -93,7 +93,7 @@ public: /** * \brief Process all queued events. - * + * * Iterates through the event queue and triggers callbacks for each queued event. * Events are removed from the queue once processed. */ @@ -101,7 +101,7 @@ public: /** * \brief Clear all subscriptions. - * + * * Removes all registered event handlers and clears the subscription list. */ void clear(); @@ -109,7 +109,7 @@ public: private: /** * \brief Default constructor for the EventManager. - * + * * Constructor is private to enforce the singleton pattern. */ EventManager() = default; diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 7e893c8..5b136c6 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -37,7 +37,7 @@ private: /** * \brief A structure to store the collision data of a single collider. - * + * * This structure all components and id that are for needed within this system when calculating or handeling collisions. * The transform and rigidbody are mostly needed for location and rotation. * In rigidbody additional info is written about what the body of the object is, @@ -65,7 +65,7 @@ private: public: /** * \brief Structure representing detailed collision information between two colliders. - * + * * Includes information about the colliding objects and the resolution data for handling the collision. */ struct CollisionInfo { @@ -90,9 +90,9 @@ public: private: /** * \brief Determines the type of collider pair from two colliders. - * + * * Uses std::holds_alternative to identify the types of the provided colliders. - * + * * \param collider1 First collider variant (BoxCollider or CircleCollider). * \param collider2 Second collider variant (BoxCollider or CircleCollider). * \return The combined type of the two colliders. @@ -102,9 +102,9 @@ private: /** * \brief Calculates the current position of a collider. - * + * * Combines the Collider offset, Transform position, and Rigidbody offset to compute the position of the collider. - * + * * \param collider_offset The offset of the collider. * \param transform The Transform of the associated game object. * \param rigidbody The Rigidbody of the associated game object. @@ -116,9 +116,9 @@ private: private: /** * \brief Handles collision resolution between two colliders. - * + * * Processes collision data and adjusts objects to resolve collisions and/or calls the user oncollision script function. - * + * * \param data1 Collision data for the first collider. * \param data2 Collision data for the second collider. */ @@ -126,9 +126,9 @@ private: /** * \brief Resolves collision between two colliders and calculates the movement required. - * + * * Determines the displacement and direction needed to separate colliders based on their types. - * + * * \param data1 Collision data for the first collider. * \param data2 Collision data for the second collider. * \param type The type of collider pair. @@ -140,9 +140,9 @@ private: /** * \brief Calculates the resolution vector for two BoxColliders. - * + * * Computes the displacement required to separate two overlapping BoxColliders. - * + * * \param box_collider1 The first BoxCollider. * \param box_collider2 The second BoxCollider. * \param position1 The position of the first BoxCollider. @@ -155,13 +155,13 @@ private: /** * \brief Calculates the resolution vector for two CircleCollider. - * + * * Computes the displacement required to separate two overlapping CircleCollider. - * + * * \param circle_collider1 The first CircleCollider. * \param circle_collider2 The second CircleCollider. - * \param position1 The position of the first CircleCollider. - * \param position2 The position of the second CircleCollider. + * \param final_position1 The position of the first CircleCollider. + * \param final_position2 The position of the second CircleCollider. * \return The resolution vector for the collision. */ vec2 get_circle_circle_resolution(const CircleCollider & circle_collider1, @@ -171,14 +171,13 @@ private: /** * \brief Calculates the resolution vector for two CircleCollider. - * + * * Computes the displacement required to separate two overlapping CircleCollider. - * + * * \param circle_collider The first CircleCollider. * \param box_collider The second CircleCollider. * \param circle_position The position of the CircleCollider. * \param box_position The position of the BoxCollider. - * \param inverse Inverted true if box circle collision, false if circle box collision (inverts the direction). * \return The resolution vector for the collision. */ vec2 get_circle_box_resolution(const CircleCollider & circle_collider, @@ -188,18 +187,18 @@ private: /** * \brief Determines the appropriate collision handler for a collision. - * + * * Decides the correct resolution process based on the dynamic or static nature of the colliders involved. - * + * * \param info Collision information containing data about both colliders. */ void determine_collision_handler(CollisionInfo & info); /** * \brief Handles collisions involving static objects. - * + * * Resolves collisions by adjusting positions and modifying velocities if bounce is enabled. - * + * * \param info Collision information containing data about both colliders. */ void static_collision_handler(CollisionInfo & info); @@ -207,9 +206,9 @@ private: private: /** * \brief Checks for collisions between colliders. - * + * * Identifies collisions and generates pairs of colliding objects for further processing. - * + * * \param colliders A collection of all active colliders. * \return A list of collision pairs with their associated data. */ @@ -218,13 +217,13 @@ private: /** * \brief Checks if two collision layers have at least one common layer. - * + * * This function checks if there is any overlapping layer between the two inputs. - * It compares each layer from the first input to see - * if it exists in the second input. If at least one common layer is found, - * the function returns true, indicating that the two colliders share a common + * It compares each layer from the first input to see + * if it exists in the second input. If at least one common layer is found, + * the function returns true, indicating that the two colliders share a common * collision layer. - * + * * \param layers1 all collision layers for the first collider. * \param layers2 all collision layers for the second collider. * \return Returns true if there is at least one common layer, false otherwise. @@ -234,9 +233,9 @@ private: /** * \brief Checks for collision between two colliders. - * + * * Calls the appropriate collision detection function based on the collider types. - * + * * \param first_info Collision data for the first collider. * \param second_info Collision data for the second collider. * \param type The type of collider pair. @@ -248,7 +247,7 @@ private: /** * \brief Detects collisions between two BoxColliders. - * + * * \param box1 The first BoxCollider. * \param box2 The second BoxCollider. * \param transform1 Transform of the first object. diff --git a/src/crepe/system/ParticleSystem.h b/src/crepe/system/ParticleSystem.h index c647284..068f01c 100644 --- a/src/crepe/system/ParticleSystem.h +++ b/src/crepe/system/ParticleSystem.h @@ -25,7 +25,7 @@ public: private: /** * \brief Emits a particle from the specified emitter based on its emission properties. - * + * * \param emitter Reference to the ParticleEmitter. * \param transform Const reference to the Transform component associated with the emitter. */ @@ -34,7 +34,7 @@ private: /** * \brief Calculates the number of times particles should be emitted based on emission rate * and update count. - * + * * \param count Current update count. * \param emission Emission rate. * \return The number of particles to emit. @@ -44,7 +44,7 @@ private: /** * \brief Checks whether particles are within the emitter’s boundary, resets or stops * particles if they exit. - * + * * \param emitter Reference to the ParticleEmitter. * \param transform Const reference to the Transform component associated with the emitter. */ @@ -52,7 +52,7 @@ private: /** * \brief Generates a random angle for particle emission within the specified range. - * + * * \param min_angle Minimum emission angle in degrees. * \param max_angle Maximum emission angle in degrees. * \return Random angle in degrees. @@ -61,7 +61,7 @@ private: /** * \brief Generates a random speed for particle emission within the specified range. - * + * * \param min_speed Minimum emission speed. * \param max_speed Maximum emission speed. * \return Random speed. diff --git a/src/crepe/system/PhysicsSystem.h b/src/crepe/system/PhysicsSystem.h index 227ab69..26152a5 100644 --- a/src/crepe/system/PhysicsSystem.h +++ b/src/crepe/system/PhysicsSystem.h @@ -6,7 +6,7 @@ namespace crepe { /** * \brief System that controls all physics - * + * * This class is a physics system that uses a rigidbody and transform to add physics to a game * object. */ @@ -15,7 +15,7 @@ public: using System::System; /** * \brief updates the physics system. - * + * * It calculates new velocties and changes the postion in the transform. */ void update() override; diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 830d380..26f2c85 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -46,7 +46,8 @@ SDLContext::CameraValues RenderSystem::update_camera() { } bool sorting_comparison(const Sprite & a, const Sprite & b) { - if (a.data.sorting_in_layer != b.data.sorting_in_layer) return a.data.sorting_in_layer < b.data.sorting_in_layer; + if (a.data.sorting_in_layer != b.data.sorting_in_layer) + return a.data.sorting_in_layer < b.data.sorting_in_layer; if (a.data.order_in_layer != b.data.order_in_layer) return a.data.order_in_layer < b.data.order_in_layer; diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index de76229..e270a6b 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -18,7 +18,7 @@ class Transform; * \brief Manages rendering operations for all game objects. * * RenderSystem is responsible for rendering, clearing and presenting the screen, and - * managing the active camera. + * managing the active camera. */ class RenderSystem : public System { public: @@ -56,10 +56,10 @@ private: const double & scale); /** - * \brief renders a sprite with a Transform component on the screen + * \brief renders a sprite with a Transform component on the screen * * \param sprite the sprite component that holds all the data - * \param tm the Transform component that holds the position,rotation and scale + * \param tm the Transform component that holds the position,rotation and scale */ void render_normal(const Sprite & sprite, const SDLContext::CameraValues & cam, const Transform & tm); @@ -67,7 +67,7 @@ private: /** * \brief sort a vector sprite objects with * - * \param objs the vector that will do a sorting algorithm on + * \param objs the vector that will do a sorting algorithm on * \return returns a sorted reference vector */ RefVector sort(RefVector & objs) const; diff --git a/src/crepe/system/ScriptSystem.h b/src/crepe/system/ScriptSystem.h index 936e9ca..3db1b1e 100644 --- a/src/crepe/system/ScriptSystem.h +++ b/src/crepe/system/ScriptSystem.h @@ -8,7 +8,7 @@ class Script; /** * \brief Script system - * + * * The script system is responsible for all \c BehaviorScript components, and * calls the methods on classes derived from \c Script. */ diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp index bd99614..c753bca 100644 --- a/src/test/Profiling.cpp +++ b/src/test/Profiling.cpp @@ -70,8 +70,11 @@ public: void SetUp() override { GameObject do_not_use = mgr.new_object("DO_NOT_USE", "", {0, 0}); - do_not_use.add_component(Color::WHITE, ivec2{1080, 720}, vec2{2000, 2000}, - 1.0f); + do_not_use.add_component(ivec2{1080, 720}, vec2{2000, 2000}, + Camera::Data{ + .bg_color = Color::WHITE, + .zoom = 1.0f, + }); // initialize systems here: //calls init script_sys.update(); @@ -164,10 +167,15 @@ TEST_F(DISABLED_ProfilingTest, Profiling_2) { gameobject.add_component(vec2{0, 0}, vec2{1, 1}); gameobject.add_component().set_script(); - Color color(0, 0, 0, 0); auto img = Texture("asset/texture/square.png"); Sprite & test_sprite = gameobject.add_component( - img, color, Sprite::FlipSettings{false, false}, 1, 1, 500); + img, Sprite::Data{ + .color = {0, 0, 0, 0}, + .flip = {.flip_x = false, .flip_y = false}, + .sorting_in_layer = 1, + .order_in_layer = 1, + .size = {.y = 500}, + }); } this->game_object_count++; @@ -197,10 +205,15 @@ TEST_F(DISABLED_ProfilingTest, Profiling_3) { }); gameobject.add_component(vec2{0, 0}, vec2{1, 1}); gameobject.add_component().set_script(); - Color color(0, 0, 0, 0); auto img = Texture("asset/texture/square.png"); Sprite & test_sprite = gameobject.add_component( - img, color, Sprite::FlipSettings{false, false}, 1, 1, 500); + img, Sprite::Data{ + .color = {0, 0, 0, 0}, + .flip = {.flip_x = false, .flip_y = false}, + .sorting_in_layer = 1, + .order_in_layer = 1, + .size = {.y = 500}, + }); auto & test = gameobject.add_component(ParticleEmitter::Data{ .max_particles = 10, .emission_rate = 100, -- cgit v1.2.3