diff --git a/src/jvm_wrapper/bridge/variant_array_bridge.cpp b/src/jvm_wrapper/bridge/variant_array_bridge.cpp index 37d66626a..6d5579cd2 100644 --- a/src/jvm_wrapper/bridge/variant_array_bridge.cpp +++ b/src/jvm_wrapper/bridge/variant_array_bridge.cpp @@ -23,7 +23,7 @@ uintptr_t VariantArrayBridge::engine_call_constructor_typed(JNIEnv* p_raw_env, j StringName base_class_name; Variant script; if (userTypeIndex != -1) { - const Ref& kotlin_script {JvmScriptManager::get_instance().get_user_script_for_index(userTypeIndex)}; + const Ref& kotlin_script {JvmScriptManager::get_instance().get_named_script_for_index(userTypeIndex)}; base_class_name = kotlin_script->get_instance_base_type(); script = kotlin_script; } else if (engineTypeIndex != -1) { diff --git a/src/jvm_wrapper/memory/transfer_context.cpp b/src/jvm_wrapper/memory/transfer_context.cpp index 3a06398f2..2d4172459 100644 --- a/src/jvm_wrapper/memory/transfer_context.cpp +++ b/src/jvm_wrapper/memory/transfer_context.cpp @@ -133,7 +133,7 @@ void TransferContext::create_native_object(JNIEnv* p_raw_env, jobject p_instance int script_index {static_cast(p_script_index)}; if (script_index != -1) { KtObject* kt_object = memnew(KtObject(env, jni::JObject(p_object), ptr->is_ref_counted())); - Ref kotlin_script {JvmScriptManager::get_instance().get_user_script_for_index(script_index)}; + Ref kotlin_script {JvmScriptManager::get_instance().get_named_script_for_index(script_index)}; JvmInstance* script = memnew(JvmInstance(env, ptr, kt_object, kotlin_script.ptr())); ptr->set_script_instance(script); } diff --git a/src/jvm_wrapper/registration/kt_class.cpp b/src/jvm_wrapper/registration/kt_class.cpp index 8bee8dd58..1752d8436 100644 --- a/src/jvm_wrapper/registration/kt_class.cpp +++ b/src/jvm_wrapper/registration/kt_class.cpp @@ -41,7 +41,7 @@ KtObject* KtClass::create_instance(jni::Env& env, const Variant** p_args, int p_ #endif KtObject* jvm_instance {constructor->create_instance(env, p_args, p_owner)}; - LOG_DEV_VERBOSE(vformat("Instantiated an object with resource path %s", registered_class_name)); + LOG_DEV_VERBOSE(vformat("Instantiated a Jvm script: %s", registered_class_name)); return jvm_instance; } diff --git a/src/language/gdj_language.cpp b/src/language/gdj_language.cpp index 770452d8c..7818a9b46 100644 --- a/src/language/gdj_language.cpp +++ b/src/language/gdj_language.cpp @@ -37,10 +37,11 @@ void GdjLanguage::init() { void GdjLanguage::frame() { #ifdef TOOLS_ENABLED - JvmScriptManager::get_instance().update_all_exports_if_dirty(); + JvmScriptManager::get_instance().update_all_scripts(); #endif } + void GdjLanguage::thread_enter() { jni::Jvm::attach(); } @@ -85,7 +86,7 @@ String GdjLanguage::get_global_class_name(const String& p_path, String* r_base_t if (p_path.begins_with(ENTRY_DIRECTORY) || !p_path.ends_with(GODOT_JVM_REGISTRATION_FILE_EXTENSION)) { return {}; } String script_name = JvmScript::get_script_file_name(p_path); - Ref named_script = JvmScriptManager::get_instance().get_user_script_from_name(script_name); + Ref named_script = JvmScriptManager::get_instance().get_script_from_name(script_name); if (!named_script.is_null() && named_script.is_valid()) { if (r_base_type) { if (named_script->get_base_script().is_null()) { diff --git a/src/resource_format/jvm_resource_format_loader.cpp b/src/resource_format/jvm_resource_format_loader.cpp index 734b6059a..073e8066b 100644 --- a/src/resource_format/jvm_resource_format_loader.cpp +++ b/src/resource_format/jvm_resource_format_loader.cpp @@ -57,23 +57,11 @@ Ref JvmResourceFormatLoader::load(const String& p_path, const String& String extension = p_path.get_extension(); if (extension == GODOT_JVM_REGISTRATION_FILE_EXTENSION) { - // We don't import Kotlin scripts so p_path == p_original_path - String script_name = JvmScript::get_script_file_name(p_path); - ref = JvmScriptManager::get_instance().get_user_script_from_name(script_name); - if (ref.is_null()) { -#ifdef TOOLS_ENABLED - // If we reach that location, it means that the script file being loaded hasn't been built into the .jar. - // We create a script placeholder instead. When reloading, it will be properly updated with the correct KtClass. - ref = JvmScriptManager::get_instance().create_script(p_path); -#endif - } - } - // Path scripts are always created from the resource_loader and set in the resource cache afterward. - // If we reach that location, it means the script doesn't exist. - else if (extension == GODOT_KOTLIN_SCRIPT_EXTENSION) { - ref = JvmScriptManager::get_instance().create_script(p_path); + ref = JvmScriptManager::get_instance().get_or_create_script(p_path); + } else if (extension == GODOT_KOTLIN_SCRIPT_EXTENSION) { + ref = JvmScriptManager::get_instance().get_or_create_script(p_path); } else if (extension == GODOT_JAVA_SCRIPT_EXTENSION) { - ref = JvmScriptManager::get_instance().create_script(p_path); + ref = JvmScriptManager::get_instance().get_or_create_script(p_path); } if (ref.is_valid()) { @@ -82,8 +70,8 @@ Ref JvmResourceFormatLoader::load(const String& p_path, const String& Error load_err {read_all_file_utf8(p_path, source_code)}; if (r_error) { *r_error = load_err; } ref->set_source_code(source_code); + ref->update_script(); #endif - ref->set_path(p_path, true); } else { if (r_error) { *r_error = Error::ERR_UNAVAILABLE; } } diff --git a/src/script/jvm_script.cpp b/src/script/jvm_script.cpp index 84e7ec27e..464b2e7cf 100644 --- a/src/script/jvm_script.cpp +++ b/src/script/jvm_script.cpp @@ -59,7 +59,7 @@ bool JvmScript::inherits_script(const Ref