diff options
Diffstat (limited to 'scene/resources/curve.cpp')
-rw-r--r-- | scene/resources/curve.cpp | 91 |
1 files changed, 41 insertions, 50 deletions
diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index 397f6ca906..a68eb77378 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -392,7 +392,7 @@ void Curve::set_data(Array input) { for (int i = 0; i < input.size(); i += ELEMS) { ERR_FAIL_COND(input[i].get_type() != Variant::VECTOR2); ERR_FAIL_COND(!input[i + 1].is_num()); - ERR_FAIL_COND(input[i + 2].get_type() != Variant::REAL); + ERR_FAIL_COND(input[i + 2].get_type() != Variant::FLOAT); ERR_FAIL_COND(input[i + 3].get_type() != Variant::INT); int left_mode = input[i + 3]; @@ -524,8 +524,8 @@ void Curve::_bind_methods() { ClassDB::bind_method(D_METHOD("_get_data"), &Curve::get_data); ClassDB::bind_method(D_METHOD("_set_data", "data"), &Curve::set_data); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_value", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_min_value", "get_min_value"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_value", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_max_value", "get_max_value"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "min_value", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_min_value", "get_min_value"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_value", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_max_value", "get_max_value"); ADD_PROPERTY(PropertyInfo(Variant::INT, "bake_resolution", PROPERTY_HINT_RANGE, "1,1000,1"), "set_bake_resolution", "get_bake_resolution"); ADD_PROPERTY(PropertyInfo(Variant::INT, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data"); @@ -741,7 +741,7 @@ void Curve2D::_bake() const { pointlist.push_back(lastpos); baked_point_cache.resize(pointlist.size()); - PoolVector2Array::Write w = baked_point_cache.write(); + Vector2 *w = baked_point_cache.ptrw(); int idx = 0; for (List<Vector2>::Element *E = pointlist.front(); E; E = E->next()) { @@ -771,7 +771,7 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { return baked_point_cache.get(0); int bpc = baked_point_cache.size(); - PoolVector2Array::Read r = baked_point_cache.read(); + const Vector2 *r = baked_point_cache.ptr(); if (p_offset < 0) return r[0]; @@ -800,7 +800,7 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { } } -PoolVector2Array Curve2D::get_baked_points() const { +PackedVector2Array Curve2D::get_baked_points() const { if (baked_cache_dirty) _bake(); @@ -833,7 +833,7 @@ Vector2 Curve2D::get_closest_point(const Vector2 &p_to_point) const { if (pc == 1) return baked_point_cache.get(0); - PoolVector2Array::Read r = baked_point_cache.read(); + const Vector2 *r = baked_point_cache.ptr(); Vector2 nearest; float nearest_dist = -1.0f; @@ -869,7 +869,7 @@ float Curve2D::get_closest_offset(const Vector2 &p_to_point) const { if (pc == 1) return 0.0f; - PoolVector2Array::Read r = baked_point_cache.read(); + const Vector2 *r = baked_point_cache.ptr(); float nearest = 0.0f; float nearest_dist = -1.0f; @@ -899,9 +899,9 @@ Dictionary Curve2D::_get_data() const { Dictionary dc; - PoolVector2Array d; + PackedVector2Array d; d.resize(points.size() * 3); - PoolVector2Array::Write w = d.write(); + Vector2 *w = d.ptrw(); for (int i = 0; i < points.size(); i++) { @@ -910,8 +910,6 @@ Dictionary Curve2D::_get_data() const { w[i * 3 + 2] = points[i].pos; } - w = PoolVector2Array::Write(); - dc["points"] = d; return dc; @@ -920,11 +918,11 @@ void Curve2D::_set_data(const Dictionary &p_data) { ERR_FAIL_COND(!p_data.has("points")); - PoolVector2Array rp = p_data["points"]; + PackedVector2Array rp = p_data["points"]; int pc = rp.size(); ERR_FAIL_COND(pc % 3 != 0); points.resize(pc / 3); - PoolVector2Array::Read r = rp.read(); + const Vector2 *r = rp.ptr(); for (int i = 0; i < points.size(); i++) { @@ -936,9 +934,9 @@ void Curve2D::_set_data(const Dictionary &p_data) { baked_cache_dirty = true; } -PoolVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) const { +PackedVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) const { - PoolVector2Array tess; + PackedVector2Array tess; if (points.size() == 0) { return tess; @@ -956,7 +954,7 @@ PoolVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) const } tess.resize(pc); - PoolVector2Array::Write bpw = tess.write(); + Vector2 *bpw = tess.ptrw(); bpw[0] = points[0].pos; int pidx = 0; @@ -972,8 +970,6 @@ PoolVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) const bpw[pidx] = points[i + 1].pos; } - bpw = PoolVector2Array::Write(); - return tess; } @@ -1005,7 +1001,7 @@ void Curve2D::_bind_methods() { ClassDB::bind_method(D_METHOD("_get_data"), &Curve2D::_get_data); ClassDB::bind_method(D_METHOD("_set_data"), &Curve2D::_set_data); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "bake_interval", PROPERTY_HINT_RANGE, "0.01,512,0.01"), "set_bake_interval", "get_bake_interval"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_interval", PROPERTY_HINT_RANGE, "0.01,512,0.01"), "set_bake_interval", "get_bake_interval"); ADD_PROPERTY(PropertyInfo(Variant::INT, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data"); } @@ -1258,14 +1254,14 @@ void Curve3D::_bake() const { pointlist.push_back(Plane(lastpos, lastilt)); baked_point_cache.resize(pointlist.size()); - PoolVector3Array::Write w = baked_point_cache.write(); + Vector3 *w = baked_point_cache.ptrw(); int idx = 0; baked_tilt_cache.resize(pointlist.size()); - PoolRealArray::Write wt = baked_tilt_cache.write(); + real_t *wt = baked_tilt_cache.ptrw(); baked_up_vector_cache.resize(up_vector_enabled ? pointlist.size() : 0); - PoolVector3Array::Write up_write = baked_up_vector_cache.write(); + Vector3 *up_write = baked_up_vector_cache.ptrw(); Vector3 sideways; Vector3 up; @@ -1333,7 +1329,7 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { return baked_point_cache.get(0); int bpc = baked_point_cache.size(); - PoolVector3Array::Read r = baked_point_cache.read(); + const Vector3 *r = baked_point_cache.ptr(); if (p_offset < 0) return r[0]; @@ -1375,7 +1371,7 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const { return baked_tilt_cache.get(0); int bpc = baked_tilt_cache.size(); - PoolRealArray::Read r = baked_tilt_cache.read(); + const real_t *r = baked_tilt_cache.ptr(); if (p_offset < 0) return r[0]; @@ -1410,9 +1406,9 @@ Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) if (count == 1) return baked_up_vector_cache.get(0); - PoolVector3Array::Read r = baked_up_vector_cache.read(); - PoolVector3Array::Read rp = baked_point_cache.read(); - PoolRealArray::Read rt = baked_tilt_cache.read(); + const Vector3 *r = baked_up_vector_cache.ptr(); + const Vector3 *rp = baked_point_cache.ptr(); + const real_t *rt = baked_tilt_cache.ptr(); float offset = CLAMP(p_offset, 0.0f, baked_max_ofs); @@ -1441,7 +1437,7 @@ Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) return up.rotated(axis, up.angle_to(up1) * frac); } -PoolVector3Array Curve3D::get_baked_points() const { +PackedVector3Array Curve3D::get_baked_points() const { if (baked_cache_dirty) _bake(); @@ -1449,7 +1445,7 @@ PoolVector3Array Curve3D::get_baked_points() const { return baked_point_cache; } -PoolRealArray Curve3D::get_baked_tilts() const { +PackedFloat32Array Curve3D::get_baked_tilts() const { if (baked_cache_dirty) _bake(); @@ -1457,7 +1453,7 @@ PoolRealArray Curve3D::get_baked_tilts() const { return baked_tilt_cache; } -PoolVector3Array Curve3D::get_baked_up_vectors() const { +PackedVector3Array Curve3D::get_baked_up_vectors() const { if (baked_cache_dirty) _bake(); @@ -1478,7 +1474,7 @@ Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const { if (pc == 1) return baked_point_cache.get(0); - PoolVector3Array::Read r = baked_point_cache.read(); + const Vector3 *r = baked_point_cache.ptr(); Vector3 nearest; float nearest_dist = -1.0f; @@ -1514,7 +1510,7 @@ float Curve3D::get_closest_offset(const Vector3 &p_to_point) const { if (pc == 1) return 0.0f; - PoolVector3Array::Read r = baked_point_cache.read(); + const Vector3 *r = baked_point_cache.ptr(); float nearest = 0.0f; float nearest_dist = -1.0f; @@ -1568,12 +1564,12 @@ Dictionary Curve3D::_get_data() const { Dictionary dc; - PoolVector3Array d; + PackedVector3Array d; d.resize(points.size() * 3); - PoolVector3Array::Write w = d.write(); - PoolRealArray t; + Vector3 *w = d.ptrw(); + PackedFloat32Array t; t.resize(points.size()); - PoolRealArray::Write wt = t.write(); + real_t *wt = t.ptrw(); for (int i = 0; i < points.size(); i++) { @@ -1583,9 +1579,6 @@ Dictionary Curve3D::_get_data() const { wt[i] = points[i].tilt; } - w = PoolVector3Array::Write(); - wt = PoolRealArray::Write(); - dc["points"] = d; dc["tilts"] = t; @@ -1596,13 +1589,13 @@ void Curve3D::_set_data(const Dictionary &p_data) { ERR_FAIL_COND(!p_data.has("points")); ERR_FAIL_COND(!p_data.has("tilts")); - PoolVector3Array rp = p_data["points"]; + PackedVector3Array rp = p_data["points"]; int pc = rp.size(); ERR_FAIL_COND(pc % 3 != 0); points.resize(pc / 3); - PoolVector3Array::Read r = rp.read(); - PoolRealArray rtl = p_data["tilts"]; - PoolRealArray::Read rt = rtl.read(); + const Vector3 *r = rp.ptr(); + PackedFloat32Array rtl = p_data["tilts"]; + const real_t *rt = rtl.ptr(); for (int i = 0; i < points.size(); i++) { @@ -1615,9 +1608,9 @@ void Curve3D::_set_data(const Dictionary &p_data) { baked_cache_dirty = true; } -PoolVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) const { +PackedVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) const { - PoolVector3Array tess; + PackedVector3Array tess; if (points.size() == 0) { return tess; @@ -1635,7 +1628,7 @@ PoolVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) const } tess.resize(pc); - PoolVector3Array::Write bpw = tess.write(); + Vector3 *bpw = tess.ptrw(); bpw[0] = points[0].pos; int pidx = 0; @@ -1651,8 +1644,6 @@ PoolVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) const bpw[pidx] = points[i + 1].pos; } - bpw = PoolVector3Array::Write(); - return tess; } @@ -1691,7 +1682,7 @@ void Curve3D::_bind_methods() { ClassDB::bind_method(D_METHOD("_get_data"), &Curve3D::_get_data); ClassDB::bind_method(D_METHOD("_set_data"), &Curve3D::_set_data); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "bake_interval", PROPERTY_HINT_RANGE, "0.01,512,0.01"), "set_bake_interval", "get_bake_interval"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_interval", PROPERTY_HINT_RANGE, "0.01,512,0.01"), "set_bake_interval", "get_bake_interval"); ADD_PROPERTY(PropertyInfo(Variant::INT, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data"); ADD_GROUP("Up Vector", "up_vector_"); |