openclonk/src/game/C4GameVersion.h

60 lines
1.8 KiB
C
Raw Normal View History

2009-05-08 13:28:41 +00:00
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright (c) 2010-2016, The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
* Distributed under the terms of the ISC license; see accompanying file
* "COPYING" for details.
2009-05-08 13:28:41 +00:00
*
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
* See accompanying file "TRADEMARK" for details.
2009-05-08 13:28:41 +00:00
*
* To redistribute this file separately, substitute the full license texts
* for the above references.
2009-05-08 13:28:41 +00:00
*/
#ifndef C4GAMEVERSION_H
#define C4GAMEVERSION_H
#include "C4Version.h"
#include "lib/C4InputValidation.h"
2009-05-08 13:28:41 +00:00
struct C4GameVersion
{
2009-05-08 13:28:41 +00:00
ValidatedStdCopyStrBuf<C4InVal::VAL_NameAllowEmpty> sEngineName; // status only - not used for comparison
int32_t iVer[2];
2009-05-08 13:28:41 +00:00
C4GameVersion(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
{ Set(szEngine, iVer1, iVer2); }
void Set(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
{ sEngineName.CopyValidated(szEngine); iVer[0]=iVer1; iVer[1]=iVer2; }
2009-05-08 13:28:41 +00:00
StdStrBuf GetString() const
{ return FormatString("%s %d.%d", sEngineName.getData(), (int)iVer[0], (int)iVer[1]); }
2009-05-08 13:28:41 +00:00
bool operator == (const C4GameVersion &rCmp) const
{ return iVer[0]==rCmp.iVer[0] && iVer[1]==rCmp.iVer[1]; }
2009-05-08 13:28:41 +00:00
void CompileFunc(StdCompiler *pComp, bool fEngineName)
{
if (fEngineName)
2009-05-08 13:28:41 +00:00
{
pComp->Value(mkDefaultAdapt(sEngineName, ""));
2010-04-01 21:08:06 +00:00
pComp->Separator();
}
else if (pComp->isCompiler())
2009-05-08 13:28:41 +00:00
sEngineName = "";
pComp->Value(mkArrayAdapt(iVer,2,0));
}
};
2009-05-08 13:28:41 +00:00
// helper
inline int CompareVersion(int iVer1, int iVer2,
int iRVer1 = C4XVER1, int iRVer2 = C4XVER2)
2009-05-08 13:28:41 +00:00
{
if (iVer1 > iRVer1) return 1; if (iVer1 < iRVer1) return -1;
if (iVer2 > iRVer2) return 1; if (iVer2 < iRVer2) return -1;
return 0;
2009-05-08 13:28:41 +00:00
}
#endif // C4GAMEVERSION_H