update: rewrite draw_route from LineRenderer to LineBatch

remove LineRenderer from DebugLinesRenderer
This commit is contained in:
alexei-zebra 2025-12-21 01:28:54 +03:00
parent 963e7d78f5
commit 4d324f3090
2 changed files with 28 additions and 32 deletions

View file

@ -1,48 +1,47 @@
#include "DebugLinesRenderer.hpp" #include "DebugLinesRenderer.hpp"
#include "graphics/core/Shader.hpp"
#include "window/Camera.hpp"
#include "graphics/core/LineBatch.hpp"
#include "graphics/core/DrawContext.hpp" #include "graphics/core/DrawContext.hpp"
#include "graphics/render/LinesRenderer.hpp" #include "graphics/core/LineBatch.hpp"
#include "world/Level.hpp" #include "graphics/core/Shader.hpp"
#include "maths/voxmaths.hpp"
#include "voxels/Chunk.hpp" #include "voxels/Chunk.hpp"
#include "voxels/Pathfinding.hpp" #include "voxels/Pathfinding.hpp"
#include "maths/voxmaths.hpp" #include "window/Camera.hpp"
#include "world/Level.hpp"
bool DebugLinesRenderer::showPaths = false; bool DebugLinesRenderer::showPaths = false;
static void draw_route( static void draw_route(LineBatch& batch, const voxels::Agent& agent) {
LinesRenderer& lines, const voxels::Agent& agent
) {
const auto& route = agent.route; const auto& route = agent.route;
if (!route.found) if (!route.found) return;
return;
batch.lineWidth(1.0f);
for (int i = 1; i < route.nodes.size(); i++) { for (int i = 1; i < route.nodes.size(); i++) {
const auto& a = route.nodes.at(i - 1); const auto& a = glm::vec3(route.nodes.at(i - 1).pos);
const auto& b = route.nodes.at(i); const auto& b = glm::vec3(route.nodes.at(i).pos);
glm::vec3 a_base = a + glm::vec3(0.5);
glm::vec3 b_base = b + glm::vec3(0.5);
glm::vec3 b_up = b + glm::vec3(0.5f, 1.0f, 0.5f);
if (i == 1) { if (i == 1) {
lines.pushLine( glm::vec3 a_up = a + glm::vec3(0.5f, 1.0f, 0.5f);
glm::vec3(a.pos) + glm::vec3(0.5f),
glm::vec3(a.pos) + glm::vec3(0.5f, 1.0f, 0.5f), batch.line(
glm::vec4(1, 1, 1, 1) a_base.x, a_base.y, a_base.z, a_up.x, a_up.y, a_up.z, 1, 1, 1, 1
); );
} }
batch.line(
lines.pushLine( a_base.x, a_base.y, a_base.z, b_base.x, b_base.y, b_base.z,
glm::vec3(a.pos) + glm::vec3(0.5f), 1, 0, 1, 1
glm::vec3(b.pos) + glm::vec3(0.5f),
glm::vec4(1, 0, 1, 1)
); );
batch.line(
lines.pushLine( b_base.x, b_base.y, b_base.z, b_up.x, b_up.y, b_up.z, 1, 1, 1, 1
glm::vec3(b.pos) + glm::vec3(0.5f),
glm::vec3(b.pos) + glm::vec3(0.5f, 1.0f, 0.5f),
glm::vec4(1, 1, 1, 1)
); );
} }
batch.flush();
} }
void DebugLinesRenderer::drawBorders( void DebugLinesRenderer::drawBorders(
@ -90,13 +89,12 @@ void DebugLinesRenderer::drawCoordSystem(
batch.line(0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 0.f, 0.f, 1.f); batch.line(0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 0.f, 0.f, 1.f);
batch.line(0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 0.f, 1.f); batch.line(0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 0.f, 1.f);
batch.line(0.f, 0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 1.f); batch.line(0.f, 0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 1.f);
batch.flush();
} }
void DebugLinesRenderer::render( void DebugLinesRenderer::render(
DrawContext& pctx, DrawContext& pctx,
const Camera& camera, const Camera& camera,
LinesRenderer& renderer,
LineBatch& linesBatch, LineBatch& linesBatch,
Shader& linesShader, Shader& linesShader,
bool showChunkBorders bool showChunkBorders
@ -104,7 +102,7 @@ void DebugLinesRenderer::render(
// In-world lines // In-world lines
if (showPaths) { if (showPaths) {
for (const auto& [_, agent] : level.pathfinding->getAgents()) { for (const auto& [_, agent] : level.pathfinding->getAgents()) {
draw_route(renderer, agent); draw_route(linesBatch, agent);
} }
} }
DrawContext ctx = pctx.sub(&linesBatch); DrawContext ctx = pctx.sub(&linesBatch);

View file

@ -3,7 +3,6 @@
class DrawContext; class DrawContext;
class Camera; class Camera;
class LineBatch; class LineBatch;
class LinesRenderer;
class Shader; class Shader;
class Level; class Level;
@ -23,7 +22,6 @@ public:
void render( void render(
DrawContext& ctx, DrawContext& ctx,
const Camera& camera, const Camera& camera,
LinesRenderer& renderer,
LineBatch& linesBatch, LineBatch& linesBatch,
Shader& linesShader, Shader& linesShader,
bool showChunkBorders bool showChunkBorders