From fae623fd191575c43aadb39053e618091444114a Mon Sep 17 00:00:00 2001 From: Marc Cannon Date: Wed, 2 Jan 2013 03:45:06 +0000 Subject: [PATCH] Unbreak the OPENITG_VERSION token, which someone broke by setting it to a string instead of an integer. Added comments to clarify purpose. Added code to generate an integer token that defines a build, using its versioning data, and several constants extended to Lua space. --- src/DiagnosticsUtil.cpp | 85 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 16 deletions(-) diff --git a/src/DiagnosticsUtil.cpp b/src/DiagnosticsUtil.cpp index 6f4a159c..f73ddeae 100644 --- a/src/DiagnosticsUtil.cpp +++ b/src/DiagnosticsUtil.cpp @@ -140,26 +140,11 @@ CString DiagnosticsUtil::GetProductVer() return ProductInfo::GetBuildRevision(); } -namespace -{ - /* this allows us to use the serial numbers on home builds for - * debugging information. VersionDate and VersionNumber are extern'd - * from verstub. */ - CString GenerateDebugSerial() - { - return CString(); - } -} - CString DiagnosticsUtil::GetSerialNumber() { /* Attempt to get a serial number from the dongle */ CString sSerial = iButton::GetSerialNumber(); - /* If the dongle failed to read, generate a debug serial. */ - if( sSerial.empty() ) - sSerial = GenerateDebugSerial(); - return sSerial; } @@ -187,11 +172,79 @@ void DiagnosticsUtil::SetInputType( const CString &sType ) g_sInputType = sType; } +/* XXX: this seems pretty weighty to have here. Maybe it should + * be moved to ProductInfo since it deals with versioning... */ +namespace +{ + enum Version + { + VERSION_ALPHA, + VERSION_BETA, + VERSION_GAMMA, + VERSION_OMEGA, + NUM_VERSIONS, + VERSION_INVALID + }; + + static const CString VersionNames[] = + { + "alpha", + "beta", + "gamma", + "omega" + }; + + int ToToken( Version t ) + { + return t * 100; + } + + /* This is a dumb implementation to get the transition done; + * clean up later. */ + int GetVersionTokenFromBuildInfo() + { + CString sVersion = ProductInfo::GetVersion(); + sVersion.MakeLower(); + + Version ver = VERSION_INVALID; + + if( sVersion.find("alpha") != string::npos ) + ver = VERSION_ALPHA; + else if( sVersion.find("beta") != string::npos ) + ver = VERSION_BETA; + else if( sVersion.find("gamma") != string::npos + || sVersion.find("rc") != string::npos ) + ver = VERSION_GAMMA; + else + ver = VERSION_OMEGA; + + unsigned iVersion = 0; + + if( sscanf(sVersion, "%*[A-Za-z] %d", &iVersion) != 1 ) + LOG->Warn( "GetVersionTokenFromBuildInfo(): couldn't parse version string \"%s\"", sVersion.c_str() ); + + unsigned iToken = ToToken(ver) + iVersion; + return iToken; + } +} + // set OPENITG LUA variables from here void SetProgramGlobals( lua_State* L ) { + /* Boolean flag that says this engine is OpenITG */ LUA->SetGlobal( "OPENITG", true ); - LUA->SetGlobal( "OPENITG_VERSION", ProductInfo::GetVersion() ); + + /* Integer flag that allows for new Lua bindings to be used without + * breaking older engine builds; see below for tokens and values. */ + LUA->SetGlobal( "OPENITG_VERSION", GetVersionTokenFromBuildInfo() ); + + /* Tokens to compare the above values against */ + FOREACH_ENUM( Version, NUM_VERSIONS, v ) + { + CString s = VersionNames[v]; + s.MakeUpper(); + LUA->SetGlobal( "VERSION_" + s, ToToken(v) ); + } } REGISTER_WITH_LUA_FUNCTION( SetProgramGlobals ); -- 2.11.0