diff options
author | Josh Jones <kilauea.jones@gmail.com> | 2023-01-27 20:15:10 -0800 |
---|---|---|
committer | Josh Jones <kilauea.jones@gmail.com> | 2023-01-27 23:14:36 -0800 |
commit | 22f9ef19e1accd5d5e36ce30589ba3edd5c3d0d0 (patch) | |
tree | 5cac93ecc341df5c1c85494d500bf6fa84a26cd5 /modules/navigation/rvo_agent.cpp | |
parent | a43db5afa4bbec4772be2f296931a6d44bb4cbb3 (diff) |
Use Callable for Navigation Agent callbacks
Diffstat (limited to 'modules/navigation/rvo_agent.cpp')
-rw-r--r-- | modules/navigation/rvo_agent.cpp | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/modules/navigation/rvo_agent.cpp b/modules/navigation/rvo_agent.cpp index 979ef0d917..40f1e925be 100644 --- a/modules/navigation/rvo_agent.cpp +++ b/modules/navigation/rvo_agent.cpp @@ -32,10 +32,6 @@ #include "nav_map.h" -RvoAgent::RvoAgent() { - callback.id = ObjectID(); -} - void RvoAgent::set_map(NavMap *p_map) { map = p_map; } @@ -50,31 +46,25 @@ bool RvoAgent::is_map_changed() { } } -void RvoAgent::set_callback(ObjectID p_id, const StringName p_method, const Variant p_udata) { - callback.id = p_id; - callback.method = p_method; - callback.udata = p_udata; +void RvoAgent::set_callback(Callable p_callback) { + callback = p_callback; } bool RvoAgent::has_callback() const { - return callback.id.is_valid(); + return callback.is_valid(); } void RvoAgent::dispatch_callback() { - if (callback.id.is_null()) { + if (!callback.is_valid()) { return; } - Object *obj = ObjectDB::get_instance(callback.id); - if (!obj) { - callback.id = ObjectID(); - return; - } - - Callable::CallError responseCallError; - callback.new_velocity = Vector3(agent.newVelocity_.x(), agent.newVelocity_.y(), agent.newVelocity_.z()); + Vector3 new_velocity = Vector3(agent.newVelocity_.x(), agent.newVelocity_.y(), agent.newVelocity_.z()); - const Variant *vp[2] = { &callback.new_velocity, &callback.udata }; - int argc = (callback.udata.get_type() == Variant::NIL) ? 1 : 2; - obj->callp(callback.method, vp, argc, responseCallError); + // Invoke the callback with the new velocity. + Variant args[] = { new_velocity }; + const Variant *args_p[] = { &args[0] }; + Variant return_value; + Callable::CallError call_error; + callback.callp(args_p, 1, return_value, call_error); } |