Skip to content

Commit fd56bca

Browse files
committed
Layers: windowed mode refactor
Show game window right before game start Check if core is initialized and use Core.Params instead of commandLine in RunApplication()
1 parent f8f2ce9 commit fd56bca

File tree

7 files changed

+68
-51
lines changed

7 files changed

+68
-51
lines changed

src/Layers/xrRender/HW.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,22 +529,19 @@ void CHW::updateWindowProps(HWND m_hWnd)
529529
RECT m_rcWindowBounds;
530530
float fYOffset = 0.f;
531531
bool bCenter = false;
532-
if (strstr(Core.Params, "-center_screen"))
532+
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
533533
bCenter = true;
534534

535-
#ifndef _EDITOR
536-
if (GEnv.isDedicatedServer)
537-
bCenter = true;
538-
#endif
539-
540535
if (bCenter)
541536
{
542537
RECT DesktopRect;
543538

544539
GetClientRect(GetDesktopWindow(), &DesktopRect);
545540

546-
SetRect(&m_rcWindowBounds, (DesktopRect.right - DevPP.BackBufferWidth) / 2,
547-
(DesktopRect.bottom - DevPP.BackBufferHeight) / 2, (DesktopRect.right + DevPP.BackBufferWidth) / 2,
541+
SetRect(&m_rcWindowBounds,
542+
(DesktopRect.right - DevPP.BackBufferWidth) / 2,
543+
(DesktopRect.bottom - DevPP.BackBufferHeight) / 2,
544+
(DesktopRect.right + DevPP.BackBufferWidth) / 2,
548545
(DesktopRect.bottom + DevPP.BackBufferHeight) / 2);
549546
}
550547
else
@@ -556,9 +553,11 @@ void CHW::updateWindowProps(HWND m_hWnd)
556553

557554
AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);
558555

559-
SetWindowPos(m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
560-
(m_rcWindowBounds.right - m_rcWindowBounds.left), (m_rcWindowBounds.bottom - m_rcWindowBounds.top),
561-
SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
556+
SetWindowPos(m_hWnd, HWND_NOTOPMOST,
557+
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
558+
m_rcWindowBounds.right - m_rcWindowBounds.left,
559+
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
560+
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
562561
}
563562
}
564563
else

src/Layers/xrRenderDX10/dx10HW.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -705,18 +705,17 @@ BOOL CHW::support(D3DFORMAT fmt, DWORD type, DWORD usage)
705705

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

711710
u32 dwWindowStyle = 0;
712711
// Set window properties depending on what mode were in.
713712
if (bWindowed)
714713
{
715714
if (m_move_window)
716715
{
717-
bool bBordersMode = strstr(Core.Params, "-draw_borders");
716+
const bool drawBorders = strstr(Core.Params, "-draw_borders");
718717
dwWindowStyle = WS_VISIBLE;
719-
if (bBordersMode)
718+
if (drawBorders)
720719
dwWindowStyle |= WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
721720
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle);
722721
// When moving from fullscreen to windowed mode, it is important to
@@ -730,38 +729,40 @@ void CHW::updateWindowProps(HWND m_hWnd)
730729

731730
RECT m_rcWindowBounds;
732731
float fYOffset = 0.f;
733-
bool bCenter = false;
732+
bool centerScreen = false;
734733
if (strstr(Core.Params, "-center_screen"))
735-
bCenter = true;
734+
centerScreen = true;
736735

737-
if (bCenter)
736+
if (centerScreen)
738737
{
739738
RECT DesktopRect;
740-
741739
GetClientRect(GetDesktopWindow(), &DesktopRect);
742740

743-
SetRect(&m_rcWindowBounds, (DesktopRect.right - m_ChainDesc.BufferDesc.Width) / 2,
741+
SetRect(&m_rcWindowBounds,
742+
(DesktopRect.right - m_ChainDesc.BufferDesc.Width) / 2,
744743
(DesktopRect.bottom - m_ChainDesc.BufferDesc.Height) / 2,
745744
(DesktopRect.right + m_ChainDesc.BufferDesc.Width) / 2,
746745
(DesktopRect.bottom + m_ChainDesc.BufferDesc.Height) / 2);
747746
}
748747
else
749748
{
750-
if (bBordersMode)
749+
if (drawBorders)
751750
fYOffset = GetSystemMetrics(SM_CYCAPTION); // size of the window title bar
752751
SetRect(&m_rcWindowBounds, 0, 0, m_ChainDesc.BufferDesc.Width, m_ChainDesc.BufferDesc.Height);
753752
};
754753

755754
AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);
756755

757-
SetWindowPos(m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
758-
(m_rcWindowBounds.right - m_rcWindowBounds.left), (m_rcWindowBounds.bottom - m_rcWindowBounds.top),
759-
SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
756+
SetWindowPos(m_hWnd, HWND_NOTOPMOST,
757+
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
758+
m_rcWindowBounds.right - m_rcWindowBounds.left,
759+
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
760+
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
760761
}
761762
}
762763
else
763764
{
764-
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = (WS_POPUP | WS_VISIBLE));
765+
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
765766
}
766767

