chore: add ObjCompiling component

This commit is contained in:
Jan 2024-10-20 14:12:16 +02:00
parent f9e0bdaa7b
commit 3803ae24f5
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
17 changed files with 227 additions and 2 deletions

View File

@ -126,6 +126,7 @@ include "src/ZoneLoading.lua"
include "src/ZoneWriting.lua"
include "src/ZoneCommon.lua"
include "src/ObjCommon.lua"
include "src/ObjCompiling.lua"
include "src/ObjImage.lua"
include "src/ObjLoading.lua"
include "src/ObjWriting.lua"
@ -143,6 +144,7 @@ group "Components"
ZoneLoading:project()
ZoneWriting:project()
ObjCommon:project()
ObjCompiling:project()
ObjImage:project()
ObjLoading:project()
ObjWriting:project()

View File

@ -39,6 +39,7 @@ function Linker:project()
self:include(includes)
Utils:include(includes)
ZoneLoading:include(includes)
ObjCompiling:include(includes)
ObjLoading:include(includes)
ObjWriting:include(includes)
ZoneWriting:include(includes)
@ -46,6 +47,7 @@ function Linker:project()
Raw:use()
links:linkto(Utils)
links:linkto(ObjCompiling)
links:linkto(ZoneLoading)
links:linkto(ZoneWriting)
links:linkto(ObjLoading)

View File

@ -5,7 +5,6 @@
#include "ObjContainer/IPak/IPakWriter.h"
#include "ObjContainer/IWD/IWD.h"
#include "ObjContainer/SoundBank/SoundBankWriter.h"
#include "ObjLoading.h"
#include "ObjWriting.h"
#include "SearchPath/SearchPaths.h"
#include "Utils/ObjFileStream.h"

View File

@ -6,6 +6,7 @@
#include "Game/IW5/ZoneCreatorIW5.h"
#include "Game/T5/ZoneCreatorT5.h"
#include "Game/T6/ZoneCreatorT6.h"
#include "IObjCompiler.h"
#include "IObjLoader.h"
#include <cassert>
@ -84,12 +85,20 @@ std::unique_ptr<Zone> IZoneCreator::CreateZoneForDefinition(ZoneCreationContext&
HandleMetadata(*zone, context);
const auto* objCompiler = IObjCompiler::GetObjCompilerForGame(gameId);
const auto* objLoader = IObjLoader::GetObjLoaderForGame(gameId);
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;
if (compilerResult == ObjCompilerResult::NO_COMPILATION_DONE)
{
if (!objLoader->LoadAssetForZone(assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
return nullptr;
}
}
objLoader->FinalizeAssetsForZone(assetLoadingContext);

56
src/ObjCompiling.lua Normal file
View File

@ -0,0 +1,56 @@
ObjCompiling = {}
function ObjCompiling:include(includes)
if includes:handle(self:name()) then
ObjCommon:include(includes)
ObjLoading:include(includes)
ObjImage:include(includes)
ZoneCommon:include(includes)
includedirs {
path.join(ProjectFolder(), "ObjCompiling")
}
end
end
function ObjCompiling:link(links)
links:add(self:name())
links:linkto(Utils)
links:linkto(ObjCommon)
links:linkto(ObjLoading)
links:linkto(ObjImage)
links:linkto(ZoneCommon)
end
function ObjCompiling:use()
end
function ObjCompiling:name()
return "ObjCompiling"
end
function ObjCompiling:project()
local folder = ProjectFolder()
local includes = Includes:create()
project(self:name())
targetdir(TargetDirectoryLib)
location "%{wks.location}/src/%{prj.name}"
kind "StaticLib"
language "C++"
files {
path.join(folder, "ObjCompiling/**.h"),
path.join(folder, "ObjCompiling/**.cpp")
}
vpaths {
["*"] = {
path.join(folder, "ObjCompiling")
}
}
self:include(includes)
Utils:include(includes)
json:include(includes)
end

View File

@ -0,0 +1,8 @@
#include "ObjCompilerIW3.h"
using namespace IW3;
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
{
return ObjCompilerResult::NO_COMPILATION_DONE;
}

View File

@ -0,0 +1,12 @@
#pragma once
#include "IObjCompiler.h"
namespace IW3
{
class ObjCompiler final : public IObjCompiler
{
public:
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
};
} // namespace IW3

View File

@ -0,0 +1,8 @@
#include "ObjCompilerIW4.h"
using namespace IW4;
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
{
return ObjCompilerResult::NO_COMPILATION_DONE;
}

View File

@ -0,0 +1,12 @@
#pragma once
#include "IObjCompiler.h"
namespace IW4
{
class ObjCompiler final : public IObjCompiler
{
public:
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
};
} // namespace IW4

View File

@ -0,0 +1,8 @@
#include "ObjCompilerIW5.h"
using namespace IW5;
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
{
return ObjCompilerResult::NO_COMPILATION_DONE;
}

View File

@ -0,0 +1,12 @@
#pragma once
#include "IObjCompiler.h"
namespace IW5
{
class ObjCompiler final : public IObjCompiler
{
public:
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
};
} // namespace IW5

View File

@ -0,0 +1,8 @@
#include "ObjCompilerT5.h"
using namespace T5;
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
{
return ObjCompilerResult::NO_COMPILATION_DONE;
}

View File

@ -0,0 +1,12 @@
#pragma once
#include "IObjCompiler.h"
namespace T5
{
class ObjCompiler final : public IObjCompiler
{
public:
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
};
} // namespace T5

View File

@ -0,0 +1,8 @@
#include "ObjCompilerT6.h"
using namespace T6;
ObjCompilerResult ObjCompiler::CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
{
return ObjCompilerResult::NO_COMPILATION_DONE;
}

View File

@ -0,0 +1,12 @@
#pragma once
#include "IObjCompiler.h"
namespace T6
{
class ObjCompiler final : public IObjCompiler
{
public:
ObjCompilerResult CompileAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
};
} // namespace T6

View File

@ -0,0 +1,27 @@
#include "IObjCompiler.h"
#include "Game/IW3/ObjCompilerIW3.h"
#include "Game/IW4/ObjCompilerIW4.h"
#include "Game/IW5/ObjCompilerIW5.h"
#include "Game/T5/ObjCompilerT5.h"
#include "Game/T6/ObjCompilerT6.h"
#include <cassert>
const IObjCompiler* IObjCompiler::GetObjCompilerForGame(GameId game)
{
static const IObjCompiler* objCompilers[static_cast<unsigned>(GameId::COUNT)]{
new IW3::ObjCompiler(),
new IW4::ObjCompiler(),
new IW5::ObjCompiler(),
new T5::ObjCompiler(),
new T6::ObjCompiler(),
};
static_assert(std::extent_v<decltype(objCompilers)> == static_cast<unsigned>(GameId::COUNT));
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT));
const auto* result = objCompilers[static_cast<unsigned>(game)];
assert(result);
return result;
}

View File

@ -0,0 +1,30 @@
#pragma once
#include "AssetLoading/AssetLoadingContext.h"
#include "SearchPath/ISearchPath.h"
#include "Zone/Zone.h"
#include <cstdint>
#include <string>
enum class ObjCompilerResult : std::uint8_t
{
COMPILED,
NO_COMPILATION_DONE,
FAILURE
};
class IObjCompiler
{
public:
IObjCompiler() = default;
virtual ~IObjCompiler() = default;
IObjCompiler(const IObjCompiler& other) = default;
IObjCompiler(IObjCompiler&& other) noexcept = default;
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;
static const IObjCompiler* GetObjCompilerForGame(GameId game);
};