mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 07:42:54 +00:00
chore: adjust asset creation process to use separated AssetCreators
This commit is contained in:
parent
63046f5681
commit
4f0a405bdc
@ -1,15 +0,0 @@
|
||||
#include "ZoneCreatorIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
GameId ZoneCreator::GetGameId() const
|
||||
{
|
||||
return GameId::IW3;
|
||||
}
|
||||
|
||||
asset_type_t ZoneCreator::GetImageAssetType() const
|
||||
{
|
||||
return ASSET_TYPE_IMAGE;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ZoneCreation/ZoneCreator.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class ZoneCreator final : public IZoneCreator
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] GameId GetGameId() const override;
|
||||
[[nodiscard]] asset_type_t GetImageAssetType() const override;
|
||||
};
|
||||
} // namespace IW3
|
@ -1,15 +0,0 @@
|
||||
#include "ZoneCreatorIW4.h"
|
||||
|
||||
#include "Game/IW4/IW4.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
GameId ZoneCreator::GetGameId() const
|
||||
{
|
||||
return GameId::IW4;
|
||||
}
|
||||
|
||||
asset_type_t ZoneCreator::GetImageAssetType() const
|
||||
{
|
||||
return ASSET_TYPE_IMAGE;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ZoneCreation/ZoneCreator.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class ZoneCreator final : public IZoneCreator
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] GameId GetGameId() const override;
|
||||
[[nodiscard]] asset_type_t GetImageAssetType() const override;
|
||||
};
|
||||
} // namespace IW4
|
@ -1,15 +0,0 @@
|
||||
#include "ZoneCreatorIW5.h"
|
||||
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
GameId ZoneCreator::GetGameId() const
|
||||
{
|
||||
return GameId::IW5;
|
||||
}
|
||||
|
||||
asset_type_t ZoneCreator::GetImageAssetType() const
|
||||
{
|
||||
return ASSET_TYPE_IMAGE;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ZoneCreation/ZoneCreator.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class ZoneCreator final : public IZoneCreator
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] GameId GetGameId() const override;
|
||||
[[nodiscard]] asset_type_t GetImageAssetType() const override;
|
||||
};
|
||||
} // namespace IW5
|
@ -1,15 +0,0 @@
|
||||
#include "ZoneCreatorT5.h"
|
||||
|
||||
#include "Game/T5/T5.h"
|
||||
|
||||
using namespace T5;
|
||||
|
||||
GameId ZoneCreator::GetGameId() const
|
||||
{
|
||||
return GameId::T5;
|
||||
}
|
||||
|
||||
asset_type_t ZoneCreator::GetImageAssetType() const
|
||||
{
|
||||
return ASSET_TYPE_IMAGE;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ZoneCreation/ZoneCreator.h"
|
||||
|
||||
namespace T5
|
||||
{
|
||||
class ZoneCreator final : public IZoneCreator
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] GameId GetGameId() const override;
|
||||
[[nodiscard]] asset_type_t GetImageAssetType() const override;
|
||||
};
|
||||
} // namespace T5
|
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ZoneCreation/ZoneCreator.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class ZoneCreator final : public IZoneCreator
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] GameId GetGameId() const override;
|
||||
[[nodiscard]] asset_type_t GetImageAssetType() const override;
|
||||
|
||||
protected:
|
||||
void HandleMetadata(Zone& zone, const ZoneCreationContext& context) const override;
|
||||
};
|
||||
} // namespace T6
|
@ -344,8 +344,7 @@ class LinkerImpl final : public Linker
|
||||
if (!LoadGdtFilesFromZoneDefinition(context.m_gdt_files, zoneDefinition, &paths.m_gdt_paths.GetSearchPaths()))
|
||||
return nullptr;
|
||||
|
||||
const auto* creator = IZoneCreator::GetCreatorForGame(zoneDefinition.m_game);
|
||||
return creator->CreateZoneForDefinition(context);
|
||||
return zone_creator::CreateZoneForDefinition(zoneDefinition.m_game, context);
|
||||
}
|
||||
|
||||
bool WriteZoneToFile(const LinkerPathManager& paths, const std::string& projectName, Zone* zone) const
|
||||
@ -390,41 +389,41 @@ class LinkerImpl final : public Linker
|
||||
return result;
|
||||
}
|
||||
|
||||
bool BuildIPak(const LinkerPathManager& paths, const std::string& projectName, const ZoneDefinition& zoneDefinition, SearchPaths& assetSearchPaths) const
|
||||
{
|
||||
const fs::path ipakFolderPath(paths.m_linker_paths->BuildOutputFolderPath(projectName, zoneDefinition.m_game));
|
||||
auto ipakFilePath(ipakFolderPath);
|
||||
ipakFilePath.append(std::format("{}.ipak", zoneDefinition.m_name));
|
||||
// bool BuildIPak(const LinkerPathManager& paths, const std::string& projectName, const ZoneDefinition& zoneDefinition, SearchPaths& assetSearchPaths) const
|
||||
// {
|
||||
// const fs::path ipakFolderPath(paths.m_linker_paths->BuildOutputFolderPath(projectName, zoneDefinition.m_game));
|
||||
// auto ipakFilePath(ipakFolderPath);
|
||||
// ipakFilePath.append(std::format("{}.ipak", zoneDefinition.m_name));
|
||||
|
||||
fs::create_directories(ipakFolderPath);
|
||||
// fs::create_directories(ipakFolderPath);
|
||||
|
||||
std::ofstream stream(ipakFilePath, std::fstream::out | std::fstream::binary);
|
||||
if (!stream.is_open())
|
||||
return false;
|
||||
// std::ofstream stream(ipakFilePath, std::fstream::out | std::fstream::binary);
|
||||
// if (!stream.is_open())
|
||||
// return false;
|
||||
|
||||
const auto ipakWriter = IPakWriter::Create(stream, &assetSearchPaths);
|
||||
const auto imageAssetType = IZoneCreator::GetCreatorForGame(zoneDefinition.m_game)->GetImageAssetType();
|
||||
for (const auto& assetEntry : zoneDefinition.m_assets)
|
||||
{
|
||||
if (assetEntry.m_is_reference)
|
||||
continue;
|
||||
// const auto ipakWriter = IPakWriter::Create(stream, &assetSearchPaths);
|
||||
// const auto imageAssetType = IZoneCreator::GetCreatorForGame(zoneDefinition.m_game)->GetImageAssetType();
|
||||
// for (const auto& assetEntry : zoneDefinition.m_assets)
|
||||
// {
|
||||
// if (assetEntry.m_is_reference)
|
||||
// continue;
|
||||
|
||||
if (assetEntry.m_asset_type == imageAssetType)
|
||||
ipakWriter->AddImage(assetEntry.m_asset_name);
|
||||
}
|
||||
// if (assetEntry.m_asset_type == imageAssetType)
|
||||
// ipakWriter->AddImage(assetEntry.m_asset_name);
|
||||
// }
|
||||
|
||||
if (!ipakWriter->Write())
|
||||
{
|
||||
std::cerr << "Writing ipak failed.\n";
|
||||
stream.close();
|
||||
return false;
|
||||
}
|
||||
// if (!ipakWriter->Write())
|
||||
// {
|
||||
// std::cerr << "Writing ipak failed.\n";
|
||||
// stream.close();
|
||||
// return false;
|
||||
// }
|
||||
|
||||
std::cout << std::format("Created ipak \"{}\"\n", ipakFilePath.string());
|
||||
// std::cout << std::format("Created ipak \"{}\"\n", ipakFilePath.string());
|
||||
|
||||
stream.close();
|
||||
return true;
|
||||
}
|
||||
// stream.close();
|
||||
// return true;
|
||||
// }
|
||||
|
||||
bool BuildProject(LinkerPathManager& paths, const std::string& projectName, const std::string& targetName) const
|
||||
{
|
||||
|
@ -1,34 +1,11 @@
|
||||
#include "ZoneCreator.h"
|
||||
|
||||
#include "AssetLoading/AssetLoadingContext.h"
|
||||
#include "Game/IW3/ZoneCreatorIW3.h"
|
||||
#include "Game/IW4/ZoneCreatorIW4.h"
|
||||
#include "Game/IW5/ZoneCreatorIW5.h"
|
||||
#include "Game/T5/ZoneCreatorT5.h"
|
||||
#include "Game/T6/ZoneCreatorT6.h"
|
||||
#include "IObjCompiler.h"
|
||||
#include "IObjLoader.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
const IZoneCreator* IZoneCreator::GetCreatorForGame(GameId game)
|
||||
{
|
||||
static const IZoneCreator* zoneCreators[static_cast<unsigned>(GameId::COUNT)]{
|
||||
new IW3::ZoneCreator(),
|
||||
new IW4::ZoneCreator(),
|
||||
new IW5::ZoneCreator(),
|
||||
new T5::ZoneCreator(),
|
||||
new T6::ZoneCreator(),
|
||||
};
|
||||
static_assert(std::extent_v<decltype(zoneCreators)> == static_cast<unsigned>(GameId::COUNT));
|
||||
|
||||
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT));
|
||||
const auto* result = zoneCreators[static_cast<unsigned>(game)];
|
||||
assert(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
std::unique_ptr<Zone> CreateZone(const ZoneCreationContext& context, const GameId gameId)
|
||||
@ -64,43 +41,37 @@ namespace
|
||||
context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference);
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyIgnoredAssetsToLoadingContext(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext)
|
||||
{
|
||||
for (const auto& ignoreEntry : creationContext.m_ignored_assets.m_entries)
|
||||
loadingContext.m_ignored_asset_map[ignoreEntry.m_name] = ignoreEntry.m_type;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Zone> IZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
|
||||
namespace zone_creator
|
||||
{
|
||||
const auto gameId = GetGameId();
|
||||
|
||||
std::unique_ptr<Zone> CreateZoneForDefinition(GameId gameId, ZoneCreationContext& context)
|
||||
{
|
||||
auto zone = CreateZone(context, gameId);
|
||||
InitializeAssetPools(*zone, gameId);
|
||||
|
||||
AssetLoadingContext assetLoadingContext(*zone, *context.m_asset_search_path, CreateGdtList(context));
|
||||
IgnoreReferencesFromAssets(context);
|
||||
ApplyIgnoredAssetsToLoadingContext(context, assetLoadingContext);
|
||||
|
||||
HandleMetadata(*zone, context);
|
||||
IgnoredAssetLookup ignoredAssetLookup(context.m_ignored_assets);
|
||||
|
||||
const auto* objCompiler = IObjCompiler::GetObjCompilerForGame(gameId);
|
||||
const auto* objLoader = IObjLoader::GetObjLoaderForGame(gameId);
|
||||
|
||||
AssetCreatorCollection creatorCollection(*zone);
|
||||
objCompiler->ConfigureCreatorCollection(creatorCollection, *zone, *context.m_definition);
|
||||
objLoader->ConfigureCreatorCollection(creatorCollection);
|
||||
|
||||
AssetCreationContext creationContext(zone.get(), &creatorCollection, &ignoredAssetLookup);
|
||||
|
||||
for (const auto& assetEntry : context.m_definition->m_assets)
|
||||
{
|
||||
const auto compilerResult = objCompiler->CompileAssetForZone(assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name);
|
||||
if (compilerResult == ObjCompilerResult::FAILURE)
|
||||
return nullptr;
|
||||
const auto* createdAsset = creationContext.LoadDependencyGeneric(assetEntry.m_asset_type, assetEntry.m_asset_name);
|
||||
|
||||
if (compilerResult == ObjCompilerResult::NO_COMPILATION_DONE)
|
||||
{
|
||||
if (!objLoader->LoadAssetForZone(assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
|
||||
if (!createdAsset)
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
objLoader->FinalizeAssetsForZone(assetLoadingContext);
|
||||
creatorCollection.FinalizeZone(creationContext);
|
||||
|
||||
return zone;
|
||||
}
|
||||
}
|
||||
} // namespace zone_creator
|
||||
|
@ -3,23 +3,7 @@
|
||||
#include "Zone/Zone.h"
|
||||
#include "ZoneCreationContext.h"
|
||||
|
||||
class IZoneCreator
|
||||
namespace zone_creator
|
||||
{
|
||||
public:
|
||||
IZoneCreator() = default;
|
||||
virtual ~IZoneCreator() = default;
|
||||
IZoneCreator(const IZoneCreator& other) = default;
|
||||
IZoneCreator(IZoneCreator&& other) noexcept = default;
|
||||
IZoneCreator& operator=(const IZoneCreator& other) = default;
|
||||
IZoneCreator& operator=(IZoneCreator&& other) noexcept = default;
|
||||
|
||||
[[nodiscard]] virtual GameId GetGameId() const = 0;
|
||||
[[nodiscard]] virtual asset_type_t GetImageAssetType() const = 0;
|
||||
|
||||
[[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const;
|
||||
|
||||
static const IZoneCreator* GetCreatorForGame(GameId game);
|
||||
|
||||
protected:
|
||||
virtual void HandleMetadata(Zone& zone, const ZoneCreationContext& context) const {}
|
||||
};
|
||||
[[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(GameId game, ZoneCreationContext& context);
|
||||
}
|
||||
|
@ -2,7 +2,4 @@
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
return ObjCompilerResult::NO_COMPILATION_DONE;
|
||||
}
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
|
@ -7,6 +7,6 @@ namespace IW3
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
};
|
||||
} // namespace IW3
|
||||
|
@ -2,7 +2,4 @@
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
return ObjCompilerResult::NO_COMPILATION_DONE;
|
||||
}
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
|
@ -7,6 +7,6 @@ namespace IW4
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
};
|
||||
} // namespace IW4
|
||||
|
@ -2,7 +2,4 @@
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
return ObjCompilerResult::NO_COMPILATION_DONE;
|
||||
}
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
|
@ -7,6 +7,6 @@ namespace IW5
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
};
|
||||
} // namespace IW5
|
||||
|
@ -2,7 +2,4 @@
|
||||
|
||||
using namespace T5;
|
||||
|
||||
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
return ObjCompilerResult::NO_COMPILATION_DONE;
|
||||
}
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
|
@ -7,6 +7,6 @@ namespace T5
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
};
|
||||
} // namespace T5
|
||||
|
0
src/ObjCompiling/Game/T6/Image/ImageCompilerT6.cpp
Normal file
0
src/ObjCompiling/Game/T6/Image/ImageCompilerT6.cpp
Normal file
0
src/ObjCompiling/Game/T6/Image/ImageCompilerT6.h
Normal file
0
src/ObjCompiling/Game/T6/Image/ImageCompilerT6.h
Normal file
@ -1,30 +1,30 @@
|
||||
#include "ZoneCreatorT6.h"
|
||||
#include "KeyValuePairsCreator.h"
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "IObjLoader.h"
|
||||
#include "ObjLoading.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
GameId ZoneCreator::GetGameId() const
|
||||
KeyValuePairsCreator::KeyValuePairsCreator(const Zone& zone, const ZoneDefinition& zoneDefinition)
|
||||
: m_zone(zone),
|
||||
m_zone_definition(zoneDefinition)
|
||||
{
|
||||
return GameId::T6;
|
||||
}
|
||||
|
||||
asset_type_t ZoneCreator::GetImageAssetType() const
|
||||
AssetCreationResult KeyValuePairsCreator::CreateAsset(const std::string& assetName, AssetCreationContext& context)
|
||||
{
|
||||
return ASSET_TYPE_IMAGE;
|
||||
return AssetCreationResult::NoAction();
|
||||
}
|
||||
|
||||
void ZoneCreator::HandleMetadata(Zone& zone, const ZoneCreationContext& context) const
|
||||
void KeyValuePairsCreator::FinalizeZone(AssetCreationContext& context)
|
||||
{
|
||||
std::vector<KeyValuePair> kvpList;
|
||||
auto& memory = *m_zone.GetMemory();
|
||||
|
||||
for (const auto& metaData : context.m_definition->m_properties.m_properties)
|
||||
for (const auto& metaData : m_zone_definition.m_properties.m_properties)
|
||||
{
|
||||
if (metaData.first.rfind("level.", 0) == 0)
|
||||
{
|
||||
@ -49,21 +49,21 @@ void ZoneCreator::HandleMetadata(Zone& zone, const ZoneCreationContext& context)
|
||||
keyHash = Common::Com_HashKey(strValue.c_str(), 64);
|
||||
}
|
||||
|
||||
KeyValuePair kvp{keyHash, Common::Com_HashKey(zone.m_name.c_str(), 64), zone.GetMemory()->Dup(metaData.second.c_str())};
|
||||
KeyValuePair kvp{keyHash, Common::Com_HashKey(m_zone.m_name.c_str(), 64), memory.Dup(metaData.second.c_str())};
|
||||
kvpList.push_back(kvp);
|
||||
}
|
||||
}
|
||||
|
||||
if (!kvpList.empty())
|
||||
{
|
||||
auto* kvps = zone.GetMemory()->Create<KeyValuePairs>();
|
||||
kvps->name = zone.GetMemory()->Dup(zone.m_name.c_str());
|
||||
auto* kvps = memory.Create<KeyValuePairs>();
|
||||
kvps->name = memory.Dup(m_zone.m_name.c_str());
|
||||
kvps->numVariables = static_cast<int>(kvpList.size());
|
||||
kvps->keyValuePairs = zone.GetMemory()->Alloc<KeyValuePair>(kvpList.size());
|
||||
kvps->keyValuePairs = m_zone.GetMemory()->Alloc<KeyValuePair>(kvpList.size());
|
||||
|
||||
for (auto i = 0u; i < kvpList.size(); i++)
|
||||
kvps->keyValuePairs[i] = kvpList[i];
|
||||
|
||||
zone.m_pools->AddAsset(std::make_unique<XAssetInfo<KeyValuePairs>>(ASSET_TYPE_KEYVALUEPAIRS, zone.m_name, kvps));
|
||||
context.AddAsset(AssetRegistration<AssetKeyValuePairs>(m_zone.m_name, kvps));
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Zone/Definition/ZoneDefinition.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class KeyValuePairsCreator : public AssetCreator<AssetKeyValuePairs>
|
||||
{
|
||||
public:
|
||||
KeyValuePairsCreator(const Zone& zone, const ZoneDefinition& zoneDefinition);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
|
||||
void FinalizeZone(AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
const Zone& m_zone;
|
||||
const ZoneDefinition& m_zone_definition;
|
||||
};
|
||||
} // namespace T6
|
@ -1,8 +1,7 @@
|
||||
#include "ObjCompilerT6.h"
|
||||
|
||||
#include "Game/T6/T6.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
return ObjCompilerResult::NO_COMPILATION_DONE;
|
||||
}
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
|
@ -7,6 +7,6 @@ namespace T6
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
};
|
||||
} // namespace T6
|
||||
|
@ -1,19 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/AssetCreatorCollection.h"
|
||||
#include "AssetLoading/AssetLoadingContext.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Zone/Definition/ZoneDefinition.h"
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
enum class ObjCompilerResult : std::uint8_t
|
||||
{
|
||||
COMPILED,
|
||||
NO_COMPILATION_DONE,
|
||||
FAILURE
|
||||
};
|
||||
|
||||
class IObjCompiler
|
||||
{
|
||||
public:
|
||||
@ -24,7 +19,7 @@ public:
|
||||
IObjCompiler& operator=(const IObjCompiler& other) = default;
|
||||
IObjCompiler& operator=(IObjCompiler&& other) noexcept = default;
|
||||
|
||||
virtual ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const = 0;
|
||||
virtual void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const = 0;
|
||||
|
||||
static const IObjCompiler* GetObjCompilerForGame(GameId game);
|
||||
};
|
||||
|
135
src/ObjLoading/Asset/AssetCreationContext.cpp
Normal file
135
src/ObjLoading/Asset/AssetCreationContext.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
#include "AssetCreationContext.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
IgnoredAssetLookup::IgnoredAssetLookup(const AssetList& assetList)
|
||||
{
|
||||
m_ignored_asset_lookup.reserve(assetList.m_entries.size());
|
||||
for (const auto& asset : assetList.m_entries)
|
||||
{
|
||||
m_ignored_asset_lookup.emplace(asset.m_name, asset.m_type);
|
||||
}
|
||||
}
|
||||
|
||||
bool IgnoredAssetLookup::IsAssetIgnored(asset_type_t assetType, const std::string& name) const
|
||||
{
|
||||
const auto entries = m_ignored_asset_lookup.equal_range(name);
|
||||
|
||||
for (auto i = entries.first; i != entries.second; ++i)
|
||||
{
|
||||
if (i->second == assetType)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
GenericAssetRegistration::GenericAssetRegistration(const asset_type_t type, std::string name, void* asset)
|
||||
: m_type(type),
|
||||
m_name(std::move(name)),
|
||||
m_asset(asset)
|
||||
{
|
||||
}
|
||||
|
||||
void GenericAssetRegistration::AddDependency(XAssetInfoGeneric* dependency)
|
||||
{
|
||||
m_dependencies.emplace(dependency);
|
||||
}
|
||||
|
||||
void GenericAssetRegistration::AddScriptString(scr_string_t scriptString)
|
||||
{
|
||||
m_used_script_strings.emplace(scriptString);
|
||||
}
|
||||
|
||||
void GenericAssetRegistration::AddIndirectAssetReference(IndirectAssetReference indirectAssetReference)
|
||||
{
|
||||
m_indirect_asset_references.emplace(std::move(indirectAssetReference));
|
||||
}
|
||||
|
||||
std::unique_ptr<XAssetInfoGeneric> GenericAssetRegistration::CreateXAssetInfo()
|
||||
{
|
||||
std::vector<XAssetInfoGeneric*> dependencies(m_dependencies.begin(), m_dependencies.end());
|
||||
std::vector<scr_string_t> scriptStrings(m_used_script_strings.begin(), m_used_script_strings.end());
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences(m_indirect_asset_references.begin(), m_indirect_asset_references.end());
|
||||
|
||||
return std::make_unique<XAssetInfoGeneric>(
|
||||
m_type, std::move(m_name), m_asset, std::move(dependencies), std::move(scriptStrings), std::move(indirectAssetReferences));
|
||||
}
|
||||
|
||||
AssetCreationContext::AssetCreationContext(Zone* zone, const AssetCreatorCollection* creators, const IgnoredAssetLookup* ignoredAssetLookup)
|
||||
: m_zone(zone),
|
||||
m_creators(creators),
|
||||
m_ignored_asset_lookup(ignoredAssetLookup)
|
||||
{
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetCreationContext::AddAssetGeneric(GenericAssetRegistration registration) const
|
||||
{
|
||||
auto xAssetInfo = registration.CreateXAssetInfo();
|
||||
xAssetInfo->m_zone = m_zone;
|
||||
|
||||
const auto assetType = xAssetInfo->m_type;
|
||||
const auto* pAssetName = xAssetInfo->m_name.c_str();
|
||||
|
||||
auto* addedAsset = m_zone->m_pools->AddAsset(std::move(xAssetInfo));
|
||||
if (addedAsset == nullptr)
|
||||
std::cerr << std::format("Failed to add asset of type \"{}\" to pool: \"{}\"\n", *m_zone->m_pools->GetAssetTypeName(assetType), pAssetName);
|
||||
|
||||
return addedAsset;
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetCreationContext::LoadDefaultAssetDependency(const asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
const auto result = m_creators->CreateDefaultAsset(assetType, assetName, *this);
|
||||
if (result.HasTakenAction() && !result.HasFailed())
|
||||
return result.GetAssetInfo();
|
||||
|
||||
std::cerr << std::format("Failed to create default asset of type {}\n", *m_zone->m_pools->GetAssetTypeName(assetType));
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetCreationContext::LoadDependencyGeneric(const asset_type_t assetType, const std::string& assetName)
|
||||
{
|
||||
auto* alreadyLoadedAsset = m_zone->m_pools->GetAssetOrAssetReference(assetType, assetName);
|
||||
if (alreadyLoadedAsset)
|
||||
return alreadyLoadedAsset;
|
||||
|
||||
if (m_ignored_asset_lookup->IsAssetIgnored(assetType, assetName))
|
||||
return LoadDefaultAssetDependency(assetType, std::format(",{}", assetName));
|
||||
|
||||
const auto result = m_creators->CreateAsset(assetType, assetName, *this);
|
||||
if (result.HasTakenAction())
|
||||
{
|
||||
if (!result.HasFailed())
|
||||
return result.GetAssetInfo();
|
||||
|
||||
std::cerr << std::format(
|
||||
"Could not load indirectly referenced asset \"{}\" of type \"{}\"\n", assetName, *m_zone->m_pools->GetAssetTypeName(assetType));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << std::format("Could not find creator for asset \"{}\" of type \"{}\"\n", assetName, *m_zone->m_pools->GetAssetTypeName(assetType));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IndirectAssetReference AssetCreationContext::LoadIndirectAssetReferenceGeneric(asset_type_t assetType, const std::string& assetName)
|
||||
{
|
||||
auto* alreadyLoadedAsset = m_zone->m_pools->GetAssetOrAssetReference(assetType, assetName);
|
||||
if (alreadyLoadedAsset)
|
||||
return IndirectAssetReference(assetType, assetName);
|
||||
|
||||
if (m_ignored_asset_lookup->IsAssetIgnored(assetType, assetName))
|
||||
return IndirectAssetReference(assetType, assetName);
|
||||
|
||||
const auto result = m_creators->CreateAsset(assetType, assetName, *this);
|
||||
if (!result.HasTakenAction() && !result.HasFailed())
|
||||
{
|
||||
std::cerr << std::format(
|
||||
"Could not load indirectly referenced asset \"{}\" of type \"{}\"\n", assetName, *m_zone->m_pools->GetAssetTypeName(assetType));
|
||||
}
|
||||
return IndirectAssetReference(assetType, assetName);
|
||||
}
|
85
src/ObjLoading/Asset/AssetCreationContext.h
Normal file
85
src/ObjLoading/Asset/AssetCreationContext.h
Normal file
@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetCreatorCollection.h"
|
||||
#include "AssetLoading/IZoneAssetLoaderState.h"
|
||||
#include "AssetRegistration.h"
|
||||
#include "Game/IAsset.h"
|
||||
#include "Pool/XAssetInfo.h"
|
||||
#include "Zone/AssetList/AssetList.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <typeindex>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
class AssetCreatorCollection;
|
||||
|
||||
class IgnoredAssetLookup
|
||||
{
|
||||
public:
|
||||
explicit IgnoredAssetLookup(const AssetList& assetList);
|
||||
|
||||
[[nodiscard]] bool IsAssetIgnored(asset_type_t assetType, const std::string& name) const;
|
||||
|
||||
std::unordered_multimap<std::string, asset_type_t> m_ignored_asset_lookup;
|
||||
};
|
||||
|
||||
class AssetCreationContext
|
||||
{
|
||||
public:
|
||||
AssetCreationContext(Zone* zone, const AssetCreatorCollection* creators, const IgnoredAssetLookup* ignoredAssetLookup);
|
||||
|
||||
template<typename AssetType> XAssetInfo<typename AssetType::Type>* AddAsset(AssetRegistration<AssetType> registration)
|
||||
{
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
return static_cast<XAssetInfo<typename AssetType::Type>*>(AddAssetGeneric(std::move(registration)));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AddAssetGeneric(GenericAssetRegistration registration) const;
|
||||
|
||||
template<typename AssetType> XAssetInfo<typename AssetType::Type>* LoadDependency(const std::string& assetName)
|
||||
{
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
return static_cast<XAssetInfo<typename AssetType::Type>*>(LoadDependencyInternal(AssetType::EnumEntry, assetName));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* LoadDependencyGeneric(asset_type_t assetType, const std::string& assetName);
|
||||
|
||||
template<typename AssetType> IndirectAssetReference LoadIndirectAssetReference(const std::string& assetName)
|
||||
{
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
return LoadIndirectAssetReferenceInternal(AssetType::EnumEntry, assetName);
|
||||
}
|
||||
|
||||
IndirectAssetReference LoadIndirectAssetReferenceGeneric(asset_type_t assetType, const std::string& assetName);
|
||||
|
||||
template<typename T> T* GetZoneAssetLoaderState()
|
||||
{
|
||||
static_assert(std::is_base_of_v<IZoneAssetLoaderState, T>, "T must inherit IZoneAssetLoaderState");
|
||||
// T must also have a public default constructor
|
||||
|
||||
const auto foundEntry = m_zone_asset_loader_states.find(typeid(T));
|
||||
if (foundEntry != m_zone_asset_loader_states.end())
|
||||
return dynamic_cast<T*>(foundEntry->second.get());
|
||||
|
||||
auto newState = std::make_unique<T>();
|
||||
newState->SetZone(&m_zone);
|
||||
auto* newStatePtr = newState.get();
|
||||
m_zone_asset_loader_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetLoaderState>>(typeid(T), std::move(newState)));
|
||||
return newStatePtr;
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] XAssetInfoGeneric* LoadDefaultAssetDependency(asset_type_t assetType, const std::string& assetName) const;
|
||||
|
||||
Zone* m_zone;
|
||||
const AssetCreatorCollection* m_creators;
|
||||
const IgnoredAssetLookup* m_ignored_asset_lookup;
|
||||
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetLoaderState>> m_zone_asset_loader_states;
|
||||
};
|
65
src/ObjLoading/Asset/AssetCreatorCollection.cpp
Normal file
65
src/ObjLoading/Asset/AssetCreatorCollection.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include "AssetCreatorCollection.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
AssetCreatorCollection::AssetCreatorCollection(const Zone& zone)
|
||||
{
|
||||
m_asset_creators_by_type.resize(zone.m_pools->GetAssetTypeCount());
|
||||
}
|
||||
|
||||
void AssetCreatorCollection::AddAssetCreator(std::unique_ptr<IAssetCreator> creator)
|
||||
{
|
||||
const auto maybeHandlingAssetType = creator->GetHandlingAssetType();
|
||||
assert(!maybeHandlingAssetType || static_cast<unsigned>(*maybeHandlingAssetType) < m_asset_creators_by_type.size());
|
||||
if (maybeHandlingAssetType && static_cast<unsigned>(*maybeHandlingAssetType) < m_asset_creators_by_type.size())
|
||||
m_asset_creators_by_type[static_cast<unsigned>(*maybeHandlingAssetType)].emplace_back(creator.get());
|
||||
|
||||
m_asset_creators.emplace_back(std::move(creator));
|
||||
}
|
||||
|
||||
void AssetCreatorCollection::AddDefaultAssetCreator(std::unique_ptr<IDefaultAssetCreator> defaultAssetCreator)
|
||||
{
|
||||
const auto handlingAssetType = defaultAssetCreator->GetHandlingAssetType();
|
||||
assert(static_cast<unsigned>(handlingAssetType) < m_default_asset_creators_by_type.size());
|
||||
assert(!m_default_asset_creators_by_type[handlingAssetType]);
|
||||
|
||||
if (static_cast<unsigned>(handlingAssetType) < m_default_asset_creators_by_type.size())
|
||||
m_default_asset_creators_by_type[handlingAssetType] = std::move(defaultAssetCreator);
|
||||
}
|
||||
|
||||
AssetCreationResult AssetCreatorCollection::CreateAsset(const asset_type_t assetType, const std::string& assetName, AssetCreationContext& context) const
|
||||
{
|
||||
assert(assetType >= 0 && static_cast<unsigned>(assetType) < m_asset_creators_by_type.size());
|
||||
|
||||
if (assetType >= 0 && static_cast<unsigned>(assetType) < m_asset_creators_by_type.size())
|
||||
{
|
||||
for (const auto& creator : m_asset_creators_by_type[assetType])
|
||||
{
|
||||
const auto result = creator->CreateAsset(assetName, context);
|
||||
if (result.HasTakenAction())
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return AssetCreationResult::NoAction();
|
||||
}
|
||||
|
||||
AssetCreationResult
|
||||
AssetCreatorCollection::CreateDefaultAsset(const asset_type_t assetType, const std::string& assetName, const AssetCreationContext& context) const
|
||||
{
|
||||
assert(assetType >= 0 && static_cast<unsigned>(assetType) < m_default_asset_creators_by_type.size());
|
||||
|
||||
if (assetType >= 0 && static_cast<unsigned>(assetType) < m_default_asset_creators_by_type.size() && m_default_asset_creators_by_type[assetType])
|
||||
{
|
||||
auto defaultAsset = m_default_asset_creators_by_type[assetType]->CreateDefaultAsset(assetName);
|
||||
return AssetCreationResult::Success(context.AddAssetGeneric(std::move(defaultAsset)));
|
||||
}
|
||||
|
||||
return AssetCreationResult::NoAction();
|
||||
}
|
||||
|
||||
void AssetCreatorCollection::FinalizeZone(AssetCreationContext& context) const
|
||||
{
|
||||
for (const auto& creator : m_asset_creators)
|
||||
creator->FinalizeZone(context);
|
||||
}
|
32
src/ObjLoading/Asset/AssetCreatorCollection.h
Normal file
32
src/ObjLoading/Asset/AssetCreatorCollection.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetCreationContext.h"
|
||||
#include "Game/IGame.h"
|
||||
#include "IAssetCreator.h"
|
||||
#include "IDefaultAssetCreator.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class AssetCreationContext;
|
||||
class IAssetCreator;
|
||||
class AssetCreationResult;
|
||||
class IDefaultAssetCreator;
|
||||
|
||||
class AssetCreatorCollection
|
||||
{
|
||||
public:
|
||||
explicit AssetCreatorCollection(const Zone& zone);
|
||||
|
||||
void AddAssetCreator(std::unique_ptr<IAssetCreator> creator);
|
||||
void AddDefaultAssetCreator(std::unique_ptr<IDefaultAssetCreator> defaultAssetCreator);
|
||||
|
||||
AssetCreationResult CreateAsset(asset_type_t assetType, const std::string& assetName, AssetCreationContext& context) const;
|
||||
AssetCreationResult CreateDefaultAsset(asset_type_t assetType, const std::string& assetName, const AssetCreationContext& context) const;
|
||||
void FinalizeZone(AssetCreationContext& context) const;
|
||||
|
||||
private:
|
||||
std::vector<std::vector<IAssetCreator*>> m_asset_creators_by_type;
|
||||
std::vector<std::unique_ptr<IDefaultAssetCreator>> m_default_asset_creators_by_type;
|
||||
std::vector<std::unique_ptr<IAssetCreator>> m_asset_creators;
|
||||
};
|
51
src/ObjLoading/Asset/AssetRegistration.h
Normal file
51
src/ObjLoading/Asset/AssetRegistration.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IAsset.h"
|
||||
#include "Pool/XAssetInfo.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
class GenericAssetRegistration
|
||||
{
|
||||
protected:
|
||||
GenericAssetRegistration(asset_type_t type, std::string name, void* asset);
|
||||
|
||||
public:
|
||||
GenericAssetRegistration(const GenericAssetRegistration& other) = delete;
|
||||
GenericAssetRegistration(GenericAssetRegistration&& other) = default;
|
||||
GenericAssetRegistration& operator=(const GenericAssetRegistration& other) = delete;
|
||||
GenericAssetRegistration& operator=(GenericAssetRegistration&& other) noexcept = default;
|
||||
|
||||
void AddDependency(XAssetInfoGeneric* dependency);
|
||||
void AddScriptString(scr_string_t scriptString);
|
||||
void AddIndirectAssetReference(IndirectAssetReference indirectAssetReference);
|
||||
|
||||
std::unique_ptr<XAssetInfoGeneric> CreateXAssetInfo();
|
||||
|
||||
private:
|
||||
asset_type_t m_type;
|
||||
std::string m_name;
|
||||
void* m_asset;
|
||||
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
|
||||
std::unordered_set<scr_string_t> m_used_script_strings;
|
||||
std::unordered_set<IndirectAssetReference> m_indirect_asset_references;
|
||||
};
|
||||
|
||||
template<typename AssetType> class AssetRegistration : public GenericAssetRegistration
|
||||
{
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
public:
|
||||
AssetRegistration(std::string assetName, typename AssetType::Type* asset)
|
||||
: GenericAssetRegistration(AssetType::EnumEntry, std::move(assetName), asset)
|
||||
{
|
||||
}
|
||||
|
||||
AssetRegistration(const AssetRegistration& other) = delete;
|
||||
AssetRegistration(AssetRegistration&& other) = default;
|
||||
AssetRegistration& operator=(const AssetRegistration& other) = delete;
|
||||
AssetRegistration& operator=(AssetRegistration&& other) noexcept = default;
|
||||
};
|
37
src/ObjLoading/Asset/IAssetCreator.cpp
Normal file
37
src/ObjLoading/Asset/IAssetCreator.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "IAssetCreator.h"
|
||||
|
||||
AssetCreationResult AssetCreationResult::Success(XAssetInfoGeneric* assetInfo)
|
||||
{
|
||||
return AssetCreationResult(true, assetInfo);
|
||||
}
|
||||
|
||||
AssetCreationResult AssetCreationResult::Failure()
|
||||
{
|
||||
return AssetCreationResult(true, nullptr);
|
||||
}
|
||||
|
||||
AssetCreationResult AssetCreationResult::NoAction()
|
||||
{
|
||||
return AssetCreationResult(false, nullptr);
|
||||
}
|
||||
|
||||
bool AssetCreationResult::HasTakenAction() const
|
||||
{
|
||||
return m_taken_action;
|
||||
}
|
||||
|
||||
bool AssetCreationResult::HasFailed() const
|
||||
{
|
||||
return m_taken_action && m_asset_info == nullptr;
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetCreationResult::GetAssetInfo() const
|
||||
{
|
||||
return m_asset_info;
|
||||
}
|
||||
|
||||
AssetCreationResult::AssetCreationResult(const bool takenAction, XAssetInfoGeneric* assetInfo)
|
||||
: m_taken_action(takenAction),
|
||||
m_asset_info(assetInfo)
|
||||
{
|
||||
}
|
57
src/ObjLoading/Asset/IAssetCreator.h
Normal file
57
src/ObjLoading/Asset/IAssetCreator.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetCreationContext.h"
|
||||
#include "Game/IAsset.h"
|
||||
#include "Pool/XAssetInfo.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
class AssetCreationResult
|
||||
{
|
||||
public:
|
||||
static AssetCreationResult Success(XAssetInfoGeneric* assetInfo);
|
||||
static AssetCreationResult Failure();
|
||||
static AssetCreationResult NoAction();
|
||||
|
||||
[[nodiscard]] bool HasTakenAction() const;
|
||||
[[nodiscard]] bool HasFailed() const;
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAssetInfo() const;
|
||||
|
||||
private:
|
||||
AssetCreationResult(bool takenAction, XAssetInfoGeneric* assetInfo);
|
||||
|
||||
bool m_taken_action;
|
||||
XAssetInfoGeneric* m_asset_info;
|
||||
};
|
||||
|
||||
class AssetCreationContext;
|
||||
|
||||
class IAssetCreator
|
||||
{
|
||||
public:
|
||||
IAssetCreator() = default;
|
||||
virtual ~IAssetCreator() = default;
|
||||
IAssetCreator(const IAssetCreator& other) = default;
|
||||
IAssetCreator(IAssetCreator&& other) noexcept = default;
|
||||
IAssetCreator& operator=(const IAssetCreator& other) = default;
|
||||
IAssetCreator& operator=(IAssetCreator&& other) noexcept = default;
|
||||
|
||||
[[nodiscard]] virtual std::optional<asset_type_t> GetHandlingAssetType() const = 0;
|
||||
virtual AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) = 0;
|
||||
virtual void FinalizeZone(AssetCreationContext& context) {};
|
||||
};
|
||||
|
||||
template<typename AssetType> class AssetCreator : public IAssetCreator
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
[[nodiscard]] std::optional<asset_type_t> GetHandlingAssetType() const override
|
||||
{
|
||||
return AssetType::EnumEntry;
|
||||
};
|
||||
};
|
46
src/ObjLoading/Asset/IDefaultAssetCreator.h
Normal file
46
src/ObjLoading/Asset/IDefaultAssetCreator.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetCreationContext.h"
|
||||
#include "AssetRegistration.h"
|
||||
#include "Game/IAsset.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
class GenericAssetRegistration;
|
||||
template<typename AssetType> class AssetRegistration;
|
||||
|
||||
class IDefaultAssetCreator
|
||||
{
|
||||
public:
|
||||
IDefaultAssetCreator() = default;
|
||||
virtual ~IDefaultAssetCreator() = default;
|
||||
IDefaultAssetCreator(const IDefaultAssetCreator& other) = default;
|
||||
IDefaultAssetCreator(IDefaultAssetCreator&& other) noexcept = default;
|
||||
IDefaultAssetCreator& operator=(const IDefaultAssetCreator& other) = default;
|
||||
IDefaultAssetCreator& operator=(IDefaultAssetCreator&& other) noexcept = default;
|
||||
|
||||
[[nodiscard]] virtual asset_type_t GetHandlingAssetType() const = 0;
|
||||
virtual GenericAssetRegistration CreateDefaultAsset(const std::string& assetName) const = 0;
|
||||
};
|
||||
|
||||
template<typename AssetType> class DefaultAssetCreator : public IDefaultAssetCreator
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
[[nodiscard]] asset_type_t GetHandlingAssetType() const override
|
||||
{
|
||||
return AssetType::EnumEntry;
|
||||
}
|
||||
|
||||
GenericAssetRegistration CreateDefaultAsset(const std::string& assetName) const override
|
||||
{
|
||||
return CreateDefaultAssetInternal(assetName);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual AssetRegistration<typename AssetType::Type> CreateDefaultAssetInternal(const std::string& assetName) const = 0;
|
||||
};
|
@ -62,6 +62,8 @@ void ObjLoader::LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& z
|
||||
|
||||
void ObjLoader::UnloadContainersOfZone(Zone& zone) const {}
|
||||
|
||||
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection) const {}
|
||||
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext& context, const asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, context);
|
||||
|
@ -22,6 +22,8 @@ namespace IW3
|
||||
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
|
||||
void UnloadContainersOfZone(Zone& zone) const override;
|
||||
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection) const override;
|
||||
|
||||
bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext& context) const override;
|
||||
};
|
||||
|
@ -106,6 +106,8 @@ void ObjLoader::LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& z
|
||||
|
||||
void ObjLoader::UnloadContainersOfZone(Zone& zone) const {}
|
||||
|
||||
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection) const {}
|
||||
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, context);
|
||||
|
@ -17,6 +17,8 @@ namespace IW4
|
||||
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
|
||||
void UnloadContainersOfZone(Zone& zone) const override;
|
||||
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection) const override;
|
||||
|
||||
bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext& context) const override;
|
||||
|
||||
|
@ -113,6 +113,8 @@ void ObjLoader::LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& z
|
||||
|
||||
void ObjLoader::UnloadContainersOfZone(Zone& zone) const {}
|
||||
|
||||
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection) const {}
|
||||
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext& context, const asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, context);
|
||||
|
@ -17,6 +17,8 @@ namespace IW5
|
||||
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
|
||||
void UnloadContainersOfZone(Zone& zone) const override;
|
||||
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection) const override;
|
||||
|
||||
bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext& context) const override;
|
||||
|
||||
|
@ -70,6 +70,8 @@ void ObjLoader::LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& z
|
||||
|
||||
void ObjLoader::UnloadContainersOfZone(Zone& zone) const {}
|
||||
|
||||
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection) const {}
|
||||
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, context);
|
||||
|
@ -17,6 +17,8 @@ namespace T5
|
||||
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
|
||||
void UnloadContainersOfZone(Zone& zone) const override;
|
||||
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection) const override;
|
||||
|
||||
bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext& context) const override;
|
||||
|
||||
|
@ -356,6 +356,8 @@ namespace T6
|
||||
IPak::Repository.RemoveContainerReferences(&zone);
|
||||
}
|
||||
|
||||
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection) const {}
|
||||
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext& context, const asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, context);
|
||||
|
@ -22,6 +22,8 @@ namespace T6
|
||||
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
|
||||
void UnloadContainersOfZone(Zone& zone) const override;
|
||||
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection) const override;
|
||||
|
||||
bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext& context) const override;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/AssetCreatorCollection.h"
|
||||
#include "AssetLoading/AssetLoadingContext.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Zone/Zone.h"
|
||||
@ -27,6 +28,8 @@ public:
|
||||
*/
|
||||
virtual void UnloadContainersOfZone(Zone& zone) const = 0;
|
||||
|
||||
virtual void ConfigureCreatorCollection(AssetCreatorCollection& collection) const = 0;
|
||||
|
||||
virtual bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const = 0;
|
||||
virtual void FinalizeAssetsForZone(AssetLoadingContext& context) const = 0;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user