diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/Audio_asset.cpp | 16 | ||||
-rw-r--r-- | src/crepe/api/Audio_asset.h | 18 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 17 | ||||
-rw-r--r-- | src/crepe/api/Image_asset.cpp | 14 | ||||
-rw-r--r-- | src/crepe/api/Image_asset.h | 18 | ||||
-rw-r--r-- | src/crepe/api/map_asset.cpp | 12 | ||||
-rw-r--r-- | src/crepe/api/map_asset.h | 14 | ||||
-rw-r--r-- | src/crepe/api/resource.h | 23 | ||||
-rw-r--r-- | src/crepe/api/resource_manager.cpp | 25 | ||||
-rw-r--r-- | src/crepe/api/resource_manager.h | 59 | ||||
-rw-r--r-- | src/crepe/api/spritesheet.cpp | 16 | ||||
-rw-r--r-- | src/crepe/api/spritesheet.h | 21 |
12 files changed, 248 insertions, 5 deletions
diff --git a/src/crepe/api/Audio_asset.cpp b/src/crepe/api/Audio_asset.cpp new file mode 100644 index 0000000..a9b04ed --- /dev/null +++ b/src/crepe/api/Audio_asset.cpp @@ -0,0 +1,16 @@ + + + + +#include "Audio_asset.h" +#include <string> + + +using namespace crepe::api; + +Audio::Audio(const std::string& content){ + this->m_content = content; +} + +Audio::~Audio(){ +} diff --git a/src/crepe/api/Audio_asset.h b/src/crepe/api/Audio_asset.h new file mode 100644 index 0000000..0b8e48e --- /dev/null +++ b/src/crepe/api/Audio_asset.h @@ -0,0 +1,18 @@ +#pragma once + + +#include "resource.h" +#include <string> + + +namespace crepe::api { + + +class Audio : public Resource { + +public: + Audio(const std::string&); + ~Audio(); + +}; +} diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index feb03ef..4f3fada 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -1,11 +1,18 @@ target_sources(crepe PUBLIC - # AudioSource.cpp - Resource.cpp + Image_asset.cpp + map_asset.cpp + Audio_asset.cpp + spritesheet.cpp + resource_manager.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES - AudioSource.h + resource.h + Image_asset.h + map_asset.h + Audio_asset.h + spritesheet.h + resource_manager.h Component.h - Resource.h + AudioSource.h ) - diff --git a/src/crepe/api/Image_asset.cpp b/src/crepe/api/Image_asset.cpp new file mode 100644 index 0000000..57431c4 --- /dev/null +++ b/src/crepe/api/Image_asset.cpp @@ -0,0 +1,14 @@ + + +#include "Image_asset.h" +#include <string> + +using namespace crepe::api; + +Texture::Texture(const std::string& content){ + this->m_content = content; +} + + +Texture::~Texture(){ +} diff --git a/src/crepe/api/Image_asset.h b/src/crepe/api/Image_asset.h new file mode 100644 index 0000000..69549af --- /dev/null +++ b/src/crepe/api/Image_asset.h @@ -0,0 +1,18 @@ +#pragma once + + + +#include "resource.h" +#include <string> + +namespace crepe::api { + + +class Texture : public Resource { + +public: + Texture(const std::string&); + ~Texture(); +}; + +} diff --git a/src/crepe/api/map_asset.cpp b/src/crepe/api/map_asset.cpp new file mode 100644 index 0000000..bbabe2b --- /dev/null +++ b/src/crepe/api/map_asset.cpp @@ -0,0 +1,12 @@ + + + + +#include "map_asset.h" + +Map::Map(const std::string& content){ + this->m_content = content; +} + +Map::~Map(){ +} diff --git a/src/crepe/api/map_asset.h b/src/crepe/api/map_asset.h new file mode 100644 index 0000000..a3b994f --- /dev/null +++ b/src/crepe/api/map_asset.h @@ -0,0 +1,14 @@ +#pragma once + +#include "resource.h" +#include <string> + + +using namespace crepe::api; + +class Map : public Resource { + +public: + Map(const std::string& ); + ~Map(); +}; diff --git a/src/crepe/api/resource.h b/src/crepe/api/resource.h new file mode 100644 index 0000000..e6456f9 --- /dev/null +++ b/src/crepe/api/resource.h @@ -0,0 +1,23 @@ +#pragma once + + +#include <string> + +namespace crepe::api { + +class Resource{ + +public: + + virtual ~Resource() =default; + + const std::string& getContent() const{ + return this->m_content; + } + +protected: + std::string m_content; +}; + + +} diff --git a/src/crepe/api/resource_manager.cpp b/src/crepe/api/resource_manager.cpp new file mode 100644 index 0000000..a5644ee --- /dev/null +++ b/src/crepe/api/resource_manager.cpp @@ -0,0 +1,25 @@ + + +#include "resource_manager.h" +#include <string> +#include <unordered_map> + +using namespace crepe::api; + +ResourceManager* ResourceManager::get_instance(){ + static ResourceManager instance; + return &instance; +} + + +ResourceManager::~ResourceManager(){ + m_resources.clear(); +} + + +void ResourceManager::Unload(const std::string& file_path){ + if(m_resources.find(file_path) != m_resources.end()){ + m_resources.erase(file_path); + } +} + diff --git a/src/crepe/api/resource_manager.h b/src/crepe/api/resource_manager.h new file mode 100644 index 0000000..1b91524 --- /dev/null +++ b/src/crepe/api/resource_manager.h @@ -0,0 +1,59 @@ +#pragma once + + + +#include <memory> +#include <string> +#include <unordered_map> +#include <utility> + + +#include "api/resource.h" +#include "fabricator/resource_fabricator.h" + + + namespace crepe::api{ + +class ResourceManager{ + + +private: + + std::unordered_map< std::string, std::unique_ptr<api::Resource>> m_resources; + + +protected: + ResourceManager() = default; + ~ResourceManager(); + +public: + ResourceManager(const ResourceManager &) = delete; + ResourceManager(ResourceManager &&) = delete; + ResourceManager &operator=(const ResourceManager &) = delete; + ResourceManager &operator=(ResourceManager &&) = delete; + + static ResourceManager& get_instance(); + + + +public: + template<typename T> + T* Load(const std::string& file_path){ + + if (m_resources.find(file_path) != m_resources.end()) { + return static_cast<T*>(m_resources[file_path].get()); + } + + std::unique_ptr<api::Resource> resource = ResourceFactory::create_resource<T>(file_path); + if (resource) { + m_resources[file_path] = std::move(resource); + return static_cast<T*>(m_resources[file_path].get() ); + } + + return nullptr; + } + + void Unload(const std::string& file_path); + +}; +} diff --git a/src/crepe/api/spritesheet.cpp b/src/crepe/api/spritesheet.cpp new file mode 100644 index 0000000..f42a782 --- /dev/null +++ b/src/crepe/api/spritesheet.cpp @@ -0,0 +1,16 @@ + + +#include "spritesheet.h" + +#include <string> + +using namespace crepe::api; + +SpriteSheet::SpriteSheet(const std::string& content){ + this->m_content = content; +} + +SpriteSheet::~SpriteSheet(){ +} + + diff --git a/src/crepe/api/spritesheet.h b/src/crepe/api/spritesheet.h new file mode 100644 index 0000000..7f49156 --- /dev/null +++ b/src/crepe/api/spritesheet.h @@ -0,0 +1,21 @@ +#pragma once + + + + +#include "resource.h" +#include <string> + + +namespace crepe::api { + + + +class SpriteSheet : public Resource{ + +public: + SpriteSheet(const std::string&); + ~SpriteSheet(); + +}; +} |