Skip to content

Commit

Permalink
added new optional params to packed_scene wrapper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mangonels authored Aug 23, 2024
1 parent 6b915bb commit 456a858
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/util/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 456a858

Please sign in to comment.