mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-01 08:41:52 +00:00
chore: generalize default asset creators
This commit is contained in:
@ -1,39 +0,0 @@
|
||||
#include "AssetLoaderStringTable.h"
|
||||
|
||||
#include "Csv/CsvStream.h"
|
||||
#include "Game/IW3/CommonIW3.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "StringTable/StringTableLoader.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
void* AssetLoaderStringTable::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* stringTable = memory->Create<StringTable>();
|
||||
memset(stringTable, 0, sizeof(StringTable));
|
||||
stringTable->name = memory->Dup(assetName.c_str());
|
||||
return stringTable;
|
||||
}
|
||||
|
||||
bool AssetLoaderStringTable::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderStringTable::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;
|
||||
|
||||
string_table::StringTableLoaderV1<StringTable> loader;
|
||||
auto* stringTable = loader.LoadFromStream(assetName, *memory, *file.m_stream);
|
||||
|
||||
manager->AddAsset<AssetStringTable>(assetName, stringTable);
|
||||
|
||||
return true;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderStringTable final : public BasicAssetLoader<AssetStringTable>
|
||||
{
|
||||
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, Zone* zone) const override;
|
||||
};
|
||||
} // namespace IW3
|
@ -1,16 +0,0 @@
|
||||
#include "DefaultCreatorImageIW3.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
DefaultCreatorImage::DefaultCreatorImage(MemoryManager& memory)
|
||||
: m_memory(memory)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult DefaultCreatorImage::CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const
|
||||
{
|
||||
auto* asset = m_memory.Alloc<GfxImage>();
|
||||
asset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetImage>(assetName, asset));
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IDefaultAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class DefaultCreatorImage : public DefaultAssetCreator<AssetImage>
|
||||
{
|
||||
public:
|
||||
explicit DefaultCreatorImage(MemoryManager& memory);
|
||||
AssetCreationResult CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
};
|
||||
} // namespace IW3
|
@ -4,7 +4,6 @@
|
||||
#include "Game/IW3/GameIW3.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Image/AssetLoaderImageIW3.h"
|
||||
#include "Image/DefaultCreatorImageIW3.h"
|
||||
#include "Localize/AssetLoaderLocalizeIW3.h"
|
||||
#include "ObjLoading.h"
|
||||
|
||||
@ -22,33 +21,33 @@ namespace
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorPhysPreset>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorXAnim>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorXModel>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorMaterial>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorTechniqueSet>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorImage>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorSound>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorSoundCurve>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorLoadedSound>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorClipMap>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorClipMapPvs>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorComWorld>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorGameWorldSp>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorGameWorldMp>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorMapEnts>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorGfxWorld>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorLightDef>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorFont>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorMenuList>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorMenu>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorLocalize>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorWeapon>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorSoundDriverGlobals>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorFx>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorImpactFx>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorRawFile>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorStringTable>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysPreset>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetXAnim>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetXModel>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetMaterial>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetTechniqueSet>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetImage>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetSound>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetSoundCurve>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetLoadedSound>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetClipMap>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetClipMapPvs>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetComWorld>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetGameWorldSp>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetGameWorldMp>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetMapEnts>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetGfxWorld>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetLightDef>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetFont>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetMenuList>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetMenu>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetLocalize>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetWeapon>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetSoundDriverGlobals>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetFx>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetImpactFx>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetRawFile>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetStringTable>>(memory));
|
||||
}
|
||||
|
||||
void ConfigureGlobalAssetPoolsLoaders(AssetCreatorCollection& collection, Zone& zone)
|
||||
|
@ -1,16 +0,0 @@
|
||||
#include "DefaultCreatorRawFileIW3.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
DefaultCreatorRawFile::DefaultCreatorRawFile(MemoryManager& memory)
|
||||
: m_memory(memory)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult DefaultCreatorRawFile::CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const
|
||||
{
|
||||
auto* asset = m_memory.Alloc<RawFile>();
|
||||
asset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, asset));
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IDefaultAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class DefaultCreatorRawFile : public DefaultAssetCreator<AssetRawFile>
|
||||
{
|
||||
public:
|
||||
explicit DefaultCreatorRawFile(MemoryManager& memory);
|
||||
AssetCreationResult CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
};
|
||||
} // namespace IW3
|
@ -0,0 +1,29 @@
|
||||
#include "AssetLoaderStringTableIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "StringTable/StringTableLoader.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
AssetLoaderStringTable::AssetLoaderStringTable(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult AssetLoaderStringTable::CreateAsset(const std::string& assetName, AssetCreationContext& context)
|
||||
{
|
||||
const auto file = m_search_path.Open(assetName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
string_table::StringTableLoaderV1<StringTable> loader;
|
||||
auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream);
|
||||
if (!stringTable)
|
||||
return AssetCreationResult::Failure();
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderStringTable final : public AssetCreator<AssetRawFile>
|
||||
{
|
||||
public:
|
||||
AssetLoaderStringTable(MemoryManager& memory, ISearchPath& searchPath);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
} // namespace IW3
|
Reference in New Issue
Block a user