Skip to content

Commit 67d3bcf

Browse files
committed
Entry point refactoring
1 parent ae05a5e commit 67d3bcf

File tree

6 files changed

+134
-115
lines changed

6 files changed

+134
-115
lines changed

src/xrCore/xrCore.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pc
7272
Memory._initialize();
7373

7474
InitLog();
75-
Msg("%s %s build %d, %s\n", "xdOpenXRay", GetBuildConfiguration(), buildId, buildDate);
75+
Msg("%s %s build %d, %s\n", "OpenXRay", GetBuildConfiguration(), buildId, buildDate);
76+
Msg("command line %s\n", Params);
7677
_initialize_cpu();
7778
R_ASSERT(CPU::ID.hasFeature(CpuFeature::Sse));
7879
ttapi.initialize();

src/xrEngine/main.cpp

Lines changed: 18 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,22 @@ void Startup()
173173
if (loadArgs)
174174
Console->Execute(loadArgs + 1);
175175
// Initialize APP
176-
ShowWindow(Device.m_hWnd, SW_SHOWNORMAL);
177176
Device.Create();
178177
LALib.OnCreate();
179178
pApp = new CApplication();
180179
g_pGamePersistent = dynamic_cast<IGame_Persistent*>(NEW_INSTANCE(CLSID_GAME_PERSISTANT));
181180
R_ASSERT(g_pGamePersistent);
182181
g_SpatialSpace = new ISpatial_DB("Spatial obj");
183182
g_SpatialSpacePhysic = new ISpatial_DB("Spatial phys");
184-
// Destroy LOGO
183+
184+
// Show main window and destroy splash
185+
ShowWindow(Device.m_hWnd, SW_SHOWNORMAL);
185186
if (logoWindow != nullptr)
186187
{
187188
DestroyWindow(logoWindow);
188189
logoWindow = nullptr;
189190
}
191+
190192
// Main cycle
191193
Memory.mem_usage();
192194
Device.Run();
@@ -224,92 +226,24 @@ static INT_PTR CALLBACK LogoWndProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp)
224226
return true;
225227
}
226228

227-
class StickyKeyFilter
229+
XR_EXPORT int RunApplication(pcstr commandLine)
228230
{
229-
bool screensaverState;
230-
STICKYKEYS stickyKeys;
231-
FILTERKEYS filterKeys;
232-
TOGGLEKEYS toggleKeys;
233-
DWORD stickyKeysFlags;
234-
DWORD filterKeysFlags;
235-
DWORD toggleKeysFlags;
236-
237-
public:
238-
StickyKeyFilter()
239-
{
240-
screensaverState = false;
241-
stickyKeysFlags = 0;
242-
filterKeysFlags = 0;
243-
toggleKeysFlags = 0;
244-
stickyKeys = {};
245-
filterKeys = {};
246-
toggleKeys = {};
247-
stickyKeys.cbSize = sizeof(stickyKeys);
248-
filterKeys.cbSize = sizeof(filterKeys);
249-
toggleKeys.cbSize = sizeof(toggleKeys);
250-
}
251-
252-
void initialize()
253-
{
254-
SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &screensaverState, 0);
255-
256-
if (screensaverState)
257-
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, nullptr, 0);
258-
259-
SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
260-
SystemParametersInfo(SPI_GETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
261-
SystemParametersInfo(SPI_GETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);
262-
263-
if (stickyKeys.dwFlags & SKF_AVAILABLE)
264-
{
265-
stickyKeysFlags = stickyKeys.dwFlags;
266-
stickyKeys.dwFlags = 0;
267-
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
268-
}
269-
270-
if (filterKeys.dwFlags & FKF_AVAILABLE)
271-
{
272-
filterKeysFlags = filterKeys.dwFlags;
273-
filterKeys.dwFlags = 0;
274-
SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
275-
}
276-
277-
if (toggleKeys.dwFlags & TKF_AVAILABLE)
278-
{
279-
toggleKeysFlags = toggleKeys.dwFlags;
280-
toggleKeys.dwFlags = 0;
281-
SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);
282-
}
283-
}
284-
285-
~StickyKeyFilter()
231+
if (strstr(commandLine, "-nosplash") == 0)
286232
{
287-
if (screensaverState)
288-
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, nullptr, 0);
289-
if (stickyKeysFlags)
290-
{
291-
stickyKeys.dwFlags = stickyKeysFlags;
292-
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
293-
}
294-
if (filterKeysFlags)
295-
{
296-
filterKeys.dwFlags = filterKeysFlags;
297-
SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
298-
}
299-
if (toggleKeysFlags)
300-
{
301-
toggleKeys.dwFlags = toggleKeysFlags;
302-
SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);
303-
}
233+
logoWindow = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_STARTUP), nullptr, LogoWndProc);
234+
const HWND logoPicture = GetDlgItem(logoWindow, IDC_STATIC_LOGO);
235+
RECT logoRect;
236+
GetWindowRect(logoPicture, &logoRect);
237+
#ifndef DEBUG
238+
HWND prevWindow = (strstr(commandLine, "-splashnotop") == NULL) ? HWND_TOPMOST : HWND_NOTOPMOST;
239+
#else
240+
const HWND prevWindow = HWND_NOTOPMOST;
241+
#endif
242+
SetWindowPos(logoWindow, prevWindow, 0, 0, logoRect.right - logoRect.left, logoRect.bottom - logoRect.top,
243+
SWP_NOMOVE | SWP_SHOWWINDOW);
244+
UpdateWindow(logoWindow);
304245
}
305-
};
306246

