Cleaned up preview generation thread, fixes #5499
This commit is contained in:
parent
dd01286137
commit
15d52d6c95
|
@ -33,6 +33,7 @@
|
||||||
#include "io/resource_saver.h"
|
#include "io/resource_saver.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "editor_scale.h"
|
#include "editor_scale.h"
|
||||||
|
#include "message_queue.h"
|
||||||
|
|
||||||
Ref<Texture> EditorResourcePreviewGenerator::generate_from_path(const String& p_path) {
|
Ref<Texture> EditorResourcePreviewGenerator::generate_from_path(const String& p_path) {
|
||||||
|
|
||||||
|
@ -83,12 +84,10 @@ void EditorResourcePreview::_preview_ready(const String& p_str,const Ref<Texture
|
||||||
|
|
||||||
cache[path]=item;
|
cache[path]=item;
|
||||||
|
|
||||||
Object *recv = ObjectDB::get_instance(id);
|
|
||||||
if (recv) {
|
|
||||||
recv->call_deferred(p_func,path,p_texture,p_ud);
|
|
||||||
}
|
|
||||||
|
|
||||||
preview_mutex->unlock();
|
preview_mutex->unlock();
|
||||||
|
|
||||||
|
MessageQueue::get_singleton()->push_call(id,p_func,path,p_texture,p_ud);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Texture> EditorResourcePreview::_generate_preview(const QueueItem& p_item,const String& cache_base) {
|
Ref<Texture> EditorResourcePreview::_generate_preview(const QueueItem& p_item,const String& cache_base) {
|
||||||
|
@ -107,6 +106,7 @@ Ref<Texture> EditorResourcePreview::_generate_preview(const QueueItem& p_item,co
|
||||||
Ref<Texture> generated;
|
Ref<Texture> generated;
|
||||||
|
|
||||||
for(int i=0;i<preview_generators.size();i++) {
|
for(int i=0;i<preview_generators.size();i++) {
|
||||||
|
|
||||||
if (!preview_generators[i]->handles(type))
|
if (!preview_generators[i]->handles(type))
|
||||||
continue;
|
continue;
|
||||||
if (p_item.resource.is_valid()) {
|
if (p_item.resource.is_valid()) {
|
||||||
|
@ -157,7 +157,19 @@ void EditorResourcePreview::_thread() {
|
||||||
|
|
||||||
QueueItem item = queue.front()->get();
|
QueueItem item = queue.front()->get();
|
||||||
queue.pop_front();
|
queue.pop_front();
|
||||||
|
|
||||||
|
if (cache.has(item.path)) {
|
||||||
|
//already has it because someone loaded it, just let it know it's ready
|
||||||
|
if (item.resource.is_valid()) {
|
||||||
|
item.path+=":"+itos(cache[item.path].last_hash); //keep last hash (see description of what this is in condition below)
|
||||||
|
}
|
||||||
|
|
||||||
|
_preview_ready(item.path,cache[item.path].preview,item.id,item.function,item.userdata);
|
||||||
|
|
||||||
preview_mutex->unlock();
|
preview_mutex->unlock();
|
||||||
|
} else {
|
||||||
|
preview_mutex->unlock();
|
||||||
|
|
||||||
|
|
||||||
Ref<Texture> texture;
|
Ref<Texture> texture;
|
||||||
|
|
||||||
|
@ -166,18 +178,12 @@ void EditorResourcePreview::_thread() {
|
||||||
int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
|
int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
|
||||||
thumbnail_size*=EDSCALE;
|
thumbnail_size*=EDSCALE;
|
||||||
|
|
||||||
if (cache.has(item.path)) {
|
|
||||||
//already has it because someone loaded it, just let it know it's ready
|
|
||||||
if (item.resource.is_valid()) {
|
|
||||||
item.path+=":"+itos(cache[item.path].last_hash); //keep last hash (see description of what this is in condition below)
|
|
||||||
}
|
|
||||||
call_deferred("_preview_ready",item.path,cache[item.path].preview,item.id,item.function,item.userdata);
|
|
||||||
|
|
||||||
} else if (item.resource.is_valid()){
|
if (item.resource.is_valid()){
|
||||||
|
|
||||||
texture=_generate_preview(item,String());
|
texture=_generate_preview(item,String());
|
||||||
//adding hash to the end of path (should be ID:<objid>:<hash>) because of 5 argument limit to call_deferred
|
//adding hash to the end of path (should be ID:<objid>:<hash>) because of 5 argument limit to call_deferred
|
||||||
call_deferred("_preview_ready",item.path+":"+itos(item.resource->hash_edited_version()),texture,item.id,item.function,item.userdata);
|
_preview_ready(item.path+":"+itos(item.resource->hash_edited_version()),texture,item.id,item.function,item.userdata);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -246,9 +252,11 @@ void EditorResourcePreview::_thread() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//print_line("notify of preview ready");
|
//print_line("notify of preview ready");
|
||||||
call_deferred("_preview_ready",item.path,texture,item.id,item.function,item.userdata);
|
_preview_ready(item.path,texture,item.id,item.function,item.userdata);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
preview_mutex->unlock();
|
preview_mutex->unlock();
|
||||||
|
|
Loading…
Reference in New Issue