Files
Seele/src/Engine/Asset/AssetRegistry.h
T

91 lines
3.2 KiB
C++
Raw Normal View History

2020-06-02 11:46:18 +02:00
#pragma once
#include "MinimalEngine.h"
#include "Asset.h"
2023-02-13 14:56:13 +01:00
#include "Containers/Map.h"
2020-06-02 11:46:18 +02:00
#include <string>
namespace Seele
{
2021-04-01 16:40:14 +02:00
DECLARE_REF(TextureLoader)
2022-04-13 13:01:35 +02:00
DECLARE_REF(FontLoader)
2021-04-01 16:40:14 +02:00
DECLARE_REF(MeshLoader)
DECLARE_REF(MaterialLoader)
DECLARE_REF(TextureAsset)
2022-04-13 13:01:35 +02:00
DECLARE_REF(FontAsset)
2021-04-01 16:40:14 +02:00
DECLARE_REF(MeshAsset)
DECLARE_REF(MaterialAsset)
DECLARE_NAME_REF(Gfx, Graphics)
2023-02-01 22:13:04 +01:00
2020-06-02 11:46:18 +02:00
class AssetRegistry
{
public:
~AssetRegistry();
2023-01-29 18:58:59 +01:00
static void init(const std::string& rootFolder, Gfx::PGraphics graphics);
2020-06-02 11:46:18 +02:00
2023-02-13 14:56:13 +01:00
static std::filesystem::path getRootFolder();
2020-09-19 14:36:50 +02:00
2020-06-02 11:46:18 +02:00
static PMeshAsset findMesh(const std::string& filePath);
static PTextureAsset findTexture(const std::string& filePath);
2022-04-13 13:01:35 +02:00
static PFontAsset findFont(const std::string& name);
2020-06-02 11:46:18 +02:00
static PMaterialAsset findMaterial(const std::string& filePath);
2020-09-19 14:36:50 +02:00
2021-04-01 16:40:14 +02:00
static std::ofstream createWriteStream(const std::string& relativePath, std::ios_base::openmode openmode = std::ios::out);
static std::ifstream createReadStream(const std::string& relativePath, std::ios_base::openmode openmode = std::ios::in);
2023-02-01 22:13:04 +01:00
static void importMesh(struct MeshImportArgs args);
static void importTexture(struct TextureImportArgs args);
static void importFont(struct FontImportArgs args);
static void importMaterial(struct MaterialImportArgs args);
static void set(AssetRegistry registry);
2023-02-13 14:56:13 +01:00
static void loadRegistry();
static void saveRegistry();
2023-02-01 22:13:04 +01:00
AssetRegistry();
2020-06-02 11:46:18 +02:00
private:
2023-01-21 18:43:21 +01:00
struct AssetFolder
{
2023-02-13 14:56:13 +01:00
std::string folderPath;
Map<std::string, AssetFolder*> children;
2023-01-21 18:43:21 +01:00
//Todo: Seele::Map doesn't really work with strings for some reason, so just use std::map for now
2023-02-13 14:56:13 +01:00
Map<std::string, PTextureAsset> textures;
Map<std::string, PFontAsset> fonts;
Map<std::string, PMeshAsset> meshes;
Map<std::string, PMaterialAsset> materials;
AssetFolder(std::string_view folderPath);
~AssetFolder();
2023-01-21 18:43:21 +01:00
};
2020-06-02 11:46:18 +02:00
static AssetRegistry& get();
2023-01-29 18:58:59 +01:00
void initialize(const std::filesystem::path& rootFolder, Gfx::PGraphics graphics);
2023-02-13 14:56:13 +01:00
void loadRegistryInternal();
void peekFolder(AssetFolder* folder);
void loadFolder(AssetFolder* folder);
void saveRegistryInternal();
void saveFolder(const std::filesystem::path& folderPath, AssetFolder* folder);
void saveAsset(PAsset asset, uint64 identifier, const std::filesystem::path& folderPath, std::string name);
2020-06-02 11:46:18 +02:00
2023-02-13 14:56:13 +01:00
void registerMesh(PMeshAsset mesh);
void registerTexture(PTextureAsset texture);
void registerFont(PFontAsset font);
void registerMaterial(PMaterialAsset material);
2020-09-19 14:36:50 +02:00
2023-02-13 14:56:13 +01:00
AssetFolder* getOrCreateFolder(std::string foldername);
2020-09-19 14:36:50 +02:00
2021-04-01 16:40:14 +02:00
std::ofstream internalCreateWriteStream(const std::string& relativePath, std::ios_base::openmode openmode = std::ios::out);
std::ifstream internalCreateReadStream(const std::string& relaitvePath, std::ios_base::openmode openmode = std::ios::in);
2020-09-19 14:36:50 +02:00
2020-06-08 01:44:47 +02:00
std::filesystem::path rootFolder;
2023-02-13 14:56:13 +01:00
AssetFolder* assetRoot;
2023-01-29 18:58:59 +01:00
Gfx::PGraphics graphics;
2020-06-02 11:46:18 +02:00
UPTextureLoader textureLoader;
2022-04-13 13:01:35 +02:00
UPFontLoader fontLoader;
2020-06-02 11:46:18 +02:00
UPMeshLoader meshLoader;
UPMaterialLoader materialLoader;
friend class TextureLoader;
2022-04-13 13:01:35 +02:00
friend class FontLoader;
2020-06-02 11:46:18 +02:00
friend class MaterialLoader;
friend class MeshLoader;
};
}