mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-26 14:21:49 +00:00
chore: adjust asset creation process to use separated AssetCreators
This commit is contained in:
@ -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,69 +0,0 @@
|
||||
#include "ZoneCreatorT6.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
|
||||
{
|
||||
return GameId::T6;
|
||||
}
|
||||
|
||||
asset_type_t ZoneCreator::GetImageAssetType() const
|
||||
{
|
||||
return ASSET_TYPE_IMAGE;
|
||||
}
|
||||
|
||||
void ZoneCreator::HandleMetadata(Zone& zone, const ZoneCreationContext& context) const
|
||||
{
|
||||
std::vector<KeyValuePair> kvpList;
|
||||
|
||||
for (const auto& metaData : context.m_definition->m_properties.m_properties)
|
||||
{
|
||||
if (metaData.first.rfind("level.", 0) == 0)
|
||||
{
|
||||
const std::string strValue = metaData.first.substr(std::char_traits<char>::length("level."));
|
||||
if (strValue.empty())
|
||||
continue;
|
||||
|
||||
int keyHash;
|
||||
if (strValue[0] == '@')
|
||||
{
|
||||
char* endPtr;
|
||||
keyHash = strtol(&strValue[1], &endPtr, 16);
|
||||
|
||||
if (endPtr != &strValue[strValue.size()])
|
||||
{
|
||||
std::cerr << std::format("Could not parse metadata key \"{}\" as hash\n", metaData.first);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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())};
|
||||
kvpList.push_back(kvp);
|
||||
}
|
||||
}
|
||||
|
||||
if (!kvpList.empty())
|
||||
{
|
||||
auto* kvps = zone.GetMemory()->Create<KeyValuePairs>();
|
||||
kvps->name = zone.GetMemory()->Dup(zone.m_name.c_str());
|
||||
kvps->numVariables = static_cast<int>(kvpList.size());
|
||||
kvps->keyValuePairs = 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));
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
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);
|
||||
|
||||
const auto* objCompiler = IObjCompiler::GetObjCompilerForGame(gameId);
|
||||
const auto* objLoader = IObjLoader::GetObjLoaderForGame(gameId);
|
||||
for (const auto& assetEntry : context.m_definition->m_assets)
|
||||
std::unique_ptr<Zone> CreateZoneForDefinition(GameId gameId, ZoneCreationContext& context)
|
||||
{
|
||||
const auto compilerResult = objCompiler->CompileAssetForZone(assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name);
|
||||
if (compilerResult == ObjCompilerResult::FAILURE)
|
||||
return nullptr;
|
||||
auto zone = CreateZone(context, gameId);
|
||||
InitializeAssetPools(*zone, gameId);
|
||||
|
||||
if (compilerResult == ObjCompilerResult::NO_COMPILATION_DONE)
|
||||
IgnoreReferencesFromAssets(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)
|
||||
{
|
||||
if (!objLoader->LoadAssetForZone(assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
|
||||
const auto* createdAsset = creationContext.LoadDependencyGeneric(assetEntry.m_asset_type, assetEntry.m_asset_name);
|
||||
|
||||
if (!createdAsset)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
creatorCollection.FinalizeZone(creationContext);
|
||||
|
||||
return zone;
|
||||
}
|
||||
|
||||
objLoader->FinalizeAssetsForZone(assetLoadingContext);
|
||||
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user