Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve building IWD and IPak obj containers #286

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -143,6 +144,7 @@ group "Components"
ZoneLoading:project()
ZoneWriting:project()
ObjCommon:project()
ObjCompiling:project()
ObjImage:project()
ObjLoading:project()
ObjWriting:project()
Expand Down
2 changes: 2 additions & 0 deletions src/Linker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ function Linker:project()
self:include(includes)
Utils:include(includes)
ZoneLoading:include(includes)
ObjCompiling:include(includes)
ObjLoading:include(includes)
ObjWriting:include(includes)
ZoneWriting:include(includes)

Raw:use()

links:linkto(Utils)
links:linkto(ObjCompiling)
links:linkto(ZoneLoading)
links:linkto(ZoneWriting)
links:linkto(ObjLoading)
Expand Down
59 changes: 1 addition & 58 deletions src/Linker/Game/IW3/ZoneCreatorIW3.cpp
Original file line number Diff line number Diff line change
@@ -1,71 +1,14 @@
#include "ZoneCreatorIW3.h"

#include "AssetLoading/AssetLoadingContext.h"
#include "Game/IW3/GameAssetPoolIW3.h"
#include "Game/IW3/GameIW3.h"
#include "IObjLoader.h"
#include "ObjLoading.h"
#include "Utils/StringUtils.h"
#include "Game/IW3/IW3.h"

using namespace IW3;

std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context)
{
std::vector<Gdt*> gdtList;
gdtList.reserve(context.m_gdt_files.size());
for (const auto& gdt : context.m_gdt_files)
gdtList.push_back(gdt.get());

return gdtList;
}

void ZoneCreator::ApplyIgnoredAssets(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;
}

void ZoneCreator::CreateZoneAssetPools(Zone* zone) const
{
zone->m_pools = std::make_unique<GameAssetPoolIW3>(zone, zone->m_priority);

for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
zone->m_pools->InitPoolDynamic(assetType);
}

GameId ZoneCreator::GetGameId() const
{
return GameId::IW3;
}

std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, IGame::GetGameById(GameId::IW3));
CreateZoneAssetPools(zone.get());

for (const auto& assetEntry : context.m_definition->m_assets)
{
if (!assetEntry.m_is_reference)
continue;

context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference);
}

const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(*zone, *context.m_asset_search_path, CreateGdtList(context));
ApplyIgnoredAssets(context, *assetLoadingContext);

const auto* objLoader = IObjLoader::GetObjLoaderForGame(GameId::IW3);
for (const auto& assetEntry : context.m_definition->m_assets)
{
if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
return nullptr;
}

objLoader->FinalizeAssetsForZone(*assetLoadingContext);

return zone;
}

asset_type_t ZoneCreator::GetImageAssetType() const
{
return ASSET_TYPE_IMAGE;
Expand Down
7 changes: 0 additions & 7 deletions src/Linker/Game/IW3/ZoneCreatorIW3.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#pragma once

#include "AssetLoading/AssetLoadingContext.h"
#include "Zone/ZoneTypes.h"
#include "ZoneCreation/ZoneCreator.h"

namespace IW3
{
class ZoneCreator final : public IZoneCreator
{
static std::vector<Gdt*> CreateGdtList(const ZoneCreationContext& context);
static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext);
void CreateZoneAssetPools(Zone* zone) const;

public:
[[nodiscard]] GameId GetGameId() const override;
[[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override;
[[nodiscard]] asset_type_t GetImageAssetType() const override;
};
} // namespace IW3
58 changes: 1 addition & 57 deletions src/Linker/Game/IW4/ZoneCreatorIW4.cpp
Original file line number Diff line number Diff line change
@@ -1,70 +1,14 @@
#include "ZoneCreatorIW4.h"

#include "Game/IW4/GameAssetPoolIW4.h"
#include "Game/IW4/GameIW4.h"
#include "IObjLoader.h"
#include "ObjLoading.h"
#include "Utils/StringUtils.h"
#include "Game/IW4/IW4.h"

using namespace IW4;

std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context)
{
std::vector<Gdt*> gdtList;
gdtList.reserve(context.m_gdt_files.size());
for (const auto& gdt : context.m_gdt_files)
gdtList.push_back(gdt.get());

return gdtList;
}

void ZoneCreator::ApplyIgnoredAssets(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;
}

void ZoneCreator::CreateZoneAssetPools(Zone* zone) const
{
zone->m_pools = std::make_unique<GameAssetPoolIW4>(zone, zone->m_priority);

for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
zone->m_pools->InitPoolDynamic(assetType);
}

GameId ZoneCreator::GetGameId() const
{
return GameId::IW4;
}

std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, IGame::GetGameById(GameId::IW4));
CreateZoneAssetPools(zone.get());

for (const auto& assetEntry : context.m_definition->m_assets)
{
if (!assetEntry.m_is_reference)
continue;

context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference);
}

const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(*zone, *context.m_asset_search_path, CreateGdtList(context));
ApplyIgnoredAssets(context, *assetLoadingContext);

const auto* objLoader = IObjLoader::GetObjLoaderForGame(GameId::IW4);
for (const auto& assetEntry : context.m_definition->m_assets)
{
if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
return nullptr;
}

objLoader->FinalizeAssetsForZone(*assetLoadingContext);

return zone;
}

