aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/CMakeLists.txt1
-rw-r--r--src/crepe/api/Audio_asset.cpp16
-rw-r--r--src/crepe/api/Audio_asset.h18
-rw-r--r--src/crepe/api/CMakeLists.txt17
-rw-r--r--src/crepe/api/Image_asset.cpp14
-rw-r--r--src/crepe/api/Image_asset.h18
-rw-r--r--src/crepe/api/map_asset.cpp12
-rw-r--r--src/crepe/api/map_asset.h14
-rw-r--r--src/crepe/api/resource.h23
-rw-r--r--src/crepe/api/resource_manager.cpp25
-rw-r--r--src/crepe/api/resource_manager.h59
-rw-r--r--src/crepe/api/spritesheet.cpp16
-rw-r--r--src/crepe/api/spritesheet.h21
-rw-r--r--src/crepe/fabricator/CMakeLists.txt8
-rw-r--r--src/crepe/fabricator/resource_fabricator.cpp26
-rw-r--r--src/crepe/fabricator/resource_fabricator.h29
16 files changed, 312 insertions, 5 deletions
diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt
index 3a60840..ed6ebe5 100644
--- a/src/crepe/CMakeLists.txt
+++ b/src/crepe/CMakeLists.txt
@@ -10,4 +10,5 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
add_subdirectory(api)
add_subdirectory(util)
+add_subdirectory(fabricator)
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();
+
+};
+}
diff --git a/src/crepe/fabricator/CMakeLists.txt b/src/crepe/fabricator/CMakeLists.txt
new file mode 100644
index 0000000..4fd7eea
--- /dev/null
+++ b/src/crepe/fabricator/CMakeLists.txt
@@ -0,0 +1,8 @@
+target_sources(crepe PUBLIC
+ resource_fabricator.cpp
+)
+
+target_sources(crepe PUBLIC FILE_SET HEADERS FILES
+ resource_fabricator.h
+)
+
diff --git a/src/crepe/fabricator/resource_fabricator.cpp b/src/crepe/fabricator/resource_fabricator.cpp
new file mode 100644
index 0000000..0633a40
--- /dev/null
+++ b/src/crepe/fabricator/resource_fabricator.cpp
@@ -0,0 +1,26 @@
+
+
+#include "resource_fabricator.h"
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <vector>
+
+
+
+
+std::string ResourceFactory::convert_file_to_string(const std::string& path){
+ std::ifstream file(path, std::ios::binary | std::ios::ate);
+ if (!file.is_open()) {
+ std::cerr << "Failed to open file: " << path << std::endl;
+ return "";
+ }
+
+ std::ifstream::pos_type fileSize = file.tellg();
+ file.seekg(0, std::ios::beg);
+
+ std::vector<char> bytes(fileSize);
+ file.read(bytes.data(), fileSize);
+
+ return std::string(bytes.begin(), bytes.end());
+}
diff --git a/src/crepe/fabricator/resource_fabricator.h b/src/crepe/fabricator/resource_fabricator.h
new file mode 100644
index 0000000..9299ed3
--- /dev/null
+++ b/src/crepe/fabricator/resource_fabricator.h
@@ -0,0 +1,29 @@
+#pragma once
+
+
+
+#include "api/resource.h"
+#include <memory>
+#include <string>
+
+
+
+
+class ResourceFactory {
+
+public:
+
+ template<typename T>
+ static std::unique_ptr<crepe::api::Resource> create_resource(const std::string& file_path){
+
+ return std::make_unique<T>(convert_file_to_string(file_path));
+ }
+
+private:
+ static std::string convert_file_to_string(const std::string& path);
+
+};
+
+
+
+