Skip to content

Commit

Permalink
xrEngine: splash screen creation refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Feb 9, 2018
1 parent c520f41 commit f8f2ce9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 39 deletions.
43 changes: 4 additions & 39 deletions src/xrEngine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#include "Text_Console.h"
#include "xrSASH.h"
#include "xr_ioc_cmd.h"
#include "splash.h"

#ifdef MASTER_GOLD
#define NO_MULTI_INSTANCES
#endif

// global variables
ENGINE_API CApplication* pApp = nullptr;
ENGINE_API CInifile* pGameIni = nullptr;
ENGINE_API bool g_bBenchmark = false;
string512 g_sBenchmarkName;
Expand All @@ -34,8 +34,6 @@ ENGINE_API string_path g_sLaunchWorkingFolder;

namespace
{
HWND logoWindow = nullptr;

void RunBenchmark(pcstr name);
}

Expand Down Expand Up @@ -166,13 +164,15 @@ ENGINE_API void Startup()
{
execUserScript();
InitSound();

// ...command line for auto start
pcstr startArgs = strstr(Core.Params, "-start ");
if (startArgs)
Console->Execute(startArgs + 1);
pcstr loadArgs = strstr(Core.Params, "-load ");
if (loadArgs)
Console->Execute(loadArgs + 1);

// Initialize APP
Device.Create();
LALib.OnCreate();
Expand All @@ -183,12 +183,8 @@ ENGINE_API void Startup()
g_SpatialSpacePhysic = new ISpatial_DB("Spatial phys");

// Show main window and destroy splash
splash::hide();
ShowWindow(Device.m_hWnd, SW_SHOWNORMAL);
if (logoWindow != nullptr)
{
DestroyWindow(logoWindow);
logoWindow = nullptr;
}

// Main cycle
Memory.mem_usage();
Expand All @@ -212,39 +208,8 @@ ENGINE_API void Startup()
destroySound();
}

static INT_PTR CALLBACK LogoWndProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_DESTROY: break;
case WM_CLOSE: DestroyWindow(hw); break;
case WM_COMMAND:
if (LOWORD(wp) == IDCANCEL)
DestroyWindow(hw);
break;
default: return false;
}
return true;
}

ENGINE_API int RunApplication(pcstr commandLine)
{
if (strstr(commandLine, "-nosplash") == 0)
{
logoWindow = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_STARTUP), nullptr, LogoWndProc);
const HWND logoPicture = GetDlgItem(logoWindow, IDC_STATIC_LOGO);
RECT logoRect;
GetWindowRect(logoPicture, &logoRect);
#ifndef DEBUG
HWND prevWindow = (strstr(commandLine, "-splashnotop") == NULL) ? HWND_TOPMOST : HWND_NOTOPMOST;
#else
const HWND prevWindow = HWND_NOTOPMOST;
#endif
SetWindowPos(logoWindow, prevWindow, 0, 0, logoRect.right - logoRect.left, logoRect.bottom - logoRect.top,
SWP_NOMOVE | SWP_SHOWWINDOW);
UpdateWindow(logoWindow);
}

if (!IsDebuggerPresent())
{
u32 heapFragmentation = 2;
Expand Down
47 changes: 47 additions & 0 deletions src/xrEngine/splash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "stdafx.h"
#include "xr_3da/resource.h"
#include "splash.h"

HWND logoWindow = nullptr;

static INT_PTR CALLBACK LogoWndProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_DESTROY: break;
case WM_CLOSE: DestroyWindow(hw); break;
case WM_COMMAND:
if (LOWORD(wp) == IDCANCEL)
DestroyWindow(hw);
break;
default: return false;
}
return true;
}

namespace splash
{
void show(const bool topmost)
{
if (logoWindow)
return;

logoWindow = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_STARTUP), nullptr, LogoWndProc);
const HWND logoPicture = GetDlgItem(logoWindow, IDC_STATIC_LOGO);
RECT logoRect;
GetWindowRect(logoPicture, &logoRect);
const HWND prevWindow = topmost ? HWND_TOPMOST : HWND_NOTOPMOST;
SetWindowPos(logoWindow, prevWindow, 0, 0, logoRect.right - logoRect.left, logoRect.bottom - logoRect.top,
SWP_NOMOVE | SWP_SHOWWINDOW);
UpdateWindow(logoWindow);
}

void hide()
{
if (logoWindow != nullptr)
{
DestroyWindow(logoWindow);
logoWindow = nullptr;
}
}
}
7 changes: 7 additions & 0 deletions src/xrEngine/splash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace splash
{
void ENGINE_API show(const bool topmost);
void ENGINE_API hide();
}
1 change: 1 addition & 0 deletions src/xrEngine/x_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

//---------------------------------------------------------------------

ENGINE_API CApplication* pApp = nullptr;
extern CRenderDevice Device;

#ifdef MASTER_GOLD
Expand Down
2 changes: 2 additions & 0 deletions src/xrEngine/xrEngine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<ClInclude Include="pure_relcase.h" />
<ClInclude Include="Rain.h" />
<ClInclude Include="Render.h" />
<ClInclude Include="splash.h" />
<ClInclude Include="StatGraph.h" />
<ClInclude Include="Stats.h" />
<ClInclude Include="stdafx.h" />
Expand Down Expand Up @@ -375,6 +376,7 @@
<ClCompile Include="pure_relcase.cpp" />
<ClCompile Include="Rain.cpp" />
<ClCompile Include="Render.cpp" />
<ClCompile Include="splash.cpp" />
<ClCompile Include="StatGraph.cpp" />
<ClCompile Include="Stats.cpp" />
<ClCompile Include="stdafx.cpp">
Expand Down
6 changes: 6 additions & 0 deletions src/xrEngine/xrEngine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@
<Filter>General\Profiler</Filter>
</ClInclude>
<ClInclude Include="main.h" />
<ClInclude Include="splash.h">
<Filter>General</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="defines.cpp">
Expand Down Expand Up @@ -873,6 +876,9 @@
<ClCompile Include="profiler.cpp">
<Filter>General\Profiler</Filter>
</ClCompile>
<ClCompile Include="splash.cpp">
<Filter>General</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="ClientServer.txt" />
Expand Down
11 changes: 11 additions & 0 deletions src/xr_3da/entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
#include "StickyKeyFilter.hpp"

#include "xrEngine/main.h"
#include "xrEngine/splash.h"

int entry_point(pcstr commandLine)
{
if (strstr(commandLine, "-nosplash") == nullptr)
{
#ifndef DEBUG
const bool topmost = strstr(commandLine, "-splashnotop") == nullptr ? true : false;
#else
constexpr bool topmost = false;
#endif
splash::show(topmost);
}

if (strstr(commandLine, "-dedicated"))
GEnv.isDedicatedServer = true;

Expand Down

0 comments on commit f8f2ce9

Please sign in to comment.