Skip to content

Commit f8f2ce9

Browse files
committed
xrEngine: splash screen creation refactor
1 parent c520f41 commit f8f2ce9

File tree

7 files changed

+78
-39
lines changed

7 files changed

+78
-39
lines changed

src/xrEngine/main.cpp

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
#include "Text_Console.h"
1919
#include "xrSASH.h"
2020
#include "xr_ioc_cmd.h"
21+
#include "splash.h"
2122

2223
#ifdef MASTER_GOLD
2324
#define NO_MULTI_INSTANCES
2425
#endif
2526

2627
// global variables
27-
ENGINE_API CApplication* pApp = nullptr;
2828
ENGINE_API CInifile* pGameIni = nullptr;
2929
ENGINE_API bool g_bBenchmark = false;
3030
string512 g_sBenchmarkName;
@@ -34,8 +34,6 @@ ENGINE_API string_path g_sLaunchWorkingFolder;
3434

3535
namespace
3636
{
37-
HWND logoWindow = nullptr;
38-
3937
void RunBenchmark(pcstr name);
4038
}
4139

@@ -166,13 +164,15 @@ ENGINE_API void Startup()
166164
{
167165
execUserScript();
168166
InitSound();
167+
169168
// ...command line for auto start
170169
pcstr startArgs = strstr(Core.Params, "-start ");
171170
if (startArgs)
172171
Console->Execute(startArgs + 1);
173172
pcstr loadArgs = strstr(Core.Params, "-load ");
174173
if (loadArgs)
175174
Console->Execute(loadArgs + 1);
175+
176176
// Initialize APP
177177
Device.Create();
178178
LALib.OnCreate();
@@ -183,12 +183,8 @@ ENGINE_API void Startup()
183183
g_SpatialSpacePhysic = new ISpatial_DB("Spatial phys");
184184

185185
// Show main window and destroy splash
186+
splash::hide();
186187
ShowWindow(Device.m_hWnd, SW_SHOWNORMAL);
187-
if (logoWindow != nullptr)
188-
{
189-
DestroyWindow(logoWindow);
190-
logoWindow = nullptr;
191-
}
192188

193189
// Main cycle
194190
Memory.mem_usage();
@@ -212,39 +208,8 @@ ENGINE_API void Startup()
212208
destroySound();
213209
}
214210

215-
static INT_PTR CALLBACK LogoWndProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp)
216-
{
217-
switch (msg)
218-
{
219-
case WM_DESTROY: break;
220-
case WM_CLOSE: DestroyWindow(hw); break;
221-
case WM_COMMAND:
222-
if (LOWORD(wp) == IDCANCEL)
223-
DestroyWindow(hw);
224-
break;
225-
default: return false;
226-
}
227-
return true;
228-
}
229-
230211
ENGINE_API int RunApplication(pcstr commandLine)
231212
{
232-
if (strstr(commandLine, "-nosplash") == 0)
233-
{
234-
logoWindow = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_STARTUP), nullptr, LogoWndProc);
235-
const HWND logoPicture = GetDlgItem(logoWindow, IDC_STATIC_LOGO);
236-
RECT logoRect;
237-
GetWindowRect(logoPicture, &logoRect);
238-
#ifndef DEBUG
239-
HWND prevWindow = (strstr(commandLine, "-splashnotop") == NULL) ? HWND_TOPMOST : HWND_NOTOPMOST;
240-
#else
241-
const HWND prevWindow = HWND_NOTOPMOST;
242-
#endif
243-
SetWindowPos(logoWindow, prevWindow, 0, 0, logoRect.right - logoRect.left, logoRect.bottom - logoRect.top,
244-
SWP_NOMOVE | SWP_SHOWWINDOW);
245-
UpdateWindow(logoWindow);
246-
}
247-
248213
if (!IsDebuggerPresent())
249214
{
250215
u32 heapFragmentation = 2;

src/xrEngine/splash.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "stdafx.h"
2+
#include "xr_3da/resource.h"
3+
#include "splash.h"
4+
5+
HWND logoWindow = nullptr;
6+
7+
static INT_PTR CALLBACK LogoWndProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp)
8+
{
9+
switch (msg)
10+
{
11+
case WM_DESTROY: break;
12+
case WM_CLOSE: DestroyWindow(hw); break;
13+
case WM_COMMAND:
14+
if (LOWORD(wp) == IDCANCEL)
15+
DestroyWindow(hw);
16+
break;
17+
default: return false;
18+
}
19+
return true;
20+
}
21+
22+
namespace splash
23+
{
24+
void show(const bool topmost)
25+
{
26+
if (logoWindow)
27+
return;
28+
29+
logoWindow = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_STARTUP), nullptr, LogoWndProc);
30+
const HWND logoPicture = GetDlgItem(logoWindow, IDC_STATIC_LOGO);
31+
RECT logoRect;
32+
GetWindowRect(logoPicture, &logoRect);
33+
const HWND prevWindow = topmost ? HWND_TOPMOST : HWND_NOTOPMOST;
34+
SetWindowPos(logoWindow, prevWindow, 0, 0, logoRect.right - logoRect.left, logoRect.bottom - logoRect.top,
35+
SWP_NOMOVE | SWP_SHOWWINDOW);
36+
UpdateWindow(logoWindow);
37+
}
38+
39+
void hide()
40+
{
41+
if (logoWindow != nullptr)
42+
{
43+
DestroyWindow(logoWindow);
44+
logoWindow = nullptr;
45+
}
46+
}
47+
}

