Added bool to allow astar points to be connected in one direction only
(cherry picked from commit 2262a59ab3
)
This commit is contained in:
parent
c2c1d2076c
commit
f0beb36652
2 changed files with 6 additions and 4 deletions
|
@ -86,7 +86,7 @@ void AStar::remove_point(int p_id) {
|
||||||
points.erase(p_id);
|
points.erase(p_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AStar::connect_points(int p_id, int p_with_id) {
|
void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
|
||||||
|
|
||||||
ERR_FAIL_COND(!points.has(p_id));
|
ERR_FAIL_COND(!points.has(p_id));
|
||||||
ERR_FAIL_COND(!points.has(p_with_id));
|
ERR_FAIL_COND(!points.has(p_with_id));
|
||||||
|
@ -95,6 +95,8 @@ void AStar::connect_points(int p_id, int p_with_id) {
|
||||||
Point *a = points[p_id];
|
Point *a = points[p_id];
|
||||||
Point *b = points[p_with_id];
|
Point *b = points[p_with_id];
|
||||||
a->neighbours.push_back(b);
|
a->neighbours.push_back(b);
|
||||||
|
|
||||||
|
if (bidirectional)
|
||||||
b->neighbours.push_back(a);
|
b->neighbours.push_back(a);
|
||||||
|
|
||||||
Segment s(p_id, p_with_id);
|
Segment s(p_id, p_with_id);
|
||||||
|
@ -401,7 +403,7 @@ void AStar::_bind_methods() {
|
||||||
ObjectTypeDB::bind_method(_MD("get_point_weight_scale", "id"), &AStar::get_point_weight_scale);
|
ObjectTypeDB::bind_method(_MD("get_point_weight_scale", "id"), &AStar::get_point_weight_scale);
|
||||||
ObjectTypeDB::bind_method(_MD("remove_point", "id"), &AStar::remove_point);
|
ObjectTypeDB::bind_method(_MD("remove_point", "id"), &AStar::remove_point);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("connect_points", "id", "to_id"), &AStar::connect_points);
|
ObjectTypeDB::bind_method(_MD("connect_points", "id", "to_id"), &AStar::connect_points, DEFVAL(true));
|
||||||
ObjectTypeDB::bind_method(_MD("disconnect_points", "id", "to_id"), &AStar::disconnect_points);
|
ObjectTypeDB::bind_method(_MD("disconnect_points", "id", "to_id"), &AStar::disconnect_points);
|
||||||
ObjectTypeDB::bind_method(_MD("are_points_connected", "id", "to_id"), &AStar::are_points_connected);
|
ObjectTypeDB::bind_method(_MD("are_points_connected", "id", "to_id"), &AStar::are_points_connected);
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ public:
|
||||||
float get_point_weight_scale(int p_id) const;
|
float get_point_weight_scale(int p_id) const;
|
||||||
void remove_point(int p_id);
|
void remove_point(int p_id);
|
||||||
|
|
||||||
void connect_points(int p_id, int p_with_id);
|
void connect_points(int p_id, int p_with_id, bool bidirectional = true);
|
||||||
void disconnect_points(int p_id, int p_with_id);
|
void disconnect_points(int p_id, int p_with_id);
|
||||||
bool are_points_connected(int p_id, int p_with_id) const;
|
bool are_points_connected(int p_id, int p_with_id) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue