diff options
author | reduz <reduzio@gmail.com> | 2021-08-21 22:52:44 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-08-22 08:23:58 -0300 |
commit | 3682978aee06cd5cf26ba462a4e44d352e9e0cd1 (patch) | |
tree | fee311b675144ae3a5fecc58857912ea250b1bb7 /core/math | |
parent | 2a5c64f2a188360d09f793c0dbd35e1911b4c073 (diff) |
Replace BIND_VMETHOD by new GDVIRTUAL syntax
* New syntax is type safe.
* New syntax allows for type safe virtuals in native extensions.
* New syntax permits extremely fast calling.
Note: Everything was replaced where possible except for `_gui_input` `_input` and `_unhandled_input`.
These will require API rework on a separate PR as they work different than the rest of the functions.
Added a new method flag METHOD_FLAG_OBJECT_CORE, used internally. Allows to not dump the core virtuals like `_notification` to the json API, since each language will implement those as it is best fits.
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/a_star.cpp | 28 | ||||
-rw-r--r-- | core/math/a_star.h | 8 |
2 files changed, 24 insertions, 12 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 322eb7ac61..b380860522 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -382,8 +382,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { } real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) { - return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); + real_t scost; + if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_to_id, scost)) { + return scost; } Point *from_point; @@ -398,8 +399,9 @@ real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) { - return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); + real_t scost; + if (GDVIRTUAL_CALL(_compute_cost, p_from_id, p_to_id, scost)) { + return scost; } Point *from_point; @@ -557,8 +559,8 @@ void AStar::_bind_methods() { ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStar::get_point_path); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id"), &AStar::get_id_path); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_estimate_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_compute_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); + GDVIRTUAL_BIND(_estimate_cost, "from_id", "to_id") + GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id") } AStar::~AStar() { @@ -654,8 +656,9 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const { } real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) { - return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); + real_t scost; + if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_to_id, scost)) { + return scost; } AStar::Point *from_point; @@ -670,8 +673,9 @@ real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) { - return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); + real_t scost; + if (GDVIRTUAL_CALL(_compute_cost, p_from_id, p_to_id, scost)) { + return scost; } AStar::Point *from_point; @@ -875,6 +879,6 @@ void AStar2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStar2D::get_point_path); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id"), &AStar2D::get_id_path); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_estimate_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_compute_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); + GDVIRTUAL_BIND(_estimate_cost, "from_id", "to_id") + GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id") } diff --git a/core/math/a_star.h b/core/math/a_star.h index 44758cb046..64fa32a325 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -31,7 +31,9 @@ #ifndef A_STAR_H #define A_STAR_H +#include "core/object/gdvirtual.gen.inc" #include "core/object/ref_counted.h" +#include "core/object/script_language.h" #include "core/templates/oa_hash_map.h" /** @@ -122,6 +124,9 @@ protected: virtual real_t _estimate_cost(int p_from_id, int p_to_id); virtual real_t _compute_cost(int p_from_id, int p_to_id); + GDVIRTUAL2RC(real_t, _estimate_cost, int64_t, int64_t) + GDVIRTUAL2RC(real_t, _compute_cost, int64_t, int64_t) + public: int get_available_point_id() const; @@ -169,6 +174,9 @@ protected: virtual real_t _estimate_cost(int p_from_id, int p_to_id); virtual real_t _compute_cost(int p_from_id, int p_to_id); + GDVIRTUAL2RC(real_t, _estimate_cost, int64_t, int64_t) + GDVIRTUAL2RC(real_t, _compute_cost, int64_t, int64_t) + public: int get_available_point_id() const; |