diff --git a/SHADE_Engine/src/Assets/Asset Types/SHNavDataAsset.h b/SHADE_Engine/src/Assets/Asset Types/SHNavDataAsset.h new file mode 100644 index 00000000..650c6136 --- /dev/null +++ b/SHADE_Engine/src/Assets/Asset Types/SHNavDataAsset.h @@ -0,0 +1,30 @@ +/*************************************************************************//** + * \file SHNavDataAsset.h + * \author Loh Xiao Qi + * \date 20 March 2023 + * \brief + * + * Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. + *****************************************************************************/ +#pragma once + +#include "SH_API.h" + +#include + +#include "Math/Vector/SHVec3.h" +#include "SHAssetData.h" + +namespace SHADE +{ + struct SH_API SHNavDataAsset : SHAssetData + { + uint16_t rows; + uint16_t cols; + SHVec3 origin; + SHVec3 size; + std::vector grid; + }; +} diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.cpp index a8663dde..b1ccde87 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.cpp @@ -5,8 +5,12 @@ #include +#include "Assets/Asset Types/SHNavDataAsset.h" + namespace SHADE { + struct SHNavDataAsset; + SHAssetData* SHBinaryLoader::Load(AssetPath path) { std::ifstream file{ path, std::ios::in | std::ios::binary }; @@ -21,7 +25,11 @@ namespace SHADE if (extension == ANIM_CONTAINER_EXTENSION) { - LoadAnimClipContainer(file, result, path); + LoadAnimClipContainer(file, result); + } + else if(extension == NAV_DATA_EXTENSION) + { + LoadNavData(file, result); } file.close(); @@ -43,13 +51,17 @@ namespace SHADE if (extension == ANIM_CONTAINER_EXTENSION) { - WriteAnimClipContainer(file, data, path); + WriteAnimClipContainer(file, data); + } + else if(extension == NAV_DATA_EXTENSION) + { + WriteNavData(file, data); } file.close(); } - void SHBinaryLoader::WriteAnimClipContainer(std::ofstream& file, SHAssetData const* data, AssetPath path) + void SHBinaryLoader::WriteAnimClipContainer(std::ofstream& file, SHAssetData const* data) { auto const& anim = *dynamic_cast(data); file.write( @@ -84,7 +96,7 @@ namespace SHADE } } - void SHBinaryLoader::LoadAnimClipContainer(std::ifstream& file, SHAssetData*& result, AssetPath path) + void SHBinaryLoader::LoadAnimClipContainer(std::ifstream& file, SHAssetData*& result) { auto const data = new SHAnimClipContainerAsset(); @@ -126,4 +138,58 @@ namespace SHADE result = data; } + + void SHBinaryLoader::WriteNavData(std::ofstream& file, SHAssetData const* data) + { + auto const& navData = *reinterpret_cast(data); + file.write( + reinterpret_cast(&navData.rows), + sizeof(uint32_t) + ); + + file.write( + reinterpret_cast(&navData.origin), + sizeof(SHVec3) * 2 + ); + + auto const count {navData.grid.size()}; + file.write( + reinterpret_cast(&count), + sizeof(count) + ); + + file.write( + reinterpret_cast(navData.grid.data()), + count + ); + } + + void SHBinaryLoader::LoadNavData(std::ifstream& file, SHAssetData*& result) + { + auto const data = new SHNavDataAsset(); + + file.read( + reinterpret_cast(&data->rows), + sizeof(uint32_t) + ); + + file.read( + reinterpret_cast(&data->origin), + sizeof(SHVec3) * 2 + ); + + size_t count; + file.read( + reinterpret_cast(&count), + sizeof(size_t) + ); + + data->grid.resize(count); + file.read( + reinterpret_cast(data->grid.data()), + count + ); + + result = data; + } } diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.h b/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.h index 5689901d..fa3daf64 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.h +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.h @@ -11,7 +11,10 @@ namespace SHADE private: //Individual functions to write files - void WriteAnimClipContainer(std::ofstream& file,SHAssetData const* data, AssetPath path); - void LoadAnimClipContainer(std::ifstream& file,SHAssetData*& result, AssetPath path); + void WriteAnimClipContainer(std::ofstream& file,SHAssetData const* data); + void LoadAnimClipContainer(std::ifstream& file,SHAssetData*& result); + + void WriteNavData(std::ofstream& file, SHAssetData const* data); + void LoadNavData(std::ifstream& file, SHAssetData*& result); }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/SHAssetMacros.h b/SHADE_Engine/src/Assets/SHAssetMacros.h index f12cc56f..0616471c 100644 --- a/SHADE_Engine/src/Assets/SHAssetMacros.h +++ b/SHADE_Engine/src/Assets/SHAssetMacros.h @@ -61,6 +61,7 @@ enum class AssetType : AssetTypeMeta ANIM_CONTAINER, ANIM_CLIP, ANIM_CONTROLLER, + NAV_DATA, MAX_COUNT }; constexpr size_t TYPE_COUNT{ static_cast(AssetType::MAX_COUNT) }; @@ -84,6 +85,7 @@ constexpr std::string_view PREFAB_FOLDER{ "/Prefabs/" }; constexpr std::string_view MATERIAL_FOLDER{ "/Materials/" }; constexpr std::string_view ANIM_CLIP_FOLDER{ "/Animation Clips/" }; constexpr std::string_view ANIM_CONTROLLER_FOLDER{ "/Animation Controllers/" }; +constexpr std::string_view NAV_DATA_FOLDER{ "/Navigation Data/" }; // ASSET EXTENSIONS @@ -102,6 +104,7 @@ constexpr std::string_view TEXTURE_EXTENSION {".shtex"}; constexpr std::string_view MODEL_EXTENSION{ ".shmodel" }; constexpr std::string_view ANIM_CONTAINER_EXTENSION{ ".shanimcontainer" }; constexpr std::string_view ANIM_CONTROLLER_EXTENSION{ ".shanimcontroller" }; +constexpr std::string_view NAV_DATA_EXTENSION{ ".shnav" }; constexpr std::string_view FILLER_EXTENSION{"dummy"}; constexpr std::string_view EXTENSIONS[] = { @@ -119,7 +122,8 @@ constexpr std::string_view EXTENSIONS[] = { AUDIO_BANK_EXTENSION, ANIM_CONTAINER_EXTENSION, ANIM_CONTROLLER_EXTENSION, - FILLER_EXTENSION + FILLER_EXTENSION, + NAV_DATA_EXTENSION }; constexpr size_t EXTENSIONS_COUNT{ static_cast(AssetType::MAX_COUNT) }; diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index dc9d9587..14b5b0a7 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -33,6 +33,8 @@ #include "Filesystem/SHFileSystem.h" #include + +#include "Asset Types/SHNavDataAsset.h" #include "Assets/Events/SHAssetManagerEvents.h" #include "Events/SHEventManager.hpp" @@ -259,6 +261,17 @@ namespace SHADE } break; + case AssetType::NAV_DATA: + newPath += NAV_DATA_FOLDER; + newPath += name; + newPath += NAV_DATA_EXTENSION; + + { + auto navData = new SHNavDataAsset(); + data = navData; + } + break; + default: SHLOG_ERROR("[Asset Manager] Asset type of {} not an internal parent asset type, cannot be created", name); return 0; @@ -336,7 +349,8 @@ namespace SHADE asset.type == AssetType::SCENE || asset.type == AssetType::PREFAB || asset.type == AssetType::MATERIAL || - asset.type == AssetType::ANIM_CONTAINER + asset.type == AssetType::ANIM_CONTAINER || + asset.type == AssetType::NAV_DATA ) { if (assetData.contains(id)) @@ -585,17 +599,20 @@ namespace SHADE void SHAssetManager:: InitLoaders() noexcept { loaders[static_cast(AssetType::SHADER)] = dynamic_cast(new SHShaderSourceLoader()); - loaders[static_cast(AssetType::SHADER_BUILT_IN)] = loaders[static_cast(AssetType::SHADER)]; loaders[static_cast(AssetType::TEXTURE)] = dynamic_cast(new SHTextureLoader()); loaders[static_cast(AssetType::MODEL)] = dynamic_cast(new SHModelLoader()); loaders[static_cast(AssetType::SCENE)] = dynamic_cast(new SHTextBasedLoader()); + loaders[static_cast(AssetType::FONT)] = dynamic_cast(new SHFontLoader()); + loaders[static_cast(AssetType::ANIM_CONTAINER)] = dynamic_cast(new SHBinaryLoader()); + loaders[static_cast(AssetType::PREFAB)] = loaders[static_cast(AssetType::SCENE)]; loaders[static_cast(AssetType::MATERIAL)] = loaders[static_cast(AssetType::SCENE)]; + loaders[static_cast(AssetType::AUDIO_BANK)] = loaders[static_cast(AssetType::SCENE)]; + loaders[static_cast(AssetType::SHADER_BUILT_IN)] = loaders[static_cast(AssetType::SHADER)]; + loaders[static_cast(AssetType::NAV_DATA)] = loaders[static_cast(AssetType::ANIM_CONTAINER)]; + loaders[static_cast(AssetType::MESH)] = nullptr; loaders[static_cast(AssetType::SCRIPT)] = nullptr; - loaders[static_cast(AssetType::FONT)] = dynamic_cast(new SHFontLoader()); - loaders[static_cast(AssetType::AUDIO_BANK)] = loaders[static_cast(AssetType::SCENE)]; - loaders[static_cast(AssetType::ANIM_CONTAINER)] = dynamic_cast(new SHBinaryLoader()); loaders[static_cast(AssetType::ANIM_CLIP)] = nullptr; } @@ -892,6 +909,21 @@ namespace SHADE SHAssetMetaHandler::WriteMetaData(assetCollection[newAsset.id]); } + else if (ext == NAV_DATA_EXTENSION) + { + SHAsset newAsset{ + path.stem().string(), + GenerateAssetID(AssetType::NAV_DATA), + AssetType::NAV_DATA, + path, + false + }; + + assetCollection.emplace(newAsset.id, newAsset); + SHAssetMetaHandler::WriteMetaData(newAsset); + + return newAsset.id; + } } void SHAssetManager::BuildAssetCollection() noexcept @@ -950,7 +982,8 @@ namespace rttr value("Script", AssetType::SCRIPT), value("Font", AssetType::FONT), value("Animation Container", AssetType::ANIM_CONTAINER), - value("Animation Clip", AssetType::ANIM_CLIP) + value("Animation Clip", AssetType::ANIM_CLIP), + value("Navigation Data", AssetType::NAV_DATA) ); } }