@@ -128,10 +128,11 @@ func try_load_cached_file(cache_key: String) -> Variant:
128128 return TMFileUtil .load_json_file (file_path )
129129 return null
130130
131-
131+ # in memory cache
132132var _cached_pairs = {}
133-
133+ var mutex : Mutex = Mutex . new ()
134134func load_gltf_thread_task (cache_key : String ) -> Promise :
135+ mutex .lock ()
135136 if _cached_pairs .has (cache_key ):
136137 print ("Cache found... not loading twice" )
137138 return _cached_pairs [cache_key ].promise
@@ -145,30 +146,21 @@ func load_gltf_thread_task(cache_key: String) -> Promise:
145146 return
146147 var file_name : String = _storage_cache .get (pair .key , "" )
147148 var file_path : String = get_file_path (file_name )
148-
149149 var task_id = WorkerThreadPool .add_task (func ():
150- # future: we'll pack all the assets to .tscn and dependencies
151- # it should be faster than packing / repacking things. maybe even .scn files.
152- # if ResourceLoader.exists(file_path + ".tscn"):
153- # var node = ResourceLoader.load(file_path + ".tscn").instantiate()
154- # call_thread_safe("_cached_file_is_loaded", pair, node)
155- # return
156150 var node = TMFileUtil .load_gltf_file_as_node (file_path , Zone .is_host ())
157- # var scene: PackedScene = PackedScene.new()
158- # scene.pack(node)
159- # ResourceSaver.save(scene, file_path + ".tscn")
160- # print("Path: ", file_path + ".tscn")
161151 call_thread_safe ("_cached_file_is_loaded" , pair , node )
162152 )
163153
164-
154+ mutex . unlock ()
165155 return pair .promise
166156
167157## THIS MUST BE ON THE MAIN THREAD
168158func _cached_file_is_loaded (pair , node ):
159+ mutex .lock ()
169160 print ("Node name: " , node .get_name ())
170161 if node == null :
171162 push_error ("Can't load GLTF" )
172163 pair .promise .set_error ("Failed to load mesh, ignoring and skipping" )
173164 return
174165 pair .promise .set_result (node )
166+ mutex .unlock ()
0 commit comments