Skip to content

Commit 5529556

Browse files
committed
Moved part of the window management code from renderers to xrEngine
1 parent 92be298 commit 5529556

File tree

12 files changed

+67
-197
lines changed

12 files changed

+67
-197
lines changed

src/Layers/xrRender/D3DXRenderBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class D3DXRenderBase : public IRender, public pureFrame
190190
// Init
191191
virtual void SetupStates() override;
192192
virtual void OnDeviceCreate(const char* shName) override;
193-
virtual void Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool) override;
193+
virtual void Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2) override;
194194
virtual void SetupGPU(bool bForceGPU_SW, bool bForceGPU_NonPure, bool bForceGPU_REF) override;
195195
// Overdraw
196196
virtual void overdrawBegin() override;

src/Layers/xrRender/HW.cpp

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ void CHW::DestroyD3D()
3636
_RELEASE(pD3D);
3737
}
3838

39-
void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
39+
void CHW::CreateDevice(SDL_Window* m_sdlWnd)
4040
{
41-
m_move_window = move_window;
4241
CreateD3D();
4342

4443
bool bWindowed = !psDeviceFlags.is(rsFullscreen);
45-
if (GEnv.isDedicatedServer)
44+
if (GEnv.isDedicatedServer || Device.editor())
4645
bWindowed = true;
4746

4847
m_DriverType = Caps.bForceGPU_REF ? D3DDEVTYPE_REF : D3DDEVTYPE_HAL;
@@ -214,7 +213,6 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
214213
Msg("* Texture memory: %d M", memory / (1024 * 1024));
215214
Msg("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice)) / 100.f);
216215

217-
updateWindowProps(m_sdlWnd);
218216
fill_vid_mode_list(this);
219217
}
220218

@@ -240,7 +238,7 @@ void CHW::DestroyDevice()
240238
//////////////////////////////////////////////////////////////////////
241239
// Resetting device
242240
//////////////////////////////////////////////////////////////////////
243-
void CHW::Reset(SDL_Window* m_sdlWnd)
241+
void CHW::Reset()
244242
{
245243
#ifdef DEBUG
246244
_RELEASE(dwDebugSB);
@@ -284,9 +282,6 @@ void CHW::Reset(SDL_Window* m_sdlWnd)
284282
#ifdef DEBUG
285283
R_CHK(pDevice->CreateStateBlock(D3DSBT_ALL, &dwDebugSB));
286284
#endif
287-
288-
updateWindowProps(m_sdlWnd);
289-
SDL_ShowWindow(m_sdlWnd);
290285
}
291286

292287
D3DFORMAT CHW::selectDepthStencil(D3DFORMAT fTarget)
@@ -466,55 +461,6 @@ BOOL CHW::support(D3DFORMAT fmt, DWORD type, DWORD usage)
466461
return TRUE;
467462
}
468463

