diff options
-rw-r--r-- | editor/filesystem_dock.cpp | 28 | ||||
-rw-r--r-- | editor/filesystem_dock.h | 2 | ||||
-rw-r--r-- | main/main.cpp | 4 | ||||
-rw-r--r-- | scene/2d/audio_stream_player_2d.cpp | 6 | ||||
-rw-r--r-- | scene/3d/audio_stream_player_3d.cpp | 6 | ||||
-rw-r--r-- | scene/audio/audio_stream_player.cpp | 6 | ||||
-rw-r--r-- | scene/resources/audio_stream_polyphonic.cpp | 30 | ||||
-rw-r--r-- | scene/resources/audio_stream_polyphonic.h | 5 |
8 files changed, 41 insertions, 46 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 54d5ddacab..a078c58e72 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2941,12 +2941,19 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) { } } -void FileSystemDock::_get_imported_files(const String &p_path, Vector<String> &r_files) const { +bool FileSystemDock::_get_imported_files(const String &p_path, String &r_extension, Vector<String> &r_files) const { if (!p_path.ends_with("/")) { if (FileAccess::exists(p_path + ".import")) { + if (r_extension.is_empty()) { + r_extension = p_path.get_extension(); + } else if (r_extension != p_path.get_extension()) { + r_files.clear(); + return false; // File type mismatch, stop search. + } + r_files.push_back(p_path); } - return; + return true; } Ref<DirAccess> da = DirAccess::open(p_path); @@ -2955,11 +2962,14 @@ void FileSystemDock::_get_imported_files(const String &p_path, Vector<String> &r while (!n.is_empty()) { if (n != "." && n != ".." && !n.ends_with(".import")) { String npath = p_path + n + (da->current_is_dir() ? "/" : ""); - _get_imported_files(npath, r_files); + if (!_get_imported_files(npath, r_extension, r_files)) { + return false; + } } n = da->get_next(); } da->list_dir_end(); + return true; } void FileSystemDock::_update_import_dock() { @@ -2984,10 +2994,16 @@ void FileSystemDock::_update_import_dock() { } } - // Expand directory selection + if (!selected.is_empty() && selected[0] == "res://") { + // Scanning res:// is costly and unlikely to yield any useful results. + return; + } + + // Expand directory selection. Vector<String> efiles; - for (int i = 0; i < selected.size(); i++) { - _get_imported_files(selected[i], efiles); + String extension; + for (const String &fpath : selected) { + _get_imported_files(fpath, extension, efiles); } // Check import. diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 3f12b73043..42a72b7ee8 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -214,7 +214,7 @@ private: void _file_multi_selected(int p_index, bool p_selected); void _tree_multi_selected(Object *p_item, int p_column, bool p_selected); - void _get_imported_files(const String &p_path, Vector<String> &r_files) const; + bool _get_imported_files(const String &p_path, String &r_extension, Vector<String> &r_files) const; void _update_import_dock(); void _get_all_items_in_dir(EditorFileSystemDirectory *p_efsd, Vector<String> &r_files, Vector<String> &r_folders) const; diff --git a/main/main.cpp b/main/main.cpp index 2326e519bf..cfde124b90 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2165,7 +2165,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { if (id) { agile_input_event_flushing = GLOBAL_DEF("input_devices/buffering/agile_event_flushing", false); - if (bool(GLOBAL_DEF("input_devices/pointing/emulate_touch_from_mouse", false)) && + if (bool(GLOBAL_DEF_BASIC("input_devices/pointing/emulate_touch_from_mouse", false)) && !(editor || project_manager)) { if (!DisplayServer::get_singleton()->is_touchscreen_available()) { //only if no touchscreen ui hint, set emulation @@ -2173,7 +2173,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { } } - id->set_emulate_mouse_from_touch(bool(GLOBAL_DEF("input_devices/pointing/emulate_mouse_from_touch", true))); + id->set_emulate_mouse_from_touch(bool(GLOBAL_DEF_BASIC("input_devices/pointing/emulate_mouse_from_touch", true))); } MAIN_PRINT("Main: Load Translations and Remaps"); diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index c4de3a124b..7b681eac7a 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -391,10 +391,8 @@ bool AudioStreamPlayer2D::get_stream_paused() const { } Ref<AudioStreamPlayback> AudioStreamPlayer2D::get_stream_playback() { - if (!stream_playbacks.is_empty()) { - return stream_playbacks[stream_playbacks.size() - 1]; - } - return nullptr; + ERR_FAIL_COND_V_MSG(stream_playbacks.is_empty(), Ref<AudioStreamPlayback>(), "Player is inactive. Call play() before requesting get_stream_playback()."); + return stream_playbacks[stream_playbacks.size() - 1]; } void AudioStreamPlayer2D::set_max_polyphony(int p_max_polyphony) { diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 73493f981e..7ed18d2d41 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -784,10 +784,8 @@ bool AudioStreamPlayer3D::get_stream_paused() const { } Ref<AudioStreamPlayback> AudioStreamPlayer3D::get_stream_playback() { - if (!stream_playbacks.is_empty()) { - return stream_playbacks[stream_playbacks.size() - 1]; - } - return nullptr; + ERR_FAIL_COND_V_MSG(stream_playbacks.is_empty(), Ref<AudioStreamPlayback>(), "Player is inactive. Call play() before requesting get_stream_playback()."); + return stream_playbacks[stream_playbacks.size() - 1]; } void AudioStreamPlayer3D::set_max_polyphony(int p_max_polyphony) { diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp index 42f76068e7..d40fc10441 100644 --- a/scene/audio/audio_stream_player.cpp +++ b/scene/audio/audio_stream_player.cpp @@ -308,10 +308,8 @@ void AudioStreamPlayer::_bus_layout_changed() { } Ref<AudioStreamPlayback> AudioStreamPlayer::get_stream_playback() { - if (!stream_playbacks.is_empty()) { - return stream_playbacks[stream_playbacks.size() - 1]; - } - return nullptr; + ERR_FAIL_COND_V_MSG(stream_playbacks.is_empty(), Ref<AudioStreamPlayback>(), "Player is inactive. Call play() before requesting get_stream_playback()."); + return stream_playbacks[stream_playbacks.size() - 1]; } void AudioStreamPlayer::_bind_methods() { diff --git a/scene/resources/audio_stream_polyphonic.cpp b/scene/resources/audio_stream_polyphonic.cpp index 3f460275a9..f7299b0789 100644 --- a/scene/resources/audio_stream_polyphonic.cpp +++ b/scene/resources/audio_stream_polyphonic.cpp @@ -87,7 +87,6 @@ void AudioStreamPlaybackPolyphonic::stop() { AudioServer::get_singleton()->lock(); } s.active.clear(); - s.finalizing.clear(); s.finish_request.clear(); s.stream_playback.unref(); s.stream.unref(); @@ -145,7 +144,6 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, if (s.pending_play.is_set()) { // Did not get the chance to play, was finalized too soon. s.active.clear(); - s.finalizing.set(); continue; } next_volume = 0; @@ -163,6 +161,8 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, int offset = 0; float volume = prev_volume; + bool stream_done = false; + while (todo) { int to_mix = MIN(todo, int(INTERNAL_BUFFER_LEN)); int mixed = s.stream_playback->mix(internal_buffer, s.pitch_scale, to_mix); @@ -175,7 +175,7 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, if (mixed < to_mix) { // Stream is done. s.active.clear(); - s.finalizing.set(); + stream_done = true; break; } @@ -183,34 +183,22 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, offset += to_mix; } + if (stream_done) { + continue; + } + if (s.finish_request.is_set()) { s.active.clear(); - s.finalizing.set(); } } return p_frames; } -void AudioStreamPlaybackPolyphonic::_check_finalized_streams() { - if (!active) { - return; - } - - for (Stream &s : streams) { - if (!s.active.is_set() && s.finalizing.is_set()) { - s.stream_playback.unref(); - s.stream.unref(); - s.finalizing.clear(); - s.finish_request.clear(); - } - } -} - AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::play_stream(const Ref<AudioStream> &p_stream, float p_from_offset, float p_volume_db, float p_pitch_scale) { ERR_FAIL_COND_V(p_stream.is_null(), INVALID_ID); for (uint32_t i = 0; i < streams.size(); i++) { - if (!streams[i].active.is_set() && !streams[i].finish_request.is_set() && !streams[i].finalizing.is_set()) { + if (!streams[i].active.is_set()) { // Can use this stream, as it's not active. streams[i].stream = p_stream; streams[i].stream_playback = streams[i].stream->instantiate_playback(); @@ -219,6 +207,7 @@ AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::play_stream(con streams[i].prev_volume_db = p_volume_db; streams[i].pitch_scale = p_pitch_scale; streams[i].id = id_counter++; + streams[i].finish_request.clear(); streams[i].pending_play.set(); streams[i].active.set(); return (ID(i) << INDEX_SHIFT) | ID(streams[i].id); @@ -282,5 +271,4 @@ void AudioStreamPlaybackPolyphonic::_bind_methods() { } AudioStreamPlaybackPolyphonic::AudioStreamPlaybackPolyphonic() { - SceneTree::get_singleton()->connect(SNAME("process_frame"), callable_mp(this, &AudioStreamPlaybackPolyphonic::_check_finalized_streams)); } diff --git a/scene/resources/audio_stream_polyphonic.h b/scene/resources/audio_stream_polyphonic.h index b5ccc7eb7f..e414401b6f 100644 --- a/scene/resources/audio_stream_polyphonic.h +++ b/scene/resources/audio_stream_polyphonic.h @@ -63,7 +63,6 @@ class AudioStreamPlaybackPolyphonic : public AudioStreamPlayback { SafeFlag active; SafeFlag pending_play; SafeFlag finish_request; - SafeFlag finalizing; float play_offset = 0; float pitch_scale = 1.0; Ref<AudioStream> stream; @@ -73,7 +72,7 @@ class AudioStreamPlaybackPolyphonic : public AudioStreamPlayback { uint32_t id = 0; Stream() : - active(false), pending_play(false), finish_request(false), finalizing(false) {} + active(false), pending_play(false), finish_request(false) {} }; LocalVector<Stream> streams; @@ -84,8 +83,6 @@ class AudioStreamPlaybackPolyphonic : public AudioStreamPlayback { _FORCE_INLINE_ Stream *_find_stream(int64_t p_id); - void _check_finalized_streams(); - friend class AudioStreamPolyphonic; protected: |