Skip to content

Commit

Permalink
Layers: windowed mode refactor
Browse files Browse the repository at this point in the history
Show game window right before game start
Check if core is initialized and use Core.Params instead of commandLine
in RunApplication()
  • Loading branch information
Xottab-DUTY committed Feb 9, 2018
1 parent f8f2ce9 commit fd56bca
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 51 deletions.
21 changes: 10 additions & 11 deletions src/Layers/xrRender/HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,22 +529,19 @@ void CHW::updateWindowProps(HWND m_hWnd)
RECT m_rcWindowBounds;
float fYOffset = 0.f;
bool bCenter = false;
if (strstr(Core.Params, "-center_screen"))
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
bCenter = true;

#ifndef _EDITOR
if (GEnv.isDedicatedServer)
bCenter = true;
#endif

if (bCenter)
{
RECT DesktopRect;

GetClientRect(GetDesktopWindow(), &DesktopRect);

SetRect(&m_rcWindowBounds, (DesktopRect.right - DevPP.BackBufferWidth) / 2,
(DesktopRect.bottom - DevPP.BackBufferHeight) / 2, (DesktopRect.right + DevPP.BackBufferWidth) / 2,
SetRect(&m_rcWindowBounds,
(DesktopRect.right - DevPP.BackBufferWidth) / 2,
(DesktopRect.bottom - DevPP.BackBufferHeight) / 2,
(DesktopRect.right + DevPP.BackBufferWidth) / 2,
(DesktopRect.bottom + DevPP.BackBufferHeight) / 2);
}
else
Expand All @@ -556,9 +553,11 @@ void CHW::updateWindowProps(HWND m_hWnd)

AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);

SetWindowPos(m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
(m_rcWindowBounds.right - m_rcWindowBounds.left), (m_rcWindowBounds.bottom - m_rcWindowBounds.top),
SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
SetWindowPos(m_hWnd, HWND_NOTOPMOST,
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
m_rcWindowBounds.right - m_rcWindowBounds.left,
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
}
}
else
Expand Down
29 changes: 15 additions & 14 deletions src/Layers/xrRenderDX10/dx10HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,18 +705,17 @@ BOOL CHW::support(D3DFORMAT fmt, DWORD type, DWORD usage)

void CHW::updateWindowProps(HWND m_hWnd)
{
// BOOL bWindowed = strstr(Core.Params,"-dedicated") ? TRUE : !psDeviceFlags.is (rsFullscreen);
BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);
const bool bWindowed = !psDeviceFlags.is(rsFullscreen);

u32 dwWindowStyle = 0;
// Set window properties depending on what mode were in.
if (bWindowed)
{
if (m_move_window)
{
bool bBordersMode = strstr(Core.Params, "-draw_borders");
const bool drawBorders = strstr(Core.Params, "-draw_borders");
dwWindowStyle = WS_VISIBLE;
if (bBordersMode)
if (drawBorders)
dwWindowStyle |= WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle);
// When moving from fullscreen to windowed mode, it is important to
Expand All @@ -730,38 +729,40 @@ void CHW::updateWindowProps(HWND m_hWnd)

RECT m_rcWindowBounds;
float fYOffset = 0.f;
bool bCenter = false;
bool centerScreen = false;
if (strstr(Core.Params, "-center_screen"))
bCenter = true;
centerScreen = true;

if (bCenter)
if (centerScreen)
{
RECT DesktopRect;

GetClientRect(GetDesktopWindow(), &DesktopRect);

SetRect(&m_rcWindowBounds, (DesktopRect.right - m_ChainDesc.BufferDesc.Width) / 2,
SetRect(&m_rcWindowBounds,
(DesktopRect.right - m_ChainDesc.BufferDesc.Width) / 2,
(DesktopRect.bottom - m_ChainDesc.BufferDesc.Height) / 2,
(DesktopRect.right + m_ChainDesc.BufferDesc.Width) / 2,
(DesktopRect.bottom + m_ChainDesc.BufferDesc.Height) / 2);
}
else
{
if (bBordersMode)
if (drawBorders)
fYOffset = GetSystemMetrics(SM_CYCAPTION); // size of the window title bar
SetRect(&m_rcWindowBounds, 0, 0, m_ChainDesc.BufferDesc.Width, m_ChainDesc.BufferDesc.Height);
};

AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);

SetWindowPos(m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
(m_rcWindowBounds.right - m_rcWindowBounds.left), (m_rcWindowBounds.bottom - m_rcWindowBounds.top),
SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
SetWindowPos(m_hWnd, HWND_NOTOPMOST,
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
m_rcWindowBounds.right - m_rcWindowBounds.left,
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
}
}
else
{
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = (WS_POPUP | WS_VISIBLE));
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
}

ShowCursor(FALSE);
Expand Down
38 changes: 24 additions & 14 deletions src/Layers/xrRenderGL/glHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,18 @@ void CHW::Reset(HWND hwnd)

