SP3-102 SP3-248 Saving of SHMETA files with asset IDs, retrieval of asset data under works, currently all assets are loaded into memory automatically
This commit is contained in:
parent
bda38049ea
commit
b10f490e45
|
@ -0,0 +1,3 @@
|
|||
Name: Cube.003
|
||||
ID: 110152941
|
||||
Type:
|
|
@ -0,0 +1,3 @@
|
|||
Name: Cube.012
|
||||
ID: 107348815
|
||||
Type:
|
|
@ -0,0 +1,3 @@
|
|||
Name: RaccoonPreTexturedVer1_Base9
|
||||
ID: 91918845
|
||||
Type:
|
|
@ -104,10 +104,10 @@ namespace Sandbox
|
|||
|
||||
//TODO: REMOVE AFTER PRESENTATION
|
||||
//SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf");
|
||||
SHAssetManager::LoadDataTemp("../../Assets/Cube.012.shmesh");
|
||||
//SHAssetManager::LoadDataTemp("../../Assets/Cube.012.shmesh");
|
||||
//SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds");
|
||||
//SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds");
|
||||
SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.shtex");
|
||||
//SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.shtex");
|
||||
//TODO: REMOVE AFTER PRESENTATION
|
||||
|
||||
|
||||
|
@ -125,6 +125,8 @@ namespace Sandbox
|
|||
SHSceneManager::InitSceneManager<SBTestScene>("TestScene");
|
||||
|
||||
SHFrameRateController::UpdateFRC();
|
||||
|
||||
SHAssetManager::Load();
|
||||
}
|
||||
|
||||
void SBApplication::Update(void)
|
||||
|
@ -154,6 +156,7 @@ namespace Sandbox
|
|||
|
||||
SHSceneManager::Exit();
|
||||
SHSystemManager::Exit();
|
||||
SHAssetManager::Unload();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace SHADE
|
|||
{
|
||||
bool compiled;
|
||||
|
||||
std::string name;
|
||||
uint32_t numBytes;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include <fstream>
|
||||
|
||||
void SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept
|
||||
std::string SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept
|
||||
{
|
||||
std::string newPath{ path.string() };
|
||||
newPath = newPath.substr(0, newPath.find_last_of('/') + 1);
|
||||
|
@ -67,4 +67,6 @@ void SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPat
|
|||
);
|
||||
|
||||
file.close();
|
||||
|
||||
return newPath;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@ namespace SHADE
|
|||
{
|
||||
private:
|
||||
public:
|
||||
static void CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept;
|
||||
static std::string CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept;
|
||||
};
|
||||
}
|
|
@ -142,8 +142,7 @@ namespace SHADE
|
|||
SHLOG_ERROR("Unable to open SHMesh File: {}", path.string());
|
||||
}
|
||||
|
||||
std::string name{ path.filename().string() };
|
||||
name = name.substr(0, name.find_last_of('.'));
|
||||
const std::string name{ path.stem().string() };
|
||||
|
||||
file.seekg(0);
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace SHADE
|
|||
|
||||
static void LoadExternal(std::vector<SHMeshAsset>& meshes, AssetPath path) noexcept;
|
||||
|
||||
static void LoadSHMesh(SHMeshAsset& meshes, AssetPath path) noexcept;
|
||||
public:
|
||||
static void LoadMesh(std::vector<SHMeshAsset>& meshes, AssetPath path) noexcept;
|
||||
static void LoadSHMesh(SHMeshAsset& meshes, AssetPath path) noexcept;
|
||||
};
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
void SHTextureCompiler::CompileTextureBinary(SHTextureAsset const& asset, AssetPath path)
|
||||
std::string SHTextureCompiler::CompileTextureBinary(SHTextureAsset const& asset, AssetPath path)
|
||||
{
|
||||
std::string newPath{ path.string() };
|
||||
newPath = newPath.substr(0, newPath.find_last_of('.'));
|
||||
|
@ -69,5 +69,7 @@ namespace SHADE
|
|||
);
|
||||
|
||||
file.close();
|
||||
|
||||
return newPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ namespace SHADE
|
|||
{
|
||||
struct SHTextureCompiler
|
||||
{
|
||||
static void CompileTextureBinary(SHTextureAsset const& asset, AssetPath path);
|
||||
static std::string CompileTextureBinary(SHTextureAsset const& asset, AssetPath path);
|
||||
};
|
||||
}
|
|
@ -93,6 +93,7 @@ namespace SHADE
|
|||
std::memcpy(pixel, file.GetImageData()->m_mem, totalBytes);
|
||||
//pixel = std::move(reinterpret_cast<SHTexture::PixelChannel const*>(file.GetDDSData()));
|
||||
|
||||
asset.name = path.stem().string();
|
||||
asset.compiled = false;
|
||||
asset.numBytes = static_cast<uint32_t>(totalBytes);
|
||||
asset.width = file.GetWidth();
|
||||
|
|
|
@ -26,8 +26,8 @@ namespace SHADE
|
|||
|
||||
|
||||
static void LoadTinyDDS(AssetPath path, SHTextureAsset& asset) noexcept;
|
||||
static void LoadSHTexture(AssetPath path, SHTextureAsset& asset) noexcept;
|
||||
public:
|
||||
static void LoadImageAsset(AssetPath paths, SHTextureAsset& image);
|
||||
static void LoadSHTexture(AssetPath path, SHTextureAsset& asset) noexcept;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ typedef FMOD::Sound* SHSound;
|
|||
#define ASSET_META_VER "1.0"
|
||||
|
||||
// Asset type enum
|
||||
enum class AssetType : uint8_t
|
||||
enum class AssetType : AssetTypeMeta
|
||||
{
|
||||
INVALID = 0,
|
||||
AUDIO = 1,
|
||||
|
@ -57,7 +57,12 @@ enum class AssetType : uint8_t
|
|||
};
|
||||
|
||||
//Directory
|
||||
#define ASSET_ROOT "./Assets/"
|
||||
#ifdef _PUBLISH
|
||||
#define ASSET_ROOT "Assets"
|
||||
#else
|
||||
#define ASSET_ROOT "../../Assets"
|
||||
#endif
|
||||
|
||||
|
||||
// ASSET EXTENSIONS
|
||||
#define META_EXTENSION ".shmeta"
|
||||
|
|
|
@ -307,12 +307,22 @@ namespace SHADE
|
|||
|
||||
for (auto const& mesh : meshes)
|
||||
{
|
||||
meshCollection.emplace(GenerateAssetID(AssetType::MESH), mesh);
|
||||
auto id{ GenerateAssetID(AssetType::MESH) };
|
||||
meshCollection.emplace(id, mesh);
|
||||
|
||||
AssetPath path;
|
||||
if (!mesh.compiled)
|
||||
{
|
||||
SHMeshCompiler::CompileMeshBinary(mesh, asset.path);
|
||||
path = SHMeshCompiler::CompileMeshBinary(mesh, asset.path);
|
||||
}
|
||||
|
||||
assetCollection.emplace_back(
|
||||
mesh.header.meshName,
|
||||
id,
|
||||
AssetType::MESH,
|
||||
path,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,11 +332,20 @@ namespace SHADE
|
|||
|
||||
SHTextureLoader::LoadImageAsset(asset.path, image);
|
||||
|
||||
textureCollection.emplace(GenerateAssetID(AssetType::DDS), image);
|
||||
|
||||
if (!image.compiled)
|
||||
{
|
||||
SHTextureCompiler::CompileTextureBinary(image, asset.path);
|
||||
auto id{ GenerateAssetID(AssetType::TEXTURE) };
|
||||
textureCollection.emplace(id, image);
|
||||
|
||||
auto path{ SHTextureCompiler::CompileTextureBinary(image, asset.path) };
|
||||
|
||||
assetCollection.emplace_back(
|
||||
image.name,
|
||||
id,
|
||||
AssetType::TEXTURE,
|
||||
path,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -344,8 +363,24 @@ namespace SHADE
|
|||
****************************************************************************/
|
||||
void SHAssetManager::LoadAllData() noexcept
|
||||
{
|
||||
//TODO Remove when on demand loading is done
|
||||
for (auto const& asset : assetCollection)
|
||||
{
|
||||
switch (asset.type)
|
||||
{
|
||||
case AssetType::MESH:
|
||||
meshCollection.emplace(asset.id, SHMeshAsset());
|
||||
SHMeshLoader::LoadSHMesh(meshCollection[asset.id], asset.path);
|
||||
break;
|
||||
|
||||
case AssetType::TEXTURE:
|
||||
textureCollection.emplace(asset.id, SHTextureAsset());
|
||||
SHTextureLoader::LoadSHTexture(asset.path, textureCollection[asset.id]);
|
||||
break;
|
||||
|
||||
default:
|
||||
void;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,40 +397,51 @@ namespace SHADE
|
|||
std::vector<AssetPath> metaFiles;
|
||||
std::vector<AssetPath> AssetFiles;
|
||||
|
||||
//TODO: Write new function for file manager to loop through all files
|
||||
SHFileSystem::StartupFillDirectories(ASSET_ROOT);
|
||||
FolderPointer rootFolder = SHFileSystem::GetRoot();
|
||||
|
||||
for (auto const& meta : metaFiles)
|
||||
for (auto const dir : std::filesystem::recursive_directory_iterator(ASSET_ROOT))
|
||||
{
|
||||
for (std::vector<AssetPath>::const_iterator it{ AssetFiles.cbegin() };
|
||||
it != AssetFiles.cend();
|
||||
++it)
|
||||
if (dir.path().extension().string() == META_EXTENSION)
|
||||
{
|
||||
// Asset exists for meta file
|
||||
std::string fileExtCheck{ it->filename().string() };
|
||||
fileExtCheck += META_EXTENSION;
|
||||
if (meta.filename().string() == fileExtCheck)
|
||||
{
|
||||
RegisterAsset(meta, *it);
|
||||
AssetFiles.erase(it);
|
||||
break;
|
||||
}
|
||||
auto meta{ SHAssetMetaHandler::RetrieveMetaData(dir.path()) };
|
||||
|
||||
assetCollection.push_back(meta);
|
||||
assetRegistry.emplace(meta.id, meta);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Write new function for file manager to loop through all files
|
||||
//SHFileSystem::StartupFillDirectories(ASSET_ROOT);
|
||||
//FolderPointer rootFolder = SHFileSystem::GetRoot();
|
||||
|
||||
//for (auto const& meta : metaFiles)
|
||||
//{
|
||||
// for (std::vector<AssetPath>::const_iterator it{ AssetFiles.cbegin() };
|
||||
// it != AssetFiles.cend();
|
||||
// ++it)
|
||||
// {
|
||||
// // Asset exists for meta file
|
||||
// std::string fileExtCheck{ it->filename().string() };
|
||||
// fileExtCheck += META_EXTENSION;
|
||||
// if (meta.filename().string() == fileExtCheck)
|
||||
// {
|
||||
// RegisterAsset(meta, *it);
|
||||
// AssetFiles.erase(it);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//TODO: Handle if meta does not match all assets (if meta exist and asset doesnt, vice versa)
|
||||
for (auto const& file : AssetFiles)
|
||||
{
|
||||
if (IsRecognised(file.extension().string().c_str()))
|
||||
{
|
||||
SHAssetMetaHandler::WriteMetaData(RegisterAssetNew(file));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Unsupported File Format: " << file.filename() << "\n";
|
||||
}
|
||||
}
|
||||
//for (auto const& file : AssetFiles)
|
||||
//{
|
||||
// if (IsRecognised(file.extension().string().c_str()))
|
||||
// {
|
||||
// SHAssetMetaHandler::WriteMetaData(RegisterAssetNew(file));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// std::cout << "Unsupported File Format: " << file.filename() << "\n";
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
AssetID SHAssetManager::RetrieveAsset(char const* path) noexcept
|
||||
|
|
|
@ -72,6 +72,13 @@ namespace SHADE
|
|||
std::string line;
|
||||
SHAsset meta;
|
||||
|
||||
// Get resource name
|
||||
GetFieldValue(metaFile, line);
|
||||
std::stringstream nameStream{ line };
|
||||
AssetName name;
|
||||
nameStream >> name;
|
||||
meta.name = name;
|
||||
|
||||
// Get resource id
|
||||
GetFieldValue(metaFile, line);
|
||||
std::stringstream idStream{ line };
|
||||
|
@ -88,6 +95,8 @@ namespace SHADE
|
|||
|
||||
metaFile.close();
|
||||
|
||||
meta.path = path.parent_path().string() + "/" + path.stem().string();
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
|
@ -103,7 +112,7 @@ namespace SHADE
|
|||
std::string path{ meta.path.string() };
|
||||
path.append(META_EXTENSION);
|
||||
|
||||
std::ofstream metaFile{ path, std::ios_base::out };
|
||||
std::ofstream metaFile{ path, std::ios_base::out | std::ios_base::trunc };
|
||||
|
||||
if (!metaFile.is_open())
|
||||
{
|
||||
|
@ -113,17 +122,17 @@ namespace SHADE
|
|||
|
||||
metaFile << "Name: " << meta.name << "\n";
|
||||
metaFile << "ID: " << meta.id << "\n";
|
||||
metaFile << "Type: " << static_cast<int>(meta.type) << std::endl;
|
||||
metaFile << "Type: " << static_cast<AssetTypeMeta>(meta.type) << std::endl;
|
||||
|
||||
//TODO Add in information that is specific to types like mesh
|
||||
switch(meta.type)
|
||||
{
|
||||
case AssetType::MESH:
|
||||
break;
|
||||
////TODO Add in information that is specific to types like mesh
|
||||
//switch(meta.type)
|
||||
//{
|
||||
//case AssetType::MESH:
|
||||
// break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//default:
|
||||
// break;
|
||||
//}
|
||||
|
||||
metaFile.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue