Skip to content

Commit 9a02223

Browse files
author
nitrocaster
committed
Move build id calculation to xrCore.
1 parent 2ee0035 commit 9a02223

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

src/xrCore/xrCore.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#endif // DEBUG
1717

1818
XRCORE_API xrCore Core;
19-
XRCORE_API u32 build_id;
20-
XRCORE_API LPCSTR build_date;
2119

2220
namespace CPU
2321
{
@@ -107,7 +105,8 @@ void xrCore::_initialize(LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs,
107105
#endif
108106
#endif
109107
FS._initialize(flags, 0, fs_fname);
110-
Msg("'%s' build %d, %s\n", "xrCore", build_id, build_date);
108+
CalculateBuildId();
109+
Msg("'%s' build %d, %s\n", "xrCore", buildId, buildDate);
111110
EFS._initialize();
112111
#ifdef DEBUG
113112
#ifndef _EDITOR
@@ -147,6 +146,41 @@ void xrCore::_destroy()
147146
}
148147
}
149148

149+
void xrCore::CalculateBuildId()
150+
{
151+
const int startDay = 31;
152+
const int startMonth = 1;
153+
const int startYear = 1999;
154+
const char *monthId[12] =
155+
{
156+
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
157+
};
158+
const int daysInMonth[12] =
159+
{
160+
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
161+
};
162+
buildDate = __DATE__;
163+
int days;
164+
int months = 0;
165+
int years;
166+
string16 month;
167+
string256 buffer;
168+
xr_strcpy(buffer, buildDate);
169+
sscanf(buffer, "%s %d %d", month, &days, &years);
170+
for (int i = 0; i<12; i++)
171+
{
172+
if (_stricmp(monthId[i], month))
173+
continue;
174+
months = i;
175+
break;
176+
}
177+
buildId = (years- startYear)*365+days-startDay;
178+
for (int i = 0; i<months; i++)
179+
buildId += daysInMonth[i];
180+
for (int i = 0; i<startMonth-1; i++)
181+
buildId -= daysInMonth[i];
182+
}
183+
150184
//. why ???
151185
#ifdef _EDITOR
152186
BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpvReserved)

src/xrCore/xrCore.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ class destructor
200200
// ********************************************** The Core definition
201201
class XRCORE_API xrCore
202202
{
203+
private:
204+
const char *buildDate;
205+
u32 buildId;
206+
203207
public:
204208
string64 ApplicationName;
205209
string_path ApplicationPath;
@@ -213,6 +217,11 @@ class XRCORE_API xrCore
213217
public:
214218
void _initialize(LPCSTR ApplicationName, LogCallback cb = 0, BOOL init_fs = TRUE, LPCSTR fs_fname = 0, bool plugin = false);
215219
void _destroy();
220+
const char *GetBuildDate() const { return buildDate; }
221+
u32 GetBuildId() const { return buildId; }
222+
223+
private:
224+
void CalculateBuildId();
216225
};
217226

218227
extern XRCORE_API xrCore Core;

src/xrEngine/main.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
ENGINE_API bool g_dedicated_server = false;
2424
ENGINE_API CApplication *pApp = nullptr;
2525
ENGINE_API CInifile* pGameIni = nullptr;
26-
XRCORE_API const char *build_date;
27-
XRCORE_API u32 build_id;
2826
ENGINE_API bool g_bBenchmark = false;
2927
string512 g_sBenchmarkName;
3028
ENGINE_API string512 g_sLaunchOnExit_params;
@@ -36,41 +34,6 @@ namespace
3634
HWND logoWindow = nullptr;
3735

3836
void RunBenchmark(const char *name);
39-
40-
void CalculateBuildId()
41-
{
42-
const int startDay = 31;
43-
const int startMonth = 1;
44-
const int startYear = 1999;
45-
const char *monthId[12] =
46-
{
47-
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
48-
};
49-
const int daysInMonth[12] =
50-
{
51-
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
52-
};
53-
build_date = __DATE__;
54-
int days;
55-
int months = 0;
56-
int years;
57-
string16 month;
58-
string256 buffer;
59-
xr_strcpy(buffer, build_date);
60-
sscanf(buffer, "%s %d %d", month, &days, &years);
61-
for (int i = 0; i<12; i++)
62-
{
63-
if (_stricmp(monthId[i], month))
64-
continue;
65-
months = i;
66-
break;
67-
}
68-
build_id = (years- startYear)*365+days-startDay;
69-
for (int i = 0; i<months; i++)
70-
build_id += daysInMonth[i];
71-
for (int i = 0; i<startMonth-1; i++)
72-
build_id -= daysInMonth[i];
73-
}
7437
}
7538

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

0 commit comments

Comments
 (0)