diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-11-05 09:35:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-05 09:35:23 +0100 |
commit | 2b46e2e1d4bd4b062a379b8adb791ffd9444934c (patch) | |
tree | 998ad37a2615b7baa868aec5ba05d4bd06e3b044 /servers | |
parent | 578460f7fb7b694f4601e8e6fdc4a5ee67de4067 (diff) | |
parent | ac24070056871442b0559e7875372f40aadf8d02 (diff) |
Merge pull request #54620 from briansemrau/request-frame-callable
Use Callable in RenderingServer `request_frame_drawn_callback`
Diffstat (limited to 'servers')
-rw-r--r-- | servers/rendering/rendering_server_default.cpp | 26 | ||||
-rw-r--r-- | servers/rendering/rendering_server_default.h | 10 | ||||
-rw-r--r-- | servers/rendering_server.cpp | 2 | ||||
-rw-r--r-- | servers/rendering_server.h | 4 |
4 files changed, 14 insertions, 28 deletions
diff --git a/servers/rendering/rendering_server_default.cpp b/servers/rendering/rendering_server_default.cpp index 107c9f8040..2ce9a20b6b 100644 --- a/servers/rendering/rendering_server_default.cpp +++ b/servers/rendering/rendering_server_default.cpp @@ -64,14 +64,8 @@ void RenderingServerDefault::_free(RID p_rid) { /* EVENT QUEUING */ -void RenderingServerDefault::request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) { - ERR_FAIL_NULL(p_where); - FrameDrawnCallbacks fdc; - fdc.object = p_where->get_instance_id(); - fdc.method = p_method; - fdc.param = p_userdata; - - frame_drawn_callbacks.push_back(fdc); +void RenderingServerDefault::request_frame_drawn_callback(const Callable &p_callable) { + frame_drawn_callbacks.push_back(p_callable); } void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { @@ -103,15 +97,13 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { RSG::scene->update_visibility_notifiers(); while (frame_drawn_callbacks.front()) { - Object *obj = ObjectDB::get_instance(frame_drawn_callbacks.front()->get().object); - if (obj) { - Callable::CallError ce; - const Variant *v = &frame_drawn_callbacks.front()->get().param; - obj->call(frame_drawn_callbacks.front()->get().method, &v, 1, ce); - if (ce.error != Callable::CallError::CALL_OK) { - String err = Variant::get_call_error_text(obj, frame_drawn_callbacks.front()->get().method, &v, 1, ce); - ERR_PRINT("Error calling frame drawn function: " + err); - } + Callable c = frame_drawn_callbacks.front()->get(); + Variant result; + Callable::CallError ce; + c.call(nullptr, 0, result, ce); + if (ce.error != Callable::CallError::CALL_OK) { + String err = Variant::get_callable_error_text(c, nullptr, 0, ce); + ERR_PRINT("Error calling frame drawn function: " + err); } frame_drawn_callbacks.pop_front(); diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h index a25bd3dae5..9a592a9265 100644 --- a/servers/rendering/rendering_server_default.h +++ b/servers/rendering/rendering_server_default.h @@ -58,13 +58,7 @@ class RenderingServerDefault : public RenderingServer { static int changes; RID test_cube; - struct FrameDrawnCallbacks { - ObjectID object; - StringName method; - Variant param; - }; - - List<FrameDrawnCallbacks> frame_drawn_callbacks; + List<Callable> frame_drawn_callbacks; static void _changes_changed() {} @@ -880,7 +874,7 @@ public: /* EVENT QUEUING */ - virtual void request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) override; + virtual void request_frame_drawn_callback(const Callable &p_callable) override; virtual void draw(bool p_swap_buffers, double frame_step) override; virtual void sync() override; diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 1b16949768..cdf7fa530e 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2701,7 +2701,7 @@ void RenderingServer::_bind_methods() { /* Misc */ - ClassDB::bind_method(D_METHOD("request_frame_drawn_callback", "where", "method", "userdata"), &RenderingServer::request_frame_drawn_callback); + ClassDB::bind_method(D_METHOD("request_frame_drawn_callback", "callable"), &RenderingServer::request_frame_drawn_callback); ClassDB::bind_method(D_METHOD("has_changed"), &RenderingServer::has_changed); ClassDB::bind_method(D_METHOD("get_rendering_info", "info"), &RenderingServer::get_rendering_info); ClassDB::bind_method(D_METHOD("get_video_adapter_name"), &RenderingServer::get_video_adapter_name); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 3125268e1c..f35a633bf3 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -1435,10 +1435,10 @@ public: virtual void free(RID p_rid) = 0; ///< free RIDs associated with the rendering server - virtual void request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) = 0; - /* EVENT QUEUING */ + virtual void request_frame_drawn_callback(const Callable &p_callable) = 0; + virtual void draw(bool p_swap_buffers = true, double frame_step = 0.0) = 0; virtual void sync() = 0; virtual bool has_changed() const = 0; |