Add AssetLoaders for Qdb, ScriptParseTree and Slug

This commit is contained in:
Jan 2021-03-23 01:28:33 +01:00
parent 74f2bff716
commit 0ff06cad72
7 changed files with 183 additions and 3 deletions

View File

@ -0,0 +1,43 @@
#include "AssetLoaderQdb.h"
#include <cstring>
#include "Game/T6/T6.h"
#include "Pool/GlobalAssetPool.h"
using namespace T6;
void* AssetLoaderQdb::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
{
auto* qdb = memory->Create<Qdb>();
memset(qdb, 0, sizeof(Qdb));
qdb->name = memory->Dup(assetName.c_str());
return qdb;
}
bool AssetLoaderQdb::CanLoadFromRaw() const
{
return true;
}
bool AssetLoaderQdb::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) const
{
const auto file = searchPath->Open(assetName);
if (!file.IsOpen())
return false;
auto* qdb = memory->Create<Qdb>();
qdb->name = memory->Dup(assetName.c_str());
qdb->len = static_cast<int>(file.m_length);
auto* fileBuffer = static_cast<char*>(memory->Alloc(static_cast<size_t>(file.m_length + 1)));
file.m_stream->read(fileBuffer, file.m_length);
if (file.m_stream->gcount() != file.m_length)
return false;
fileBuffer[qdb->len] = '\0';
qdb->buffer = static_cast<char16*>(fileBuffer);
manager->AddAsset(ASSET_TYPE_QDB, assetName, qdb);
return true;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "Game/T6/T6.h"
#include "AssetLoading/BasicAssetLoader.h"
#include "AssetLoading/IAssetLoadingManager.h"
#include "SearchPath/ISearchPath.h"
namespace T6
{
class AssetLoaderQdb final : public BasicAssetLoader<ASSET_TYPE_QDB, Qdb>
{
public:
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
_NODISCARD bool CanLoadFromRaw() const override;
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) const override;
};
}

View File

@ -0,0 +1,43 @@
#include "AssetLoaderScriptParseTree.h"
#include <cstring>
#include "Game/T6/T6.h"
#include "Pool/GlobalAssetPool.h"
using namespace T6;
void* AssetLoaderScriptParseTree::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
{
auto* scriptParseTree = memory->Create<ScriptParseTree>();
memset(scriptParseTree, 0, sizeof(ScriptParseTree));
scriptParseTree->name = memory->Dup(assetName.c_str());
return scriptParseTree;
}
bool AssetLoaderScriptParseTree::CanLoadFromRaw() const
{
return true;
}
bool AssetLoaderScriptParseTree::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) const
{
const auto file = searchPath->Open(assetName);
if (!file.IsOpen())
return false;
auto* scriptParseTree = memory->Create<ScriptParseTree>();
scriptParseTree->name = memory->Dup(assetName.c_str());
scriptParseTree->len = static_cast<int>(file.m_length);
auto* fileBuffer = static_cast<char*>(memory->Alloc(static_cast<size_t>(file.m_length + 1)));
file.m_stream->read(fileBuffer, file.m_length);
if (file.m_stream->gcount() != file.m_length)
return false;
fileBuffer[scriptParseTree->len] = '\0';
scriptParseTree->buffer = static_cast<char16*>(fileBuffer);
manager->AddAsset(ASSET_TYPE_SCRIPTPARSETREE, assetName, scriptParseTree);
return true;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "Game/T6/T6.h"
#include "AssetLoading/BasicAssetLoader.h"
#include "AssetLoading/IAssetLoadingManager.h"
#include "SearchPath/ISearchPath.h"
namespace T6
{
class AssetLoaderScriptParseTree final : public BasicAssetLoader<ASSET_TYPE_SCRIPTPARSETREE, ScriptParseTree>
{
public:
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
_NODISCARD bool CanLoadFromRaw() const override;
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) const override;
};
}

View File