469-
void CHW::updateWindowProps(SDL_Window *m_sdlWnd)
470-
{
471-
bool bWindowed = !psDeviceFlags.is(rsFullscreen);
472-
473-
if (GEnv.isDedicatedServer)
474-
bWindowed = true;
475-
476-
u32 dwWindowStyle = 0;
477-
// Set window properties depending on what mode were in.
478-
if (bWindowed)
479-
{
480-
if (m_move_window)
481-
{
482-
if(NULL != strstr(Core.Params, "-draw_borders"))
483-
SDL_SetWindowBordered(m_sdlWnd, SDL_TRUE);
484-
// When moving from fullscreen to windowed mode, it is important to
485-
// adjust the window size after recreating the device rather than
486-
// beforehand to ensure that you get the window size you want. For
487-
// example, when switching from 640x480 fullscreen to windowed with
488-
// a 1000x600 window on a 1024x768 desktop, it is impossible to set
489-
// the window size to 1000x600 until after the display mode has
490-
// changed to 1024x768, because windows cannot be larger than the
491-
// desktop.
492-
493-
bool centerScreen = false;
494-
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
495-
centerScreen = true;
496-
497-
SDL_SetWindowSize(m_sdlWnd, DevPP.BackBufferWidth, DevPP.BackBufferHeight);
498-
499-
if (centerScreen)
500-
{
501-
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
502-
}
503-
else
504-
{
505-
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
506-
}
507-
}
508-
}
509-
else
510-
{
511-
SDL_ShowWindow(m_sdlWnd);
512-
}
513-
514-
if (!GEnv.isDedicatedServer)
515-
SDL_SetWindowGrab(m_sdlWnd, SDL_TRUE);
516-
}
517-
518464
struct uniqueRenderingMode
519465
{
520466
uniqueRenderingMode(pcstr v) : value(v) {}

src/Layers/xrRender/HW.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class CHW
2525
void DestroyD3D();
2626
#endif // !USE_OGL
2727

28-
void CreateDevice(SDL_Window* m_sdlWnd, bool move_window);
28+
void CreateDevice(SDL_Window* m_sdlWnd);
2929

3030
void DestroyDevice();
3131

32-
void Reset(SDL_Window* m_sdlWnd);
32+
void Reset();
3333

3434
#ifndef USE_OGL
3535
void selectResolution(u32& dwWidth, u32& dwHeight, BOOL bWindowed);
@@ -40,7 +40,6 @@ class CHW
4040
BOOL support(D3DFORMAT fmt, DWORD type, DWORD usage);
4141
#endif // !USE_OGL
4242

43-
void updateWindowProps(SDL_Window* m_sdlWnd);
4443
#ifdef DEBUG
4544
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
4645
void Validate(void){};
@@ -145,9 +144,6 @@ class CHW
145144
#endif // USE_OGL
146145

147146
int maxRefreshRate = 200; // ECO_RENDER add
148-
149-
private:
150-
bool m_move_window = true;
151147
};
152148

153149
extern ECORE_API CHW HW;

src/Layers/xrRender/r__dsgraph_build.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,15 +804,15 @@ void D3DXRenderBase::DestroyHW()
804804
HW.DestroyDevice();
805805
}
806806

807-
void D3DXRenderBase::Reset(SDL_Window *hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2)
807+
void D3DXRenderBase::Reset(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2)
808808
{
809809
#if defined(DEBUG) && !defined(USE_OGL)
810810
_SHOW_REF("*ref -CRenderDevice::ResetTotal: DeviceREF:", HW.pDevice);
811811
#endif // DEBUG
812812

813813
Resources->reset_begin();
814814
Memory.mem_compact();
815-
HW.Reset(hWnd);
815+
HW.Reset();
816816

817817
#if defined(USE_OGL)
818818
dwWidth = psCurrentVidMode[0];
@@ -900,9 +900,9 @@ void D3DXRenderBase::OnDeviceCreate(const char* shName)
900900
}
901901
}
902902

903-
void D3DXRenderBase::Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool move_window)
903+
void D3DXRenderBase::Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2)
904904
{
905-
HW.CreateDevice(hWnd, move_window);
905+
HW.CreateDevice(hWnd);
906906
#if defined(USE_OGL)
907907
dwWidth = psCurrentVidMode[0];
908908
dwHeight = psCurrentVidMode[1];

src/Layers/xrRenderDX10/dx10HW.cpp

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@ void CHW::DestroyD3D()
6464
_RELEASE(m_pFactory);
6565
}
6666

67-
void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
67+
void CHW::CreateDevice(SDL_Window* m_sdlWnd)
6868
{
69-
m_move_window = move_window;
7069
CreateD3D();
7170

72-
bool bWindowed = !psDeviceFlags.is(rsFullscreen);
71+
bool bWindowed = !psDeviceFlags.is(rsFullscreen) || Device.editor();
7372

7473
m_DriverType = Caps.bForceGPU_REF ? D3D_DRIVER_TYPE_REFERENCE : D3D_DRIVER_TYPE_HARDWARE;
7574

@@ -196,10 +195,7 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
196195
const auto memory = Desc.DedicatedVideoMemory;
197196
Msg("* Texture memory: %d M", memory / (1024 * 1024));
198197
//Msg("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice)) / 100.f);
199-
#ifndef _EDITOR
200-
updateWindowProps(m_sdlWnd);
201198
fill_vid_mode_list(this);
202-
#endif
203199
}
204200

