Skip to content

Commit 8fdd7d1

Browse files
committed
Introduced game material system versioning helpers (#392)
This will be used to determine the specific version of gamemtl.xr being used (e.g. SOC, or older builds)
1 parent 3b42b00 commit 8fdd7d1

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/xrMaterialSystem/GameMtlLib.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ void CGameMtlLibrary::Load()
173173
IReader& fs = *F;
174174

175175
R_ASSERT(fs.find_chunk(GAMEMTLS_CHUNK_VERSION));
176-
const u16 version = fs.r_u16();
177-
if (GAMEMTL_CURRENT_VERSION != version)
176+
m_version = static_cast<EGameMtlVersion>(fs.r_u16());
177+
if (GAMEMTL_CURRENT_VERSION != m_version)
178178
{
179-
Log("CGameMtlLibrary: invalid version. Library can't load.");
179+
Msg("CGameMtlLibrary: unsupported version [%u]. Library can't load.", m_version);
180180
FS.r_close(F);
181181
return;
182182
}

src/xrMaterialSystem/GameMtlLib.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#define MTL_EXPORT_API XR_IMPORT
1515
#endif
1616

17-
constexpr u16 GAMEMTL_CURRENT_VERSION = 0x0001;
18-
1917
constexpr u32 GAMEMTLS_CHUNK_VERSION = 0x1000;
2018
constexpr u32 GAMEMTLS_CHUNK_AUTOINC = 0x1001;
2119
constexpr u32 GAMEMTLS_CHUNK_MTLS = 0x1002;
@@ -46,6 +44,22 @@ constexpr u32 GAMEMTL_NONE_IDX = u16(-1);
4644

4745
constexpr pcstr GAMEMTL_FILENAME = "gamemtl.xr";
4846

47+
enum EGameMtlVersion : u16
48+
{
49+
// The big issue is that GSC had version 1 in SOC,
50+
// then they introduced a significant change in CS,
51+
// but didn't changed the version number...
52+
// In fact, they NEVER have changed the number
53+
// since the system was introduced in 2002.
54+
// So, we introduce helper values:
55+
GAMEMTL_VERSION_SOC = u16(-1),
56+
57+
GAMEMTL_VERSION_UNKNOWN = 0,
58+
59+
// Real version numbers in GAMEMTL_FILENAME:
60+
GAMEMTL_CURRENT_VERSION = 1, // SOC/CS/COP
61+
};
62+
4963
// fwd. decl.
5064
class IReader;
5165
class IWriter;
@@ -233,6 +247,7 @@ class MTL_EXPORT_API CGameMtlLibrary
233247
GameMtlPairVec material_pairs_rt;
234248

235249
u32 m_file_age{};
250+
EGameMtlVersion m_version{};
236251

237252
public:
238253
CGameMtlLibrary();

0 commit comments

Comments
 (0)