r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
Debug.hpp
Go to the documentation of this file.
1///
2/// @file Debug.hpp
3/// @brief This file contains the debug system definition
4/// @namespace ecs
5///
6
7#pragma once
8
9#include <ranges>
10
11#include "ECS/Component.hpp"
12#include "ECS/Registry.hpp"
14
15namespace ecs
16{
17
18 ///
19 /// @class DebugSystem
20 /// @brief Class for debug system
21 /// @namespace ecs
22 ///
23 class DebugSystem final : public ASystem
24 {
25 public:
26 explicit DebugSystem(const std::shared_ptr<eng::IRenderer> &renderer, bool &showDebug)
27 : m_renderer(renderer), m_showDebug(showDebug)
28 {
29 }
30
31 ~DebugSystem() override = default;
32
33 DebugSystem(const DebugSystem &) = delete;
34 DebugSystem &operator=(const DebugSystem &) = delete;
37
38 void update(Registry &registry, float dt) override
39 {
40
41 const auto &circleShapes = registry.getAll<Hitbox>();
42 const auto &transforms = registry.getAll<Transform>();
43 for (const auto &key : circleShapes | std::views::keys)
44 {
45 if (!registry.hasComponent<Hitbox>(key) || !registry.hasComponent<Transform>(key))
46 {
47 continue;
48 }
49
50 const auto *transform = registry.getComponent<Transform>(key);
51 const auto *hitbox = registry.getComponent<Hitbox>(key);
52
53 if ((transform == nullptr) || (hitbox == nullptr))
54 {
55 continue;
56 }
57 const float hitboxX = transform->x + hitbox->offsetX - hitbox->radius;
58 const float hitboxY = transform->y + hitbox->offsetY - hitbox->radius;
59 m_renderer->setCircleShapePosition("hitbox_" + std::to_string(key), hitboxX, hitboxY);
60 if (m_showDebug)
61 {
62 m_renderer->drawCircleShape("hitbox_" + std::to_string(key));
63 }
64 }
65 }
66
67 private:
68 const std::shared_ptr<eng::IRenderer> &m_renderer;
70
71 }; // class DebugSystem
72} // namespace ecs
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 debug system.
Definition Debug.hpp:24
DebugSystem(const DebugSystem &)=delete
bool & m_showDebug
Definition Debug.hpp:69
DebugSystem(DebugSystem &&)=delete
void update(Registry &registry, float dt) override
Definition Debug.hpp:38
const std::shared_ptr< eng::IRenderer > & m_renderer
Definition Debug.hpp:68
~DebugSystem() override=default
DebugSystem(const std::shared_ptr< eng::IRenderer > &renderer, bool &showDebug)
Definition Debug.hpp:26
DebugSystem & operator=(DebugSystem &&)=delete
DebugSystem & operator=(const DebugSystem &)=delete
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