205201
void CHW::DestroyDevice()
@@ -241,7 +237,7 @@ void CHW::DestroyDevice()
241237
//////////////////////////////////////////////////////////////////////
242238
// Resetting device
243239
//////////////////////////////////////////////////////////////////////
244-
void CHW::Reset(SDL_Window* m_sdlWnd)
240+
void CHW::Reset()
245241
{
246242
DXGI_SWAP_CHAIN_DESC& cd = m_ChainDesc;
247243
BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);
@@ -265,9 +261,6 @@ void CHW::Reset(SDL_Window* m_sdlWnd)
265261
CHK_DX(m_pSwapChain->ResizeBuffers(
266262
cd.BufferCount, desc.Width, desc.Height, desc.Format, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH));
267263
UpdateViews();
268-
269-
updateWindowProps(m_sdlWnd);
270-
SDL_ShowWindow(m_sdlWnd);
271264
}
272265

273266
D3DFORMAT CHW::selectDepthStencil(D3DFORMAT /*fTarget*/)
@@ -353,52 +346,6 @@ BOOL CHW::support(D3DFORMAT fmt, DWORD type, DWORD usage)
353346
return TRUE;
354347
}
355348

356-
void CHW::updateWindowProps(SDL_Window* m_sdlWnd)
357-
{
358-
bool bWindowed = !psDeviceFlags.is(rsFullscreen);
359-
360-
u32 dwWindowStyle = 0;
361-
// Set window properties depending on what mode were in.
362-
if (bWindowed)
363-
{
364-
if (m_move_window)
365-
{
366-
if (NULL != strstr(Core.Params, "-draw_borders"))
367-
SDL_SetWindowBordered(m_sdlWnd, SDL_TRUE);
368-
// When moving from fullscreen to windowed mode, it is important to
369-
// adjust the window size after recreating the device rather than
370-
// beforehand to ensure that you get the window size you want. For
371-
// example, when switching from 640x480 fullscreen to windowed with
372-
// a 1000x600 window on a 1024x768 desktop, it is impossible to set
373-
// the window size to 1000x600 until after the display mode has
374-
// changed to 1024x768, because windows cannot be larger than the
375-
// desktop.
376-
377-
bool centerScreen = false;
378-
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
379-
centerScreen = true;
380-
381-
SDL_SetWindowSize(m_sdlWnd, m_ChainDesc.BufferDesc.Width, m_ChainDesc.BufferDesc.Height);
382-
383-
if (centerScreen)
384-
{
385-
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
386-
}
387-
else
388-
{
389-
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
390-
}
391-
}
392-
}
393-
else
394-
{
395-
SDL_ShowWindow(m_sdlWnd);
396-
}
397-
398-
if (!GEnv.isDedicatedServer)
399-
SDL_SetWindowGrab(m_sdlWnd, SDL_TRUE);
400-
}
401-
402349
struct uniqueRenderingMode
403350
{
404351
uniqueRenderingMode(pcstr v) : value(v) {}

src/Layers/xrRenderGL/glHW.cpp

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ CHW::CHW() :
3434
pFB(0),
3535
m_hWnd(nullptr),
3636
m_hDC(nullptr),
37-
m_hRC(nullptr),
38-
m_move_window(true) {}
37+
m_hRC(nullptr) {}
3938

4039
CHW::~CHW() {}
4140
//////////////////////////////////////////////////////////////////////
4241
// Construction/Destruction
4342
//////////////////////////////////////////////////////////////////////
44-
void CHW::CreateDevice(SDL_Window *hWnd, bool move_window)
43+
void CHW::CreateDevice(SDL_Window* hWnd)
4544
{
4645
m_hWnd = hWnd;
47-
m_move_window = move_window;
4846

4947
R_ASSERT(m_hWnd);
5048

@@ -94,11 +92,7 @@ void CHW::CreateDevice(SDL_Window *hWnd, bool move_window)
9492

9593
// Create render target and depth-stencil views here
9694
UpdateViews();
97-
98-
#ifndef _EDITOR
99-
updateWindowProps(m_hWnd);
10095
fill_vid_mode_list(this);
101-
#endif
10296
}
10397

10498
void CHW::DestroyDevice()
@@ -119,10 +113,8 @@ void CHW::DestroyDevice()
119113
//////////////////////////////////////////////////////////////////////
120114
// Resetting device
121115
//////////////////////////////////////////////////////////////////////
122-
void CHW::Reset(SDL_Window* hwnd)
116+
void CHW::Reset()
123117
{
124-
BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);
125-
126118
CHK_GL(glDeleteProgramPipelines(1, &pPP));
127119
CHK_GL(glDeleteFramebuffers(1, &pFB));
128120
CHK_GL(glDeleteFramebuffers(1, &pCFB));
@@ -131,57 +123,6 @@ void CHW::Reset(SDL_Window* hwnd)
131123
CHK_GL(glDeleteTextures(1, &pBaseZB));
132124

133125
UpdateViews();
134-
135-
updateWindowProps(hwnd);
136-
SDL_ShowWindow(hwnd);
137-
}
138-
139-
void CHW::updateWindowProps(SDL_Window* m_sdlWnd)
140-
{
141-
bool bWindowed = !psDeviceFlags.is(rsFullscreen);
142-
143-
u32 dwWindowStyle = 0;
144-
// Set window properties depending on what mode were in.
145-
if (bWindowed)
146-
{
147-
if (m_move_window)
148-
{
149-
if (NULL != strstr(Core.Params, "-draw_borders"))
150-
SDL_SetWindowBordered(m_sdlWnd, SDL_TRUE);
151-
// When moving from fullscreen to windowed mode, it is important to
152-
// adjust the window size after recreating the device rather than
153-
// beforehand to ensure that you get the window size you want. For
154-
// example, when switching from 640x480 fullscreen to windowed with
155-
// a 1000x600 window on a 1024x768 desktop, it is impossible to set
156-
// the window size to 1000x600 until after the display mode has
157-
// changed to 1024x768, because windows cannot be larger than the
158-
// desktop.
159-
160-
bool centerScreen = false;
161-
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
162-
centerScreen = true;
163-
164-
SDL_SetWindowSize(m_sdlWnd, psCurrentVidMode[0], psCurrentVidMode[1]);
165-
166-
if (centerScreen)
167-
{
168-
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
169-
}
170-
else
171-
{
172-
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
173-
}
174-
}
175-
}
176-
else
177-
{
178-
SDL_SetWindowPosition(m_sdlWnd, 0, 0);
179-
SDL_SetWindowSize(m_sdlWnd, psCurrentVidMode[0], psCurrentVidMode[1]);
180-
SDL_ShowWindow(m_sdlWnd);
181-
}
182-
183-
if (!GEnv.isDedicatedServer)
184-
SDL_SetWindowGrab(m_sdlWnd, SDL_TRUE);
185126
}
186127

187128
struct uniqueRenderingMode

src/xrEngine/Device_Initialize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ void CRenderDevice::Initialize()
4646

4747
if (!m_sdlWnd)
4848
{
49-
Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL;
49+
Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
5050
#if SDL_VERSION_ATLEAST(2, 0, 5)
5151
flags |= SDL_WINDOW_ALWAYS_ON_TOP;
5252
#endif
5353

54-
m_sdlWnd = SDL_CreateWindow("S.T.A.L.K.E.R.: Call of Pripyat", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, flags);
54+
m_sdlWnd = SDL_CreateWindow("S.T.A.L.K.E.R.: Call of Pripyat", 0, 0, 640, 480, flags);
5555

5656
R_ASSERT3(m_sdlWnd, "Unable to create SDL window", SDL_GetError());
5757
}

0 commit comments

Comments
 (0)