diff options
-rw-r--r-- | core/config/project_settings.cpp | 5 | ||||
-rw-r--r-- | core/config/project_settings.h | 2 | ||||
-rw-r--r-- | editor/editor_paths.cpp | 2 | ||||
-rw-r--r-- | platform/linuxbsd/tts_linux.cpp | 135 | ||||
-rw-r--r-- | platform/linuxbsd/tts_linux.h | 8 | ||||
-rw-r--r-- | tests/core/test_time.h | 4 |
6 files changed, 91 insertions, 65 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index f0de22f2ef..56e9057a2a 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -656,6 +656,7 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level"); + project_loaded = err == OK; return err; } @@ -1106,6 +1107,10 @@ bool ProjectSettings::is_using_datapack() const { return using_datapack; } +bool ProjectSettings::is_project_loaded() const { + return project_loaded; +} + bool ProjectSettings::_property_can_revert(const StringName &p_name) const { if (!props.has(p_name)) { return false; diff --git a/core/config/project_settings.h b/core/config/project_settings.h index 50cb274831..a0249ef267 100644 --- a/core/config/project_settings.h +++ b/core/config/project_settings.h @@ -95,6 +95,7 @@ protected: String resource_path; HashMap<StringName, PropertyInfo> custom_prop_info; bool using_datapack = false; + bool project_loaded = false; List<String> input_presets; HashSet<String> custom_features; @@ -190,6 +191,7 @@ public: Variant get_setting_with_override(const StringName &p_name) const; bool is_using_datapack() const; + bool is_project_loaded() const; bool has_custom_feature(const String &p_feature) const; diff --git a/editor/editor_paths.cpp b/editor/editor_paths.cpp index 36ebeb8c33..389c16fd66 100644 --- a/editor/editor_paths.cpp +++ b/editor/editor_paths.cpp @@ -218,7 +218,7 @@ EditorPaths::EditorPaths() { // Validate or create project-specific editor data dir, // including shader cache subdir. - if (Engine::get_singleton()->is_project_manager_hint() || Main::is_cmdline_tool()) { + if (Engine::get_singleton()->is_project_manager_hint() || (Main::is_cmdline_tool() && !ProjectSettings::get_singleton()->is_project_loaded())) { // Nothing to create, use shared editor data dir for shader cache. Engine::get_singleton()->set_shader_cache_path(data_dir); } else { diff --git a/platform/linuxbsd/tts_linux.cpp b/platform/linuxbsd/tts_linux.cpp index 04d7c5444f..6b8584ef6c 100644 --- a/platform/linuxbsd/tts_linux.cpp +++ b/platform/linuxbsd/tts_linux.cpp @@ -35,6 +35,11 @@ TTS_Linux *TTS_Linux::singleton = nullptr; +void TTS_Linux::_bind_methods() { + ClassDB::bind_method(D_METHOD("_speech_event", "msg_id", "client_id", "type"), &TTS_Linux::_speech_event); + ClassDB::bind_method(D_METHOD("_speech_index_mark", "msg_id", "client_id", "type", "index_mark"), &TTS_Linux::_speech_index_mark); +} + void TTS_Linux::speech_init_thread_func(void *p_userdata) { TTS_Linux *tts = (TTS_Linux *)p_userdata; if (tts) { @@ -76,76 +81,84 @@ void TTS_Linux::speech_init_thread_func(void *p_userdata) { void TTS_Linux::speech_event_index_mark(size_t p_msg_id, size_t p_client_id, SPDNotificationType p_type, char *p_index_mark) { TTS_Linux *tts = TTS_Linux::get_singleton(); - if (tts && tts->ids.has(p_msg_id)) { - MutexLock thread_safe_method(tts->_thread_safe_); - // Get word offset from the index mark injected to the text stream. - String mark = String::utf8(p_index_mark); - DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_BOUNDARY, tts->ids[p_msg_id], mark.to_int()); + if (tts) { + tts->call_deferred(SNAME("_speech_index_mark"), p_msg_id, p_client_id, (int)p_type, String::utf8(p_index_mark)); + } +} + +void TTS_Linux::_speech_index_mark(size_t p_msg_id, size_t p_client_id, int p_type, const String &p_index_mark) { + _THREAD_SAFE_METHOD_ + + if (ids.has(p_msg_id)) { + DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_BOUNDARY, ids[p_msg_id], p_index_mark.to_int()); } } void TTS_Linux::speech_event_callback(size_t p_msg_id, size_t p_client_id, SPDNotificationType p_type) { TTS_Linux *tts = TTS_Linux::get_singleton(); if (tts) { - MutexLock thread_safe_method(tts->_thread_safe_); - List<DisplayServer::TTSUtterance> &queue = tts->queue; - if (!tts->paused && tts->ids.has(p_msg_id)) { - if (p_type == SPD_EVENT_END) { - DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_ENDED, tts->ids[p_msg_id]); - tts->ids.erase(p_msg_id); - tts->last_msg_id = -1; - tts->speaking = false; - } else if (p_type == SPD_EVENT_CANCEL) { - DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, tts->ids[p_msg_id]); - tts->ids.erase(p_msg_id); - tts->last_msg_id = -1; - tts->speaking = false; - } + tts->call_deferred(SNAME("_speech_event"), p_msg_id, p_client_id, (int)p_type); + } +} + +void TTS_Linux::_speech_event(size_t p_msg_id, size_t p_client_id, int p_type) { + _THREAD_SAFE_METHOD_ + + if (!paused && ids.has(p_msg_id)) { + if ((SPDNotificationType)p_type == SPD_EVENT_END) { + DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_ENDED, ids[p_msg_id]); + ids.erase(p_msg_id); + last_msg_id = -1; + speaking = false; + } else if ((SPDNotificationType)p_type == SPD_EVENT_CANCEL) { + DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, ids[p_msg_id]); + ids.erase(p_msg_id); + last_msg_id = -1; + speaking = false; } - if (!tts->speaking && queue.size() > 0) { - DisplayServer::TTSUtterance &message = queue.front()->get(); - - // Inject index mark after each word. - String text; - String language; - SPDVoice **voices = spd_list_synthesis_voices(tts->synth); - if (voices != nullptr) { - SPDVoice **voices_ptr = voices; - while (*voices_ptr != nullptr) { - if (String::utf8((*voices_ptr)->name) == message.voice) { - language = String::utf8((*voices_ptr)->language); - break; - } - voices_ptr++; - } - free_spd_voices(voices); - } - PackedInt32Array breaks = TS->string_get_word_breaks(message.text, language); - for (int i = 0; i < breaks.size(); i += 2) { - const int start = breaks[i]; - const int end = breaks[i + 1]; - text += message.text.substr(start, end - start + 1); - text += "<mark name=\"" + String::num_int64(end, 10) + "\"/>"; - } + } + if (!speaking && queue.size() > 0) { + DisplayServer::TTSUtterance &message = queue.front()->get(); - spd_set_synthesis_voice(tts->synth, message.voice.utf8().get_data()); - spd_set_volume(tts->synth, message.volume * 2 - 100); - spd_set_voice_pitch(tts->synth, (message.pitch - 1) * 100); - float rate = 0; - if (message.rate > 1.f) { - rate = log10(MIN(message.rate, 2.5f)) / log10(2.5f) * 100; - } else if (message.rate < 1.f) { - rate = log10(MAX(message.rate, 0.5f)) / log10(0.5f) * -100; + // Inject index mark after each word. + String text; + String language; + SPDVoice **voices = spd_list_synthesis_voices(synth); + if (voices != nullptr) { + SPDVoice **voices_ptr = voices; + while (*voices_ptr != nullptr) { + if (String::utf8((*voices_ptr)->name) == message.voice) { + language = String::utf8((*voices_ptr)->language); + break; + } + voices_ptr++; } - spd_set_voice_rate(tts->synth, rate); - spd_set_data_mode(tts->synth, SPD_DATA_SSML); - tts->last_msg_id = spd_say(tts->synth, SPD_TEXT, text.utf8().get_data()); - tts->ids[tts->last_msg_id] = message.id; - DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_STARTED, message.id); - - queue.pop_front(); - tts->speaking = true; + free_spd_voices(voices); } + PackedInt32Array breaks = TS->string_get_word_breaks(message.text, language); + for (int i = 0; i < breaks.size(); i += 2) { + const int start = breaks[i]; + const int end = breaks[i + 1]; + text += message.text.substr(start, end - start + 1); + text += "<mark name=\"" + String::num_int64(end, 10) + "\"/>"; + } + spd_set_synthesis_voice(synth, message.voice.utf8().get_data()); + spd_set_volume(synth, message.volume * 2 - 100); + spd_set_voice_pitch(synth, (message.pitch - 1) * 100); + float rate = 0; + if (message.rate > 1.f) { + rate = log10(MIN(message.rate, 2.5f)) / log10(2.5f) * 100; + } else if (message.rate < 1.f) { + rate = log10(MAX(message.rate, 0.5f)) / log10(0.5f) * -100; + } + spd_set_voice_rate(synth, rate); + spd_set_data_mode(synth, SPD_DATA_SSML); + last_msg_id = spd_say(synth, SPD_TEXT, text.utf8().get_data()); + ids[last_msg_id] = message.id; + DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_STARTED, message.id); + + queue.pop_front(); + speaking = true; } } @@ -204,7 +217,7 @@ void TTS_Linux::speak(const String &p_text, const String &p_voice, int p_volume, if (is_paused()) { resume(); } else { - speech_event_callback(0, 0, SPD_EVENT_BEGIN); + _speech_event(0, 0, (int)SPD_EVENT_BEGIN); } } diff --git a/platform/linuxbsd/tts_linux.h b/platform/linuxbsd/tts_linux.h index 3fe7b659d0..3fcbe3207b 100644 --- a/platform/linuxbsd/tts_linux.h +++ b/platform/linuxbsd/tts_linux.h @@ -45,7 +45,8 @@ #include <libspeechd.h> #endif -class TTS_Linux { +class TTS_Linux : public Object { + GDCLASS(TTS_Linux, Object); _THREAD_SAFE_CLASS_ List<DisplayServer::TTSUtterance> queue; @@ -63,6 +64,11 @@ class TTS_Linux { static TTS_Linux *singleton; +protected: + static void _bind_methods(); + void _speech_event(size_t p_msg_id, size_t p_client_id, int p_type); + void _speech_index_mark(size_t p_msg_id, size_t p_client_id, int p_type, const String &p_index_mark); + public: static TTS_Linux *get_singleton(); diff --git a/tests/core/test_time.h b/tests/core/test_time.h index 7c8465cd12..6e31324359 100644 --- a/tests/core/test_time.h +++ b/tests/core/test_time.h @@ -91,7 +91,7 @@ TEST_CASE("[Time] Datetime dictionary conversion methods") { datetime[YEAR_KEY] = 2014; datetime[MONTH_KEY] = 2; datetime[DAY_KEY] = 9; - datetime[WEEKDAY_KEY] = Weekday::WEEKDAY_SUNDAY; + datetime[WEEKDAY_KEY] = (int64_t)Weekday::WEEKDAY_SUNDAY; datetime[HOUR_KEY] = 22; datetime[MINUTE_KEY] = 10; datetime[SECOND_KEY] = 30; @@ -100,7 +100,7 @@ TEST_CASE("[Time] Datetime dictionary conversion methods") { date_only[YEAR_KEY] = 2014; date_only[MONTH_KEY] = 2; date_only[DAY_KEY] = 9; - date_only[WEEKDAY_KEY] = Weekday::WEEKDAY_SUNDAY; + date_only[WEEKDAY_KEY] = (int64_t)Weekday::WEEKDAY_SUNDAY; Dictionary time_only; time_only[HOUR_KEY] = 22; |