Merge pull request #45618 from RandomShaper/modernize_mt_3.2

Backport of all the multi-threading modernization (3.2)
This commit is contained in:
Hein-Pieter van Braam
2021-02-18 20:47:24 +01:00
committed by GitHub
191 changed files with 1688 additions and 4522 deletions
+9 -6
View File
@@ -158,7 +158,7 @@ void AudioStreamPreviewGenerator::_preview_thread(void *p_preview) {
preview->playback->stop();
preview->generating = false;
preview->generating.clear();
}
Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref<AudioStream> &p_stream) {
@@ -175,7 +175,7 @@ Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref<
Preview *preview = &previews[p_stream->get_instance_id()];
preview->base_stream = p_stream;
preview->playback = preview->base_stream->instance_playback();
preview->generating = true;
preview->generating.set();
preview->id = p_stream->get_instance_id();
float len_s = preview->base_stream->get_length();
@@ -199,8 +199,10 @@ Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref<
preview->preview->preview = maxmin;
preview->preview->length = len_s;
if (preview->playback.is_valid())
preview->thread = Thread::create(_preview_thread, preview);
if (preview->playback.is_valid()) {
preview->thread = memnew(Thread);
preview->thread->start(_preview_thread, preview);
}
return preview->preview;
}
@@ -218,9 +220,10 @@ void AudioStreamPreviewGenerator::_notification(int p_what) {
if (p_what == NOTIFICATION_PROCESS) {
List<ObjectID> to_erase;
for (Map<ObjectID, Preview>::Element *E = previews.front(); E; E = E->next()) {
if (!E->get().generating) {
if (!E->get().generating.is_set()) {
if (E->get().thread) {
Thread::wait_to_finish(E->get().thread);
E->get().thread->wait_to_finish();
memdelete(E->get().thread);
E->get().thread = NULL;
}
if (!ObjectDB::get_instance(E->key())) { //no longer in use, get rid of preview
+13 -1
View File
@@ -32,6 +32,7 @@
#define AUDIO_STREAM_PREVIEW_H
#include "core/os/thread.h"
#include "core/safe_refcount.h"
#include "scene/main/node.h"
#include "servers/audio/audio_stream.h"
@@ -60,9 +61,20 @@ class AudioStreamPreviewGenerator : public Node {
Ref<AudioStreamPreview> preview;
Ref<AudioStream> base_stream;
Ref<AudioStreamPlayback> playback;
volatile bool generating;
SafeFlag generating;
ObjectID id;
Thread *thread;
// Needed for the bookkeeping of the Map
Preview &operator=(const Preview &p_rhs) {
preview = p_rhs.preview;
base_stream = p_rhs.base_stream;
playback = p_rhs.playback;
generating.set_to(generating.is_set());
id = p_rhs.id;
thread = p_rhs.thread;
return *this;
}
};
Map<ObjectID, Preview> previews;
+16 -25
View File
@@ -609,7 +609,7 @@ void EditorFileSystem::scan() {
if (false /*&& bool(Globals::get_singleton()->get("debug/disable_scan"))*/)
return;
if (scanning || scanning_changes || thread)
if (scanning || scanning_changes || thread.is_started())
return;
_update_extensions();
@@ -632,13 +632,13 @@ void EditorFileSystem::scan() {
first_scan = false;
} else {
ERR_FAIL_COND(thread);
ERR_FAIL_COND(thread.is_started());
set_process(true);
Thread::Settings s;
scanning = true;
scan_total = 0;
s.priority = Thread::PRIORITY_LOW;
thread = Thread::create(_thread_func, this, s);
thread.start(_thread_func, this, s);
//tree->hide();
//progress->show();
}
@@ -1067,7 +1067,7 @@ void EditorFileSystem::get_changed_sources(List<String> *r_changed) {
void EditorFileSystem::scan_changes() {
if (first_scan || // Prevent a premature changes scan from inhibiting the first full scan
scanning || scanning_changes || thread) {
scanning || scanning_changes || thread.is_started()) {
scan_changes_pending = true;
set_process(true);
return;
@@ -1097,12 +1097,12 @@ void EditorFileSystem::scan_changes() {
emit_signal("sources_changed", sources_changed.size() > 0);
} else {
ERR_FAIL_COND(thread_sources);
ERR_FAIL_COND(thread_sources.is_started());
set_process(true);
scan_total = 0;
Thread::Settings s;
s.priority = Thread::PRIORITY_LOW;
thread_sources = Thread::create(_thread_func_sources, this, s);
thread_sources.start(_thread_func_sources, this, s);
}
}
@@ -1116,17 +1116,14 @@ void EditorFileSystem::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
Thread *active_thread = thread ? thread : thread_sources;
if (use_threads && active_thread) {
Thread &active_thread = thread.is_started() ? thread : thread_sources;
if (use_threads && active_thread.is_started()) {
//abort thread if in progress
abort_scan = true;
while (scanning) {
OS::get_singleton()->delay_usec(1000);
}
Thread::wait_to_finish(active_thread);
memdelete(active_thread);
thread = NULL;
thread_sources = NULL;
active_thread.wait_to_finish();
WARN_PRINT("Scan thread aborted...");
set_process(false);
}
@@ -1151,9 +1148,7 @@ void EditorFileSystem::_notification(int p_what) {
set_process(false);
Thread::wait_to_finish(thread_sources);
memdelete(thread_sources);
thread_sources = NULL;
thread_sources.wait_to_finish();
if (_update_scan_actions())
emit_signal("filesystem_changed");
emit_signal("sources_changed", sources_changed.size() > 0);
@@ -1168,9 +1163,7 @@ void EditorFileSystem::_notification(int p_what) {
memdelete(filesystem);
filesystem = new_filesystem;
new_filesystem = NULL;
Thread::wait_to_finish(thread);
memdelete(thread);
thread = NULL;
thread.wait_to_finish();
_update_scan_actions();
emit_signal("filesystem_changed");
emit_signal("sources_changed", sources_changed.size() > 0);
@@ -1452,10 +1445,10 @@ void EditorFileSystem::_scan_script_classes(EditorFileSystemDirectory *p_dir) {
void EditorFileSystem::update_script_classes() {
if (!update_script_classes_queued)
if (!update_script_classes_queued.is_set())
return;
update_script_classes_queued = false;
update_script_classes_queued.clear();
ScriptServer::global_classes_clear();
if (get_filesystem()) {
_scan_script_classes(get_filesystem());
@@ -1474,11 +1467,11 @@ void EditorFileSystem::update_script_classes() {
}
void EditorFileSystem::_queue_update_script_classes() {
if (update_script_classes_queued) {
if (update_script_classes_queued.is_set()) {
return;
}
update_script_classes_queued = true;
update_script_classes_queued.set();
call_deferred("update_script_classes");
}
@@ -2135,11 +2128,9 @@ EditorFileSystem::EditorFileSystem() {
filesystem = memnew(EditorFileSystemDirectory); //like, empty
filesystem->parent = NULL;
thread = NULL;
scanning = false;
importing = false;
use_threads = true;
thread_sources = NULL;
new_filesystem = NULL;
abort_scan = false;
@@ -2155,7 +2146,7 @@ EditorFileSystem::EditorFileSystem() {
memdelete(da);
scan_total = 0;
update_script_classes_queued = false;
update_script_classes_queued.clear();
first_scan = true;
scan_changes_pending = false;
revalidate_import_files = false;
+5 -3
View File
@@ -34,8 +34,10 @@
#include "core/os/dir_access.h"
#include "core/os/thread.h"
#include "core/os/thread_safe.h"
#include "core/safe_refcount.h"
#include "core/set.h"
#include "scene/main/node.h"
class FileAccess;
struct EditorProgressBG;
@@ -136,7 +138,7 @@ class EditorFileSystem : public Node {
};
bool use_threads;
Thread *thread;
Thread thread;
static void _thread_func(void *_userdata);
EditorFileSystemDirectory *new_filesystem;
@@ -200,7 +202,7 @@ class EditorFileSystem : public Node {
void _scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess *da, const ScanProgress &p_progress);
Thread *thread_sources;
Thread thread_sources;
bool scanning_changes;
bool scanning_changes_done;
@@ -231,7 +233,7 @@ class EditorFileSystem : public Node {
};
void _scan_script_classes(EditorFileSystemDirectory *p_dir);
volatile bool update_script_classes_queued;
SafeFlag update_script_classes_queued;
void _queue_update_script_classes();
String _get_global_script_class(const String &p_type, const String &p_path, String *r_extends, String *r_icon_path) const;
+7 -13
View File
@@ -5735,13 +5735,13 @@ void EditorNode::_print_handler(void *p_this, const String &p_string, bool p_err
static void _execute_thread(void *p_ud) {
EditorNode::ExecuteThreadArgs *eta = (EditorNode::ExecuteThreadArgs *)p_ud;
Error err = OS::get_singleton()->execute(eta->path, eta->args, true, NULL, &eta->output, &eta->exitcode, true, eta->execute_output_mutex);
Error err = OS::get_singleton()->execute(eta->path, eta->args, true, NULL, &eta->output, &eta->exitcode, true, &eta->execute_output_mutex);
print_verbose("Thread exit status: " + itos(eta->exitcode));
if (err != OK) {
eta->exitcode = err;
}
eta->done = true;
eta->done.set();
}
int EditorNode::execute_and_show_output(const String &p_title, const String &p_path, const List<String> &p_arguments, bool p_close_on_ok, bool p_close_on_errors) {
@@ -5755,31 +5755,25 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p
ExecuteThreadArgs eta;
eta.path = p_path;
eta.args = p_arguments;
eta.execute_output_mutex = Mutex::create();
eta.exitcode = 255;
eta.done = false;
int prev_len = 0;
eta.execute_output_thread = Thread::create(_execute_thread, &eta);
eta.execute_output_thread.start(_execute_thread, &eta);
ERR_FAIL_COND_V(!eta.execute_output_thread, 0);
while (!eta.done) {
eta.execute_output_mutex->lock();
while (!eta.done.is_set()) {
eta.execute_output_mutex.lock();
if (prev_len != eta.output.length()) {
String to_add = eta.output.substr(prev_len, eta.output.length());
prev_len = eta.output.length();
execute_outputs->add_text(to_add);
Main::iteration();
}
eta.execute_output_mutex->unlock();
eta.execute_output_mutex.unlock();
OS::get_singleton()->delay_usec(1000);
}
Thread::wait_to_finish(eta.execute_output_thread);
memdelete(eta.execute_output_thread);
memdelete(eta.execute_output_mutex);
eta.execute_output_thread.wait_to_finish();
execute_outputs->add_text("\nExit Code: " + itos(eta.exitcode));
if (p_close_on_errors && eta.exitcode != 0) {
+4 -3
View File
@@ -31,6 +31,7 @@
#ifndef EDITOR_NODE_H
#define EDITOR_NODE_H
#include "core/safe_refcount.h"
#include "editor/editor_data.h"
#include "editor/editor_folding.h"
#include "editor/editor_run.h"
@@ -106,10 +107,10 @@ public:
String path;
List<String> args;
String output;
Thread *execute_output_thread;
Mutex *execute_output_mutex;
Thread execute_output_thread;
Mutex execute_output_mutex;
int exitcode;
volatile bool done;
SafeFlag done;
};
private:
+27 -36
View File
@@ -109,7 +109,7 @@ void EditorResourcePreview::_thread_func(void *ud) {
void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Texture> &p_texture, const Ref<Texture> &p_small_texture, ObjectID id, const StringName &p_func, const Variant &p_ud) {
preview_mutex->lock();
preview_mutex.lock();
String path = p_str;
uint32_t hash = 0;
@@ -131,7 +131,7 @@ void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Textur
cache[path] = item;
preview_mutex->unlock();
preview_mutex.unlock();
MessageQueue::get_singleton()->push_call(id, p_func, path, p_texture, p_small_texture, p_ud);
}
@@ -217,11 +217,11 @@ void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref<
void EditorResourcePreview::_thread() {
exited = false;
while (!exit) {
exited.clear();
while (!exit.is_set()) {
preview_sem->wait();
preview_mutex->lock();
preview_sem.wait();
preview_mutex.lock();
if (queue.size()) {
@@ -237,10 +237,10 @@ void EditorResourcePreview::_thread() {
_preview_ready(path, cache[item.path].preview, cache[item.path].small_preview, item.id, item.function, item.userdata);
preview_mutex->unlock();
preview_mutex.unlock();
} else {
preview_mutex->unlock();
preview_mutex.unlock();
Ref<ImageTexture> texture;
Ref<ImageTexture> small_texture;
@@ -347,10 +347,10 @@ void EditorResourcePreview::_thread() {
}
} else {
preview_mutex->unlock();
preview_mutex.unlock();
}
}
exited = true;
exited.set();
}
void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p_res, Object *p_receiver, const StringName &p_receiver_func, const Variant &p_userdata) {
@@ -358,7 +358,7 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p
ERR_FAIL_NULL(p_receiver);
ERR_FAIL_COND(!p_res.is_valid());
preview_mutex->lock();
preview_mutex.lock();
String path_id = "ID:" + itos(p_res->get_instance_id());
@@ -366,7 +366,7 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p
cache[path_id].order = order++;
p_receiver->call(p_receiver_func, path_id, cache[path_id].preview, cache[path_id].small_preview, p_userdata);
preview_mutex->unlock();
preview_mutex.unlock();
return;
}
@@ -380,18 +380,18 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p
item.userdata = p_userdata;
queue.push_back(item);
preview_mutex->unlock();
preview_sem->post();
preview_mutex.unlock();
preview_sem.post();
}
void EditorResourcePreview::queue_resource_preview(const String &p_path, Object *p_receiver, const StringName &p_receiver_func, const Variant &p_userdata) {
ERR_FAIL_NULL(p_receiver);
preview_mutex->lock();
preview_mutex.lock();
if (cache.has(p_path)) {
cache[p_path].order = order++;
p_receiver->call(p_receiver_func, p_path, cache[p_path].preview, cache[p_path].small_preview, p_userdata);
preview_mutex->unlock();
preview_mutex.unlock();
return;
}
@@ -402,8 +402,8 @@ void EditorResourcePreview::queue_resource_preview(const String &p_path, Object
item.userdata = p_userdata;
queue.push_back(item);
preview_mutex->unlock();
preview_sem->post();
preview_mutex.unlock();
preview_sem.post();
}
void EditorResourcePreview::add_preview_generator(const Ref<EditorResourcePreviewGenerator> &p_generator) {
@@ -436,7 +436,7 @@ void EditorResourcePreview::_bind_methods() {
void EditorResourcePreview::check_for_invalidation(const String &p_path) {
preview_mutex->lock();
preview_mutex.lock();
bool call_invalidated = false;
if (cache.has(p_path)) {
@@ -448,7 +448,7 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) {
}
}
preview_mutex->unlock();
preview_mutex.unlock();
if (call_invalidated) { //do outside mutex
call_deferred("emit_signal", "preview_invalidated", p_path);
@@ -456,37 +456,28 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) {
}
void EditorResourcePreview::start() {
ERR_FAIL_COND_MSG(thread, "Thread already started.");
thread = Thread::create(_thread_func, this);
ERR_FAIL_COND_MSG(thread.is_started(), "Thread already started.");
thread.start(_thread_func, this);
}
void EditorResourcePreview::stop() {
if (thread) {
exit = true;
preview_sem->post();
while (!exited) {
if (thread.is_started()) {
exit.set();
preview_sem.post();
while (!exited.is_set()) {
OS::get_singleton()->delay_usec(10000);
VisualServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on visual server
}
Thread::wait_to_finish(thread);
memdelete(thread);
thread = NULL;
thread.wait_to_finish();
}
}
EditorResourcePreview::EditorResourcePreview() {
thread = NULL;
singleton = this;
preview_mutex = Mutex::create();
preview_sem = Semaphore::create();
order = 0;
exit = false;
exited = false;
}
EditorResourcePreview::~EditorResourcePreview() {
stop();
memdelete(preview_mutex);
memdelete(preview_sem);
}
+6 -5
View File
@@ -33,6 +33,7 @@
#include "core/os/semaphore.h"
#include "core/os/thread.h"
#include "core/safe_refcount.h"
#include "scene/main/node.h"
#include "scene/resources/texture.h"
@@ -70,11 +71,11 @@ class EditorResourcePreview : public Node {
List<QueueItem> queue;
Mutex *preview_mutex;
Semaphore *preview_sem;
Thread *thread;
volatile bool exit;
volatile bool exited;
Mutex preview_mutex;
Semaphore preview_sem;
Thread thread;
SafeFlag exit;
SafeFlag exited;
struct Item {
Ref<Texture> preview;
+11 -15
View File
@@ -42,9 +42,9 @@
void EditorFileServer::_close_client(ClientData *cd) {
cd->connection->disconnect_from_host();
cd->efs->wait_mutex->lock();
cd->efs->to_wait.insert(cd->thread);
cd->efs->wait_mutex->unlock();
cd->efs->wait_mutex.lock();
cd->efs->to_wait.insert(&cd->thread);
cd->efs->wait_mutex.unlock();
while (cd->files.size()) {
memdelete(cd->files.front()->get());
cd->files.erase(cd->files.front());
@@ -291,20 +291,19 @@ void EditorFileServer::_thread_start(void *s) {
cd->connection = self->server->take_connection();
cd->efs = self;
cd->quit = false;
cd->thread = Thread::create(_subthread_start, cd);
cd->thread.start(_subthread_start, cd);
}
}
self->wait_mutex->lock();
self->wait_mutex.lock();
while (self->to_wait.size()) {
Thread *w = self->to_wait.front()->get();
self->to_wait.erase(w);
self->wait_mutex->unlock();
Thread::wait_to_finish(w);
memdelete(w);
self->wait_mutex->lock();
self->wait_mutex.unlock();
w->wait_to_finish();
self->wait_mutex.lock();
}
self->wait_mutex->unlock();
self->wait_mutex.unlock();
OS::get_singleton()->delay_usec(100000);
}
@@ -331,11 +330,10 @@ void EditorFileServer::stop() {
EditorFileServer::EditorFileServer() {
server.instance();
wait_mutex = Mutex::create();
quit = false;
active = false;
cmd = CMD_NONE;
thread = Thread::create(_thread_start, this);
thread.start(_thread_start, this);
EDITOR_DEF("filesystem/file_server/port", 6010);
EDITOR_DEF("filesystem/file_server/password", "");
@@ -344,7 +342,5 @@ EditorFileServer::EditorFileServer() {
EditorFileServer::~EditorFileServer() {
quit = true;
Thread::wait_to_finish(thread);
memdelete(thread);
memdelete(wait_mutex);
thread.wait_to_finish();
}
+3 -3
View File
@@ -49,7 +49,7 @@ class EditorFileServer : public Object {
struct ClientData {
Thread *thread;
Thread thread;
Ref<StreamPeerTCP> connection;
Map<int, FileAccess *> files;
EditorFileServer *efs;
@@ -62,8 +62,8 @@ class EditorFileServer : public Object {
static void _close_client(ClientData *cd);
static void _subthread_start(void *s);
Mutex *wait_mutex;
Thread *thread;
Mutex wait_mutex;
Thread thread;
static void _thread_start(void *);
bool quit;
Command cmd;
+9 -15
View File
@@ -38,7 +38,7 @@
void ResourceImporterTexture::_texture_reimport_srgb(const Ref<StreamTexture> &p_tex) {
singleton->mutex->lock();
singleton->mutex.lock();
StringName path = p_tex->get_path();
if (!singleton->make_flags.has(path)) {
@@ -47,12 +47,12 @@ void ResourceImporterTexture::_texture_reimport_srgb(const Ref<StreamTexture> &p
singleton->make_flags[path] |= MAKE_SRGB_FLAG;
singleton->mutex->unlock();
singleton->mutex.unlock();
}
void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture> &p_tex) {
singleton->mutex->lock();
singleton->mutex.lock();
StringName path = p_tex->get_path();
if (!singleton->make_flags.has(path)) {
@@ -61,12 +61,12 @@ void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture> &p_t
singleton->make_flags[path] |= MAKE_3D_FLAG;
singleton->mutex->unlock();
singleton->mutex.unlock();
}
void ResourceImporterTexture::_texture_reimport_normal(const Ref<StreamTexture> &p_tex) {
singleton->mutex->lock();
singleton->mutex.lock();
StringName path = p_tex->get_path();
if (!singleton->make_flags.has(path)) {
@@ -75,7 +75,7 @@ void ResourceImporterTexture::_texture_reimport_normal(const Ref<StreamTexture>
singleton->make_flags[path] |= MAKE_NORMAL_FLAG;
singleton->mutex->unlock();
singleton->mutex.unlock();
}
void ResourceImporterTexture::update_imports() {
@@ -83,10 +83,10 @@ void ResourceImporterTexture::update_imports() {
if (EditorFileSystem::get_singleton()->is_scanning() || EditorFileSystem::get_singleton()->is_importing()) {
return; // do nothing for now
}
mutex->lock();
mutex.lock();
if (make_flags.empty()) {
mutex->unlock();
mutex.unlock();
return;
}
@@ -128,7 +128,7 @@ void ResourceImporterTexture::update_imports() {
make_flags.clear();
mutex->unlock();
mutex.unlock();
if (to_reimport.size()) {
EditorFileSystem::get_singleton()->reimport_files(to_reimport);
@@ -611,10 +611,4 @@ ResourceImporterTexture::ResourceImporterTexture() {
StreamTexture::request_3d_callback = _texture_reimport_3d;
StreamTexture::request_srgb_callback = _texture_reimport_srgb;
StreamTexture::request_normal_callback = _texture_reimport_normal;
mutex = Mutex::create();
}
ResourceImporterTexture::~ResourceImporterTexture() {
memdelete(mutex);
}
+1 -2
View File
@@ -46,7 +46,7 @@ protected:
MAKE_NORMAL_FLAG = 4
};
Mutex *mutex;
Mutex mutex;
Map<StringName, int> make_flags;
static void _texture_reimport_srgb(const Ref<StreamTexture> &p_tex);
@@ -94,7 +94,6 @@ public:
virtual String get_import_settings_string() const;
ResourceImporterTexture();
~ResourceImporterTexture();
};
#endif // RESOURCEIMPORTTEXTURE_H
+9 -9
View File
@@ -308,7 +308,7 @@ EditorPackedScenePreviewPlugin::EditorPackedScenePreviewPlugin() {
void EditorMaterialPreviewPlugin::_preview_done(const Variant &p_udata) {
preview_done = true;
preview_done.set();
}
void EditorMaterialPreviewPlugin::_bind_methods() {
@@ -336,10 +336,10 @@ Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Size
VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
preview_done = false;
preview_done.clear();
VS::get_singleton()->request_frame_drawn_callback(const_cast<EditorMaterialPreviewPlugin *>(this), "_preview_done", Variant());
while (!preview_done) {
while (!preview_done.is_set()) {
OS::get_singleton()->delay_usec(10);
}
@@ -699,7 +699,7 @@ EditorAudioStreamPreviewPlugin::EditorAudioStreamPreviewPlugin() {
void EditorMeshPreviewPlugin::_preview_done(const Variant &p_udata) {
preview_done = true;
preview_done.set();
}
void EditorMeshPreviewPlugin::_bind_methods() {
@@ -737,10 +737,10 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 &p
VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
preview_done = false;
preview_done.clear();
VS::get_singleton()->request_frame_drawn_callback(const_cast<EditorMeshPreviewPlugin *>(this), "_preview_done", Variant());
while (!preview_done) {
while (!preview_done.is_set()) {
OS::get_singleton()->delay_usec(10);
}
@@ -819,7 +819,7 @@ EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() {
void EditorFontPreviewPlugin::_preview_done(const Variant &p_udata) {
preview_done = true;
preview_done.set();
}
void EditorFontPreviewPlugin::_bind_methods() {
@@ -861,11 +861,11 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, c
font->draw(canvas_item, pos, sampled_text);
preview_done = false;
preview_done.clear();
VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
VS::get_singleton()->request_frame_drawn_callback(const_cast<EditorFontPreviewPlugin *>(this), "_preview_done", Variant());
while (!preview_done) {
while (!preview_done.is_set()) {
OS::get_singleton()->delay_usec(10);
}
+5 -3
View File
@@ -33,6 +33,8 @@
#include "editor/editor_resource_preview.h"
#include "core/safe_refcount.h"
void post_process_preview(Ref<Image> p_image);
class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator {
@@ -92,7 +94,7 @@ class EditorMaterialPreviewPlugin : public EditorResourcePreviewGenerator {
RID light2;
RID light_instance2;
RID camera;
mutable volatile bool preview_done;
mutable SafeFlag preview_done;
void _preview_done(const Variant &p_udata);
@@ -137,7 +139,7 @@ class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator {
RID light2;
RID light_instance2;
RID camera;
mutable volatile bool preview_done;
mutable SafeFlag preview_done;
void _preview_done(const Variant &p_udata);
@@ -160,7 +162,7 @@ class EditorFontPreviewPlugin : public EditorResourcePreviewGenerator {
RID viewport_texture;
RID canvas;
RID canvas_item;
mutable volatile bool preview_done;
mutable SafeFlag preview_done;
void _preview_done(const Variant &p_udata);