void CHW::updateWindowProps(HWND m_hWnd)
{
bool bWindowed = true;
#ifndef _EDITOR
if (!GEnv.isDedicatedServer)
bWindowed = !psDeviceFlags.is(rsFullscreen);
#endif
const bool bWindowed = !psDeviceFlags.is(rsFullscreen);

u32 dwWindowStyle = 0;
// Set window properties depending on what mode were in.
if (bWindowed)
{
if (m_move_window)
{
dwWindowStyle = WS_BORDER | WS_VISIBLE;
if (!strstr(Core.Params, "-no_dialog_header"))
dwWindowStyle |= WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
const bool drawBorders = strstr(Core.Params, "-draw_borders");
dwWindowStyle = WS_VISIBLE;
if (drawBorders)
dwWindowStyle |= WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle);
// When moving from fullscreen to windowed mode, it is important to
// adjust the window size after recreating the device rather than
Expand All @@ -215,22 +212,36 @@ void CHW::updateWindowProps(HWND m_hWnd)
// desktop.

RECT m_rcWindowBounds;
RECT DesktopRect;
float fYOffset = 0.f;
bool centerScreen = false;
if (strstr(Core.Params, "-center_screen"))
centerScreen = true;

GetClientRect(GetDesktopWindow(), &DesktopRect);
if (centerScreen)
{
RECT DesktopRect;
GetClientRect(GetDesktopWindow(), &DesktopRect);

SetRect(&m_rcWindowBounds,
SetRect(&m_rcWindowBounds,
(DesktopRect.right - psCurrentVidMode[0]) / 2,
(DesktopRect.bottom - psCurrentVidMode[1]) / 2,
(DesktopRect.right + psCurrentVidMode[0]) / 2,
(DesktopRect.bottom + psCurrentVidMode[1]) / 2);
}
else
{
if (drawBorders)
fYOffset = GetSystemMetrics(SM_CYCAPTION); // size of the window title bar
SetRect(&m_rcWindowBounds, 0, 0, psCurrentVidMode[0], psCurrentVidMode[1]);
}

AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);

SetWindowPos(m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top,
SetWindowPos(m_hWnd, HWND_NOTOPMOST,
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
m_rcWindowBounds.right - m_rcWindowBounds.left,
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
}
}
else
Expand All @@ -242,7 +253,6 @@ void CHW::updateWindowProps(HWND m_hWnd)
SetForegroundWindow(m_hWnd);
}


struct _uniq_mode
{
_uniq_mode(LPCSTR v): _val(v) {}
Expand Down
14 changes: 11 additions & 3 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ void CRenderDevice::Run()
}
// Start all threads
mt_bMustExit = FALSE;
ShowWindow(m_hWnd, SW_SHOWNORMAL);
thread_spawn(SecondaryThreadProc, "X-RAY Secondary thread", 0, this);
// Message cycle
seqAppStart.Process(rp_AppStart);
Expand Down Expand Up @@ -481,10 +482,17 @@ void CRenderDevice::RemoveSeqFrame(pureFrame* f)
CRenderDevice* get_device() { return &Device; }
u32 script_time_global() { return Device.dwTimeGlobal; }
u32 script_time_global_async() { return Device.TimerAsync_MMT(); }
SCRIPT_EXPORT(Device, (), {

SCRIPT_EXPORT(Device, (),
{
using namespace luabind;
module(luaState)[def("time_global", &script_time_global), def("time_global_async", &script_time_global_async),
def("device", &get_device), def("is_enough_address_space_available", &is_enough_address_space_available)];
module(luaState)
[
def("time_global", &script_time_global),
def("time_global_async", &script_time_global_async),
def("device", &get_device),
def("is_enough_address_space_available", &is_enough_address_space_available)
];
});

CLoadScreenRenderer::CLoadScreenRenderer() : b_registered(false), b_need_user_input(false) {}
Expand Down
13 changes: 6 additions & 7 deletions src/xrEngine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,8 @@ ENGINE_API void Startup()
g_SpatialSpace = new ISpatial_DB("Spatial obj");
g_SpatialSpacePhysic = new ISpatial_DB("Spatial phys");

// Show main window and destroy splash
splash::hide();
ShowWindow(Device.m_hWnd, SW_SHOWNORMAL);

// Main cycle
splash::hide();
Memory.mem_usage();
Device.Run();
// Destroy APP
Expand All @@ -208,8 +205,10 @@ ENGINE_API void Startup()
destroySound();
}

ENGINE_API int RunApplication(pcstr commandLine)
ENGINE_API int RunApplication()
{
R_ASSERT2(Core.Params, "Core must be initialized");

if (!IsDebuggerPresent())
{
u32 heapFragmentation = 2;
Expand Down Expand Up @@ -244,7 +243,7 @@ ENGINE_API int RunApplication(pcstr commandLine)
Engine.External.CreateRendererList();

pcstr benchName = "-batch_benchmark ";
if (strstr(commandLine, benchName))
if (strstr(Core.Params, benchName))
{
u32 sz = xr_strlen(benchName);
string64 benchmarkName;
Expand All @@ -254,7 +253,7 @@ ENGINE_API int RunApplication(pcstr commandLine)
}

pcstr sashName = "-openautomate ";
if (strstr(commandLine, sashName))
if (strstr(Core.Params, sashName))
{
u32 sz = xr_strlen(sashName);
string512 sashArg;
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ ENGINE_API void InitSound();
ENGINE_API void destroySound();

ENGINE_API void Startup();
ENGINE_API int RunApplication(pcstr commandLine);
ENGINE_API int RunApplication();
2 changes: 1 addition & 1 deletion src/xr_3da/entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int entry_point(pcstr commandLine)
}
Core.Initialize("OpenXRay", nullptr, true, *fsgame ? fsgame : nullptr);

return RunApplication(commandLine);
return RunApplication();
}

int StackoverflowFilter(const int exceptionCode)
Expand Down

0 comments on commit fd56bca

Please sign in to comment.