1
1
#include " jvm_resource_format_loader.h"
2
2
3
- #include " hash.h"
4
3
#include " api/language/names.h"
5
4
#include " api/script/jvm_script.h"
6
5
#include " api/script/jvm_script_manager.h"
7
6
#include " api/script/language/gdj_script.h"
8
7
#include " api/script/language/java_script.h"
9
8
#include " api/script/language/kotlin_script.h"
10
9
#include " api/script/language/scala_script.h"
10
+ #include < classes/file_access.hpp>
11
+ #include < classes/resource_uid.hpp>
12
+ #include " engine/utilities.h"
13
+ #include " hash.h"
11
14
12
15
using namespace godot ;
13
16
14
- void JvmResourceFormatLoader::get_recognized_extensions (List<String>* p_extensions) const {
15
- p_extensions->push_back (GODOT_JVM_REGISTRATION_FILE_EXTENSION);
16
- p_extensions->push_back (GODOT_KOTLIN_SCRIPT_EXTENSION);
17
- p_extensions->push_back (GODOT_JAVA_SCRIPT_EXTENSION);
18
- p_extensions->push_back (GODOT_SCALA_SCRIPT_EXTENSION);
17
+ PackedStringArray JvmResourceFormatLoader::_get_recognized_extensions () const {
18
+ PackedStringArray extensions;
19
+ extensions.push_back (GODOT_JVM_REGISTRATION_FILE_EXTENSION);
20
+ extensions.push_back (GODOT_KOTLIN_SCRIPT_EXTENSION);
21
+ extensions.push_back (GODOT_JAVA_SCRIPT_EXTENSION);
22
+ extensions.push_back (GODOT_SCALA_SCRIPT_EXTENSION);
23
+ return extensions;
19
24
}
20
25
21
- String JvmResourceFormatLoader::get_resource_type (const String& p_path) const {
26
+ String JvmResourceFormatLoader::_get_resource_type (const String& p_path) const {
22
27
String ext = p_path.get_extension ().to_lower ();
23
28
24
29
if (ext == GODOT_JVM_REGISTRATION_FILE_EXTENSION) {
@@ -33,22 +38,22 @@ String JvmResourceFormatLoader::get_resource_type(const String& p_path) const {
33
38
return " " ;
34
39
}
35
40
36
- bool JvmResourceFormatLoader::handles_type (const String & p_type) const {
37
- return p_type == " Script"
38
- || p_type == GODOT_JVM_SCRIPT_NAME
39
- || p_type == GODOT_KOTLIN_SCRIPT_NAME
40
- || p_type == GODOT_JAVA_SCRIPT_NAME
41
- || p_type == GODOT_SCALA_SCRIPT_NAME;
41
+ bool JvmResourceFormatLoader::_handles_type (const StringName & p_type) const {
42
+ return p_type == SNAME ( " Script" )
43
+ || p_type == SNAME ( GODOT_JVM_SCRIPT_NAME)
44
+ || p_type == SNAME ( GODOT_KOTLIN_SCRIPT_NAME)
45
+ || p_type == SNAME ( GODOT_JAVA_SCRIPT_NAME)
46
+ || p_type == SNAME ( GODOT_SCALA_SCRIPT_NAME) ;
42
47
}
43
48
44
49
Error JvmResourceFormatLoader::read_all_file_utf8 (const String& p_path, String& r_content) {
45
50
Vector<uint8_t > source_file;
46
- Error err ;
47
- Ref<FileAccess> file_access { FileAccess::open (p_path, FileAccess::READ, &err)} ;
51
+ Ref<FileAccess> file_access { FileAccess::open (p_path, FileAccess::READ)} ;
52
+ Error err = FileAccess::get_open_error () ;
48
53
JVM_ERR_FAIL_COND_V_MSG (err != OK, err, " Cannot open file '" + p_path + " '." );
49
54
50
55
uint64_t len = file_access->get_length ();
51
- source_file.resize (len + 1 );
56
+ source_file.resize (( int64_t ) len + 1 );
52
57
uint8_t * w = source_file.ptrw ();
53
58
uint64_t r = file_access->get_buffer (w, len);
54
59
ERR_FAIL_COND_V (r != len, ERR_CANT_OPEN);
@@ -61,7 +66,7 @@ Error JvmResourceFormatLoader::read_all_file_utf8(const String& p_path, String&
61
66
return OK;
62
67
}
63
68
64
- Ref<Resource> JvmResourceFormatLoader::load (const String& p_path, const String& p_original_path, Error* r_error, bool p_use_sub_threads, float * r_progress, CacheMode p_cache_mode) {
69
+ Variant JvmResourceFormatLoader::_load (const String& p_path, const String& p_original_path, bool p_use_sub_threads, int32_t p_cache_mode) {
65
70
Ref<JvmScript> jvm_script;
66
71
67
72
String extension = p_path.get_extension ();
@@ -79,40 +84,30 @@ Ref<Resource> JvmResourceFormatLoader::load(const String& p_path, const String&
79
84
} else if (extension == GODOT_SCALA_SCRIPT_EXTENSION) {
80
85
jvm_script = JvmScriptManager::get_instance ()->get_or_create_source_script <ScalaScript>(p_path, &script_is_new, r_error);
81
86
} else {
82
- if (r_error) { *r_error = Error::ERR_FILE_UNRECOGNIZED; }
83
87
return nullptr ;
84
88
}
85
89
86
- if (jvm_script.is_valid ()) {
87
90
#ifdef TOOLS_ENABLED
88
- if (!script_is_new && is_source) {
89
- MessageQueue::get_singleton ()->push_callable (
90
- callable_mp (JvmScriptManager::get_instance (), &JvmScriptManager::invalidate_source).bind (Ref<SourceScript>(jvm_script))
91
- );
92
- }
93
- #endif
94
- } else {
95
- if (r_error) { *r_error = Error::ERR_UNAVAILABLE; }
91
+ if (jvm_script.is_valid () && !script_is_new && is_source) {
92
+ callable_mp (JvmScriptManager::get_instance (), &JvmScriptManager::invalidate_source).bind (Ref<SourceScript>(jvm_script))
93
+ .call_deferred ();
96
94
}
95
+ #endif
97
96
98
97
return jvm_script;
99
98
}
100
99
101
- ResourceUID::ID JvmResourceFormatLoader::get_resource_uid (const String& p_path) const {
100
+ int64_t JvmResourceFormatLoader::_get_resource_uid (const String& p_path) const {
102
101
String extension = p_path.get_extension ();
103
- ResourceUID::ID id = ResourceUID::INVALID_ID;
102
+ int64_t id = ResourceUID::INVALID_ID;
104
103
if (extension == GODOT_JVM_REGISTRATION_FILE_EXTENSION) {
105
- id = (JvmScript::get_script_file_name (p_path) + UUID_HASH_SEED). hash64 ( );
104
+ id = (int64_t ) hash64 ( JvmScript::get_script_file_name (p_path) + UUID_HASH_SEED);
106
105
id &= 0x7FFFFFFFFFFFFFFF ;
107
106
} else if (extension == GODOT_KOTLIN_SCRIPT_EXTENSION || extension == GODOT_JAVA_SCRIPT_EXTENSION || extension == GODOT_SCALA_SCRIPT_EXTENSION) {
108
107
String source;
109
108
Error error;
110
- id = (String (SourceScript::parse_source_to_fqdn (p_path, source, &error)) + UUID_HASH_SEED). hash64 ( );
109
+ id = (int64_t ) hash64 ( String (SourceScript::parse_source_to_fqdn (p_path, source, &error)) + UUID_HASH_SEED);
111
110
id &= 0x7FFFFFFFFFFFFFFF ;
112
111
}
113
112
return id;
114
- }
115
-
116
- bool JvmResourceFormatLoader::has_custom_uid_support () const {
117
- return true ;
118
- }
113
+ }
0 commit comments