Copperfield Engine 0.1
C++ Game Engine
Loading...
Searching...
No Matches
resource_manager.hpp
Go to the documentation of this file.
1#pragma once
2#include <future>
3#include <unordered_map>
4
5#include "buffer.hpp"
6#include "load_obj.hpp"
7#include "math/vector_2.h"
8#include "math/vector_3.h"
9#include "texture.hpp"
10#include "globals.hpp"
11#include "sound/soundbuffer.h"
12
13class JobSystem;
14class Engine;
15
18
20enum class ResourceType {
21 kMesh,
22 kTexture,
23 kSound,
24};
25
28public:
29 friend Engine;
30
31 ResourceManager(JobSystem& jobs);
33
35 ResourceManager(const ResourceManager& other) = delete;
42
51 void loadResource(const ResourceType& resource_type,
52 const std::string& file_path,
53 const std::string& identifier);
54
60
66 const Mesh& getMesh(const std::string& id) const;
67
73 const Mesh& getMesh(const BasicMesh id) const;
74
80 const Texture& getTexture(const std::string& id) const;
81
86 const Texture& getEmptyTexture() const;
87
93 const SoundBuffer& getSound(const std::string& id) const;
94
95
96
97
98 bool addMesh(const std::string& id, const std::vector<coma::Vec3>& pos,
99 const std::vector<coma::Vec3>& normal,
100 const std::vector<coma::Vec3>& color,
101 const std::vector<coma::Vec2>& uv,
102 const std::vector<unsigned int>& indices);
103
104 bool addTexture(const std::string& id, const unsigned int tex_id,
105 const Format internal_format,
106 const ColorFormat color_format, const Filter min_filter,
107 const Filter mag_filter, const Wrap wrap_s, const Wrap wrap_t,
108 const Wrap wrap_r, const DataType data_type);
109
110 bool addSound(const std::string& id, int buffid, SoundData sound_info_);
111
112private:
113
114 JobSystem* job_system_;
115 std::vector<std::future<std::optional<Obj>>> loading_meshes_;
116 std::vector<std::future<std::optional<Texture>>> loading_textures_;
117 std::vector<std::future<std::optional<SoundBuffer>>> loading_sounds_;
118 std::unordered_map<std::string, Mesh> meshes_;
119 std::unordered_map<std::string, Texture> textures_;
120 std::unordered_map<std::string, SoundBuffer> soundbuffers_;
121};
Intiliazes the ComponentManager and the ResourceManager and ofers functions to retrieve them.
Definition: engine.hpp:12
Stores and offers access to all meshes, textures, and sounds of the engine.
Definition: resource_manager.hpp:27
ResourceManager & operator=(ResourceManager &&other)=delete
Move assignment operator (deleted).
ResourceManager & operator=(ResourceManager &other)=delete
Copy assignment operator (deleted).
const SoundBuffer & getSound(const std::string &id) const
Retrieve a SoundBuffer.
void loadResource(const ResourceType &resource_type, const std::string &file_path, const std::string &identifier)
Load an external asset from a file using multithreading.
bool WaitResourceLoad()
Stops the program, waiting for resource loading to complete.
ResourceManager(ResourceManager &&other)=delete
Move constructor (deleted).
const Texture & getEmptyTexture() const
Retrieve a white texture.
const Mesh & getMesh(const BasicMesh id) const
Retrieve a mesh.
ResourceManager(const ResourceManager &other)=delete
Copy constructor (deleted).
const Texture & getTexture(const std::string &id) const
Retrieve a texture.
const Mesh & getMesh(const std::string &id) const
Retrieve a mesh.
contains globally accessible enums
BasicMesh
meshed loaded by default by the engine
Definition: globals.hpp:141
ResourceType
Types of resources to load.
Definition: resource_manager.hpp:20
@ kSound
Sound accepts .wav.
@ kTexture
Texture accepts .png and .jpg.
@ kMesh
Mesh accepts .obj.