asset_type_t ZoneCreator::GetImageAssetType() const
{
return ASSET_TYPE_IMAGE;
Expand Down
7 changes: 0 additions & 7 deletions src/Linker/Game/IW4/ZoneCreatorIW4.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#pragma once

#include "AssetLoading/AssetLoadingContext.h"
#include "Zone/ZoneTypes.h"
#include "ZoneCreation/ZoneCreator.h"

namespace IW4
{
class ZoneCreator final : public IZoneCreator
{
static std::vector<Gdt*> CreateGdtList(const ZoneCreationContext& context);
static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext);
void CreateZoneAssetPools(Zone* zone) const;

public:
[[nodiscard]] GameId GetGameId() const override;
[[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override;
[[nodiscard]] asset_type_t GetImageAssetType() const override;
};
} // namespace IW4
58 changes: 1 addition & 57 deletions src/Linker/Game/IW5/ZoneCreatorIW5.cpp
Original file line number Diff line number Diff line change
@@ -1,70 +1,14 @@
#include "ZoneCreatorIW5.h"

#include "Game/IW5/GameAssetPoolIW5.h"
#include "Game/IW5/GameIW5.h"
#include "IObjLoader.h"
#include "ObjLoading.h"
#include "Utils/StringUtils.h"
#include "Game/IW5/IW5.h"

using namespace IW5;

std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context)
{
std::vector<Gdt*> gdtList;
gdtList.reserve(context.m_gdt_files.size());
for (const auto& gdt : context.m_gdt_files)
gdtList.push_back(gdt.get());

return gdtList;
}

void ZoneCreator::ApplyIgnoredAssets(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;
}

void ZoneCreator::CreateZoneAssetPools(Zone* zone) const
{
zone->m_pools = std::make_unique<GameAssetPoolIW5>(zone, zone->m_priority);

for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
zone->m_pools->InitPoolDynamic(assetType);
}

GameId ZoneCreator::GetGameId() const
{
return GameId::IW5;
}

std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, IGame::GetGameById(GameId::IW5));
CreateZoneAssetPools(zone.get());

for (const auto& assetEntry : context.m_definition->m_assets)
{
if (!assetEntry.m_is_reference)
continue;

context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference);
}

const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(*zone, *context.m_asset_search_path, CreateGdtList(context));
ApplyIgnoredAssets(context, *assetLoadingContext);

const auto* objLoader = IObjLoader::GetObjLoaderForGame(GameId::IW5);
for (const auto& assetEntry : context.m_definition->m_assets)
{
if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
return nullptr;
}

objLoader->FinalizeAssetsForZone(*assetLoadingContext);

return zone;
}

asset_type_t ZoneCreator::GetImageAssetType() const
{
return ASSET_TYPE_IMAGE;
Expand Down
8 changes: 1 addition & 7 deletions src/Linker/Game/IW5/ZoneCreatorIW5.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#pragma once
#include "AssetLoading/AssetLoadingContext.h"
#include "Zone/ZoneTypes.h"

#include "ZoneCreation/ZoneCreator.h"

namespace IW5
{
class ZoneCreator final : public IZoneCreator
{
static std::vector<Gdt*> CreateGdtList(const ZoneCreationContext& context);
static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext);
void CreateZoneAssetPools(Zone* zone) const;

public:
[[nodiscard]] GameId GetGameId() const override;
[[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override;
[[nodiscard]] asset_type_t GetImageAssetType() const override;
};
} // namespace IW5
59 changes: 1 addition & 58 deletions src/Linker/Game/T5/ZoneCreatorT5.cpp
Original file line number Diff line number Diff line change
@@ -1,71 +1,14 @@
#include "ZoneCreatorT5.h"

#include "AssetLoading/AssetLoadingContext.h"
#include "Game/T5/GameAssetPoolT5.h"
#include "Game/T5/GameT5.h"
#include "IObjLoader.h"
#include "ObjLoading.h"
#include "Utils/StringUtils.h"
#include "Game/T5/T5.h"

using namespace T5;

std::vector<Gdt*> ZoneCreator::CreateGdtList(ZoneCreationContext& context)
{
std::vector<Gdt*> gdtList;
gdtList.reserve(context.m_gdt_files.size());
for (const auto& gdt : context.m_gdt_files)
gdtList.push_back(gdt.get());

return gdtList;
}

void ZoneCreator::ApplyIgnoredAssets(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;
}

void ZoneCreator::CreateZoneAssetPools(Zone* zone) const
{
zone->m_pools = std::make_unique<GameAssetPoolT5>(zone, zone->m_priority);

for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
zone->m_pools->InitPoolDynamic(assetType);
}

GameId ZoneCreator::GetGameId() const
{
return GameId::T5;
}

std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, IGame::GetGameById(GameId::T5));
CreateZoneAssetPools(zone.get());

for (const auto& assetEntry : context.m_definition->m_assets)
{
if (!assetEntry.m_is_reference)
continue;

context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference);
}

const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(*zone, *context.m_asset_search_path, CreateGdtList(context));
ApplyIgnoredAssets(context, *assetLoadingContext);

const auto* objLoader = IObjLoader::GetObjLoaderForGame(GameId::T5);
for (const auto& assetEntry : context.m_definition->m_assets)
{
if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
return nullptr;
}

objLoader->FinalizeAssetsForZone(*assetLoadingContext);

return zone;
}

asset_type_t ZoneCreator::GetImageAssetType() const
{
return ASSET_TYPE_IMAGE;
Expand Down
Loading