aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/AudioSource.h1
-rw-r--r--src/crepe/api/CMakeLists.txt2
-rw-r--r--src/crepe/api/Config.h27
-rw-r--r--src/crepe/api/ResourceManager.cpp41
-rw-r--r--src/crepe/api/ResourceManager.h69
5 files changed, 3 insertions, 137 deletions
diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h
index 1264790..0950129 100644
--- a/src/crepe/api/AudioSource.h
+++ b/src/crepe/api/AudioSource.h
@@ -3,6 +3,7 @@
#include "../Component.h"
#include "../types.h"
+#include "GameObject.h"
#include "Asset.h"
namespace crepe {
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index a2e21fa..ad82924 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -7,7 +7,6 @@ target_sources(crepe PUBLIC
Transform.cpp
Color.cpp
Texture.cpp
- ResourceManager.cpp
Sprite.cpp
SaveManager.cpp
Config.cpp
@@ -39,7 +38,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
Vector2.hpp
Color.h
Texture.h
- ResourceManager.h
SaveManager.h
Scene.h
Metadata.h
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 0c9d116..5bd6913 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -11,35 +11,12 @@ namespace crepe {
* modified *before* execution is handed over from the game programmer to the engine (i.e. the
* main loop is started).
*/
-class Config final {
-public:
+struct Config final {
//! Retrieve handle to global Config instance
static Config & get_instance();
-private:
- Config() = default;
- ~Config() = default;
- Config(const Config &) = default;
- Config(Config &&) = default;
- Config & operator=(const Config &) = default;
- Config & operator=(Config &&) = default;
-
-public:
//! Logging-related settings
- struct {
- /**
- * \brief Log level
- *
- * Only messages with equal or higher priority than this value will be logged.
- */
- Log::Level level = Log::Level::INFO;
- /**
- * \brief Colored log output
- *
- * Enables log coloring using ANSI escape codes.
- */
- bool color = true;
- } log;
+ Log::Config log;
//! Save manager
struct {
diff --git a/src/crepe/api/ResourceManager.cpp b/src/crepe/api/ResourceManager.cpp
deleted file mode 100644
index 7877ed9..0000000
--- a/src/crepe/api/ResourceManager.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#include <stdexcept>
-
-#include "util/Log.h"
-
-#include "ResourceManager.h"
-
-using namespace crepe;
-using namespace std;
-
-ResourceManager & ResourceManager::get_instance() {
- static ResourceManager instance;
- return instance;
-}
-
-ResourceManager::~ResourceManager() { dbg_trace(); }
-ResourceManager::ResourceManager() { dbg_trace(); }
-
-void ResourceManager::clear() {
- this->resources.clear();
-}
-
-template <typename T>
-T & ResourceManager::cache(const Asset & asset) {
- dbg_trace();
- static_assert(is_base_of<Resource, T>::value, "cache must recieve a derivative class of Resource");
-
- if (!this->resources.contains(asset))
- this->resources[asset] = make_unique<T>(asset);
-
- Resource * resource = this->resources.at(asset).get();
- T * concrete_resource = dynamic_cast<T *>(resource);
-
- if (concrete_resource == nullptr)
- throw runtime_error(format("ResourceManager: mismatch between requested type and actual type of resource ({})", asset.get_path()));
-
- return *concrete_resource;
-}
-
-#include "../facade/Sound.h"
-template Sound & ResourceManager::cache(const Asset &);
-
diff --git a/src/crepe/api/ResourceManager.h b/src/crepe/api/ResourceManager.h
deleted file mode 100644
index efdd5c5..0000000
--- a/src/crepe/api/ResourceManager.h
+++ /dev/null
@@ -1,69 +0,0 @@
-#pragma once
-
-#include <memory>
-#include <unordered_map>
-
-#include "Asset.h"
-#include "Resource.h"
-
-namespace crepe {
-
-class Sound;
-
-/**
- * \brief The ResourceManager is responsible for storing and managing assets over
- * multiple scenes.
- *
- * The ResourceManager 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 ResourceManager is
- * destroyed, at which point the cached assets are cleared.
- */
-class ResourceManager {
-
-private:
- //! A cache that holds all the assets, accessible by their file path, over multiple scenes.
- std::unordered_map<const Asset, std::unique_ptr<Resource>> resources;
-
-private:
- ResourceManager(); // dbg_trace
- virtual ~ResourceManager(); // dbg_trace
-
- ResourceManager(const ResourceManager &) = delete;
- ResourceManager(ResourceManager &&) = delete;
- ResourceManager & operator=(const ResourceManager &) = delete;
- ResourceManager & operator=(ResourceManager &&) = delete;
-
-public:
- /**
- * \brief Retrieves the singleton instance of the ResourceManager.
- *
- * \return A reference to the single instance of the ResourceManager.
- */
- static ResourceManager & get_instance();
-
-public:
- /**
- * \brief Caches an asset by loading it from the given file path.
- *
- * \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 reference to the resource
- *
- * This template function caches the asset at the given file path. If the
- * asset is already cached, the existing instance will be returned.
- * Otherwise, the concrete resource will be instantiated and added to the
- * cache.
- */
- template <typename T>
- T & cache(const Asset & asset);
-
- //! Clear the resource cache
- void clear();
-};
-
-} // namespace crepe
-