307-
XR_EXPORT int RunApplication(pcstr commandLine)
308-
{
309-
if (strstr(commandLine, "-dedicated"))
310-
GEnv.isDedicatedServer = true;
311-
312-
xrDebug::Initialize(GEnv.isDedicatedServer);
313247
if (!IsDebuggerPresent())
314248
{
315249
u32 heapFragmentation = 2;
@@ -326,51 +260,22 @@ XR_EXPORT int RunApplication(pcstr commandLine)
326260
return 2;
327261
}
328262
#endif
329-
//SetThreadAffinityMask(GetCurrentThread(), 1);
330-
if (strstr(commandLine, "-nosplash") == 0)
331-
{
332-
logoWindow = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_STARTUP), nullptr, LogoWndProc);
333-
HWND logoPicture = GetDlgItem(logoWindow, IDC_STATIC_LOGO);
334-
RECT logoRect;
335-
GetWindowRect(logoPicture, &logoRect);
336-
#ifndef DEBUG
337-
HWND prevWindow = (strstr(commandLine, "-splashnotop") == NULL) ? HWND_TOPMOST : HWND_NOTOPMOST;
338-
#else
339-
HWND prevWindow = HWND_NOTOPMOST;
340-
#endif
341-
SetWindowPos(logoWindow, prevWindow, 0, 0, logoRect.right - logoRect.left, logoRect.bottom - logoRect.top,
342-
SWP_NOMOVE | SWP_SHOWWINDOW);
343-
UpdateWindow(logoWindow);
344-
}
345263
*g_sLaunchOnExit_app = 0;
346264
*g_sLaunchOnExit_params = 0;
347265

348-
pcstr fsltx = "-fsltx ";
349-
string_path fsgame = "";
350-
if (strstr(commandLine, fsltx))
351-
{
352-
u32 sz = xr_strlen(fsltx);
353-
sscanf(strstr(commandLine, fsltx) + sz, "%[^ ] ", fsgame);
354-
}
355-
Core.Initialize("xray", nullptr, true, *fsgame ? fsgame : nullptr);
356266
InitSettings();
357267
// Adjust player & computer name for Asian
358268
if (pSettings->line_exist("string_table", "no_native_input"))
359269
{
360270
xr_strcpy(Core.UserName, sizeof(Core.UserName), "Player");
361271
xr_strcpy(Core.CompName, sizeof(Core.CompName), "Computer");
362272
}
363-
364-
StickyKeyFilter filter;
365-
if (!GEnv.isDedicatedServer)
366-
filter.initialize();
367273

368274
FPU::m24r();
369275
InitEngine();
370276
InitInput();
371277
InitConsole();
372278
Engine.External.CreateRendererList();
373-
Msg("command line %s", commandLine);
374279

375280
pcstr benchName = "-batch_benchmark ";
376281
if (strstr(commandLine, benchName))

