From 37ac6a646111306219df188b2e11d5007739660d Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Wed, 23 Apr 2025 12:03:38 -0600 Subject: [PATCH] Save-state loading doesn't use cached versions --- src/game/game.gd | 14 +++++++++++--- src/util/loading_tools.gd | 2 +- src/world/world.gd | 4 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/game/game.gd b/src/game/game.gd index a40552b..d01dc1e 100644 --- a/src/game/game.gd +++ b/src/game/game.gd @@ -60,18 +60,26 @@ func _initial_load() -> void: ## The loading screen will be shown until the scene is loaded. func queue_scene(path: String) -> Promise: _unload_content() - return queue_load(path, ScenePromise.new(), "PackedScene").finally(_finish_scene_load) + return ( + queue_load(path, ResourceLoader.CACHE_MODE_REUSE, ScenePromise.new(), "PackedScene") + . finally(_finish_scene_load) + ) ## Queue a resource to be loaded in the background. ## ## Returns a `Promise` which can be used to attach callbacks ## which will be called with the resource after it is loaded. -func queue_load(path: String, promise: Promise = null, type_hint: String = "") -> Promise: +func queue_load( + path: String, + cache_mode: ResourceLoader.CacheMode = ResourceLoader.CACHE_MODE_REUSE, + promise: Promise = null, + type_hint: String = "" +) -> Promise: if not promise: promise = Promise.new() _loading_resources[path] = promise - ResourceLoader.load_threaded_request(path, type_hint) + ResourceLoader.load_threaded_request(path, type_hint, false, cache_mode) return promise diff --git a/src/util/loading_tools.gd b/src/util/loading_tools.gd index 91a4ebc..6263f45 100644 --- a/src/util/loading_tools.gd +++ b/src/util/loading_tools.gd @@ -19,4 +19,4 @@ static func load_level(level_path: String, save: SaveState = null) -> void: static func load_save(save_path: String) -> void: var chain_load := func(save: SaveState) -> void: load_level(save.level_path, save) - Game.instance.queue_load(save_path).then(chain_load) + Game.instance.queue_load(save_path, ResourceLoader.CACHE_MODE_REPLACE_DEEP).then(chain_load) diff --git a/src/world/world.gd b/src/world/world.gd index ce2b7af..5141505 100644 --- a/src/world/world.gd +++ b/src/world/world.gd @@ -79,7 +79,9 @@ func on_game_over() -> void: # reload the level from the last save var save_path := current_level.get_save_path() if FileAccess.file_exists(save_path): - Game.instance.queue_load(save_path).finally(_reload_saved) + Game.instance.queue_load(save_path, ResourceLoader.CACHE_MODE_REPLACE_DEEP).finally( + _reload_saved + ) else: load_level(current_level_scene)