mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-10 21:09:38 +01:00
Reorganize NavigationPolygon.
This commit is contained in:
parent
b4cc1c3096
commit
0bfa40bb09
@ -30,8 +30,8 @@
|
||||
|
||||
#include "navigation_polygon.h"
|
||||
|
||||
#include "core/core_string_names.h"
|
||||
#include "core/config/engine.h"
|
||||
#include "core/core_string_names.h"
|
||||
#include "core/os/mutex.h"
|
||||
#include "scene/2d/navigation_2d.h"
|
||||
#include "scene/resources/navigation_mesh.h"
|
||||
@ -96,45 +96,6 @@ PoolVector<Vector2> NavigationPolygon::get_vertices() const {
|
||||
return vertices;
|
||||
}
|
||||
|
||||
void NavigationPolygon::_set_polygons(const Array &p_array) {
|
||||
{
|
||||
MutexLock lock(navmesh_generation);
|
||||
navmesh.unref();
|
||||
}
|
||||
polygons.resize(p_array.size());
|
||||
for (int i = 0; i < p_array.size(); i++) {
|
||||
polygons.write[i].indices = p_array[i];
|
||||
}
|
||||
}
|
||||
|
||||
Array NavigationPolygon::_get_polygons() const {
|
||||
Array ret;
|
||||
ret.resize(polygons.size());
|
||||
for (int i = 0; i < ret.size(); i++) {
|
||||
ret[i] = polygons[i].indices;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NavigationPolygon::_set_outlines(const Array &p_array) {
|
||||
outlines.resize(p_array.size());
|
||||
for (int i = 0; i < p_array.size(); i++) {
|
||||
outlines.write[i] = p_array[i];
|
||||
}
|
||||
rect_cache_dirty = true;
|
||||
}
|
||||
|
||||
Array NavigationPolygon::_get_outlines() const {
|
||||
Array ret;
|
||||
ret.resize(outlines.size());
|
||||
for (int i = 0; i < ret.size(); i++) {
|
||||
ret[i] = outlines[i];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NavigationPolygon::add_polygon(const Vector<int> &p_polygon) {
|
||||
Polygon polygon;
|
||||
polygon.indices = p_polygon;
|
||||
@ -326,6 +287,52 @@ void NavigationPolygon::make_polygons_from_outlines() {
|
||||
emit_signal(CoreStringNames::get_singleton()->changed);
|
||||
}
|
||||
|
||||
NavigationPolygon::NavigationPolygon() {
|
||||
rect_cache_dirty = true;
|
||||
}
|
||||
|
||||
NavigationPolygon::~NavigationPolygon() {
|
||||
}
|
||||
|
||||
void NavigationPolygon::_set_polygons(const Array &p_array) {
|
||||
{
|
||||
MutexLock lock(navmesh_generation);
|
||||
navmesh.unref();
|
||||
}
|
||||
polygons.resize(p_array.size());
|
||||
for (int i = 0; i < p_array.size(); i++) {
|
||||
polygons.write[i].indices = p_array[i];
|
||||
}
|
||||
}
|
||||
|
||||
Array NavigationPolygon::_get_polygons() const {
|
||||
Array ret;
|
||||
ret.resize(polygons.size());
|
||||
for (int i = 0; i < ret.size(); i++) {
|
||||
ret[i] = polygons[i].indices;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NavigationPolygon::_set_outlines(const Array &p_array) {
|
||||
outlines.resize(p_array.size());
|
||||
for (int i = 0; i < p_array.size(); i++) {
|
||||
outlines.write[i] = p_array[i];
|
||||
}
|
||||
rect_cache_dirty = true;
|
||||
}
|
||||
|
||||
Array NavigationPolygon::_get_outlines() const {
|
||||
Array ret;
|
||||
ret.resize(outlines.size());
|
||||
for (int i = 0; i < ret.size(); i++) {
|
||||
ret[i] = outlines[i];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NavigationPolygon::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &NavigationPolygon::set_vertices);
|
||||
ClassDB::bind_method(D_METHOD("get_vertices"), &NavigationPolygon::get_vertices);
|
||||
@ -355,10 +362,3 @@ void NavigationPolygon::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons", "_get_polygons");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "outlines", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_outlines", "_get_outlines");
|
||||
}
|
||||
|
||||
NavigationPolygon::NavigationPolygon() {
|
||||
rect_cache_dirty = true;
|
||||
}
|
||||
|
||||
NavigationPolygon::~NavigationPolygon() {
|
||||
}
|
||||
|
@ -38,29 +38,6 @@ class NavigationMesh;
|
||||
class NavigationPolygon : public Resource {
|
||||
GDCLASS(NavigationPolygon, Resource);
|
||||
|
||||
PoolVector<Vector2> vertices;
|
||||
struct Polygon {
|
||||
Vector<int> indices;
|
||||
};
|
||||
Vector<Polygon> polygons;
|
||||
Vector<PoolVector<Vector2>> outlines;
|
||||
|
||||
mutable Rect2 item_rect;
|
||||
mutable bool rect_cache_dirty;
|
||||
|
||||
Mutex navmesh_generation;
|
||||
// Navigation mesh
|
||||
Ref<NavigationMesh> navmesh;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
void _set_polygons(const Array &p_array);
|
||||
Array _get_polygons() const;
|
||||
|
||||
void _set_outlines(const Array &p_array);
|
||||
Array _get_outlines() const;
|
||||
|
||||
public:
|
||||
#ifdef TOOLS_ENABLED
|
||||
Rect2 _edit_get_rect() const;
|
||||
@ -90,6 +67,30 @@ public:
|
||||
|
||||
NavigationPolygon();
|
||||
~NavigationPolygon();
|
||||
|
||||
protected:
|
||||
void _set_polygons(const Array &p_array);
|
||||
Array _get_polygons() const;
|
||||
|
||||
void _set_outlines(const Array &p_array);
|
||||
Array _get_outlines() const;
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
PoolVector<Vector2> vertices;
|
||||
struct Polygon {
|
||||
Vector<int> indices;
|
||||
};
|
||||
Vector<Polygon> polygons;
|
||||
Vector<PoolVector<Vector2>> outlines;
|
||||
|
||||
mutable Rect2 item_rect;
|
||||
mutable bool rect_cache_dirty;
|
||||
|
||||
Mutex navmesh_generation;
|
||||
// Navigation mesh
|
||||
Ref<NavigationMesh> navmesh;
|
||||
};
|
||||
|
||||
#endif // NAVIGATIONPOLYGON_H
|
||||
|
Loading…
Reference in New Issue
Block a user