src/xr_3da/StickyKeyFilter.hpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#pragma once
2+
3+
class StickyKeyFilter
4+
{
5+
bool screensaverState;
6+
STICKYKEYS stickyKeys;
7+
FILTERKEYS filterKeys;
8+
TOGGLEKEYS toggleKeys;
9+
DWORD stickyKeysFlags;
10+
DWORD filterKeysFlags;
11+
DWORD toggleKeysFlags;
12+
13+
public:
14+
StickyKeyFilter()
15+
{
16+
screensaverState = false;
17+
stickyKeysFlags = 0;
18+
filterKeysFlags = 0;
19+
toggleKeysFlags = 0;
20+
stickyKeys = {};
21+
filterKeys = {};
22+
toggleKeys = {};
23+
stickyKeys.cbSize = sizeof(stickyKeys);
24+
filterKeys.cbSize = sizeof(filterKeys);
25+
toggleKeys.cbSize = sizeof(toggleKeys);
26+
}
27+
28+
void initialize()
29+
{
30+
SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &screensaverState, 0);
31+
32+
if (screensaverState)
33+
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, nullptr, 0);
34+
35+
SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
36+
SystemParametersInfo(SPI_GETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
37+
SystemParametersInfo(SPI_GETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);
38+
39+
if (stickyKeys.dwFlags & SKF_AVAILABLE)
40+
{
41+
stickyKeysFlags = stickyKeys.dwFlags;
42+
stickyKeys.dwFlags = 0;
43+
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
44+
}
45+
46+
if (filterKeys.dwFlags & FKF_AVAILABLE)
47+
{
48+
filterKeysFlags = filterKeys.dwFlags;
49+
filterKeys.dwFlags = 0;
50+
SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
51+
}
52+
53+
if (toggleKeys.dwFlags & TKF_AVAILABLE)
54+
{
55+
toggleKeysFlags = toggleKeys.dwFlags;
56+
toggleKeys.dwFlags = 0;
57+
SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);
58+
}
59+
}
60+
61+
~StickyKeyFilter()
62+
{
63+
if (screensaverState)
64+
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, nullptr, 0);
65+
if (stickyKeysFlags)
66+
{
67+
stickyKeys.dwFlags = stickyKeysFlags;
68+
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
69+
}
70+
if (filterKeysFlags)
71+
{
72+
filterKeys.dwFlags = filterKeysFlags;
73+
SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
74+
}
75+
if (toggleKeysFlags)
76+
{
77+
toggleKeys.dwFlags = toggleKeysFlags;
78+
SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);
79+
}
80+
}
81+
};

src/xr_3da/entry_point.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
#include "stdafx.h"
2+
#include "resource.h"
3+
4+
#include "StickyKeyFilter.hpp"
5+
#include "xrCore/xrCore.h"
26
#include "xrCore/xrDebug_macros.h"
37

48
extern ENGINE_API int RunApplication(pcstr);
59

10+
int entry_point(pcstr commandLine)
11+
{
12+
if (strstr(commandLine, "-dedicated"))
13+
GEnv.isDedicatedServer = true;
14+
15+
xrDebug::Initialize(GEnv.isDedicatedServer);
16+
17+
StickyKeyFilter filter;
18+
if (!GEnv.isDedicatedServer)
19+
filter.initialize();
20+
21+
pcstr fsltx = "-fsltx ";
22+
string_path fsgame = "";
23+
if (strstr(commandLine, fsltx))
24+
{
25+
const u32 sz = xr_strlen(fsltx);
26+
sscanf(strstr(commandLine, fsltx) + sz, "%[^ ] ", fsgame);
27+
}
28+
Core.Initialize("OpenXRay", nullptr, true, *fsgame ? fsgame : nullptr);
29+
30+
return RunApplication(commandLine);
31+
}
32+
633
int StackoverflowFilter(const int exceptionCode)
734
{
835
if (exceptionCode == EXCEPTION_STACK_OVERFLOW)
@@ -16,7 +43,7 @@ int APIENTRY WinMain(HINSTANCE inst, HINSTANCE prevInst, char* commandLine, int
1643
// BugTrap can't handle stack overflow exception, so handle it here
1744
__try
1845
{
19-
result = RunApplication(commandLine);
46+
result = entry_point(commandLine);
2047
}
2148
__except (StackoverflowFilter(GetExceptionCode()))
2249
{

src/xr_3da/xr_3da.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,14 @@
108108
<ProjectReference Include="$(SolutionDir)xrEngine\xrEngine.vcxproj">
109109
<Project>{2578c6d8-660d-48ae-9322-7422f8664f06}</Project>
110110
</ProjectReference>
111+
<ProjectReference Include="..\Layers\xrAPI\xrAPI.vcxproj">
112+
<Project>{1daec516-e52c-4a3c-a4da-ae3553e6e0f8}</Project>
113+
</ProjectReference>
111114
</ItemGroup>
112115
<ItemGroup>
113116
<ClInclude Include="resource.h" />
114117
<ClInclude Include="stdafx.h" />
118+
<ClInclude Include="StickyKeyFilter.hpp" />
115119
</ItemGroup>
116120
<ItemGroup>
117121
<ResourceCompile Include="resource.rc" />

src/xr_3da/xr_3da.vcxproj.filters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ClInclude Include="resource.h">
1010
<Filter>resources</Filter>
1111
</ClInclude>
12+
<ClInclude Include="StickyKeyFilter.hpp" />
1213
</ItemGroup>
1314
<ItemGroup>
1415
<Filter Include="resources">

0 commit comments

Comments
 (0)