Brunot
Loading...
Searching...
No Matches
DebugDraw.h
Go to the documentation of this file.
1// DebugDraw.h
2// File: DebugDraw.h
3// Description: A system to collect lines and render them all at once each frame for debug information. recommended uses
4// are hitboxes, paths, relationships, grids, and vectors.
5// Author(s): Aidan Hartman (aidan.hartman@digipen.edu)
6// 2025 / 11 / 07
7// (C) Digipen 2025
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15
16#pragma once
17
18// true or false
19#ifdef _DEBUG
20#define DEBUG_DRAW_START_ACTIVE true
21#else
22#define DEBUG_DRAW_START_ACTIVE false
23#endif
24
25#include "Framework/System.h"
26#include "Graphics/VAO.h"
27
28namespace gfx
29{
30class Line;
31}
32
33
35// namespace gfx
36// {
37// struct Vertex;
38// }
39#include "Graphics/Vertex.h"
40
41namespace sys
42{
43class DebugDraw : public System
44{
45public:
46#pragma region static_functions
47
51 static auto getEnum() -> Type
52 {
53 return Type::DebugDraw;
54 }
55
61 static auto drawLine(const gfx::Line& line) -> void;
62
63
64#pragma endregion
65
66 DebugDraw();
67 ~DebugDraw() override = default;
68 DebugDraw(const DebugDraw& other) = default;
69 DebugDraw(DebugDraw&& other) noexcept;
70 auto operator=(const DebugDraw& other) -> DebugDraw&;
71 auto operator=(DebugDraw&& other) noexcept -> DebugDraw& = default;
72
73
74#pragma region overridden_functions
75
76 auto clone() const -> std::unique_ptr<GameObject> override
77 {
78 return std::make_unique<DebugDraw>(*this);
79 }
80
81 auto onUpdate(float dt) -> void override;
82 auto onRender() -> void override;
83
84protected:
85 auto systemShowMenu() -> void override;
86
87public:
88 auto load(const Stream& stream) -> void override;
89 auto save(Stream& stream) const -> void override;
90 auto endWindow() -> void override;
91
92#pragma endregion
93
94#pragma region DebugDraw_Functions
95
96
101 auto addLine(const gfx::Line& line) -> void;
102
103
104#pragma endregion
105
106private:
107#pragma region member_variables
108
109 std::shared_ptr<gfx::VertexBuffer> vertexBuffer;
110 std::vector<std::pair<gfx::Vertex, gfx::Vertex>> lines;
112
113 int lineWidth{2};
114
115
116#pragma endregion
117
118#pragma region helper_functions
119 auto setupMesh() -> GLuint;
120
121#pragma endregion
122
123#pragma region static_variables
124
125#pragma endregion
126
127
128};
129}
130
138auto operator<<(sys::DebugDraw* debug, const gfx::Line& line) -> sys::DebugDraw*;
139
140#undef DEBUG_DRAW_START_ACTIVE
sys::Json Stream
Definition AudioObject.h:20
auto operator<<(sys::DebugDraw *debug, const gfx::Line &line) -> sys::DebugDraw *
stream insertion operator for adding lines to the debug draw system Uses DebugDraw pointer instead of...
Definition DebugDraw.cpp:189
#define DEBUG_DRAW_START_ACTIVE
Definition DebugDraw.h:22
unsigned int GLuint
Definition IndexBuffer.h:17
A struct for stroing vertexes and handing them to opengl.
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
Type
Definition System.h:20
@ DebugDraw
Definition System.h:37
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
Definition Line.h:32
Definition DebugDraw.h:44
int lineWidth
Definition DebugDraw.h:113
auto operator=(const DebugDraw &other) -> DebugDraw &
Definition DebugDraw.cpp:51
auto operator=(DebugDraw &&other) noexcept -> DebugDraw &=default
DebugDraw(const DebugDraw &other)=default
auto onUpdate(float dt) -> void override
called once every frame.
Definition DebugDraw.cpp:65
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition DebugDraw.h:76
static auto getEnum() -> Type
function required by all systems
Definition DebugDraw.h:51
bool active
Definition DebugDraw.h:111
static auto drawLine(const gfx::Line &line) -> void
add a line to the debug renderer.
Definition DebugDraw.cpp:36
auto onRender() -> void override
called every frame after update has been called for every object.
Definition DebugDraw.cpp:99
std::shared_ptr< gfx::VertexBuffer > vertexBuffer
Definition DebugDraw.h:109
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition DebugDraw.cpp:162
std::vector< std::pair< gfx::Vertex, gfx::Vertex > > lines
Definition DebugDraw.h:110
DebugDraw()
Definition DebugDraw.cpp:41
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition DebugDraw.cpp:149
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition DebugDraw.cpp:167
auto setupMesh() -> GLuint
Definition DebugDraw.cpp:70
~DebugDraw() override=default
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition DebugDraw.cpp:172
auto addLine(const gfx::Line &line) -> void
add a line to the debug renderer.
Definition DebugDraw.cpp:177
Definition Sprite.h:25
the type of elements in a basic_json container
Definition GameObject.h:32