-Fix to progress dialog, speding it up

-Fix potential deadlock in stream player
-Fix collada to support broken files from ColladaMaya
This commit is contained in:
Juan Linietsky 2015-12-21 09:05:49 -03:00
parent 93a6ec1e32
commit 81f62fb78c
8 changed files with 56 additions and 22 deletions

View file

@ -67,7 +67,7 @@ bool StreamPlayer::sp_mix(int32_t *p_buffer,int p_frames) {
void StreamPlayer::sp_update() {
//_THREAD_SAFE_METHOD_
_THREAD_SAFE_METHOD_
if (!paused && resampler.is_ready() && playback.is_valid()) {
if (!playback->is_playing()) {
@ -143,8 +143,6 @@ void StreamPlayer::play(float p_from_offset) {
return;
//if (is_playing())
stop();
//_THREAD_SAFE_METHOD_
playback->play(p_from_offset);
//feed the ringbuffer as long as no update callback is going on
sp_update();
@ -162,8 +160,8 @@ void StreamPlayer::stop() {
if (playback.is_null())
return;
//_THREAD_SAFE_METHOD_
AudioServer::get_singleton()->stream_set_active(stream_rid,false);
_THREAD_SAFE_METHOD_
playback->stop();
resampler.flush();

View file

@ -37,7 +37,7 @@ class StreamPlayer : public Node {
OBJ_TYPE(StreamPlayer,Node);
//_THREAD_SAFE_CLASS_
_THREAD_SAFE_CLASS_
struct InternalStream : public AudioServer::AudioStream {
StreamPlayer *player;

View file

@ -1064,7 +1064,7 @@ Error EditorExportPlatform::save_pack_file(void *p_userdata,const String& p_path
MD5Final(&ctx);
pd->f->store_buffer(ctx.digest,16);
}
pd->ep->step("Storing File: "+p_path,2+p_file*100/p_total);
pd->ep->step("Storing File: "+p_path,2+p_file*100/p_total,false);
pd->count++;
pd->ftmp->store_buffer(p_data.ptr(),p_data.size());
if (pd->alignment > 1) {
@ -1102,7 +1102,7 @@ Error EditorExportPlatform::save_zip_file(void *p_userdata,const String& p_path,
zipWriteInFileInZip(zip,p_data.ptr(),p_data.size());
zipCloseFileInZip(zip);
zd->ep->step("Storing File: "+p_path,2+p_file*100/p_total);
zd->ep->step("Storing File: "+p_path,2+p_file*100/p_total,false);
zd->count++;
return OK;

View file

@ -4040,9 +4040,9 @@ void EditorNode::progress_add_task(const String& p_task,const String& p_label, i
singleton->progress_dialog->add_task(p_task,p_label,p_steps);
}
void EditorNode::progress_task_step(const String& p_task, const String& p_state, int p_step) {
void EditorNode::progress_task_step(const String& p_task, const String& p_state, int p_step,bool p_force_redraw) {
singleton->progress_dialog->task_step(p_task,p_state,p_step);
singleton->progress_dialog->task_step(p_task,p_state,p_step,p_force_redraw);
}

View file

@ -647,7 +647,7 @@ public:
static void add_io_error(const String& p_error);
static void progress_add_task(const String& p_task,const String& p_label, int p_steps);
static void progress_task_step(const String& p_task,const String& p_state, int p_step=-1);
static void progress_task_step(const String& p_task,const String& p_state, int p_step=-1,bool p_force_refresh=true);
static void progress_end_task(const String& p_task);
static void progress_add_task_bg(const String& p_task,const String& p_label, int p_steps);
@ -674,7 +674,7 @@ public:
struct EditorProgress {
String task;
void step(const String& p_state, int p_step=-1) { EditorNode::progress_task_step(task,p_state,p_step); }
void step(const String& p_state, int p_step=-1,bool p_force_refresh=true) { EditorNode::progress_task_step(task,p_state,p_step,p_force_refresh); }
EditorProgress(const String& p_task,const String& p_label,int p_amount) { EditorNode::progress_add_task(p_task,p_label,p_amount); task=p_task; }
~EditorProgress() { EditorNode::progress_end_task(task); }
};

View file

@ -68,6 +68,7 @@ struct ColladaImport {
Map<String,NodeMap> node_map; //map from collada node to engine node
Map<String,String> node_name_map; //map from collada node to engine node
Map<String, Ref<Mesh> > mesh_cache;
Map<String, Ref<Curve3D> > curve_cache;
Map<String, Ref<Material> > material_cache;
@ -124,6 +125,7 @@ Error ColladaImport::_populate_skeleton(Skeleton *p_skeleton,Collada::Node *p_no
nm.node=p_skeleton;
nm.bone = r_bone;
node_map[p_node->id]=nm;
node_name_map[p_node->name]=p_node->id;
skeleton_bone_map[p_skeleton][joint->sid]=r_bone;
@ -345,6 +347,7 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) {
NodeMap nm;
nm.node=node;
node_map[p_node->id]=nm;
node_name_map[p_node->name]=p_node->id;
Transform xf = p_node->default_transform;
xf = collada.fix_transform( xf ) * p_node->post_transform;
@ -1906,9 +1909,20 @@ void ColladaImport::create_animations(bool p_make_tracks_in_all_bones) {
Collada::AnimationTrack &at = collada.state.animation_tracks[i];
//print_line("CHANNEL: "+at.target+" PARAM: "+at.param);
String node;
if (!node_map.has(at.target)) {
print_line("Coudlnt find node: "+at.target);
continue;
if (node_name_map.has(at.target)) {
node=node_name_map[at.target];
} else {
print_line("Coudlnt find node: "+at.target);
continue;
}
} else {
node=at.target;
}
@ -1917,8 +1931,9 @@ void ColladaImport::create_animations(bool p_make_tracks_in_all_bones) {
valid_animated_properties.push_back(i);
} else {
node_map[at.target].anim_tracks.push_back(i);
valid_animated_nodes.insert(at.target);
node_map[node].anim_tracks.push_back(i);
valid_animated_nodes.insert(node);
}
}
@ -1934,6 +1949,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
Ref<Animation> animation = Ref<Animation>( memnew( Animation ));
if (p_clip==-1) {
//print_line("default");
@ -2007,10 +2023,12 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
while(f<anim_length) {
base_snapshots.push_back(f);
f+=snapshot_interval;
if (f>=anim_length) {
base_snapshots.push_back(anim_length);
}
}
@ -2019,11 +2037,17 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
bool tracks_found=false;
for(Set<String>::Element* E=valid_animated_nodes.front();E;E=E->next()) {
// take snapshots
if (!collada.state.scene_map.has(E->get()))
if (!collada.state.scene_map.has(E->get())) {
continue;
}
NodeMap &nm = node_map[E->get()];
String path = scene->get_path_to(nm.node);
@ -2039,7 +2063,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
Collada::Node *cn = collada.state.scene_map[E->get()];
if (cn->ignore_anim) {
//print_line("warning, ignoring animation on node: "+path);
continue;
}
@ -2058,20 +2082,23 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
for(int i=0;i<at.keys.size();i++)
snapshots.push_back(at.keys[i].time);
print_line("using anim snapshots");
}
for(int i=0;i<snapshots.size();i++) {
for(List<int>::Element *ET=nm.anim_tracks.front();ET;ET=ET->next()) {
//apply tracks
if (p_clip==-1) {
if (track_filter.has(ET->get()))
if (track_filter.has(ET->get())) {
continue;
}
} else {
if (!track_filter.has(ET->get()))

View file

@ -29,7 +29,7 @@
#include "progress_dialog.h"
#include "main/main.h"
#include "message_queue.h"
#include "os/os.h"
void BackgroundProgress::_add_task(const String& p_task,const String& p_label, int p_steps) {
@ -191,10 +191,16 @@ void ProgressDialog::add_task(const String& p_task,const String& p_label,int p_s
}
void ProgressDialog::task_step(const String& p_task, const String& p_state, int p_step){
void ProgressDialog::task_step(const String& p_task, const String& p_state, int p_step,bool p_force_redraw){
ERR_FAIL_COND(!tasks.has(p_task));
if (!p_force_redraw) {
uint64_t tus = OS::get_singleton()->get_ticks_usec();
if (tus-last_progress_tick < 50000) //50ms
return;
}
Task &t=tasks[p_task];
if (p_step<0)
t.progress->set_val(t.progress->get_val()+1);
@ -202,6 +208,7 @@ void ProgressDialog::task_step(const String& p_task, const String& p_state, int
t.progress->set_val(p_step);
t.state->set_text(p_state);
last_progress_tick=OS::get_singleton()->get_ticks_usec();
Main::iteration(); // this will not work on a lot of platforms, so it's only meant for the editor
}
@ -229,4 +236,5 @@ ProgressDialog::ProgressDialog() {
add_child(main);
main->set_area_as_parent_rect();
set_exclusive(true);
last_progress_tick=0;
}

View file

@ -84,6 +84,7 @@ class ProgressDialog : public Popup {
Map<String,Task> tasks;
VBoxContainer *main;
uint64_t last_progress_tick;
void _popup();
protected:
@ -92,7 +93,7 @@ protected:
public:
void add_task(const String& p_task,const String& p_label, int p_steps);
void task_step(const String& p_task,const String& p_state, int p_step=-1);
void task_step(const String& p_task, const String& p_state, int p_step=-1, bool p_force_redraw=true);
void end_task(const String& p_task);