Asset Manager restructure #123

Merged
XiaoQiDigipen merged 14 commits from SP3-13-Assets-Manager into main 2022-10-27 14:27:27 +08:00
18 changed files with 52 additions and 31 deletions
Showing only changes of commit 2dbd2f6030 - Show all commits

View File

@ -13,9 +13,9 @@
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <vector> #include <vector>
#include "../SHAssetMacros.h" #include "Assets/SHAssetMacros.h"
#include "../Asset Types/SHMeshAsset.h" #include "Assets/Asset Types/SHMeshAsset.h"
#include "../Asset Types/SHAnimationAsset.h" #include "Assets/Asset Types/SHAnimationAsset.h"
namespace SHADE namespace SHADE
{ {

View File

@ -21,7 +21,7 @@ namespace SHADE
{ {
std::string SHShaderSourceCompiler::CompileShaderSourceToBinary(AssetPath path, SHShaderAsset const& data) noexcept std::string SHShaderSourceCompiler::CompileShaderSourceToBinary(AssetPath path, SHShaderAsset const& data) noexcept
{ {
std::string newPath{ path.string() + SHADER_SPRV_EXTENSION.data() }; std::string newPath{ path.string() + SHADER_EXTENSION.data() };
std::ofstream file{ newPath, std::ios::binary | std::ios::out | std::ios::trunc }; std::ofstream file{ newPath, std::ios::binary | std::ios::out | std::ios::trunc };

View File

@ -10,8 +10,8 @@
* of DigiPen Institute of Technology is prohibited. * of DigiPen Institute of Technology is prohibited.
*****************************************************************************/ *****************************************************************************/
#pragma once #pragma once
#include "../SHAssetMacros.h" #include "Assets/SHAssetMacros.h"
#include "../Asset Types/SHMeshAsset.h" #include "Assets/Asset Types/SHMeshAsset.h"
#include "SHAssetLoader.h" #include "SHAssetLoader.h"
namespace SHADE namespace SHADE

View File

@ -10,7 +10,7 @@
*****************************************************************************/ *****************************************************************************/
#pragma once #pragma once
#include "Assets/Libraries/SHAssetLoader.h" #include "Assets/Libraries/Loaders/SHAssetLoader.h"
#include "Assets/SHAssetMacros.h" #include "Assets/SHAssetMacros.h"
namespace SHADE namespace SHADE

View File

@ -12,8 +12,8 @@
#pragma once #pragma once
#define TINYDDSLOADER_IMPLEMENTATION #define TINYDDSLOADER_IMPLEMENTATION
#include "../SHAssetMacros.h" #include "Assets/SHAssetMacros.h"
#include "../Asset Types/SHTextureAsset.h" #include "Assets/Asset Types/SHTextureAsset.h"
#include "tinyddsloader.h" #include "tinyddsloader.h"
#include "SHAssetLoader.h" #include "SHAssetLoader.h"

View File

@ -68,34 +68,39 @@ constexpr std::string_view ASSET_ROOT {"../../Assets"};
// ASSET EXTENSIONS // ASSET EXTENSIONS
constexpr std::string_view META_EXTENSION {".shmeta"}; constexpr std::string_view META_EXTENSION {".shmeta"};
constexpr std::string_view IMAGE_EXTENSION {".png"};
constexpr std::string_view AUDIO_EXTENSION {".ogg"}; constexpr std::string_view AUDIO_EXTENSION {".ogg"};
constexpr std::string_view AUDIO_WAV_EXTENSION {".wav"}; constexpr std::string_view AUDIO_WAV_EXTENSION {".wav"};
constexpr std::string_view SHADER_EXTENSION{ ".glsl" }; constexpr std::string_view SHADER_EXTENSION{".shshader"};
constexpr std::string_view SHADER_SPRV_EXTENSION {".sprv"};
constexpr std::string_view SCRIPT_EXTENSION {".cs"}; constexpr std::string_view SCRIPT_EXTENSION {".cs"};
constexpr std::string_view SCENE_EXTENSION {".SHADE"}; constexpr std::string_view SCENE_EXTENSION {".shade"};
constexpr std::string_view PREFAB_EXTENSION {".SHPrefab"}; constexpr std::string_view PREFAB_EXTENSION {".shprefab"};
constexpr std::string_view MATERIAL_EXTENSION {".SHMat"}; constexpr std::string_view MATERIAL_EXTENSION {".shmat"};
constexpr std::string_view TEXTURE_EXTENSION {".shtex"}; constexpr std::string_view TEXTURE_EXTENSION {".shtex"};
constexpr std::string_view DDS_EXTENSION {".dds"};
constexpr std::string_view FBX_EXTENSION {".fbx"};
constexpr std::string_view GLTF_EXTENSION {".gltf"};
constexpr std::string_view MESH_EXTENSION {".shmesh"}; constexpr std::string_view MESH_EXTENSION {".shmesh"};
// EXTERNAL EXTENSIONS
constexpr std::string_view GLSL_EXTENSION{ ".glsl" };
constexpr std::string_view IMAGE_EXTENSION{ ".png" };
constexpr std::string_view DDS_EXTENSION{ ".dds" };
constexpr std::string_view FBX_EXTENSION{ ".fbx" };
constexpr std::string_view GLTF_EXTENSION{ ".gltf" };
constexpr std::string_view EXTENSIONS[] = { constexpr std::string_view EXTENSIONS[] = {
AUDIO_EXTENSION, AUDIO_EXTENSION,
SHADER_EXTENSION, SHADER_EXTENSION,
SHADER_SPRV_EXTENSION,
MATERIAL_EXTENSION, MATERIAL_EXTENSION,
IMAGE_EXTENSION,
TEXTURE_EXTENSION, TEXTURE_EXTENSION,
DDS_EXTENSION,
MESH_EXTENSION, MESH_EXTENSION,
SCRIPT_EXTENSION, SCRIPT_EXTENSION,
SCENE_EXTENSION, SCENE_EXTENSION,
PREFAB_EXTENSION, PREFAB_EXTENSION,
AUDIO_WAV_EXTENSION, AUDIO_WAV_EXTENSION,
};
constexpr std::string_view EXTERNALS[] = {
GLSL_EXTENSION,
IMAGE_EXTENSION,
DDS_EXTENSION,
FBX_EXTENSION, FBX_EXTENSION,
GLTF_EXTENSION GLTF_EXTENSION
}; };

View File

@ -14,13 +14,14 @@
#include "SHAssetMetaHandler.h" #include "SHAssetMetaHandler.h"
#include "Filesystem/SHFileSystem.h" #include "Filesystem/SHFileSystem.h"
#include "Libraries/SHAssimpLibrary.h" #include "Libraries/Loaders/SHMeshLoader.h"
#include "Libraries/SHMeshLoader.h" #include "Libraries/Loaders/SHTextureLoader.h"
#include "Libraries/SHTextureLoader.h" #include "Libraries/Loaders/SHShaderSourceLoader.h"
#include "Libraries/SHShaderSourceLoader.h"
#include "Libraries/SHMeshCompiler.h"
#include "Libraries/SHTextureCompiler.h" #include "Libraries/Compilers/SHAssimpLibrary.h"
#include "Libraries/Compilers/SHMeshCompiler.h"
#include "Libraries/Compilers/SHTextureCompiler.h"
namespace SHADE namespace SHADE
{ {
@ -65,7 +66,20 @@ namespace SHADE
// TODO // TODO
} }
AssetPath SHAssetManager::GenerateLocalPath(AssetPath path) noexcept void SHAssetManager::Exit() noexcept
{
for (auto const& loader : loaders)
{
delete loader;
}
for (auto const& data : assetData)
{
delete data.second;
}
}
AssetPath SHAssetManager::GenerateLocalPath(AssetPath path) noexcept
{ {
if (!IsRecognised(path.extension().string().c_str())) if (!IsRecognised(path.extension().string().c_str()))
{ {
@ -255,6 +269,7 @@ namespace SHADE
result.type = SHAssetMetaHandler::GetTypeFromExtension(path.extension().string()); result.type = SHAssetMetaHandler::GetTypeFromExtension(path.extension().string());
result.id = GenerateAssetID(result.type); result.id = GenerateAssetID(result.type);
result.path = path; result.path = path;
result.location = 0;
return result; return result;
} }
@ -264,8 +279,7 @@ namespace SHADE
loaders[static_cast<size_t>(AssetType::AUDIO)] = nullptr; loaders[static_cast<size_t>(AssetType::AUDIO)] = nullptr;
loaders[static_cast<size_t>(AssetType::SHADER)] = dynamic_cast<SHAssetLoader*>(new SHShaderSourceLoader()); loaders[static_cast<size_t>(AssetType::SHADER)] = dynamic_cast<SHAssetLoader*>(new SHShaderSourceLoader());
loaders[static_cast<size_t>(AssetType::MATERIAL)] = nullptr; loaders[static_cast<size_t>(AssetType::MATERIAL)] = nullptr;
loaders[static_cast<size_t>(AssetType::IMAGE)] = dynamic_cast<SHAssetLoader*>(new SHTextureLoader()); loaders[static_cast<size_t>(AssetType::TEXTURE)] = dynamic_cast<SHAssetLoader*>(new SHTextureLoader());
loaders[static_cast<size_t>(AssetType::TEXTURE)] = nullptr;
loaders[static_cast<size_t>(AssetType::MESH)] = dynamic_cast<SHAssetLoader*>(new SHMeshLoader()); loaders[static_cast<size_t>(AssetType::MESH)] = dynamic_cast<SHAssetLoader*>(new SHMeshLoader());
loaders[static_cast<size_t>(AssetType::SCRIPT)] = nullptr; loaders[static_cast<size_t>(AssetType::SCRIPT)] = nullptr;
loaders[static_cast<size_t>(AssetType::SCENE)] = nullptr; loaders[static_cast<size_t>(AssetType::SCENE)] = nullptr;

View File

@ -12,7 +12,7 @@
#include "tinyddsloader.h" #include "tinyddsloader.h"
#include "SHAsset.h" #include "SHAsset.h"
#include "Asset Types/SHAssetData.h" #include "Asset Types/SHAssetData.h"
#include "Libraries/SHAssetLoader.h" #include "Assets/Libraries/Loaders/SHAssetLoader.h"
#include <memory> #include <memory>
#include "SH_API.h" #include "SH_API.h"
@ -37,6 +37,8 @@ namespace SHADE
static void Unload() noexcept; static void Unload() noexcept;
static void Unload(AssetID assetId) noexcept; static void Unload(AssetID assetId) noexcept;
static void Exit() noexcept;
/**************************************************************************** /****************************************************************************
* \brief Load all resources that are in the folder * \brief Load all resources that are in the folder
****************************************************************************/ ****************************************************************************/