From 456a858672a3afa8f9b3fa5a1c164f9a0b336b8d Mon Sep 17 00:00:00 2001 From: PixelRain Date: Fri, 23 Aug 2024 14:14:21 +0200 Subject: [PATCH] added new optional params to packed_scene wrapper ResourceLoader has some parameters that are otherwise inaccessible, notably the CacheMode, which defaults to 1 = CACHE_MODE_REUSE. This caches previous loads and reuses them, which is pretty neat, but the use of this cache may not always be required, so it's best to give the user the option to change this mode. --- src/util/scene.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/util/scene.hpp b/src/util/scene.hpp index 1f46994..f4efd4f 100644 --- a/src/util/scene.hpp +++ b/src/util/scene.hpp @@ -119,17 +119,21 @@ namespace rl::inline utils using scene_t = TScene; using object_t = TObj; - /* Pack as preload from path. */ - packed_scene(godot::String resource_load_path) + /** Load and pack from path. */ + packed_scene(const godot::String& load_resource_path, + const godot::String& load_type_hint = godot::String(), + godot::ResourceLoader::CacheMode load_cache_mode = + godot::ResourceLoader::CacheMode::CACHE_MODE_REUSE) { - godot::ResourceLoader* resource_loader{ resource::loader::get() }; + godot::ResourceLoader* resource_loader{ loader::get() }; - bool file_access_success{ resource_loader->exists(resource_load_path) }; - runtime_assert(file_access_success); + bool resource_exists{ resource_loader->exists(load_resource_path) }; + runtime_assert(resource_exists); - if (file_access_success) + if (resource_exists) { - m_packed_resource = resource_loader->load(resource_load_path); + m_packed_resource = resource_loader->load(load_resource_path, + load_type_hint, load_cache_mode); initialized = m_packed_resource.is_valid(); } }