From 59c7588c6162a0be7dac13610e0b854f70b6d8b9 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Mon, 11 Nov 2024 19:26:42 +0100 Subject: Adjusted rendering to make it work with newer system --- src/crepe/facade/SDLContext.cpp | 2 +- src/example/rendering.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index c4c96e2..e87a2c5 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -159,7 +159,7 @@ SDLContext::texture_from_path(const std::string & path) { SDL_Surface * tmp = IMG_Load(path.c_str()); if (tmp == nullptr) { - throw Exception("surface cannot be load from %s", path.c_str()); + tmp = IMG_Load("../asset/texture/ERROR.png"); } std::unique_ptr> diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp index d554a8a..e02f6a3 100644 --- a/src/example/rendering.cpp +++ b/src/example/rendering.cpp @@ -1,3 +1,4 @@ +#include "api/Camera.h" #include #include #include @@ -23,26 +24,26 @@ int main() { auto obj1 = GameObject(1, "name", "tag", Vector2{500, 0}, 1, 0.1); auto obj2 = GameObject(2, "name", "tag", Vector2{800, 0}, 1, 0.1); - auto & mgr = AssetManager::get_instance(); // Normal adding components { Color color(0, 0, 0, 0); obj.add_component( make_shared("../asset/texture/img.png"), color, - FlipSettings{true, true}); + FlipSettings{false, false}); + obj.add_component(Color::get_red()); } - { Color color(0, 0, 0, 0); - auto img = mgr.cache("../asset/texture/second.png"); - obj1.add_component(img, color, FlipSettings{true, true}); + obj1.add_component(make_shared("../asset/texture/second.png"), color, FlipSettings{true, true}); } + /* { Color color(0, 0, 0, 0); auto img = mgr.cache("../asset/texture/second.png"); obj2.add_component(img, color, FlipSettings{true, true}); } + */ auto & sys = crepe::RenderSystem::get_instance(); auto start = std::chrono::steady_clock::now(); -- cgit v1.2.3 From 3c9b331668189e9c1a35d3d6ac6ded601f725e78 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 12 Nov 2024 15:11:27 +0100 Subject: assetmanager --- src/crepe/api/AssetManager.h | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src') diff --git a/src/crepe/api/AssetManager.h b/src/crepe/api/AssetManager.h index fefbed9..68235c3 100644 --- a/src/crepe/api/AssetManager.h +++ b/src/crepe/api/AssetManager.h @@ -7,24 +7,69 @@ namespace crepe { + +/** + * \brief The AssetManager is responsible for storing and managing assets over multiple scenes. + * + * The AssetManager ensures that assets are loaded once and can be accessed across different scenes. + * It caches assets to avoid reloading them every time a scene is loaded. Assets are retained in memory + * until the AssetManager is destroyed, at which point the cached assets are cleared. + */ class AssetManager { private: + //! A cache that holds all the assets, accessible by their file path, over multiple scenes. std::unordered_map asset_cache; private: + /** + * \brief Private constructor for the AssetManager. + * + */ AssetManager(); + + /** + * \brief Private destructor for the AssetManager. + * + */ virtual ~AssetManager(); public: + + //! Deleted copy constructor to prevent copying of the AssetManager instance. AssetManager(const AssetManager &) = delete; + + //! Deleted move constructor to prevent moving of the AssetManager instance. AssetManager(AssetManager &&) = delete; + + //! Deleted copy assignment operator to prevent copying the AssetManager instance. AssetManager & operator=(const AssetManager &) = delete; + + //! Deleted move assignment operator to prevent moving the AssetManager instance. AssetManager & operator=(AssetManager &&) = delete; + /** + * \brief Retrieves the singleton instance of the AssetManager. + * + * \return A reference to the single instance of the AssetManager. + * + */ static AssetManager & get_instance(); public: + /** + * \brief Caches an asset by loading it from the given file path. + * + * \param[in] file_path The path to the asset file to load. + * \param[in] reload If true, the asset will be reloaded from the file, even if it is already cached. + * \tparam asset The type of asset to cache (e.g., texture, sound, etc.). + * + * \return A shared pointer to the cached asset. + * + * This template function caches the asset at the given file path. If the asset is already cached + * and `reload` is false, the existing cached version will be returned. Otherwise, the asset will + * be reloaded and added to the cache. + */ template std::shared_ptr cache(const std::string & file_path, bool reload = false); -- cgit v1.2.3 From f2509e89c02894ebd3ad992324eb300103621d26 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 12 Nov 2024 18:32:56 +0100 Subject: nitpick #30 --- src/crepe/api/AssetManager.h | 48 +++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/crepe/api/AssetManager.h b/src/crepe/api/AssetManager.h index 68235c3..dbfaef3 100644 --- a/src/crepe/api/AssetManager.h +++ b/src/crepe/api/AssetManager.h @@ -7,13 +7,14 @@ namespace crepe { - /** - * \brief The AssetManager is responsible for storing and managing assets over multiple scenes. + * \brief The AssetManager is responsible for storing and managing assets over + * multiple scenes. * - * The AssetManager ensures that assets are loaded once and can be accessed across different scenes. - * It caches assets to avoid reloading them every time a scene is loaded. Assets are retained in memory - * until the AssetManager is destroyed, at which point the cached assets are cleared. + * The AssetManager ensures that assets are loaded once and can be accessed + * across different scenes. It caches assets to avoid reloading them every time + * a scene is loaded. Assets are retained in memory until the AssetManager is + * destroyed, at which point the cached assets are cleared. */ class AssetManager { @@ -22,37 +23,19 @@ private: std::unordered_map asset_cache; private: - /** - * \brief Private constructor for the AssetManager. - * - */ AssetManager(); - - /** - * \brief Private destructor for the AssetManager. - * - */ virtual ~AssetManager(); public: - - //! Deleted copy constructor to prevent copying of the AssetManager instance. AssetManager(const AssetManager &) = delete; - - //! Deleted move constructor to prevent moving of the AssetManager instance. AssetManager(AssetManager &&) = delete; - - //! Deleted copy assignment operator to prevent copying the AssetManager instance. AssetManager & operator=(const AssetManager &) = delete; - - //! Deleted move assignment operator to prevent moving the AssetManager instance. AssetManager & operator=(AssetManager &&) = delete; /** * \brief Retrieves the singleton instance of the AssetManager. * * \return A reference to the single instance of the AssetManager. - * */ static AssetManager & get_instance(); @@ -60,19 +43,20 @@ public: /** * \brief Caches an asset by loading it from the given file path. * - * \param[in] file_path The path to the asset file to load. - * \param[in] reload If true, the asset will be reloaded from the file, even if it is already cached. - * \tparam asset The type of asset to cache (e.g., texture, sound, etc.). + * \param file_path The path to the asset file to load. + * \param reload If true, the asset will be reloaded from the file, even if + * it is already cached. + * \tparam T The type of asset to cache (e.g., texture, sound, etc.). * * \return A shared pointer to the cached asset. * - * This template function caches the asset at the given file path. If the asset is already cached - * and `reload` is false, the existing cached version will be returned. Otherwise, the asset will - * be reloaded and added to the cache. + * This template function caches the asset at the given file path. If the + * asset is already cached and `reload` is false, the existing cached version + * will be returned. Otherwise, the asset will be reloaded and added to the + * cache. */ - template - std::shared_ptr cache(const std::string & file_path, - bool reload = false); + template + std::shared_ptr cache(const std::string & file_path, bool reload = false); }; } // namespace crepe -- cgit v1.2.3