diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/io/marshalls.cpp | 21 | ||||
-rw-r--r-- | core/io/marshalls.h | 2 | ||||
-rw-r--r-- | core/math/a_star_grid_2d.cpp | 32 | ||||
-rw-r--r-- | core/math/a_star_grid_2d.h | 10 | ||||
-rw-r--r-- | core/math/math_funcs.h | 10 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 2 |
6 files changed, 62 insertions, 15 deletions
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 9ba653e1a9..9f89f5d8c9 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -1813,3 +1813,24 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo return OK; } + +Vector<float> vector3_to_float32_array(const Vector3 *vecs, size_t count) { + // We always allocate a new array, and we don't memcpy. + // We also don't consider returning a pointer to the passed vectors when sizeof(real_t) == 4. + // One reason is that we could decide to put a 4th component in Vector3 for SIMD/mobile performance, + // which would cause trouble with these optimizations. + Vector<float> floats; + if (count == 0) { + return floats; + } + floats.resize(count * 3); + float *floats_w = floats.ptrw(); + for (size_t i = 0; i < count; ++i) { + const Vector3 v = vecs[i]; + floats_w[0] = v.x; + floats_w[1] = v.y; + floats_w[2] = v.z; + floats_w += 3; + } + return floats; +} diff --git a/core/io/marshalls.h b/core/io/marshalls.h index fef3a1c2c1..66e2571066 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -215,4 +215,6 @@ public: Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = nullptr, bool p_allow_objects = false, int p_depth = 0); Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false, int p_depth = 0); +Vector<float> vector3_to_float32_array(const Vector3 *vecs, size_t count); + #endif // MARSHALLS_H diff --git a/core/math/a_star_grid_2d.cpp b/core/math/a_star_grid_2d.cpp index 968102e323..cdcd0ed747 100644 --- a/core/math/a_star_grid_2d.cpp +++ b/core/math/a_star_grid_2d.cpp @@ -134,13 +134,22 @@ AStarGrid2D::DiagonalMode AStarGrid2D::get_diagonal_mode() const { return diagonal_mode; } -void AStarGrid2D::set_default_heuristic(Heuristic p_heuristic) { +void AStarGrid2D::set_default_compute_heuristic(Heuristic p_heuristic) { ERR_FAIL_INDEX((int)p_heuristic, (int)HEURISTIC_MAX); - default_heuristic = p_heuristic; + default_compute_heuristic = p_heuristic; } -AStarGrid2D::Heuristic AStarGrid2D::get_default_heuristic() const { - return default_heuristic; +AStarGrid2D::Heuristic AStarGrid2D::get_default_compute_heuristic() const { + return default_compute_heuristic; +} + +void AStarGrid2D::set_default_estimate_heuristic(Heuristic p_heuristic) { + ERR_FAIL_INDEX((int)p_heuristic, (int)HEURISTIC_MAX); + default_estimate_heuristic = p_heuristic; +} + +AStarGrid2D::Heuristic AStarGrid2D::get_default_estimate_heuristic() const { + return default_estimate_heuristic; } void AStarGrid2D::set_point_solid(const Vector2i &p_id, bool p_solid) { @@ -447,7 +456,7 @@ real_t AStarGrid2D::_estimate_cost(const Vector2i &p_from_id, const Vector2i &p_ if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_to_id, scost)) { return scost; } - return heuristics[default_heuristic](p_from_id, p_to_id); + return heuristics[default_estimate_heuristic](p_from_id, p_to_id); } real_t AStarGrid2D::_compute_cost(const Vector2i &p_from_id, const Vector2i &p_to_id) { @@ -455,7 +464,7 @@ real_t AStarGrid2D::_compute_cost(const Vector2i &p_from_id, const Vector2i &p_t if (GDVIRTUAL_CALL(_compute_cost, p_from_id, p_to_id, scost)) { return scost; } - return heuristics[default_heuristic](p_from_id, p_to_id); + return heuristics[default_compute_heuristic](p_from_id, p_to_id); } void AStarGrid2D::clear() { @@ -578,8 +587,10 @@ void AStarGrid2D::_bind_methods() { ClassDB::bind_method(D_METHOD("is_jumping_enabled"), &AStarGrid2D::is_jumping_enabled); ClassDB::bind_method(D_METHOD("set_diagonal_mode", "mode"), &AStarGrid2D::set_diagonal_mode); ClassDB::bind_method(D_METHOD("get_diagonal_mode"), &AStarGrid2D::get_diagonal_mode); - ClassDB::bind_method(D_METHOD("set_default_heuristic", "heuristic"), &AStarGrid2D::set_default_heuristic); - ClassDB::bind_method(D_METHOD("get_default_heuristic"), &AStarGrid2D::get_default_heuristic); + ClassDB::bind_method(D_METHOD("set_default_compute_heuristic", "heuristic"), &AStarGrid2D::set_default_compute_heuristic); + ClassDB::bind_method(D_METHOD("get_default_compute_heuristic"), &AStarGrid2D::get_default_compute_heuristic); + ClassDB::bind_method(D_METHOD("set_default_estimate_heuristic", "heuristic"), &AStarGrid2D::set_default_estimate_heuristic); + ClassDB::bind_method(D_METHOD("get_default_estimate_heuristic"), &AStarGrid2D::get_default_estimate_heuristic); ClassDB::bind_method(D_METHOD("set_point_solid", "id", "solid"), &AStarGrid2D::set_point_solid, DEFVAL(true)); ClassDB::bind_method(D_METHOD("is_point_solid", "id"), &AStarGrid2D::is_point_solid); ClassDB::bind_method(D_METHOD("set_point_weight_scale", "id", "weight_scale"), &AStarGrid2D::set_point_weight_scale); @@ -598,8 +609,9 @@ void AStarGrid2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "cell_size"), "set_cell_size", "get_cell_size"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "jumping_enabled"), "set_jumping_enabled", "is_jumping_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "default_heuristic", PROPERTY_HINT_ENUM, "Euclidean,Manhattan,Octile,Chebyshev,Max"), "set_default_heuristic", "get_default_heuristic"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "diagonal_mode", PROPERTY_HINT_ENUM, "Never,Always,At Least One Walkable,Only If No Obstacles,Max"), "set_diagonal_mode", "get_diagonal_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "default_compute_heuristic", PROPERTY_HINT_ENUM, "Euclidean,Manhattan,Octile,Chebyshev"), "set_default_compute_heuristic", "get_default_compute_heuristic"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "default_estimate_heuristic", PROPERTY_HINT_ENUM, "Euclidean,Manhattan,Octile,Chebyshev"), "set_default_estimate_heuristic", "get_default_estimate_heuristic"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "diagonal_mode", PROPERTY_HINT_ENUM, "Never,Always,At Least One Walkable,Only If No Obstacles"), "set_diagonal_mode", "get_diagonal_mode"); BIND_ENUM_CONSTANT(HEURISTIC_EUCLIDEAN); BIND_ENUM_CONSTANT(HEURISTIC_MANHATTAN); diff --git a/core/math/a_star_grid_2d.h b/core/math/a_star_grid_2d.h index 3b39d46a20..ca36013b61 100644 --- a/core/math/a_star_grid_2d.h +++ b/core/math/a_star_grid_2d.h @@ -65,7 +65,8 @@ private: bool jumping_enabled = false; DiagonalMode diagonal_mode = DIAGONAL_MODE_ALWAYS; - Heuristic default_heuristic = HEURISTIC_EUCLIDEAN; + Heuristic default_compute_heuristic = HEURISTIC_EUCLIDEAN; + Heuristic default_estimate_heuristic = HEURISTIC_EUCLIDEAN; struct Point { Vector2i id; @@ -161,8 +162,11 @@ public: void set_diagonal_mode(DiagonalMode p_diagonal_mode); DiagonalMode get_diagonal_mode() const; - void set_default_heuristic(Heuristic p_heuristic); - Heuristic get_default_heuristic() const; + void set_default_compute_heuristic(Heuristic p_heuristic); + Heuristic get_default_compute_heuristic() const; + + void set_default_estimate_heuristic(Heuristic p_heuristic); + Heuristic get_default_estimate_heuristic() const; void set_point_solid(const Vector2i &p_id, bool p_solid = true); bool is_point_solid(const Vector2i &p_id) const; diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 8dff8e6e7e..a998dece2a 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -453,7 +453,10 @@ public: } static _ALWAYS_INLINE_ double wrapf(double value, double min, double max) { double range = max - min; - double result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range)); + if (is_zero_approx(range)) { + return min; + } + double result = value - (range * Math::floor((value - min) / range)); if (is_equal_approx(result, max)) { return min; } @@ -461,7 +464,10 @@ public: } static _ALWAYS_INLINE_ float wrapf(float value, float min, float max) { float range = max - min; - float result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range)); + if (is_zero_approx(range)) { + return min; + } + float result = value - (range * Math::floor((value - min) / range)); if (is_equal_approx(result, max)) { return min; } diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index ac569941bf..57d62dac91 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -65,11 +65,13 @@ static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...) const, Variant *b template <class T, class... P> static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + VariantInternal::clear(&r_ret); call_with_variant_args_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals); } template <class T, class... P> static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + VariantInternal::clear(&r_ret); call_with_variant_argsc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals); } |