You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
NavigationPolygon: Implement get/set_polygon fast paths.
This commit is contained in:
committed by
Rémi Verschelde
parent
5b6d9a7dd8
commit
a1fe6ffa19
@@ -61,12 +61,12 @@ void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) {
|
||||
int rlen = iarr.size();
|
||||
const int *r = iarr.ptr();
|
||||
|
||||
Vector<int> polygon;
|
||||
for (int j = 0; j < rlen; j += 3) {
|
||||
Polygon polygon;
|
||||
polygon.indices.resize(3);
|
||||
polygon.indices.write[0] = r[j + 0] + from;
|
||||
polygon.indices.write[1] = r[j + 1] + from;
|
||||
polygon.indices.write[2] = r[j + 2] + from;
|
||||
polygon.resize(3);
|
||||
polygon.write[0] = r[j + 0] + from;
|
||||
polygon.write[1] = r[j + 1] + from;
|
||||
polygon.write[2] = r[j + 2] + from;
|
||||
polygons.push_back(polygon);
|
||||
}
|
||||
}
|
||||
@@ -318,7 +318,7 @@ void NavigationMesh::_set_polygons(const Array &p_array) {
|
||||
RWLockWrite write_lock(rwlock);
|
||||
polygons.resize(p_array.size());
|
||||
for (int i = 0; i < p_array.size(); i++) {
|
||||
polygons.write[i].indices = p_array[i];
|
||||
polygons.write[i] = p_array[i];
|
||||
}
|
||||
notify_property_list_changed();
|
||||
}
|
||||
@@ -328,17 +328,26 @@ Array NavigationMesh::_get_polygons() const {
|
||||
Array ret;
|
||||
ret.resize(polygons.size());
|
||||
for (int i = 0; i < ret.size(); i++) {
|
||||
ret[i] = polygons[i].indices;
|
||||
ret[i] = polygons[i];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NavigationMesh::set_polygons(const Vector<Vector<int>> &p_polygons) {
|
||||
RWLockWrite write_lock(rwlock);
|
||||
polygons = p_polygons;
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
||||
Vector<Vector<int>> NavigationMesh::get_polygons() const {
|
||||
RWLockRead read_lock(rwlock);
|
||||
return polygons;
|
||||
}
|
||||
|
||||
void NavigationMesh::add_polygon(const Vector<int> &p_polygon) {
|
||||
RWLockWrite write_lock(rwlock);
|
||||
Polygon polygon;
|
||||
polygon.indices = p_polygon;
|
||||
polygons.push_back(polygon);
|
||||
polygons.push_back(p_polygon);
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
||||
@@ -350,7 +359,7 @@ int NavigationMesh::get_polygon_count() const {
|
||||
Vector<int> NavigationMesh::get_polygon(int p_idx) {
|
||||
RWLockRead read_lock(rwlock);
|
||||
ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>());
|
||||
return polygons[p_idx].indices;
|
||||
return polygons[p_idx];
|
||||
}
|
||||
|
||||
void NavigationMesh::clear_polygons() {
|
||||
@@ -367,19 +376,13 @@ void NavigationMesh::clear() {
|
||||
void NavigationMesh::set_data(const Vector<Vector3> &p_vertices, const Vector<Vector<int>> &p_polygons) {
|
||||
RWLockWrite write_lock(rwlock);
|
||||
vertices = p_vertices;
|
||||
polygons.resize(p_polygons.size());
|
||||
for (int i = 0; i < p_polygons.size(); i++) {
|
||||
polygons.write[i].indices = p_polygons[i];
|
||||
}
|
||||
polygons = p_polygons;
|
||||
}
|
||||
|
||||
void NavigationMesh::get_data(Vector<Vector3> &r_vertices, Vector<Vector<int>> &r_polygons) {
|
||||
RWLockRead read_lock(rwlock);
|
||||
r_vertices = vertices;
|
||||
r_polygons.resize(polygons.size());
|
||||
for (int i = 0; i < polygons.size(); i++) {
|
||||
r_polygons.write[i] = polygons[i].indices;
|
||||
}
|
||||
r_polygons = polygons;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
||||
Reference in New Issue
Block a user