Worked on debugging and metadata stuff

This commit is contained in:
2024-09-18 23:00:52 +03:00
parent a9190fcc09
commit 43c312e371
13 changed files with 431 additions and 110 deletions

View File

@@ -13,7 +13,7 @@
#include "from_string.h"
#include "road_lines_data.h"
static ImmediateGeometry *debug_im;
ImmediateGeometry *RoadLinesData::debug_im = nullptr;
static Ref<Material> debug_material;
RoadLinesData::RoadLinesData()
{
@@ -73,10 +73,12 @@ RoadLinesData *RoadLinesData::get_singleton()
RoadLinesData::~RoadLinesData()
{
#if 0
if (debug_im) {
memdelete(debug_im);
debug_im = nullptr;
}
#endif
}
void RoadLinesData::cleanup()
@@ -159,7 +161,6 @@ uint32_t RoadLinesData::road_lines_hash(const Vector3 &v)
int z = (int)(v.z / 100);
return x ^ (y * 100) ^ (z * 10000);
}
void RoadLinesData::road_lines_curve_index(
struct RoadLinesData::road_line &rline,
std::unordered_map<uint32_t, std::vector<Vector3> >
@@ -454,20 +455,24 @@ void RoadLinesData::dump_road_lines(const std::vector<Vector3> &road_lines_nodes
}
}
static inline ImmediateGeometry *get_debug_node()
ImmediateGeometry *RoadLinesData::get_debug_node()
{
debug_im = memnew(ImmediateGeometry);
Ref<SpatialMaterial> tmpmat;
tmpmat.instance();
tmpmat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
tmpmat->set_flag(SpatialMaterial::FLAG_DISABLE_DEPTH_TEST, true);
tmpmat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
debug_material = tmpmat;
debug_im->set_material_override(debug_material);
SceneTree::get_singleton()
->get_current_scene()
->get_viewport()
->add_child(debug_im);
if (!debug_im) {
debug_im = memnew(ImmediateGeometry);
Ref<SpatialMaterial> tmpmat;
tmpmat.instance();
tmpmat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,
true);
tmpmat->set_flag(SpatialMaterial::FLAG_DISABLE_DEPTH_TEST,
true);
tmpmat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
debug_material = tmpmat;
debug_im->set_material_override(debug_material);
SceneTree::get_singleton()
->get_current_scene()
->get_viewport()
->call_deferred("add_child", debug_im);
}
return debug_im;
}
@@ -477,19 +482,35 @@ void RoadLinesData::process_lines(
std::vector<Vector3> &road_lines_nodes)
{
int i;
get_debug_node();
debug_im->clear();
get_debug_node()->clear();
index_lines(road_lines_nodes_hash, road_lines_nodes);
debug_im->begin(Mesh::PRIMITIVE_LINES);
for (i = 0; i < (int)road_lines_nodes.size(); i++) {
debug_im->set_color(Color(0.1f, 0.6f, 0.6f, 1.0f));
debug_im->add_vertex(road_lines_nodes[i]);
debug_im->set_color(Color(0.1f, 0.6f, 0.6f, 1.0f));
debug_im->add_vertex(road_lines_nodes[i] +
Vector3(0.0f, 200.0f, 0.0f));
}
debug_im->end();
insert_close_points(road_lines_nodes, 160.0f);
update_road_lines_nodes(road_lines_nodes);
dump_road_lines(road_lines_nodes);
if (debug_flags & 1) {
get_debug_node()->begin(Mesh::PRIMITIVE_LINES);
for (i = 0; i < (int)road_lines_nodes.size(); i++) {
print_line("debug_node: " + itos(i) + " " +
(road_lines_nodes[i].operator String()));
get_debug_node()->set_color(
Color(0.1f, 0.6f, 0.6f, 1.0f));
get_debug_node()->add_vertex(road_lines_nodes[i]);
get_debug_node()->set_color(
Color(0.1f, 0.6f, 0.6f, 1.0f));
get_debug_node()->add_vertex(
road_lines_nodes[i] +
Vector3(0.0f, 200.0f, 0.0f));
}
get_debug_node()->end();
}
}
void RoadLinesData::set_debug_flags(int debug_flags)
{
this->debug_flags = debug_flags;
}
int RoadLinesData::get_debug_flags() const
{
return debug_flags;
}