Add initial draft of structured data def parser to parse enums only for now

This commit is contained in:
Jan
2022-01-18 22:55:50 +01:00
parent 91cfb2e8dd
commit 1c1fbd1007
24 changed files with 792 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include "ObjLoading.h"
#include "Game/IW4/IW4.h"
#include "Parsing/StructuredDataDef/StructuredDataDefReader.h"
#include "Pool/GlobalAssetPool.h"
using namespace IW4;
@ -15,3 +16,35 @@ void* AssetLoaderStructuredDataDefSet::CreateEmptyAsset(const std::string& asset
structuredDataDefSet->name = memory->Dup(assetName.c_str());
return structuredDataDefSet;
}
bool AssetLoaderStructuredDataDefSet::CanLoadFromRaw() const
{
return true;
}
bool AssetLoaderStructuredDataDefSet::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
{
const auto file = searchPath->Open(assetName);
if (!file.IsOpen())
return false;
auto* structuredDataDefSet = memory->Create<StructuredDataDefSet>();
structuredDataDefSet->name = memory->Dup(assetName.c_str());
StructuredDataDefReader reader(*file.m_stream, assetName, [searchPath](const std::string& filename, const std::string& sourceFile) -> std::unique_ptr<std::istream>
{
auto foundFileToInclude = searchPath->Open(filename);
if (!foundFileToInclude.IsOpen() || !foundFileToInclude.m_stream)
return nullptr;
return std::move(foundFileToInclude.m_stream);
});
const auto defs = reader.ReadStructureDataDefs();
// TODO Convert defs
manager->AddAsset(ASSET_TYPE_STRUCTURED_DATA_DEF, assetName, structuredDataDefSet);
return true;
}