Merge pull request #54620 from briansemrau/request-frame-callable
Use Callable in RenderingServer `request_frame_drawn_callback`
This commit is contained in:
commit
2b46e2e1d4
|
@ -2575,12 +2575,9 @@
|
||||||
</method>
|
</method>
|
||||||
<method name="request_frame_drawn_callback">
|
<method name="request_frame_drawn_callback">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<argument index="0" name="where" type="Object" />
|
<argument index="0" name="callable" type="Callable" />
|
||||||
<argument index="1" name="method" type="StringName" />
|
|
||||||
<argument index="2" name="userdata" type="Variant" />
|
|
||||||
<description>
|
<description>
|
||||||
Schedules a callback to the corresponding named [code]method[/code] on [code]where[/code] after a frame has been drawn.
|
Schedules a callback to the given callable after a frame has been drawn.
|
||||||
The callback method must use only 1 argument which will be called with [code]userdata[/code].
|
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="scenario_create">
|
<method name="scenario_create">
|
||||||
|
|
|
@ -297,14 +297,10 @@ EditorPackedScenePreviewPlugin::EditorPackedScenePreviewPlugin() {
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void EditorMaterialPreviewPlugin::_preview_done(const Variant &p_udata) {
|
void EditorMaterialPreviewPlugin::_preview_done() {
|
||||||
preview_done.set();
|
preview_done.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorMaterialPreviewPlugin::_bind_methods() {
|
|
||||||
ClassDB::bind_method("_preview_done", &EditorMaterialPreviewPlugin::_preview_done);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EditorMaterialPreviewPlugin::handles(const String &p_type) const {
|
bool EditorMaterialPreviewPlugin::handles(const String &p_type) const {
|
||||||
return ClassDB::is_parent_class(p_type, "Material"); //any material
|
return ClassDB::is_parent_class(p_type, "Material"); //any material
|
||||||
}
|
}
|
||||||
|
@ -323,7 +319,7 @@ Ref<Texture2D> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Si
|
||||||
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture
|
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture
|
||||||
|
|
||||||
preview_done.clear();
|
preview_done.clear();
|
||||||
RS::get_singleton()->request_frame_drawn_callback(const_cast<EditorMaterialPreviewPlugin *>(this), "_preview_done", Variant());
|
RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast<EditorMaterialPreviewPlugin *>(this), &EditorMaterialPreviewPlugin::_preview_done));
|
||||||
|
|
||||||
while (!preview_done.is_set()) {
|
while (!preview_done.is_set()) {
|
||||||
OS::get_singleton()->delay_usec(10);
|
OS::get_singleton()->delay_usec(10);
|
||||||
|
@ -699,14 +695,10 @@ EditorAudioStreamPreviewPlugin::EditorAudioStreamPreviewPlugin() {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void EditorMeshPreviewPlugin::_preview_done(const Variant &p_udata) {
|
void EditorMeshPreviewPlugin::_preview_done() {
|
||||||
preview_done.set();
|
preview_done.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorMeshPreviewPlugin::_bind_methods() {
|
|
||||||
ClassDB::bind_method("_preview_done", &EditorMeshPreviewPlugin::_preview_done);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EditorMeshPreviewPlugin::handles(const String &p_type) const {
|
bool EditorMeshPreviewPlugin::handles(const String &p_type) const {
|
||||||
return ClassDB::is_parent_class(p_type, "Mesh"); //any Mesh
|
return ClassDB::is_parent_class(p_type, "Mesh"); //any Mesh
|
||||||
}
|
}
|
||||||
|
@ -738,7 +730,7 @@ Ref<Texture2D> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2
|
||||||
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture
|
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture
|
||||||
|
|
||||||
preview_done.clear();
|
preview_done.clear();
|
||||||
RS::get_singleton()->request_frame_drawn_callback(const_cast<EditorMeshPreviewPlugin *>(this), "_preview_done", Variant());
|
RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast<EditorMeshPreviewPlugin *>(this), &EditorMeshPreviewPlugin::_preview_done));
|
||||||
|
|
||||||
while (!preview_done.is_set()) {
|
while (!preview_done.is_set()) {
|
||||||
OS::get_singleton()->delay_usec(10);
|
OS::get_singleton()->delay_usec(10);
|
||||||
|
@ -814,14 +806,10 @@ EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void EditorFontPreviewPlugin::_preview_done(const Variant &p_udata) {
|
void EditorFontPreviewPlugin::_preview_done() {
|
||||||
preview_done.set();
|
preview_done.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorFontPreviewPlugin::_bind_methods() {
|
|
||||||
ClassDB::bind_method("_preview_done", &EditorFontPreviewPlugin::_preview_done);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EditorFontPreviewPlugin::handles(const String &p_type) const {
|
bool EditorFontPreviewPlugin::handles(const String &p_type) const {
|
||||||
return ClassDB::is_parent_class(p_type, "FontData") || ClassDB::is_parent_class(p_type, "Font");
|
return ClassDB::is_parent_class(p_type, "FontData") || ClassDB::is_parent_class(p_type, "Font");
|
||||||
}
|
}
|
||||||
|
@ -859,7 +847,7 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path,
|
||||||
|
|
||||||
preview_done.clear();
|
preview_done.clear();
|
||||||
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture
|
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture
|
||||||
RS::get_singleton()->request_frame_drawn_callback(const_cast<EditorFontPreviewPlugin *>(this), "_preview_done", Variant());
|
RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast<EditorFontPreviewPlugin *>(this), &EditorFontPreviewPlugin::_preview_done));
|
||||||
|
|
||||||
while (!preview_done.is_set()) {
|
while (!preview_done.is_set()) {
|
||||||
OS::get_singleton()->delay_usec(10);
|
OS::get_singleton()->delay_usec(10);
|
||||||
|
|
|
@ -94,10 +94,7 @@ class EditorMaterialPreviewPlugin : public EditorResourcePreviewGenerator {
|
||||||
RID camera;
|
RID camera;
|
||||||
mutable SafeFlag preview_done;
|
mutable SafeFlag preview_done;
|
||||||
|
|
||||||
void _preview_done(const Variant &p_udata);
|
void _preview_done();
|
||||||
|
|
||||||
protected:
|
|
||||||
static void _bind_methods();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool handles(const String &p_type) const override;
|
virtual bool handles(const String &p_type) const override;
|
||||||
|
@ -138,10 +135,7 @@ class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator {
|
||||||
RID camera;
|
RID camera;
|
||||||
mutable SafeFlag preview_done;
|
mutable SafeFlag preview_done;
|
||||||
|
|
||||||
void _preview_done(const Variant &p_udata);
|
void _preview_done();
|
||||||
|
|
||||||
protected:
|
|
||||||
static void _bind_methods();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool handles(const String &p_type) const override;
|
virtual bool handles(const String &p_type) const override;
|
||||||
|
@ -160,10 +154,7 @@ class EditorFontPreviewPlugin : public EditorResourcePreviewGenerator {
|
||||||
RID canvas_item;
|
RID canvas_item;
|
||||||
mutable SafeFlag preview_done;
|
mutable SafeFlag preview_done;
|
||||||
|
|
||||||
void _preview_done(const Variant &p_udata);
|
void _preview_done();
|
||||||
|
|
||||||
protected:
|
|
||||||
static void _bind_methods();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool handles(const String &p_type) const override;
|
virtual bool handles(const String &p_type) const override;
|
||||||
|
@ -179,10 +170,7 @@ class EditorTileMapPatternPreviewPlugin : public EditorResourcePreviewGenerator
|
||||||
|
|
||||||
mutable SafeFlag preview_done;
|
mutable SafeFlag preview_done;
|
||||||
|
|
||||||
void _preview_done(const Variant &p_udata);
|
void _preview_done();
|
||||||
|
|
||||||
protected:
|
|
||||||
static void _bind_methods();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool handles(const String &p_type) const override;
|
virtual bool handles(const String &p_type) const override;
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
TilesEditorPlugin *TilesEditorPlugin::singleton = nullptr;
|
TilesEditorPlugin *TilesEditorPlugin::singleton = nullptr;
|
||||||
|
|
||||||
void TilesEditorPlugin::_pattern_preview_done(const Variant &p_udata) {
|
void TilesEditorPlugin::_pattern_preview_done() {
|
||||||
pattern_preview_done.set();
|
pattern_preview_done.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ void TilesEditorPlugin::_thread() {
|
||||||
EditorNode::get_singleton()->add_child(viewport);
|
EditorNode::get_singleton()->add_child(viewport);
|
||||||
|
|
||||||
pattern_preview_done.clear();
|
pattern_preview_done.clear();
|
||||||
RS::get_singleton()->request_frame_drawn_callback(const_cast<TilesEditorPlugin *>(this), "_pattern_preview_done", Variant());
|
RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast<TilesEditorPlugin *>(this), &TilesEditorPlugin::_pattern_preview_done));
|
||||||
|
|
||||||
while (!pattern_preview_done.is_set()) {
|
while (!pattern_preview_done.is_set()) {
|
||||||
OS::get_singleton()->delay_usec(10);
|
OS::get_singleton()->delay_usec(10);
|
||||||
|
@ -274,10 +274,6 @@ bool TilesEditorPlugin::handles(Object *p_object) const {
|
||||||
return p_object->is_class("TileMap") || p_object->is_class("TileSet");
|
return p_object->is_class("TileMap") || p_object->is_class("TileSet");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TilesEditorPlugin::_bind_methods() {
|
|
||||||
ClassDB::bind_method(D_METHOD("_pattern_preview_done", "pattern"), &TilesEditorPlugin::_pattern_preview_done);
|
|
||||||
}
|
|
||||||
|
|
||||||
TilesEditorPlugin::TilesEditorPlugin(EditorNode *p_node) {
|
TilesEditorPlugin::TilesEditorPlugin(EditorNode *p_node) {
|
||||||
set_process_internal(true);
|
set_process_internal(true);
|
||||||
|
|
||||||
|
|
|
@ -78,13 +78,12 @@ private:
|
||||||
SafeFlag pattern_thread_exit;
|
SafeFlag pattern_thread_exit;
|
||||||
SafeFlag pattern_thread_exited;
|
SafeFlag pattern_thread_exited;
|
||||||
mutable SafeFlag pattern_preview_done;
|
mutable SafeFlag pattern_preview_done;
|
||||||
void _pattern_preview_done(const Variant &p_udata);
|
void _pattern_preview_done();
|
||||||
static void _thread_func(void *ud);
|
static void _thread_func(void *ud);
|
||||||
void _thread();
|
void _thread();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
static void _bind_methods();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
_FORCE_INLINE_ static TilesEditorPlugin *get_singleton() { return singleton; }
|
_FORCE_INLINE_ static TilesEditorPlugin *get_singleton() { return singleton; }
|
||||||
|
|
|
@ -64,14 +64,8 @@ void RenderingServerDefault::_free(RID p_rid) {
|
||||||
|
|
||||||
/* EVENT QUEUING */
|
/* EVENT QUEUING */
|
||||||
|
|
||||||
void RenderingServerDefault::request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) {
|
void RenderingServerDefault::request_frame_drawn_callback(const Callable &p_callable) {
|
||||||
ERR_FAIL_NULL(p_where);
|
frame_drawn_callbacks.push_back(p_callable);
|
||||||
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::_draw(bool p_swap_buffers, double frame_step) {
|
void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) {
|
||||||
|
@ -103,16 +97,14 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) {
|
||||||
RSG::scene->update_visibility_notifiers();
|
RSG::scene->update_visibility_notifiers();
|
||||||
|
|
||||||
while (frame_drawn_callbacks.front()) {
|
while (frame_drawn_callbacks.front()) {
|
||||||
Object *obj = ObjectDB::get_instance(frame_drawn_callbacks.front()->get().object);
|
Callable c = frame_drawn_callbacks.front()->get();
|
||||||
if (obj) {
|
Variant result;
|
||||||
Callable::CallError ce;
|
Callable::CallError ce;
|
||||||
const Variant *v = &frame_drawn_callbacks.front()->get().param;
|
c.call(nullptr, 0, result, ce);
|
||||||
obj->call(frame_drawn_callbacks.front()->get().method, &v, 1, ce);
|
|
||||||
if (ce.error != Callable::CallError::CALL_OK) {
|
if (ce.error != Callable::CallError::CALL_OK) {
|
||||||
String err = Variant::get_call_error_text(obj, frame_drawn_callbacks.front()->get().method, &v, 1, ce);
|
String err = Variant::get_callable_error_text(c, nullptr, 0, ce);
|
||||||
ERR_PRINT("Error calling frame drawn function: " + err);
|
ERR_PRINT("Error calling frame drawn function: " + err);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
frame_drawn_callbacks.pop_front();
|
frame_drawn_callbacks.pop_front();
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,13 +58,7 @@ class RenderingServerDefault : public RenderingServer {
|
||||||
static int changes;
|
static int changes;
|
||||||
RID test_cube;
|
RID test_cube;
|
||||||
|
|
||||||
struct FrameDrawnCallbacks {
|
List<Callable> frame_drawn_callbacks;
|
||||||
ObjectID object;
|
|
||||||
StringName method;
|
|
||||||
Variant param;
|
|
||||||
};
|
|
||||||
|
|
||||||
List<FrameDrawnCallbacks> frame_drawn_callbacks;
|
|
||||||
|
|
||||||
static void _changes_changed() {}
|
static void _changes_changed() {}
|
||||||
|
|
||||||
|
@ -880,7 +874,7 @@ public:
|
||||||
|
|
||||||
/* EVENT QUEUING */
|
/* 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 draw(bool p_swap_buffers, double frame_step) override;
|
||||||
virtual void sync() override;
|
virtual void sync() override;
|
||||||
|
|
|
@ -2701,7 +2701,7 @@ void RenderingServer::_bind_methods() {
|
||||||
|
|
||||||
/* Misc */
|
/* 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("has_changed"), &RenderingServer::has_changed);
|
||||||
ClassDB::bind_method(D_METHOD("get_rendering_info", "info"), &RenderingServer::get_rendering_info);
|
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);
|
ClassDB::bind_method(D_METHOD("get_video_adapter_name"), &RenderingServer::get_video_adapter_name);
|
||||||
|
|
|
@ -1435,10 +1435,10 @@ public:
|
||||||
|
|
||||||
virtual void free(RID p_rid) = 0; ///< free RIDs associated with the rendering server
|
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 */
|
/* 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 draw(bool p_swap_buffers = true, double frame_step = 0.0) = 0;
|
||||||
virtual void sync() = 0;
|
virtual void sync() = 0;
|
||||||
virtual bool has_changed() const = 0;
|
virtual bool has_changed() const = 0;
|
||||||
|
|
Loading…
Reference in New Issue