|
| 1 | +/* |
| 2 | +debug_visualizer.cpp - utilities for visualizing data for debug purposes |
| 3 | +Copyright (C) 2025 SNMetamorph |
| 4 | +
|
| 5 | +This program is free software: you can redistribute it and/or modify |
| 6 | +it under the terms of the GNU General Public License as published by |
| 7 | +the Free Software Foundation, either version 3 of the License, or |
| 8 | +(at your option) any later version. |
| 9 | +
|
| 10 | +This program is distributed in the hope that it will be useful, |
| 11 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +GNU General Public License for more details. |
| 14 | +*/ |
| 15 | + |
| 16 | +#include "debug_visualizer.h" |
| 17 | +#include "hud.h" |
| 18 | + |
| 19 | +CDebugVisualizer::Primitive::Primitive(Class type, Vector color, std::optional<float> lifespan, bool depthTest, DataVariant data) : |
| 20 | + type(type), |
| 21 | + color(color), |
| 22 | + lifespan(lifespan), |
| 23 | + depthTest(depthTest), |
| 24 | + rendered(false), |
| 25 | + data(std::move(data)) |
| 26 | +{ |
| 27 | +} |
| 28 | + |
| 29 | +CDebugVisualizer& CDebugVisualizer::GetInstance() |
| 30 | +{ |
| 31 | + static CDebugVisualizer instance; |
| 32 | + return instance; |
| 33 | +} |
| 34 | + |
| 35 | +void CDebugVisualizer::RunFrame() |
| 36 | +{ |
| 37 | + float currentTime = gEngfuncs.GetClientTime(); |
| 38 | + auto predicate = [currentTime](const Primitive& prim) { |
| 39 | + if (prim.lifespan.has_value()) { |
| 40 | + return currentTime >= prim.lifespan.value(); |
| 41 | + } |
| 42 | + return prim.rendered; |
| 43 | + }; |
| 44 | + m_primitives.erase(std::remove_if(m_primitives.begin(), m_primitives.end(), predicate), m_primitives.end()); |
| 45 | +} |
| 46 | + |
| 47 | +void CDebugVisualizer::DrawAABB(const Vector &mins, const Vector &maxs, Vector color, std::optional<float> lifespan, bool depthTest) |
| 48 | +{ |
| 49 | + m_primitives.emplace_back(Primitive::Class::AABB, color, lifespan, depthTest, AABBData{ mins, maxs }); |
| 50 | +} |
| 51 | + |
| 52 | +void CDebugVisualizer::DrawSphere(const Vector ¢er, float radius, Vector color, std::optional<float> lifespan, bool depthTest) |
| 53 | +{ |
| 54 | + m_primitives.emplace_back(Primitive::Class::Sphere, color, lifespan, depthTest, SphereData{ center, radius }); |
| 55 | +} |
| 56 | + |
| 57 | +void CDebugVisualizer::DrawVector(const Vector &position, const Vector &direction, Vector color, std::optional<float> lifespan, bool depthTest) |
| 58 | +{ |
| 59 | + m_primitives.emplace_back(Primitive::Class::Vector, color, lifespan, depthTest, VectorData{ position, direction }); |
| 60 | +} |
| 61 | + |
| 62 | +void CDebugVisualizer::DrawFrustum(const CFrustum &frustum, Vector color, std::optional<float> lifespan, bool depthTest) |
| 63 | +{ |
| 64 | + m_primitives.emplace_back(Primitive::Class::Frustum, color, lifespan, depthTest, FrustumData{ frustum }); |
| 65 | +} |
0 commit comments