R-Type
Debug.hpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2023
3 ** R-Type-epitech
4 ** File description:
5 ** Debug
6 */
7 
8 #ifdef DEBUG
9  #ifndef DEBUG_HPP_
10  #define DEBUG_HPP_
11  #include <memory>
12  #include <imgui.h>
13  #include <imgui_internal.h>
14  #include "Registry.hpp"
15  #include "utils/DeltaTime.hpp"
16  #include "Event.hpp"
17  #include "utils/Utils.hpp"
18 
19 namespace Debug
20 {
21  static const ImVec2 DEBUG_MENU_DEFAULT_WINDOW_SIZE = ImVec2((float)500, (float)500);
22  static const float DEFAULT_COMPONENT_LIST_HEIGHT = 150.0f;
23  static const float DEFAULT_EVENT_LOG_HEIGHT = 200.0f;
24  static const size_t DEFAULT_FPS_PLOT_TEXT_LENGTH = 32;
25  static const size_t DEFAULT_FPS_PLOT_NB_VALUES = 90;
26  static const double DEFAULT_FPS_PLOT_REFRESH_RATE = 60.0;
27  static const ImVec2 DEFAULT_FPS_PLOT_SIZE = ImVec2(0, 80.0f);
28  static const int DEFAULT_FPS_LIMIT_SLIDER_MAX_VALUE = 1000;
29  static const int DEFAULT_FPS_LIMIT_SLIDER_VALUE = 60;
30 
31  class DebugMenu
32  {
33  public:
38  DebugMenu(
39  GameEngine::EventManager &eventManager, GameEngine::Registry &registry, GameEngine::DeltaTime &deltaTime)
40  : _eventManager(eventManager), _registry(registry), _deltaTime(deltaTime)
41  {
42  }
44  ~DebugMenu() {}
45 
47  void draw()
48  {
49  ImGui::SetNextWindowSize(DEBUG_MENU_DEFAULT_WINDOW_SIZE, ImGuiCond_FirstUseEver);
50  ImGui::Begin("Debug Menu");
51  if (ImGui::BeginTabBar("MainTabBar")) {
52  if (ImGui::BeginTabItem("Game")) {
53  _showGameMenu();
54  }
55  if (ImGui::BeginTabItem("Registry")) {
56  _showRegistryMenu();
57  }
58  if (ImGui::BeginTabItem("Events")) {
59  _showEventsMenu();
60  }
61  ImGui::EndTabBar();
62  }
63  ImGui::End();
64  }
65 
66  private:
67  GameEngine::EventManager &_eventManager;
68  GameEngine::Registry &_registry;
69  GameEngine::DeltaTime &_deltaTime;
71  void _showGameMenu();
73  void _showRegistryMenu();
78  template <typename Component>
79  void _showComponentList(SparseArray<Component> &components, int &currentComponent)
80  {
81  if (ImGui::BeginListBox("##componentList",
82  ImVec2(ImGui::GetContentRegionAvail().x / 3.0f, DEFAULT_COMPONENT_LIST_HEIGHT))) {
83  for (int i = 0; i < _registry._nbEntities; i++) {
84  if (!components[i])
85  continue;
86  const bool is_selected = (currentComponent == i);
87  if (ImGui::Selectable(std::to_string(i).c_str(), is_selected)) {
88  currentComponent = i;
89  }
90  if (is_selected)
91  ImGui::SetItemDefaultFocus();
92  }
93  ImGui::EndListBox();
94  }
95  }
97  void _showTransfomComponentMenu();
99  void _showTextureComponentMenu();
101  void _showCameraComponentMenu();
103  void _showCollisionComponentMenu();
105  void _showMusicComponentMenu();
107  void _showPressableComponentMenu();
109  void _showTextComponentMenu();
111  void _showControllableComponentMenu();
113  void _showDamageComponentMenu();
115  void _showGravityComponentMenu();
117  void _showInputComponentMenu();
119  void _showHealthComponentMenu();
121  void _showScoreComponentMenu();
123  void _showNetworkIdComponentMenu();
125  void _showEventsMenu();
126  };
127 } // namespace Debug
128  #endif
129 #endif
DeltaTime class which handles the delta time.
Definition: DeltaTime.hpp:16
class to help create and manage all the event handlers
Definition: Event.hpp:135
Entity component system, handling entities, components and systems.
Definition: Registry.hpp:31
Array which can have empty indexes.
Definition: SparseArray.hpp:19
Definition: Registry.hpp:21