src/xrEngine/splash.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
namespace splash
4+
{
5+
void ENGINE_API show(const bool topmost);
6+
void ENGINE_API hide();
7+
}

src/xrEngine/x_ray.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
//---------------------------------------------------------------------
2222

23+
ENGINE_API CApplication* pApp = nullptr;
2324
extern CRenderDevice Device;
2425

2526
#ifdef MASTER_GOLD

src/xrEngine/xrEngine.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@
268268
<ClInclude Include="pure_relcase.h" />
269269
<ClInclude Include="Rain.h" />
270270
<ClInclude Include="Render.h" />
271+
<ClInclude Include="splash.h" />
271272
<ClInclude Include="StatGraph.h" />
272273
<ClInclude Include="Stats.h" />
273274
<ClInclude Include="stdafx.h" />
@@ -375,6 +376,7 @@
375376
<ClCompile Include="pure_relcase.cpp" />
376377
<ClCompile Include="Rain.cpp" />
377378
<ClCompile Include="Render.cpp" />
379+
<ClCompile Include="splash.cpp" />
378380
<ClCompile Include="StatGraph.cpp" />
379381
<ClCompile Include="Stats.cpp" />
380382
<ClCompile Include="stdafx.cpp">

src/xrEngine/xrEngine.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@
556556
<Filter>General\Profiler</Filter>
557557
</ClInclude>
558558
<ClInclude Include="main.h" />
559+
<ClInclude Include="splash.h">
560+
<Filter>General</Filter>
561+
</ClInclude>
559562
</ItemGroup>
560563
<ItemGroup>
561564
<ClCompile Include="defines.cpp">
@@ -873,6 +876,9 @@
873876
<ClCompile Include="profiler.cpp">
874877
<Filter>General\Profiler</Filter>
875878
</ClCompile>
879+
<ClCompile Include="splash.cpp">
880+
<Filter>General</Filter>
881+
</ClCompile>
876882
</ItemGroup>
877883
<ItemGroup>
878884
<Text Include="ClientServer.txt" />

src/xr_3da/entry_point.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
#include "StickyKeyFilter.hpp"
44

55
#include "xrEngine/main.h"
6+
#include "xrEngine/splash.h"
67

78
int entry_point(pcstr commandLine)
89
{
10+
if (strstr(commandLine, "-nosplash") == nullptr)
11+
{
12+
#ifndef DEBUG
13+
const bool topmost = strstr(commandLine, "-splashnotop") == nullptr ? true : false;
14+
#else
15+
constexpr bool topmost = false;
16+
#endif
17+
splash::show(topmost);
18+
}
19+
920
if (strstr(commandLine, "-dedicated"))
1021
GEnv.isDedicatedServer = true;
1122

0 commit comments

Comments
 (0)