Skip to content

Commit

Permalink
Entry point refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Feb 3, 2018
1 parent ae05a5e commit 67d3bcf
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 115 deletions.
3 changes: 2 additions & 1 deletion src/xrCore/xrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pc
Memory._initialize();

InitLog();
Msg("%s %s build %d, %s\n", "xdOpenXRay", GetBuildConfiguration(), buildId, buildDate);
Msg("%s %s build %d, %s\n", "OpenXRay", GetBuildConfiguration(), buildId, buildDate);
Msg("command line %s\n", Params);
_initialize_cpu();
R_ASSERT(CPU::ID.hasFeature(CpuFeature::Sse));
ttapi.initialize();
Expand Down
131 changes: 18 additions & 113 deletions src/xrEngine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,22 @@ void Startup()
if (loadArgs)
Console->Execute(loadArgs + 1);
// Initialize APP
ShowWindow(Device.m_hWnd, SW_SHOWNORMAL);
Device.Create();
LALib.OnCreate();
pApp = new CApplication();
g_pGamePersistent = dynamic_cast<IGame_Persistent*>(NEW_INSTANCE(CLSID_GAME_PERSISTANT));
R_ASSERT(g_pGamePersistent);
g_SpatialSpace = new ISpatial_DB("Spatial obj");
g_SpatialSpacePhysic = new ISpatial_DB("Spatial phys");
// Destroy LOGO

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

// Main cycle
Memory.mem_usage();
Device.Run();
Expand Down Expand Up @@ -224,92 +226,24 @@ static INT_PTR CALLBACK LogoWndProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp)
return true;
}

class StickyKeyFilter
XR_EXPORT int RunApplication(pcstr commandLine)
{
bool screensaverState;
STICKYKEYS stickyKeys;
FILTERKEYS filterKeys;
TOGGLEKEYS toggleKeys;
DWORD stickyKeysFlags;
DWORD filterKeysFlags;
DWORD toggleKeysFlags;

public:
StickyKeyFilter()
{
screensaverState = false;
stickyKeysFlags = 0;
filterKeysFlags = 0;
toggleKeysFlags = 0;
stickyKeys = {};
filterKeys = {};
toggleKeys = {};
stickyKeys.cbSize = sizeof(stickyKeys);
filterKeys.cbSize = sizeof(filterKeys);
toggleKeys.cbSize = sizeof(toggleKeys);
}

void initialize()
{
SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &screensaverState, 0);

if (screensaverState)
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, nullptr, 0);

SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
SystemParametersInfo(SPI_GETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
SystemParametersInfo(SPI_GETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);

if (stickyKeys.dwFlags & SKF_AVAILABLE)
{
stickyKeysFlags = stickyKeys.dwFlags;
stickyKeys.dwFlags = 0;
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
}

if (filterKeys.dwFlags & FKF_AVAILABLE)
{
filterKeysFlags = filterKeys.dwFlags;
filterKeys.dwFlags = 0;
SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
}

if (toggleKeys.dwFlags & TKF_AVAILABLE)
{
toggleKeysFlags = toggleKeys.dwFlags;
toggleKeys.dwFlags = 0;
SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);
}
}

~StickyKeyFilter()
if (strstr(commandLine, "-nosplash") == 0)
{
if (screensaverState)
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, nullptr, 0);
if (stickyKeysFlags)
{
stickyKeys.dwFlags = stickyKeysFlags;
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
}
if (filterKeysFlags)
{
filterKeys.dwFlags = filterKeysFlags;
SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
}
if (toggleKeysFlags)
{
toggleKeys.dwFlags = toggleKeysFlags;
SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 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);
}
};

XR_EXPORT int RunApplication(pcstr commandLine)
{
if (strstr(commandLine, "-dedicated"))
GEnv.isDedicatedServer = true;

xrDebug::Initialize(GEnv.isDedicatedServer);
if (!IsDebuggerPresent())
{
u32 heapFragmentation = 2;
Expand All @@ -326,51 +260,22 @@ XR_EXPORT int RunApplication(pcstr commandLine)
return 2;
}
#endif
//SetThreadAffinityMask(GetCurrentThread(), 1);
if (strstr(commandLine, "-nosplash") == 0)
{
logoWindow = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_STARTUP), nullptr, LogoWndProc);
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
HWND prevWindow = HWND_NOTOPMOST;
#endif
SetWindowPos(logoWindow, prevWindow, 0, 0, logoRect.right - logoRect.left, logoRect.bottom - logoRect.top,
SWP_NOMOVE | SWP_SHOWWINDOW);
UpdateWindow(logoWindow);
}
*g_sLaunchOnExit_app = 0;
*g_sLaunchOnExit_params = 0;

pcstr fsltx = "-fsltx ";
string_path fsgame = "";
if (strstr(commandLine, fsltx))
{
u32 sz = xr_strlen(fsltx);
sscanf(strstr(commandLine, fsltx) + sz, "%[^ ] ", fsgame);
}
Core.Initialize("xray", nullptr, true, *fsgame ? fsgame : nullptr);
InitSettings();
// Adjust player & computer name for Asian
if (pSettings->line_exist("string_table", "no_native_input"))
{
xr_strcpy(Core.UserName, sizeof(Core.UserName), "Player");
xr_strcpy(Core.CompName, sizeof(Core.CompName), "Computer");
}