767768
ShowCursor(FALSE);

src/Layers/xrRenderGL/glHW.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,18 @@ void CHW::Reset(HWND hwnd)
189189

190190
void CHW::updateWindowProps(HWND m_hWnd)
191191
{
192-
bool bWindowed = true;
193-
#ifndef _EDITOR
194-
if (!GEnv.isDedicatedServer)
195-
bWindowed = !psDeviceFlags.is(rsFullscreen);
196-
#endif
192+
const bool bWindowed = !psDeviceFlags.is(rsFullscreen);
197193

198194
u32 dwWindowStyle = 0;
199195
// Set window properties depending on what mode were in.
200196
if (bWindowed)
201197
{
202198
if (m_move_window)
203199
{
204-
dwWindowStyle = WS_BORDER | WS_VISIBLE;
205-
if (!strstr(Core.Params, "-no_dialog_header"))
206-
dwWindowStyle |= WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
200+
const bool drawBorders = strstr(Core.Params, "-draw_borders");
201+
dwWindowStyle = WS_VISIBLE;
202+
if (drawBorders)
203+
dwWindowStyle |= WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
207204
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle);
208205
// When moving from fullscreen to windowed mode, it is important to
209206
// adjust the window size after recreating the device rather than
@@ -215,22 +212,36 @@ void CHW::updateWindowProps(HWND m_hWnd)
215212
// desktop.
216213

217214
RECT m_rcWindowBounds;
218-
RECT DesktopRect;
215+
float fYOffset = 0.f;
216+
bool centerScreen = false;
217+
if (strstr(Core.Params, "-center_screen"))
218+
centerScreen = true;
219219

220-
GetClientRect(GetDesktopWindow(), &DesktopRect);
220+
if (centerScreen)
221+
{
222+
RECT DesktopRect;
223+
GetClientRect(GetDesktopWindow(), &DesktopRect);
221224

222-
SetRect(&m_rcWindowBounds,
225+
SetRect(&m_rcWindowBounds,
223226
(DesktopRect.right - psCurrentVidMode[0]) / 2,
224227
(DesktopRect.bottom - psCurrentVidMode[1]) / 2,
225228
(DesktopRect.right + psCurrentVidMode[0]) / 2,
226229
(DesktopRect.bottom + psCurrentVidMode[1]) / 2);
230+
}
231+
else
232+
{
233+
if (drawBorders)
234+
fYOffset = GetSystemMetrics(SM_CYCAPTION); // size of the window title bar
235+
SetRect(&m_rcWindowBounds, 0, 0, psCurrentVidMode[0], psCurrentVidMode[1]);
236+
}
227237

228238
AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);
229239

230-
SetWindowPos(m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top,
240+
SetWindowPos(m_hWnd, HWND_NOTOPMOST,
241+
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
231242
m_rcWindowBounds.right - m_rcWindowBounds.left,
232243
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
233-
SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
244+
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
234245
}
235246
}
236247
else
@@ -242,7 +253,6 @@ void CHW::updateWindowProps(HWND m_hWnd)
242253
SetForegroundWindow(m_hWnd);
243254
}
244255

245-
246256
struct _uniq_mode
247257
{
248258
_uniq_mode(LPCSTR v): _val(v) {}

src/xrEngine/device.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ void CRenderDevice::Run()
321321
}
322322
// Start all threads
323323
mt_bMustExit = FALSE;
324+
ShowWindow(m_hWnd, SW_SHOWNORMAL);
324325
thread_spawn(SecondaryThreadProc, "X-RAY Secondary thread", 0, this);
325326
// Message cycle
326327
seqAppStart.Process(rp_AppStart);
@@ -481,10 +482,17 @@ void CRenderDevice::RemoveSeqFrame(pureFrame* f)
481482
CRenderDevice* get_device() { return &Device; }
482483
u32 script_time_global() { return Device.dwTimeGlobal; }
483484
u32 script_time_global_async() { return Device.TimerAsync_MMT(); }
484-
SCRIPT_EXPORT(Device, (), {
485+
486+
SCRIPT_EXPORT(Device, (),
487+
{
485488
using namespace luabind;
486-
module(luaState)[def("time_global", &script_time_global), def("time_global_async", &script_time_global_async),
487-
def("device", &get_device), def("is_enough_address_space_available", &is_enough_address_space_available)];
489+
module(luaState)
490+
[
491+
def("time_global", &script_time_global),
492+
def("time_global_async", &script_time_global_async),
493+
def("device", &get_device),
494+
def("is_enough_address_space_available", &is_enough_address_space_available)
495+
];
488496
});
489497

490498
CLoadScreenRenderer::CLoadScreenRenderer() : b_registered(false), b_need_user_input(false) {}

src/xrEngine/main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,8 @@ ENGINE_API void Startup()
182182
g_SpatialSpace = new ISpatial_DB("Spatial obj");
183183
g_SpatialSpacePhysic = new ISpatial_DB("Spatial phys");
184184

185-
// Show main window and destroy splash
186-
splash::hide();
187-
ShowWindow(Device.m_hWnd, SW_SHOWNORMAL);
188-
189185
// Main cycle
186+
splash::hide();
190187
Memory.mem_usage();
191188
Device.Run();
192189
// Destroy APP
@@ -208,8 +205,10 @@ ENGINE_API void Startup()
208205
destroySound();
209206
}
210207

211-
ENGINE_API int RunApplication(pcstr commandLine)
208+
ENGINE_API int RunApplication()
212209
{
210+
R_ASSERT2(Core.Params, "Core must be initialized");
211+
213212
if (!IsDebuggerPresent())
214213
{
215214
u32 heapFragmentation = 2;
@@ -244,7 +243,7 @@ ENGINE_API int RunApplication(pcstr commandLine)
244243
Engine.External.CreateRendererList();
245244

246245
pcstr benchName = "-batch_benchmark ";
247-
if (strstr(commandLine, benchName))
246+
if (strstr(Core.Params, benchName))
248247
{
249248
u32 sz = xr_strlen(benchName);
250249
string64 benchmarkName;
@@ -254,7 +253,7 @@ ENGINE_API int RunApplication(pcstr commandLine)
254253
}
255254

256255
pcstr sashName = "-openautomate ";
257-
if (strstr(commandLine, sashName))
256+
if (strstr(Core.Params, sashName))
258257
{
259258
u32 sz = xr_strlen(sashName);
260259
string512 sashArg;

src/xrEngine/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ ENGINE_API void InitSound();
1616
ENGINE_API void destroySound();
1717

1818
ENGINE_API void Startup();
19-
ENGINE_API int RunApplication(pcstr commandLine);
19+
ENGINE_API int RunApplication();

src/xr_3da/entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int entry_point(pcstr commandLine)
3535
}
3636
Core.Initialize("OpenXRay", nullptr, true, *fsgame ? fsgame : nullptr);
3737

38-
return RunApplication(commandLine);
38+
return RunApplication();
3939
}
4040

4141
int StackoverflowFilter(const int exceptionCode)

0 commit comments

Comments
 (0)