Skip to content

Commit

Permalink
Merge pull request #291 from Laupetin/refactor/game-based-interfaces
Browse files Browse the repository at this point in the history
refactor: interfaces with game implementations
  • Loading branch information
Laupetin authored Oct 19, 2024
2 parents eec643f + e80b9d7 commit 3aaa821
Show file tree
Hide file tree
Showing 69 changed files with 343 additions and 470 deletions.
1 change: 1 addition & 0 deletions src/Common/Game/IGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class IGame
IGame& operator=(const IGame& other) = default;
IGame& operator=(IGame&& other) noexcept = default;

virtual GameId GetId() = 0;
virtual std::string GetFullName() = 0;
virtual std::string GetShortName() = 0;
virtual void AddZone(Zone* zone) = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/Common/Game/IW3/GameIW3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ using namespace IW3;

GameIW3 g_GameIW3;

GameId GameIW3::GetId()
{
return GameId::IW3;
}

std::string GameIW3::GetFullName()
{
return "Call Of Duty 4: Modern Warfare";
Expand Down
8 changes: 5 additions & 3 deletions src/Common/Game/IW3/GameIW3.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#pragma once
#include "Game/IGame.h"

class GameIW3 : public IGame
class GameIW3 final : public IGame
{
std::vector<Zone*> m_zones;

public:
GameId GetId() override;
std::string GetFullName() override;
std::string GetShortName() override;
void AddZone(Zone* zone) override;
void RemoveZone(Zone* zone) override;
std::vector<Zone*> GetZones() override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override;

private:
std::vector<Zone*> m_zones;
};

extern GameIW3 g_GameIW3;
5 changes: 5 additions & 0 deletions src/Common/Game/IW4/GameIW4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ using namespace IW4;

GameIW4 g_GameIW4;

GameId GameIW4::GetId()
{
return GameId::IW4;
}

std::string GameIW4::GetFullName()
{
return "Call Of Duty: Modern Warfare 2";
Expand Down
8 changes: 5 additions & 3 deletions src/Common/Game/IW4/GameIW4.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#pragma once
#include "Game/IGame.h"

class GameIW4 : public IGame
class GameIW4 final : public IGame
{
std::vector<Zone*> m_zones;

public:
GameId GetId() override;
std::string GetFullName() override;
std::string GetShortName() override;
void AddZone(Zone* zone) override;
void RemoveZone(Zone* zone) override;
std::vector<Zone*> GetZones() override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override;

private:
std::vector<Zone*> m_zones;
};

extern GameIW4 g_GameIW4;
5 changes: 5 additions & 0 deletions src/Common/Game/IW5/GameIW5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ using namespace IW5;

GameIW5 g_GameIW5;

GameId GameIW5::GetId()
{
return GameId::IW5;
}

std::string GameIW5::GetFullName()
{
return "Call Of Duty: Modern Warfare 3";
Expand Down
8 changes: 5 additions & 3 deletions src/Common/Game/IW5/GameIW5.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#pragma once
#include "Game/IGame.h"

class GameIW5 : public IGame
class GameIW5 final : public IGame
{
std::vector<Zone*> m_zones;

public:
GameId GetId() override;
std::string GetFullName() override;
std::string GetShortName() override;
void AddZone(Zone* zone) override;
void RemoveZone(Zone* zone) override;
std::vector<Zone*> GetZones() override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override;

private:
std::vector<Zone*> m_zones;
};

extern GameIW5 g_GameIW5;
5 changes: 5 additions & 0 deletions src/Common/Game/T5/GameT5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ using namespace T5;

GameT5 g_GameT5;

GameId GameT5::GetId()
{
return GameId::T5;
}

std::string GameT5::GetFullName()
{
return "Call Of Duty: Black Ops";
Expand Down
8 changes: 5 additions & 3 deletions src/Common/Game/T5/GameT5.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#pragma once
#include "Game/IGame.h"

class GameT5 : public IGame
class GameT5 final : public IGame
{
std::vector<Zone*> m_zones;

public:
GameId GetId() override;
std::string GetFullName() override;
std::string GetShortName() override;
void AddZone(Zone* zone) override;
void RemoveZone(Zone* zone) override;
std::vector<Zone*> GetZones() override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override;

private:
std::vector<Zone*> m_zones;
};

extern GameT5 g_GameT5;
5 changes: 5 additions & 0 deletions src/Common/Game/T6/GameT6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ using namespace T6;

GameT6 g_GameT6;

GameId GameT6::GetId()
{
return GameId::T6;
}

std::string GameT6::GetFullName()
{
return "Call Of Duty: Black Ops II";
Expand Down
8 changes: 5 additions & 3 deletions src/Common/Game/T6/GameT6.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#pragma once
#include "Game/IGame.h"

class GameT6 : public IGame
class GameT6 final : public IGame
{
std::vector<Zone*> m_zones;

public:
GameId GetId() override;
std::string GetFullName() override;
std::string GetShortName() override;
void AddZone(Zone* zone) override;
void RemoveZone(Zone* zone) override;
std::vector<Zone*> GetZones() override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override;

private:
std::vector<Zone*> m_zones;
};

extern GameT6 g_GameT6;
6 changes: 4 additions & 2 deletions src/Linker/Game/IW3/ZoneCreatorIW3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "AssetLoading/AssetLoadingContext.h"
#include "Game/IW3/GameAssetPoolIW3.h"
#include "Game/IW3/GameIW3.h"
#include "IObjLoader.h"
#include "ObjLoading.h"
#include "Utils/StringUtils.h"

Expand Down Expand Up @@ -53,13 +54,14 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext&
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 (!ObjLoading::LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
return nullptr;
}

ObjLoading::FinalizeAssetsForZone(*assetLoadingContext);
objLoader->FinalizeAssetsForZone(*assetLoadingContext);

return zone;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Linker/Game/IW4/ZoneCreatorIW4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

Expand Down Expand Up @@ -52,13 +53,14 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext&
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 (!ObjLoading::LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
return nullptr;
}

ObjLoading::FinalizeAssetsForZone(*assetLoadingContext);
objLoader->FinalizeAssetsForZone(*assetLoadingContext);

return zone;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Linker/Game/IW5/ZoneCreatorIW5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

Expand Down Expand Up @@ -52,13 +53,14 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext&
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 (!ObjLoading::LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
return nullptr;
}

ObjLoading::FinalizeAssetsForZone(*assetLoadingContext);
objLoader->FinalizeAssetsForZone(*assetLoadingContext);

return zone;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Linker/Game/T5/ZoneCreatorT5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "AssetLoading/AssetLoadingContext.h"
#include "Game/T5/GameAssetPoolT5.h"
#include "Game/T5/GameT5.h"
#include "IObjLoader.h"
#include "ObjLoading.h"
#include "Utils/StringUtils.h"

Expand Down Expand Up @@ -53,13 +54,14 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext&
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 (!ObjLoading::LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
return nullptr;
}

ObjLoading::FinalizeAssetsForZone(*assetLoadingContext);
objLoader->FinalizeAssetsForZone(*assetLoadingContext);

return zone;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Linker/Game/T6/ZoneCreatorT6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Game/T6/GameAssetPoolT6.h"
#include "Game/T6/GameT6.h"
#include "Game/T6/T6.h"
#include "IObjLoader.h"
#include "ObjLoading.h"
#include "Utils/StringUtils.h"

Expand Down Expand Up @@ -106,13 +107,14 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext&

HandleMetadata(zone.get(), context);

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

ObjLoading::FinalizeAssetsForZone(*assetLoadingContext);
objLoader->FinalizeAssetsForZone(*assetLoadingContext);

return zone;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Linker/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class LinkerImpl final : public Linker
{
std::unique_ptr<ZoneDefinition> zoneDefinition;
{
const auto definitionFileName = targetName + ".zone";
const auto definitionFileName = std::format("{}.zone", targetName);
const auto definitionStream = sourceSearchPath->Open(definitionFileName);
if (!definitionStream.IsOpen())
{
Expand Down
1 change: 1 addition & 0 deletions src/Linker/ZoneCreation/ZoneCreator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ZoneCreator.h"

#include "AssetLoading/AssetLoadingContext.h"
#include "Game/IW3/ZoneCreatorIW3.h"
#include "Game/IW4/ZoneCreatorIW4.h"
#include "Game/IW5/ZoneCreatorIW5.h"
Expand Down
5 changes: 0 additions & 5 deletions src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ ObjLoader::ObjLoader()
#undef REGISTER_ASSET_LOADER
}

bool ObjLoader::SupportsZone(const Zone& zone) const
{
return zone.m_game == &g_GameIW3;
}

bool ObjLoader::IsMpZone(const Zone& zone)
{
return zone.m_name.compare(0, 3, "mp_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_mp") == 0;
Expand Down
2 changes: 0 additions & 2 deletions src/ObjLoading/Game/IW3/ObjLoaderIW3.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace IW3
public:
ObjLoader();

[[nodiscard]] bool SupportsZone(const Zone& zone) const override;

void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
void UnloadContainersOfZone(Zone& zone) const override;

Expand Down
5 changes: 0 additions & 5 deletions src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ ObjLoader::ObjLoader()
#undef REGISTER_ASSET_LOADER
}

bool ObjLoader::SupportsZone(const Zone& zone) const
{
return zone.m_game == &g_GameIW4;
}

bool ObjLoader::IsMpZone(const Zone& zone)
{
return zone.m_name.compare(0, 3, "mp_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_mp") == 0;
Expand Down
2 changes: 0 additions & 2 deletions src/ObjLoading/Game/IW4/ObjLoaderIW4.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace IW4
public:
ObjLoader();

[[nodiscard]] bool SupportsZone(const Zone& zone) const override;

void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
void UnloadContainersOfZone(Zone& zone) const override;

Expand Down
5 changes: 0 additions & 5 deletions src/ObjLoading/Game/IW5/ObjLoaderIW5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ ObjLoader::ObjLoader()
#undef REGISTER_ASSET_LOADER
}

bool ObjLoader::SupportsZone(const Zone& zone) const
{
return zone.m_game == &g_GameIW5;
}

bool ObjLoader::IsMpZone(const Zone& zone)
{
return zone.m_name.compare(0, 3, "mp_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_mp") == 0;
Expand Down
2 changes: 0 additions & 2 deletions src/ObjLoading/Game/IW5/ObjLoaderIW5.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace IW5
public:
ObjLoader();

[[nodiscard]] bool SupportsZone(const Zone& zone) const override;

void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
void UnloadContainersOfZone(Zone& zone) const override;

Expand Down
5 changes: 0 additions & 5 deletions src/ObjLoading/Game/T5/ObjLoaderT5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ ObjLoader::ObjLoader()
#undef REGISTER_ASSET_LOADER
}

bool ObjLoader::SupportsZone(const Zone& zone) const
{
return zone.m_game == &g_GameT5;
}

bool ObjLoader::IsMpZone(const Zone& zone)
{
return zone.m_name.compare(0, 3, "mp_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_mp") == 0;
Expand Down
Loading

0 comments on commit 3aaa821

Please sign in to comment.