r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
FlappyDebugSystem.hpp
Go to the documentation of this file.
1///
2/// @file FlappyDebugSystem.hpp
3/// @brief This file contains the FlappyBird debug system definition
4/// @namespace gme
5///
6
7#pragma once
8
9#include <ranges>
10
11#include "ECS/Component.hpp"
12#include "ECS/Registry.hpp"
14
15namespace gme
16{
17
18 ///
19 /// @class FlappyDebugSystem
20 /// @brief Class for FlappyBird debug system that excludes pipes from circle hitbox display
21 /// @namespace gme
22 ///
23 class FlappyDebugSystem final : public ecs::ASystem
24 {
25 public:
26 explicit FlappyDebugSystem(const std::shared_ptr<eng::IRenderer> &renderer, bool &showDebug)
27 : m_renderer(renderer), m_showDebug(showDebug)
28 {
29 }
30
31 ~FlappyDebugSystem() override = default;
32
37
38 void update(ecs::Registry &registry, float /* dt */) override
39 {
40 const auto &circleShapes = registry.getAll<ecs::Hitbox>();
41 for (const auto &[key, hitboxComponent] : circleShapes)
42 {
43 if (!registry.hasComponent<ecs::Hitbox>(key) || !registry.hasComponent<ecs::Transform>(key))
44 {
45 continue;
46 }
47
48 if (registry.hasComponent<ecs::Texture>(key))
49 {
50 const auto *texture = registry.getComponent<ecs::Texture>(key);
51 if (texture && (texture->id.find("pipe") != std::string::npos))
52 {
53 continue;
54 }
55 }
56
57 const auto *transform = registry.getComponent<ecs::Transform>(key);
58 const auto *hitbox = registry.getComponent<ecs::Hitbox>(key);
59
60 if ((transform == nullptr) || (hitbox == nullptr))
61 {
62 continue;
63 }
64
65 const float hitboxX = transform->x + hitbox->offsetX - hitbox->radius;
66 const float hitboxY = transform->y + hitbox->offsetY - hitbox->radius;
67
68 const std::string circleName = "hitbox_" + std::to_string(key);
69 try
70 {
71 m_renderer->setCircleShapePosition(circleName, hitboxX, hitboxY);
72 if (m_showDebug)
73 {
74 m_renderer->drawCircleShape(circleName);
75 }
76 }
77 catch (const std::runtime_error &)
78 {
79 continue;
80 }
81 }
82 }
83
84 private:
85 const std::shared_ptr<eng::IRenderer> &m_renderer;
87 }; // class FlappyDebugSystem
88} // namespace gme
89
This file contains the component definitions.
This file contains the IRenderer class declaration.
This file contains the Registry class declaration.
Abstract class for system.
Definition ISystems.hpp:34
Class for managing entities and their components.
Definition Registry.hpp:25
bool hasComponent(Entity e)
Definition Registry.hpp:79
std::unordered_map< Entity, T > & getAll()
Definition Registry.hpp:77
T * getComponent(Entity e)
Definition Registry.hpp:71
virtual void drawCircleShape(const std::string &name)=0
virtual void setCircleShapePosition(const std::string &name, float x, float y)=0
Class for FlappyBird debug system that excludes pipes from circle hitbox display.
FlappyDebugSystem(FlappyDebugSystem &&)=delete
FlappyDebugSystem & operator=(const FlappyDebugSystem &)=delete
FlappyDebugSystem(const FlappyDebugSystem &)=delete
FlappyDebugSystem(const std::shared_ptr< eng::IRenderer > &renderer, bool &showDebug)
FlappyDebugSystem & operator=(const FlappyDebugSystem &&)=delete
const std::shared_ptr< eng::IRenderer > & m_renderer
void update(ecs::Registry &registry, float) override
~FlappyDebugSystem() override=default