Merge remote-tracking branch 'origin/NavData' into Navigation

This commit is contained in:
maverickdgg 2023-03-24 16:47:09 +08:00
commit 38d3040a04
5 changed files with 149 additions and 13 deletions

View File

@ -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 <vector>
#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<uint8_t> grid;
};
}

View File

@ -5,8 +5,12 @@
#include <fstream>
#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<SHAnimClipContainerAsset const*>(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<SHNavDataAsset const*>(data);
file.write(
reinterpret_cast<char const*>(&navData.rows),
sizeof(uint32_t)
);
file.write(
reinterpret_cast<char const*>(&navData.origin),
sizeof(SHVec3) * 2
);
auto const count {navData.grid.size()};
file.write(
reinterpret_cast<char const*>(&count),
sizeof(count)
);
file.write(
reinterpret_cast<char const*>(navData.grid.data()),
count
);
}
void SHBinaryLoader::LoadNavData(std::ifstream& file, SHAssetData*& result)
{
auto const data = new SHNavDataAsset();
file.read(
reinterpret_cast<char*>(&data->rows),
sizeof(uint32_t)
);
file.read(
reinterpret_cast<char*>(&data->origin),
sizeof(SHVec3) * 2
);
size_t count;
file.read(
reinterpret_cast<char*>(&count),
sizeof(size_t)
);
data->grid.resize(count);
file.read(
reinterpret_cast<char*>(data->grid.data()),
count
);
result = data;
}
}

View File

@ -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);
};
}

View File

@ -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<size_t>(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<size_t>(AssetType::MAX_COUNT) };

View File

@ -33,6 +33,8 @@
#include "Filesystem/SHFileSystem.h"
#include <rttr/registration.h>
#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<size_t>(AssetType::SHADER)] = dynamic_cast<SHAssetLoader*>(new SHShaderSourceLoader());
loaders[static_cast<size_t>(AssetType::SHADER_BUILT_IN)] = loaders[static_cast<size_t>(AssetType::SHADER)];
loaders[static_cast<size_t>(AssetType::TEXTURE)] = dynamic_cast<SHAssetLoader*>(new SHTextureLoader());
loaders[static_cast<size_t>(AssetType::MODEL)] = dynamic_cast<SHAssetLoader*>(new SHModelLoader());
loaders[static_cast<size_t>(AssetType::SCENE)] = dynamic_cast<SHAssetLoader*>(new SHTextBasedLoader());
loaders[static_cast<size_t>(AssetType::FONT)] = dynamic_cast<SHAssetLoader*>(new SHFontLoader());
loaders[static_cast<size_t>(AssetType::ANIM_CONTAINER)] = dynamic_cast<SHAssetLoader*>(new SHBinaryLoader());
loaders[static_cast<size_t>(AssetType::PREFAB)] = loaders[static_cast<size_t>(AssetType::SCENE)];
loaders[static_cast<size_t>(AssetType::MATERIAL)] = loaders[static_cast<size_t>(AssetType::SCENE)];
loaders[static_cast<size_t>(AssetType::AUDIO_BANK)] = loaders[static_cast<size_t>(AssetType::SCENE)];
loaders[static_cast<size_t>(AssetType::SHADER_BUILT_IN)] = loaders[static_cast<size_t>(AssetType::SHADER)];
loaders[static_cast<size_t>(AssetType::NAV_DATA)] = loaders[static_cast<size_t>(AssetType::ANIM_CONTAINER)];
loaders[static_cast<size_t>(AssetType::MESH)] = nullptr;
loaders[static_cast<size_t>(AssetType::SCRIPT)] = nullptr;
loaders[static_cast<size_t>(AssetType::FONT)] = dynamic_cast<SHAssetLoader*>(new SHFontLoader());
loaders[static_cast<size_t>(AssetType::AUDIO_BANK)] = loaders[static_cast<size_t>(AssetType::SCENE)];
loaders[static_cast<size_t>(AssetType::ANIM_CONTAINER)] = dynamic_cast<SHAssetLoader*>(new SHBinaryLoader());
loaders[static_cast<size_t>(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)
);
}
}