Skip to content

Commit

Permalink
Introduced game material system versioning helpers (#392)
Browse files Browse the repository at this point in the history
This will be used to determine the specific version of gamemtl.xr being
used (e.g. SOC, or older builds)
  • Loading branch information
Xottab-DUTY committed Dec 16, 2024
1 parent 3b42b00 commit 4afd892
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/xrMaterialSystem/GameMtlLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ void CGameMtlLibrary::Load()
IReader& fs = *F;

R_ASSERT(fs.find_chunk(GAMEMTLS_CHUNK_VERSION));
const u16 version = fs.r_u16();
if (GAMEMTL_CURRENT_VERSION != version)
m_version = static_cast<EGameMtlVersion>(fs.r_u16());
if (GAMEMTL_CURRENT_VERSION != m_version)
{
Log("CGameMtlLibrary: invalid version. Library can't load.");
Msg("CGameMtlLibrary: unsupported version [%u]. Library can't load.", m_version);
FS.r_close(F);
return;
}
Expand Down
19 changes: 17 additions & 2 deletions src/xrMaterialSystem/GameMtlLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#define MTL_EXPORT_API XR_IMPORT
#endif

constexpr u16 GAMEMTL_CURRENT_VERSION = 0x0001;

constexpr u32 GAMEMTLS_CHUNK_VERSION = 0x1000;
constexpr u32 GAMEMTLS_CHUNK_AUTOINC = 0x1001;
constexpr u32 GAMEMTLS_CHUNK_MTLS = 0x1002;
Expand Down Expand Up @@ -46,6 +44,22 @@ constexpr u32 GAMEMTL_NONE_IDX = u16(-1);

constexpr pcstr GAMEMTL_FILENAME = "gamemtl.xr";

enum EGameMtlVersion : u16
{
// The big issue is that GSC had version 1 in SOC,
// then they introduced a significant change in CS,
// but didn't change the version number...
// In fact, they NEVER have changed the number
// since the system was introduced in 2002.
// So, we introduce helper values:
GAMEMTL_VERSION_SOC = u16(-1),

GAMEMTL_VERSION_UNKNOWN = 0,

// Real version numbers in GAMEMTL_FILENAME:
GAMEMTL_CURRENT_VERSION = 1,
};

// fwd. decl.
class IReader;
class IWriter;
Expand Down Expand Up @@ -233,6 +247,7 @@ class MTL_EXPORT_API CGameMtlLibrary
GameMtlPairVec material_pairs_rt;

u32 m_file_age{};
EGameMtlVersion m_version{};

public:
CGameMtlLibrary();
Expand Down

0 comments on commit 4afd892

Please sign in to comment.