mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
feat: add post processors compiling iwds and ipaks
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
AssetCreatorCollection::AssetCreatorCollection(const Zone& zone)
|
||||
{
|
||||
m_asset_creators_by_type.resize(zone.m_pools->GetAssetTypeCount());
|
||||
m_asset_post_processors_by_type.resize(zone.m_pools->GetAssetTypeCount());
|
||||
m_default_asset_creators_by_type.resize(zone.m_pools->GetAssetTypeCount());
|
||||
}
|
||||
|
||||
@ -18,6 +19,16 @@ void AssetCreatorCollection::AddAssetCreator(std::unique_ptr<IAssetCreator> crea
|
||||
m_asset_creators.emplace_back(std::move(creator));
|
||||
}
|
||||
|
||||
void AssetCreatorCollection::AddAssetPostProcessor(std::unique_ptr<IAssetPostProcessor> postProcessor)
|
||||
{
|
||||
const auto handlingAssetType = postProcessor->GetHandlingAssetType();
|
||||
assert(static_cast<unsigned>(handlingAssetType) < m_asset_post_processors_by_type.size());
|
||||
if (static_cast<unsigned>(handlingAssetType) < m_asset_post_processors_by_type.size())
|
||||
m_asset_post_processors_by_type[static_cast<unsigned>(handlingAssetType)].emplace_back(postProcessor.get());
|
||||
|
||||
m_asset_post_processors.emplace_back(std::move(postProcessor));
|
||||
}
|
||||
|
||||
void AssetCreatorCollection::AddDefaultAssetCreator(std::unique_ptr<IDefaultAssetCreator> defaultAssetCreator)
|
||||
{
|
||||
const auto handlingAssetType = defaultAssetCreator->GetHandlingAssetType();
|
||||
@ -38,7 +49,18 @@ AssetCreationResult AssetCreatorCollection::CreateAsset(const asset_type_t asset
|
||||
{
|
||||
const auto result = creator->CreateAsset(assetName, context);
|
||||
if (result.HasTakenAction())
|
||||
{
|
||||
// Post process asset if creation was successful
|
||||
if (result.HasBeenSuccessful())
|
||||
{
|
||||
assert(static_cast<unsigned>(assetType) < m_asset_post_processors_by_type.size());
|
||||
for (auto* postProcessor : m_asset_post_processors_by_type[assetType])
|
||||
postProcessor->PostProcessAsset(*result.GetAssetInfo(), context);
|
||||
}
|
||||
|
||||
// Return result that was either successful or failed
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,4 +83,6 @@ void AssetCreatorCollection::FinalizeZone(AssetCreationContext& context) const
|
||||
{
|
||||
for (const auto& creator : m_asset_creators)
|
||||
creator->FinalizeZone(context);
|
||||
for (const auto& postProcessor : m_asset_post_processors)
|
||||
postProcessor->FinalizeZone(context);
|
||||
}
|
||||
|
@ -3,13 +3,16 @@
|
||||
#include "AssetCreationContext.h"
|
||||
#include "Game/IGame.h"
|
||||
#include "IAssetCreator.h"
|
||||
#include "IAssetPostProcessor.h"
|
||||
#include "IDefaultAssetCreator.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class AssetCreationContext;
|
||||
class IAssetCreator;
|
||||
class IAssetPostProcessor;
|
||||
class AssetCreationResult;
|
||||
class IDefaultAssetCreator;
|
||||
|
||||
@ -19,6 +22,7 @@ public:
|
||||
explicit AssetCreatorCollection(const Zone& zone);
|
||||
|
||||
void AddAssetCreator(std::unique_ptr<IAssetCreator> creator);
|
||||
void AddAssetPostProcessor(std::unique_ptr<IAssetPostProcessor> postProcessor);
|
||||
void AddDefaultAssetCreator(std::unique_ptr<IDefaultAssetCreator> defaultAssetCreator);
|
||||
|
||||
AssetCreationResult CreateAsset(asset_type_t assetType, const std::string& assetName, AssetCreationContext& context) const;
|
||||
@ -27,6 +31,8 @@ public:
|
||||
|
||||
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;
|
||||
std::vector<std::vector<IAssetPostProcessor*>> m_asset_post_processors_by_type;
|
||||
std::vector<std::unique_ptr<IAssetPostProcessor>> m_asset_post_processors;
|
||||
std::vector<std::unique_ptr<IDefaultAssetCreator>> m_default_asset_creators_by_type;
|
||||
};
|
||||
|
29
src/ObjLoading/Asset/IAssetPostProcessor.h
Normal file
29
src/ObjLoading/Asset/IAssetPostProcessor.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetCreationContext.h"
|
||||
#include "AssetCreationResult.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 AssetCreationContext;
|
||||
|
||||
class IAssetPostProcessor
|
||||
{
|
||||
public:
|
||||
IAssetPostProcessor() = default;
|
||||
virtual ~IAssetPostProcessor() = default;
|
||||
IAssetPostProcessor(const IAssetPostProcessor& other) = default;
|
||||
IAssetPostProcessor(IAssetPostProcessor&& other) noexcept = default;
|
||||
IAssetPostProcessor& operator=(const IAssetPostProcessor& other) = default;
|
||||
IAssetPostProcessor& operator=(IAssetPostProcessor&& other) noexcept = default;
|
||||
|
||||
[[nodiscard]] virtual asset_type_t GetHandlingAssetType() const = 0;
|
||||
virtual void PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) = 0;
|
||||
virtual void FinalizeZone(AssetCreationContext& context){};
|
||||
};
|
Reference in New Issue
Block a user