diff options
author | Hop311 <Hop3114@gmail.com> | 2024-04-22 01:25:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-22 01:25:58 +0200 |
commit | 61e1e14ab7d206422004b4b4c6ffbb5e5f7dec58 (patch) | |
tree | 68efc91c394ae9dc76d6e9e7cadee86e2e2a02d3 /extension/src/openvic-extension/singletons/AssetManager.hpp | |
parent | 34f161570fd7ca9381675be8a9ec3b9b409929e1 (diff) | |
parent | c574d925c5251289d9f2fc32190b44cbe766f387 (diff) |
Merge pull request #219 from OpenVicProject/asset-manager-load-flags
Add AssetManager LoadFlags
Diffstat (limited to 'extension/src/openvic-extension/singletons/AssetManager.hpp')
-rw-r--r-- | extension/src/openvic-extension/singletons/AssetManager.hpp | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/extension/src/openvic-extension/singletons/AssetManager.hpp b/extension/src/openvic-extension/singletons/AssetManager.hpp index c718d2a..0856d05 100644 --- a/extension/src/openvic-extension/singletons/AssetManager.hpp +++ b/extension/src/openvic-extension/singletons/AssetManager.hpp @@ -13,9 +13,22 @@ namespace OpenVic { static inline AssetManager* _singleton = nullptr; + public: + enum LoadFlags { + LOAD_FLAG_NONE = 0, + LOAD_FLAG_CACHE_IMAGE = 1 << 0, + LOAD_FLAG_CACHE_TEXTURE = 1 << 1, + LOAD_FLAG_FLIP_Y = 1 << 2 + }; + + constexpr friend LoadFlags operator|(LoadFlags lhs, LoadFlags rhs) { + return static_cast<LoadFlags>(static_cast<int>(lhs) | static_cast<int>(rhs)); + } + + private: struct image_asset_t { - godot::Ref<godot::Image> image; - godot::Ref<godot::ImageTexture> texture; + std::optional<godot::Ref<godot::Image>> image; + std::optional<godot::Ref<godot::ImageTexture>> texture; }; /* deque_ordered_map to avoid the need to reallocate. */ using image_asset_map_t = deque_ordered_map<godot::StringName, image_asset_t>; @@ -24,8 +37,7 @@ namespace OpenVic { image_asset_map_t image_assets; font_map_t fonts; - static godot::Ref<godot::Image> _load_image(godot::StringName const& path); - image_asset_t* _get_image_asset(godot::StringName const& path, bool flip_y); + static godot::Ref<godot::Image> _load_image(godot::StringName const& path, bool flip_y); protected: static void _bind_methods(); @@ -37,16 +49,27 @@ namespace OpenVic { ~AssetManager(); /* Search for and load an image at the specified path relative to the game defines, first checking the AssetManager's - * image cache (if cache is true) in case it has already been loaded, and returning nullptr if image loading fails. */ - godot::Ref<godot::Image> get_image(godot::StringName const& path, bool cache = true, bool flip_y = false); + * image cache in case it has already been loaded, and returning nullptr if image loading fails. If the cache image + * load flag is set then the loaded image will be stored in the AssetManager's image cache for future access; if the + * flip y load flag is set then the image will be flipped vertically before being returned (if the image is already + * in the cache then no flipping will occur, regardless of whether it was orginally flipped or not). */ + godot::Ref<godot::Image> get_image(godot::StringName const& path, LoadFlags load_flags = LOAD_FLAG_CACHE_IMAGE); - /* Create a texture from an image found at the specified path relative to the game defines, fist checking - * AssetManager's texture cache in case it has already been loaded, and returning nullptr if image loading - * or texture creation fails. */ - godot::Ref<godot::ImageTexture> get_texture(godot::StringName const& path, bool flip_y = false); + /* Create a texture from an image found at the specified path relative to the game defines, fist checking the + * AssetManager's texture cache in case it has already been loaded, and returning nullptr if image loading or texture + * creation fails. If the cache image load flag is set then the loaded image will be stored in the AssetManager's + * image cache for future access; if the cache texture load flag is set then the created texture will be stored in the + * AssetManager's texture cache for future access; if the flip y load flag is set then the image will be flipped + * vertically before being used to create the texture (if the image is already in the cache then no flipping will + * occur, regardless of whether it was orginally flipped or not). */ + godot::Ref<godot::ImageTexture> get_texture( + godot::StringName const& path, LoadFlags load_flags = LOAD_FLAG_CACHE_TEXTURE + ); /* Search for and load a font with the specified name from the game defines' font directory, first checking the * AssetManager's font cache in case it has already been loaded, and returning nullptr if font loading fails. */ godot::Ref<godot::Font> get_font(godot::StringName const& name); }; } + +VARIANT_ENUM_CAST(OpenVic::AssetManager::LoadFlags); |