-Fix in animationplayback, sound would be cut on loop

-Fix on scene importer, keeping changes to animation tracks was not working
This commit is contained in:
Juan Linietsky 2018-07-01 17:44:15 -03:00
parent 9c56a16d61
commit 896e250f2b
5 changed files with 58 additions and 5 deletions

View File

@ -1054,8 +1054,23 @@ void EditorNode::_save_scene(String p_file, int idx) {
flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
err = ResourceSaver::save(p_file, sdata, flg);
Map<RES, bool> processed;
_save_edited_subresources(scene, processed, flg);
//Map<RES, bool> processed;
//this method is slow and not always works, deprecating
//_save_edited_subresources(scene, processed, flg);
{ //instead, just find globally unsaved subresources and save them
List<Ref<Resource> > cached;
ResourceCache::get_cached_resources(&cached);
for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) {
Ref<Resource> res = E->get();
if (res->is_edited() && res->get_path().is_resource_file()) {
ResourceSaver::save(res->get_path(), res, flg);
res->set_edited(false);
}
}
}
editor_data.save_editor_external_data();
if (err == OK) {
scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_file));

View File

@ -893,7 +893,6 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
}
String ext_name = p_base_path.plus_file(_make_extname(E->get()) + ".anim");
if (FileAccess::exists(ext_name) && p_keep_animations) {
//try to keep custom animation tracks
Ref<Animation> old_anim = ResourceLoader::load(ext_name, "Animation", true);
@ -907,6 +906,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
}
}
anim->set_path(ext_name, true); //if not set, then its never saved externally
ResourceSaver::save(ext_name, anim, ResourceSaver::FLAG_CHANGE_PATH);
p_animations[anim] = anim;
}

View File

@ -144,6 +144,7 @@ void AnimationPlayerEditor::_notification(int p_what) {
ITEM_ICON(TOOL_DUPLICATE_ANIM, "Duplicate");
ITEM_ICON(TOOL_RENAME_ANIM, "Rename");
ITEM_ICON(TOOL_EDIT_TRANSITIONS, "Blend");
ITEM_ICON(TOOL_EDIT_RESOURCE, "Edit");
ITEM_ICON(TOOL_REMOVE_ANIM, "Remove");
//ITEM_ICON(TOOL_COPY_ANIM, "Copy");
//ITEM_ICON(TOOL_PASTE_ANIM, "Paste");
@ -1667,6 +1668,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay
tool_anim->get_popup()->add_separator();
tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/rename_animation", TTR("Rename...")), TOOL_RENAME_ANIM);
tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/edit_transitions", TTR("Edit Transitions...")), TOOL_EDIT_TRANSITIONS);
tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/open_animation_in_inspector", TTR("Open in Inspector")), TOOL_EDIT_RESOURCE);
tool_anim->get_popup()->add_separator();
tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/remove_animation", TTR("Remove")), TOOL_REMOVE_ANIM);
hb->add_child(tool_anim);

View File

@ -660,7 +660,22 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
nc->audio_start = p_time;
}
} else if (nc->audio_playing) {
if (nc->audio_start > p_time || (nc->audio_len > 0 && p_time - nc->audio_start < nc->audio_len)) {
bool loop = a->has_loop();
bool stop = false;
if (!loop && p_time < nc->audio_start) {
stop = true;
} else if (nc->audio_len > 0) {
float len = nc->audio_start > p_time ? (a->get_length() - nc->audio_start) + p_time : p_time - nc->audio_start;
if (len > nc->audio_len) {
stop = true;
}
}
if (stop) {
//time to stop
nc->node->call("stop");
nc->audio_playing = false;

View File

@ -1041,7 +1041,22 @@ void AnimationTree::_process_graph(float p_delta) {
t->start = time;
}
} else if (t->playing) {
if (t->start > time || (t->len > 0 && time - t->start < t->len)) {
bool loop = a->has_loop();
bool stop = false;
if (!loop && time < t->start) {
stop = true;
} else if (t->len > 0) {
float len = t->start > time ? (a->get_length() - t->start) + time : time - t->start;
if (len > t->len) {
stop=true;
}
}
if (stop) {
//time to stop
t->object->call("stop");
t->playing = false;
@ -1050,6 +1065,12 @@ void AnimationTree::_process_graph(float p_delta) {
}
}
float db = Math::linear2db(MAX(blend,0.00001));
if (t->object->has_method("set_unit_db")) {
t->object->call("set_unit_db", db);
} else {
t->object->call("set_volume_db", db);
}
} break;
case Animation::TYPE_ANIMATION: {