mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-23 17:47:17 +01:00
Backported form godot4: Fix NavigationServer internals still using float instead of real_t
Fixes that some NavigationServer internals still used float instead of real_t in some parts.
- smix8
217a27014b
This commit is contained in:
parent
7acef201ce
commit
038329e7d0
@ -45,22 +45,22 @@ void NavMap::set_up(Vector3 p_up) {
|
|||||||
regenerate_polygons = true;
|
regenerate_polygons = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMap::set_cell_size(float p_cell_size) {
|
void NavMap::set_cell_size(real_t p_cell_size) {
|
||||||
cell_size = p_cell_size;
|
cell_size = p_cell_size;
|
||||||
regenerate_polygons = true;
|
regenerate_polygons = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMap::set_cell_height(float p_cell_height) {
|
void NavMap::set_cell_height(real_t p_cell_height) {
|
||||||
cell_height = p_cell_height;
|
cell_height = p_cell_height;
|
||||||
regenerate_polygons = true;
|
regenerate_polygons = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMap::set_edge_connection_margin(float p_edge_connection_margin) {
|
void NavMap::set_edge_connection_margin(real_t p_edge_connection_margin) {
|
||||||
edge_connection_margin = p_edge_connection_margin;
|
edge_connection_margin = p_edge_connection_margin;
|
||||||
regenerate_links = true;
|
regenerate_links = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMap::set_link_connection_radius(float p_link_connection_radius) {
|
void NavMap::set_link_connection_radius(real_t p_link_connection_radius) {
|
||||||
link_connection_radius = p_link_connection_radius;
|
link_connection_radius = p_link_connection_radius;
|
||||||
regenerate_links = true;
|
regenerate_links = true;
|
||||||
}
|
}
|
||||||
@ -84,8 +84,8 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
|
|||||||
const gd::Polygon *end_poly = nullptr;
|
const gd::Polygon *end_poly = nullptr;
|
||||||
Vector3 begin_point;
|
Vector3 begin_point;
|
||||||
Vector3 end_point;
|
Vector3 end_point;
|
||||||
float begin_d = 1e20;
|
real_t begin_d = FLT_MAX;
|
||||||
float end_d = 1e20;
|
real_t end_d = FLT_MAX;
|
||||||
|
|
||||||
// Find the initial poly and the end poly on this map.
|
// Find the initial poly and the end poly on this map.
|
||||||
for (size_t i(0); i < polygons.size(); i++) {
|
for (size_t i(0); i < polygons.size(); i++) {
|
||||||
@ -101,7 +101,7 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
|
|||||||
const Face3 face(p.points[0].pos, p.points[point_id - 1].pos, p.points[point_id].pos);
|
const Face3 face(p.points[0].pos, p.points[point_id - 1].pos, p.points[point_id].pos);
|
||||||
|
|
||||||
Vector3 point = face.get_closest_point_to(p_origin);
|
Vector3 point = face.get_closest_point_to(p_origin);
|
||||||
float distance_to_point = point.distance_to(p_origin);
|
real_t distance_to_point = point.distance_to(p_origin);
|
||||||
if (distance_to_point < begin_d) {
|
if (distance_to_point < begin_d) {
|
||||||
begin_d = distance_to_point;
|
begin_d = distance_to_point;
|
||||||
begin_poly = &p;
|
begin_poly = &p;
|
||||||
@ -153,7 +153,7 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
|
|||||||
bool found_route = false;
|
bool found_route = false;
|
||||||
|
|
||||||
const gd::Polygon *reachable_end = nullptr;
|
const gd::Polygon *reachable_end = nullptr;
|
||||||
float reachable_d = 1e30;
|
real_t reachable_d = FLT_MAX;
|
||||||
bool is_reachable = true;
|
bool is_reachable = true;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -171,8 +171,8 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
|
|||||||
}
|
}
|
||||||
|
|
||||||
const gd::NavigationPoly &least_cost_poly = navigation_polys[least_cost_id];
|
const gd::NavigationPoly &least_cost_poly = navigation_polys[least_cost_id];
|
||||||
float poly_enter_cost = 0.0;
|
real_t poly_enter_cost = 0.0;
|
||||||
float poly_travel_cost = least_cost_poly.poly->owner->get_travel_cost();
|
real_t poly_travel_cost = least_cost_poly.poly->owner->get_travel_cost();
|
||||||
|
|
||||||
if (prev_least_cost_id != -1 && !(navigation_polys[prev_least_cost_id].poly->owner->get_self() == least_cost_poly.poly->owner->get_self())) {
|
if (prev_least_cost_id != -1 && !(navigation_polys[prev_least_cost_id].poly->owner->get_self() == least_cost_poly.poly->owner->get_self())) {
|
||||||
poly_enter_cost = least_cost_poly.poly->owner->get_enter_cost();
|
poly_enter_cost = least_cost_poly.poly->owner->get_enter_cost();
|
||||||
@ -181,7 +181,7 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
|
|||||||
|
|
||||||
Vector3 pathway[2] = { connection.pathway_start, connection.pathway_end };
|
Vector3 pathway[2] = { connection.pathway_start, connection.pathway_end };
|
||||||
const Vector3 new_entry = Geometry::get_closest_point_to_segment(least_cost_poly.entry, pathway);
|
const Vector3 new_entry = Geometry::get_closest_point_to_segment(least_cost_poly.entry, pathway);
|
||||||
const float new_distance = (least_cost_poly.entry.distance_to(new_entry) * poly_travel_cost) + poly_enter_cost + least_cost_poly.traveled_distance;
|
const real_t new_distance = (least_cost_poly.entry.distance_to(new_entry) * poly_travel_cost) + poly_enter_cost + least_cost_poly.traveled_distance;
|
||||||
|
|
||||||
int64_t already_visited_polygon_index = navigation_polys.find(gd::NavigationPoly(connection.polygon));
|
int64_t already_visited_polygon_index = navigation_polys.find(gd::NavigationPoly(connection.polygon));
|
||||||
|
|
||||||
@ -229,11 +229,11 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
|
|||||||
|
|
||||||
// Set as end point the furthest reachable point.
|
// Set as end point the furthest reachable point.
|
||||||
end_poly = reachable_end;
|
end_poly = reachable_end;
|
||||||
end_d = 1e20;
|
end_d = FLT_MAX;
|
||||||
for (size_t point_id = 2; point_id < end_poly->points.size(); point_id++) {
|
for (size_t point_id = 2; point_id < end_poly->points.size(); point_id++) {
|
||||||
Face3 f(end_poly->points[0].pos, end_poly->points[point_id - 1].pos, end_poly->points[point_id].pos);
|
Face3 f(end_poly->points[0].pos, end_poly->points[point_id - 1].pos, end_poly->points[point_id].pos);
|
||||||
Vector3 spoint = f.get_closest_point_to(p_destination);
|
Vector3 spoint = f.get_closest_point_to(p_destination);
|
||||||
float dpoint = spoint.distance_to(p_destination);
|
real_t dpoint = spoint.distance_to(p_destination);
|
||||||
if (dpoint < end_d) {
|
if (dpoint < end_d) {
|
||||||
end_point = spoint;
|
end_point = spoint;
|
||||||
end_d = dpoint;
|
end_d = dpoint;
|
||||||
@ -256,10 +256,10 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
|
|||||||
|
|
||||||
// Find the polygon with the minimum cost from the list of polygons to visit.
|
// Find the polygon with the minimum cost from the list of polygons to visit.
|
||||||
least_cost_id = -1;
|
least_cost_id = -1;
|
||||||
float least_cost = 1e30;
|
real_t least_cost = FLT_MAX;
|
||||||
for (List<uint32_t>::Element *element = to_visit.front(); element != nullptr; element = element->next()) {
|
for (List<uint32_t>::Element *element = to_visit.front(); element != nullptr; element = element->next()) {
|
||||||
gd::NavigationPoly *np = &navigation_polys[element->get()];
|
gd::NavigationPoly *np = &navigation_polys[element->get()];
|
||||||
float cost = np->traveled_distance;
|
real_t cost = np->traveled_distance;
|
||||||
cost += (np->entry.distance_to(end_point) * np->poly->owner->get_travel_cost());
|
cost += (np->entry.distance_to(end_point) * np->poly->owner->get_travel_cost());
|
||||||
if (cost < least_cost) {
|
if (cost < least_cost) {
|
||||||
least_cost_id = np->self_id;
|
least_cost_id = np->self_id;
|
||||||
@ -271,7 +271,7 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
|
|||||||
|
|
||||||
// Stores the further reachable end polygon, in case our goal is not reachable.
|
// Stores the further reachable end polygon, in case our goal is not reachable.
|
||||||
if (is_reachable) {
|
if (is_reachable) {
|
||||||
float d = navigation_polys[least_cost_id].entry.distance_to(p_destination) * navigation_polys[least_cost_id].poly->owner->get_travel_cost();
|
real_t d = navigation_polys[least_cost_id].entry.distance_to(p_destination) * navigation_polys[least_cost_id].poly->owner->get_travel_cost();
|
||||||
if (reachable_d > d) {
|
if (reachable_d > d) {
|
||||||
reachable_d = d;
|
reachable_d = d;
|
||||||
reachable_end = navigation_polys[least_cost_id].poly;
|
reachable_end = navigation_polys[least_cost_id].poly;
|
||||||
@ -396,7 +396,7 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
|
|||||||
Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const {
|
Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const {
|
||||||
bool use_collision = p_use_collision;
|
bool use_collision = p_use_collision;
|
||||||
Vector3 closest_point;
|
Vector3 closest_point;
|
||||||
real_t closest_point_d = 1e20;
|
real_t closest_point_d = FLT_MAX;
|
||||||
|
|
||||||
for (size_t i(0); i < polygons.size(); i++) {
|
for (size_t i(0); i < polygons.size(); i++) {
|
||||||
const gd::Polygon &p = polygons[i];
|
const gd::Polygon &p = polygons[i];
|
||||||
@ -459,7 +459,7 @@ RID NavMap::get_closest_point_owner(const Vector3 &p_point) const {
|
|||||||
|
|
||||||
gd::ClosestPointQueryResult NavMap::get_closest_point_info(const Vector3 &p_point) const {
|
gd::ClosestPointQueryResult NavMap::get_closest_point_info(const Vector3 &p_point) const {
|
||||||
gd::ClosestPointQueryResult result;
|
gd::ClosestPointQueryResult result;
|
||||||
real_t closest_point_ds = 1e20;
|
real_t closest_point_ds = FLT_MAX;
|
||||||
|
|
||||||
for (size_t i(0); i < polygons.size(); i++) {
|
for (size_t i(0); i < polygons.size(); i++) {
|
||||||
const gd::Polygon &p = polygons[i];
|
const gd::Polygon &p = polygons[i];
|
||||||
@ -661,8 +661,8 @@ void NavMap::sync() {
|
|||||||
|
|
||||||
// Compute the projection of the opposite edge on the current one
|
// Compute the projection of the opposite edge on the current one
|
||||||
Vector3 edge_vector = edge_p2 - edge_p1;
|
Vector3 edge_vector = edge_p2 - edge_p1;
|
||||||
float projected_p1_ratio = edge_vector.dot(other_edge_p1 - edge_p1) / (edge_vector.length_squared());
|
real_t projected_p1_ratio = edge_vector.dot(other_edge_p1 - edge_p1) / (edge_vector.length_squared());
|
||||||
float projected_p2_ratio = edge_vector.dot(other_edge_p2 - edge_p1) / (edge_vector.length_squared());
|
real_t projected_p2_ratio = edge_vector.dot(other_edge_p2 - edge_p1) / (edge_vector.length_squared());
|
||||||
if ((projected_p1_ratio < 0.0 && projected_p2_ratio < 0.0) || (projected_p1_ratio > 1.0 && projected_p2_ratio > 1.0)) {
|
if ((projected_p1_ratio < 0.0 && projected_p2_ratio < 0.0) || (projected_p1_ratio > 1.0 && projected_p2_ratio > 1.0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -105,23 +105,23 @@ public:
|
|||||||
return up;
|
return up;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_cell_size(float p_cell_size);
|
void set_cell_size(real_t p_cell_size);
|
||||||
float get_cell_size() const {
|
real_t get_cell_size() const {
|
||||||
return cell_size;
|
return cell_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_cell_height(float p_cell_height);
|
void set_cell_height(real_t p_cell_height);
|
||||||
float get_cell_height() const {
|
real_t get_cell_height() const {
|
||||||
return cell_height;
|
return cell_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_edge_connection_margin(float p_edge_connection_margin);
|
void set_edge_connection_margin(real_t p_edge_connection_margin);
|
||||||
float get_edge_connection_margin() const {
|
real_t get_edge_connection_margin() const {
|
||||||
return edge_connection_margin;
|
return edge_connection_margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_link_connection_radius(float p_link_connection_radius);
|
void set_link_connection_radius(real_t p_link_connection_radius);
|
||||||
float get_link_connection_radius() const {
|
real_t get_link_connection_radius() const {
|
||||||
return link_connection_radius;
|
return link_connection_radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ void NavRegion::update_polygons() {
|
|||||||
p.edges.resize(mesh_poly.size());
|
p.edges.resize(mesh_poly.size());
|
||||||
|
|
||||||
Vector3 center;
|
Vector3 center;
|
||||||
float sum(0);
|
real_t sum(0);
|
||||||
|
|
||||||
for (int j(0); j < mesh_poly.size(); j++) {
|
for (int j(0); j < mesh_poly.size(); j++) {
|
||||||
int idx = indices[j];
|
int idx = indices[j];
|
||||||
@ -144,7 +144,7 @@ void NavRegion::update_polygons() {
|
|||||||
|
|
||||||
p.clockwise = sum > 0;
|
p.clockwise = sum > 0;
|
||||||
if (mesh_poly.size() != 0) {
|
if (mesh_poly.size() != 0) {
|
||||||
p.center = center / float(mesh_poly.size());
|
p.center = center / real_t(mesh_poly.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ struct NavigationPoly {
|
|||||||
/// The entry location of this poly.
|
/// The entry location of this poly.
|
||||||
Vector3 entry;
|
Vector3 entry;
|
||||||
/// The distance to the destination.
|
/// The distance to the destination.
|
||||||
float traveled_distance;
|
real_t traveled_distance;
|
||||||
|
|
||||||
NavigationPoly() { poly = nullptr; }
|
NavigationPoly() { poly = nullptr; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user