StickyKeyFilter filter;
if (!GEnv.isDedicatedServer)
filter.initialize();

FPU::m24r();
InitEngine();
InitInput();
InitConsole();
Engine.External.CreateRendererList();
Msg("command line %s", commandLine);

pcstr benchName = "-batch_benchmark ";
if (strstr(commandLine, benchName))
Expand Down
81 changes: 81 additions & 0 deletions src/xr_3da/StickyKeyFilter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#pragma once

class StickyKeyFilter
{
bool screensaverState;
STICKYKEYS stickyKeys;
FILTERKEYS filterKeys;
TOGGLEKEYS toggleKeys;
DWORD stickyKeysFlags;
DWORD filterKeysFlags;
DWORD toggleKeysFlags;

public:
StickyKeyFilter()
{
screensaverState = false;
stickyKeysFlags = 0;
filterKeysFlags = 0;
toggleKeysFlags = 0;
stickyKeys = {};
filterKeys = {};
toggleKeys = {};
stickyKeys.cbSize = sizeof(stickyKeys);
filterKeys.cbSize = sizeof(filterKeys);
toggleKeys.cbSize = sizeof(toggleKeys);
}

void initialize()
{
SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &screensaverState, 0);

if (screensaverState)
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, nullptr, 0);

SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
SystemParametersInfo(SPI_GETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
SystemParametersInfo(SPI_GETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);

if (stickyKeys.dwFlags & SKF_AVAILABLE)
{
stickyKeysFlags = stickyKeys.dwFlags;
stickyKeys.dwFlags = 0;
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
}

if (filterKeys.dwFlags & FKF_AVAILABLE)
{
filterKeysFlags = filterKeys.dwFlags;
filterKeys.dwFlags = 0;
SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
}

if (toggleKeys.dwFlags & TKF_AVAILABLE)
{
toggleKeysFlags = toggleKeys.dwFlags;
toggleKeys.dwFlags = 0;
SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);
}
}

~StickyKeyFilter()
{
if (screensaverState)
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, nullptr, 0);
if (stickyKeysFlags)
{
stickyKeys.dwFlags = stickyKeysFlags;
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(stickyKeys), &stickyKeys, 0);
}
if (filterKeysFlags)
{
filterKeys.dwFlags = filterKeysFlags;
SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(filterKeys), &filterKeys, 0);
}
if (toggleKeysFlags)
{
toggleKeys.dwFlags = toggleKeysFlags;
SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(toggleKeys), &toggleKeys, 0);
}
}
};
29 changes: 28 additions & 1 deletion src/xr_3da/entry_point.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
#include "stdafx.h"
#include "resource.h"

#include "StickyKeyFilter.hpp"
#include "xrCore/xrCore.h"
#include "xrCore/xrDebug_macros.h"

extern ENGINE_API int RunApplication(pcstr);

int entry_point(pcstr commandLine)
{
if (strstr(commandLine, "-dedicated"))
GEnv.isDedicatedServer = true;

xrDebug::Initialize(GEnv.isDedicatedServer);

StickyKeyFilter filter;
if (!GEnv.isDedicatedServer)
filter.initialize();

pcstr fsltx = "-fsltx ";
string_path fsgame = "";
if (strstr(commandLine, fsltx))
{
const u32 sz = xr_strlen(fsltx);
sscanf(strstr(commandLine, fsltx) + sz, "%[^ ] ", fsgame);
}
Core.Initialize("OpenXRay", nullptr, true, *fsgame ? fsgame : nullptr);

return RunApplication(commandLine);
}

int StackoverflowFilter(const int exceptionCode)
{
if (exceptionCode == EXCEPTION_STACK_OVERFLOW)
Expand All @@ -16,7 +43,7 @@ int APIENTRY WinMain(HINSTANCE inst, HINSTANCE prevInst, char* commandLine, int
// BugTrap can't handle stack overflow exception, so handle it here
__try
{
result = RunApplication(commandLine);
result = entry_point(commandLine);
}
__except (StackoverflowFilter(GetExceptionCode()))
{
Expand Down
4 changes: 4 additions & 0 deletions src/xr_3da/xr_3da.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,14 @@
<ProjectReference Include="$(SolutionDir)xrEngine\xrEngine.vcxproj">
<Project>{2578c6d8-660d-48ae-9322-7422f8664f06}</Project>
</ProjectReference>
<ProjectReference Include="..\Layers\xrAPI\xrAPI.vcxproj">
<Project>{1daec516-e52c-4a3c-a4da-ae3553e6e0f8}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="StickyKeyFilter.hpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
Expand Down
1 change: 1 addition & 0 deletions src/xr_3da/xr_3da.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ClInclude Include="resource.h">
<Filter>resources</Filter>
</ClInclude>
<ClInclude Include="StickyKeyFilter.hpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="resources">
Expand Down

0 comments on commit 67d3bcf

Please sign in to comment.