Skip to content

Commit

Permalink
Move build id calculation to xrCore.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Jan 29, 2016
1 parent 2ee0035 commit 9a02223
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
40 changes: 37 additions & 3 deletions src/xrCore/xrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#endif // DEBUG

XRCORE_API xrCore Core;
XRCORE_API u32 build_id;
XRCORE_API LPCSTR build_date;

namespace CPU
{
Expand Down Expand Up @@ -107,7 +105,8 @@ void xrCore::_initialize(LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs,
#endif
#endif
FS._initialize(flags, 0, fs_fname);
Msg("'%s' build %d, %s\n", "xrCore", build_id, build_date);
CalculateBuildId();
Msg("'%s' build %d, %s\n", "xrCore", buildId, buildDate);
EFS._initialize();
#ifdef DEBUG
#ifndef _EDITOR
Expand Down Expand Up @@ -147,6 +146,41 @@ void xrCore::_destroy()
}
}

void xrCore::CalculateBuildId()
{
const int startDay = 31;
const int startMonth = 1;
const int startYear = 1999;
const char *monthId[12] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
const int daysInMonth[12] =
{
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
buildDate = __DATE__;
int days;
int months = 0;
int years;
string16 month;
string256 buffer;
xr_strcpy(buffer, buildDate);
sscanf(buffer, "%s %d %d", month, &days, &years);
for (int i = 0; i<12; i++)
{
if (_stricmp(monthId[i], month))
continue;
months = i;
break;
}
buildId = (years- startYear)*365+days-startDay;
for (int i = 0; i<months; i++)
buildId += daysInMonth[i];
for (int i = 0; i<startMonth-1; i++)
buildId -= daysInMonth[i];
}

//. why ???
#ifdef _EDITOR
BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpvReserved)
Expand Down
9 changes: 9 additions & 0 deletions src/xrCore/xrCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ class destructor
// ********************************************** The Core definition
class XRCORE_API xrCore
{
private:
const char *buildDate;
u32 buildId;

public:
string64 ApplicationName;
string_path ApplicationPath;
Expand All @@ -213,6 +217,11 @@ class XRCORE_API xrCore
public:
void _initialize(LPCSTR ApplicationName, LogCallback cb = 0, BOOL init_fs = TRUE, LPCSTR fs_fname = 0, bool plugin = false);
void _destroy();
const char *GetBuildDate() const { return buildDate; }
u32 GetBuildId() const { return buildId; }

private:
void CalculateBuildId();
};

extern XRCORE_API xrCore Core;
Expand Down
38 changes: 0 additions & 38 deletions src/xrEngine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
ENGINE_API bool g_dedicated_server = false;
ENGINE_API CApplication *pApp = nullptr;
ENGINE_API CInifile* pGameIni = nullptr;
XRCORE_API const char *build_date;
XRCORE_API u32 build_id;
ENGINE_API bool g_bBenchmark = false;
string512 g_sBenchmarkName;
ENGINE_API string512 g_sLaunchOnExit_params;
Expand All @@ -36,41 +34,6 @@ namespace
HWND logoWindow = nullptr;

void RunBenchmark(const char *name);

void CalculateBuildId()
{
const int startDay = 31;
const int startMonth = 1;
const int startYear = 1999;
const char *monthId[12] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
const int daysInMonth[12] =
{
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
build_date = __DATE__;
int days;
int months = 0;
int years;
string16 month;
string256 buffer;
xr_strcpy(buffer, build_date);
sscanf(buffer, "%s %d %d", month, &days, &years);
for (int i = 0; i<12; i++)
{
if (_stricmp(monthId[i], month))
continue;
months = i;
break;
}
build_id = (years- startYear)*365+days-startDay;
for (int i = 0; i<months; i++)
build_id += daysInMonth[i];
for (int i = 0; i<startMonth-1; i++)
build_id -= daysInMonth[i];
}
}

void InitEngine()
Expand Down Expand Up @@ -397,7 +360,6 @@ int RunApplication(const char *commandLine)
u32 sz = xr_strlen(fsltx);
sscanf(strstr(commandLine, fsltx)+sz, "%[^ ] ", fsgame);
}
CalculateBuildId();
Core._initialize("xray", NULL, TRUE, *fsgame ? fsgame : nullptr);
InitSettings();
// Adjust player & computer name for Asian
Expand Down

0 comments on commit 9a02223

Please sign in to comment.