@ -0,0 +1,43 @@
#include "AssetLoaderSlug.h"
#include <cstring>
#include "Game/T6/T6.h"
#include "Pool/GlobalAssetPool.h"
using namespace T6;
void* AssetLoaderSlug::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
{
auto* slug = memory->Create<Slug>();
memset(slug, 0, sizeof(Slug));
slug->name = memory->Dup(assetName.c_str());
return slug;
}
bool AssetLoaderSlug::CanLoadFromRaw() const
{
return true;
}
bool AssetLoaderSlug::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) const
{
const auto file = searchPath->Open(assetName);
if (!file.IsOpen())
return false;
auto* slug = memory->Create<Slug>();
slug->name = memory->Dup(assetName.c_str());
slug->len = static_cast<int>(file.m_length);
auto* fileBuffer = static_cast<char*>(memory->Alloc(static_cast<size_t>(file.m_length + 1)));
file.m_stream->read(fileBuffer, file.m_length);
if (file.m_stream->gcount() != file.m_length)
return false;
fileBuffer[slug->len] = '\0';
slug->buffer = static_cast<char16*>(fileBuffer);
manager->AddAsset(ASSET_TYPE_SLUG, assetName, slug);
return true;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "Game/T6/T6.h"
#include "AssetLoading/BasicAssetLoader.h"
#include "AssetLoading/IAssetLoadingManager.h"
#include "SearchPath/ISearchPath.h"
namespace T6
{
class AssetLoaderSlug final : public BasicAssetLoader<ASSET_TYPE_SLUG, Slug>
{
public:
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
_NODISCARD bool CanLoadFromRaw() const override;
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) const override;
};
}

View File

@ -4,7 +4,10 @@
#include "Game/T6/GameAssetPoolT6.h" #include "Game/T6/GameAssetPoolT6.h"
#include "ObjContainer/IPak/IPak.h" #include "ObjContainer/IPak/IPak.h"
#include "ObjLoading.h" #include "ObjLoading.h"
#include "AssetLoaders/AssetLoaderQdb.h"
#include "AssetLoaders/AssetLoaderRawFile.h" #include "AssetLoaders/AssetLoaderRawFile.h"
#include "AssetLoaders/AssetLoaderScriptParseTree.h"
#include "AssetLoaders/AssetLoaderSlug.h"
#include "AssetLoading/AssetLoadingManager.h" #include "AssetLoading/AssetLoadingManager.h"
#include "Image/Texture.h" #include "Image/Texture.h"
#include "Image/IwiLoader.h" #include "Image/IwiLoader.h"
@ -57,14 +60,14 @@ namespace T6
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_DDL, ddlRoot_t)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_DDL, ddlRoot_t))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_GLASSES, Glasses)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_GLASSES, Glasses))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_EMBLEMSET, EmblemSet)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_EMBLEMSET, EmblemSet))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SCRIPTPARSETREE, ScriptParseTree)) REGISTER_ASSET_LOADER(AssetLoaderScriptParseTree)
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_VEHICLEDEF, VehicleDef)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_VEHICLEDEF, VehicleDef))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MEMORYBLOCK, MemoryBlock)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MEMORYBLOCK, MemoryBlock))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_TRACER, TracerDef)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_TRACER, TracerDef))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SKINNEDVERTS, SkinnedVertsDef)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SKINNEDVERTS, SkinnedVertsDef))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_QDB, Qdb)) REGISTER_ASSET_LOADER(AssetLoaderQdb)
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SLUG, Slug)) REGISTER_ASSET_LOADER(AssetLoaderSlug)
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FOOTSTEP_TABLE, FootstepTableDef)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FOOTSTEP_TABLE, FootstepTableDef))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FOOTSTEPFX_TABLE, FootstepFXTableDef)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FOOTSTEPFX_TABLE, FootstepFXTableDef))
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_ZBARRIER, ZBarrierDef)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_ZBARRIER, ZBarrierDef))