Skip to content

Commit d341b9b

Browse files
eagleivgXottab-DUTY
authored andcommitted
xrEngine: fix build with SDL2
1 parent 264f30a commit d341b9b

19 files changed

+293
-587
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_subdirectory(Layers)
55
add_subdirectory(xrAICore)
66
add_subdirectory(xrCDB)
77
add_subdirectory(xrCore)
8-
#add_subdirectory(xrEngine)
8+
add_subdirectory(xrEngine)
99
#add_subdirectory(xrGame)
1010
#add_subdirectory(xrNetServer)
1111
add_subdirectory(xrParticles)

src/Layers/xrRender/HW.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class CHW
6868

6969
CHWCaps Caps;
7070

71-
HWND m_hWnd;
71+
SDL_Window* m_hWnd;
7272
HDC m_hDC;
73-
HGLRC m_hRC;
73+
SDL_GLContext m_hRC;
7474
#elif defined(USE_DX11)
7575
public:
7676
IDXGIFactory1* m_pFactory = nullptr;

src/Layers/xrRender/r__dsgraph_build.cpp

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

807-
void D3DXRenderBase::Reset(HWND 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);
@@ -901,7 +901,7 @@ void D3DXRenderBase::OnDeviceCreate(const char* shName)
901901
}
902902
}
903903

904-
void D3DXRenderBase::Create(HWND hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool move_window)
904+
void D3DXRenderBase::Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool move_window)
905905
{
906906
HW.CreateDevice(hWnd, move_window);
907907
#if defined(USE_OGL)

src/Layers/xrRenderDX10/dx10HW.cpp

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

67-
void CHW::CreateDevice(SDL_Window* hWnd, bool move_window)
67+
void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
6868
{
6969
m_move_window = move_window;
7070
CreateD3D();
@@ -196,7 +196,7 @@ void CHW::CreateDevice(SDL_Window* hWnd, bool move_window)
196196
Msg("* Texture memory: %d M", memory / (1024 * 1024));
197197
//Msg("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice)) / 100.f);
198198
#ifndef _EDITOR
199-
updateWindowProps(m_hWnd);
199+
updateWindowProps(m_sdlWnd);
200200
fill_vid_mode_list(this);
201201
#endif
202202
}
@@ -240,7 +240,7 @@ void CHW::DestroyDevice()
240240
//////////////////////////////////////////////////////////////////////
241241
// Resetting device
242242
//////////////////////////////////////////////////////////////////////
243-
void CHW::Reset(HWND hwnd)
243+
void CHW::Reset(SDL_Window* m_sdlWnd)
244244
{
245245
DXGI_SWAP_CHAIN_DESC& cd = m_ChainDesc;
246246
BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);
@@ -265,8 +265,8 @@ void CHW::Reset(HWND hwnd)
265265
cd.BufferCount, desc.Width, desc.Height, desc.Format, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH));
266266
UpdateViews();
267267

268-
updateWindowProps(hwnd);
269-
ShowWindow(hwnd, SW_SHOWNORMAL);
268+
updateWindowProps(m_sdlWnd);
269+
SDL_ShowWindow(m_sdlWnd);
270270
}
271271

272272
D3DFORMAT CHW::selectDepthStencil(D3DFORMAT /*fTarget*/)
@@ -352,7 +352,7 @@ BOOL CHW::support(D3DFORMAT fmt, DWORD type, DWORD usage)
352352
return TRUE;
353353
}
354354

355-
void CHW::updateWindowProps(HWND m_hWnd)
355+
void CHW::updateWindowProps(SDL_Window* m_sdlWnd)
356356
{
357357
bool bWindowed = !psDeviceFlags.is(rsFullscreen);
358358

@@ -362,11 +362,8 @@ void CHW::updateWindowProps(HWND m_hWnd)
362362
{
363363
if (m_move_window)
364364
{
365-
const bool drawBorders = strstr(Core.Params, "-draw_borders");
366-
dwWindowStyle = WS_VISIBLE;
367-
if (drawBorders)
368-
dwWindowStyle |= WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
369-
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle);
365+
if (NULL != strstr(Core.Params, "-draw_borders"))
366+
SDL_SetWindowBordered(m_sdlWnd, SDL_TRUE);
370367
// When moving from fullscreen to windowed mode, it is important to
371368
// adjust the window size after recreating the device rather than
372369
// beforehand to ensure that you get the window size you want. For
@@ -376,45 +373,29 @@ void CHW::updateWindowProps(HWND m_hWnd)
376373
// changed to 1024x768, because windows cannot be larger than the
377374
// desktop.
378375

379-
RECT m_rcWindowBounds;
380-
float fYOffset = 0.f;
381376
bool centerScreen = false;
382-
if (strstr(Core.Params, "-center_screen"))
377+
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
383378
centerScreen = true;
384379

380+
SDL_SetWindowSize(m_sdlWnd, m_ChainDesc.BufferDesc.Width, m_ChainDesc.BufferDesc.Height);
381+
385382
if (centerScreen)
386383
{
387-
RECT DesktopRect;
388-
GetClientRect(GetDesktopWindow(), &DesktopRect);
389-
390-
SetRect(&m_rcWindowBounds,
391-
(DesktopRect.right - m_ChainDesc.BufferDesc.Width) / 2,
392-
(DesktopRect.bottom - m_ChainDesc.BufferDesc.Height) / 2,
393-
(DesktopRect.right + m_ChainDesc.BufferDesc.Width) / 2,
394-
(DesktopRect.bottom + m_ChainDesc.BufferDesc.Height) / 2);
384+
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
395385
}
396386
else
397387
{
398-
if (drawBorders)
399-
fYOffset = GetSystemMetrics(SM_CYCAPTION); // size of the window title bar
400-
SetRect(&m_rcWindowBounds, 0, 0, m_ChainDesc.BufferDesc.Width, m_ChainDesc.BufferDesc.Height);
401-
};
402-
403-
AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);
404-
405-
SetWindowPos(m_hWnd, HWND_NOTOPMOST,
406-
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
407-
m_rcWindowBounds.right - m_rcWindowBounds.left,
408-
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
409-
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
388+
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
389+
}
410390
}
411391
}
412392
else
413393
{
414-
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
394+
SDL_ShowWindow(m_sdlWnd);
415395
}
416396

417-
SetForegroundWindow(m_hWnd);
397+
if (!GEnv.isDedicatedServer)
398+
SDL_SetWindowGrab(m_sdlWnd, SDL_TRUE);
418399
}
419400

420401
struct uniqueRenderingMode

src/Layers/xrRenderGL/glHW.cpp

Lines changed: 15 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -41,72 +41,39 @@ CHW::~CHW() {}
4141
//////////////////////////////////////////////////////////////////////
4242
// Construction/Destruction
4343
//////////////////////////////////////////////////////////////////////
44-
void CHW::CreateDevice(HWND hWnd, bool move_window)
44+
void CHW::CreateDevice(SDL_Window *hWnd, bool move_window)
4545
{
4646
m_hWnd = hWnd;
4747
m_move_window = move_window;
4848

4949
R_ASSERT(m_hWnd);
5050

51-
PIXELFORMATDESCRIPTOR pfd =
52-
{
53-
sizeof(PIXELFORMATDESCRIPTOR),
54-
1,
55-
PFD_DRAW_TO_WINDOW |
56-
PFD_SUPPORT_OPENGL |
57-
PFD_DOUBLEBUFFER, // Flags
58-
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
59-
32, // Color depth of the framebuffer.
60-
0, 0, 0, 0, 0, 0,
61-
0,
62-
0,
63-
0,
64-
0, 0, 0, 0,
65-
24, // Number of bits for the depthbuffer
66-
8, // Number of bits for the stencilbuffer
67-
0, // Number of Aux buffers in the framebuffer.
68-
PFD_MAIN_PLANE,
69-
0,
70-
0, 0, 0
71-
};
72-
7351
// Get the device context
74-
m_hDC = GetDC(m_hWnd);
75-
if (m_hDC == nullptr)
52+
Uint32 pixelFormat = SDL_GetWindowPixelFormat(m_hWnd);
53+
if (SDL_PIXELFORMAT_UNKNOWN == pixelFormat)
7654
{
77-
Msg("Could not get device context.");
55+
Msg("Could not get pixel format: %s", SDL_GetError());
7856
return;
7957
}
8058

81-
// Choose the closest pixel format
82-
int iPixelFormat = ChoosePixelFormat(m_hDC, &pfd);
83-
if (iPixelFormat == 0)
84-
{
85-
Msg("No pixel format found.");
86-
return;
87-
}
59+
//TODO Choose the closest pixel format
8860

89-
// Apply the pixel format to the device context
90-
if (!SetPixelFormat(m_hDC, iPixelFormat, &pfd))
91-
{
92-
Msg("Could not set pixel format.");
93-
return;
94-
}
61+
//TODO Apply the pixel format to the device context
9562

9663
// Create the context
97-
m_hRC = wglCreateContext(m_hDC);
64+
m_hRC = SDL_GL_CreateContext(m_hWnd);
9865
if (m_hRC == nullptr)
9966
{
100-
Msg("Could not create drawing context.");
67+
Msg("Could not create drawing context: %s", SDL_GetError());
10168
return;
10269
}
10370

10471
// Make the new context the current context for this thread
10572
// NOTE: This assumes the thread calling Create() is the only
10673
// thread that will use the context.
107-
if (!wglMakeCurrent(m_hDC, m_hRC))
74+
if (SDL_GL_MakeCurrent(m_hWnd, m_hRC) != 0)
10875
{
109-
Msg("Could not make context current.");
76+
Msg("Could not make context current. %s", SDL_GetError());
11077
return;
11178
}
11279

@@ -139,30 +106,21 @@ void CHW::DestroyDevice()
139106
{
140107
if (m_hRC)
141108
{
142-
if (!wglMakeCurrent(nullptr, nullptr))
143-
Msg("Could not release drawing context.");
109+
if (SDL_GL_MakeCurrent(nullptr, nullptr) != 0)
110+
Msg("Could not release drawing context: %s", SDL_GetError());
144111

145-
if (!wglDeleteContext(m_hRC))
146-
Msg("Could not delete context.");
112+
SDL_GL_DeleteContext(m_hRC);
147113

148114
m_hRC = nullptr;
149115
}
150116

151-
if (m_hDC)
152-
{
153-
if (!ReleaseDC(m_hWnd, m_hDC))
154-
Msg("Could not release device context.");
155-
156-
m_hDC = nullptr;
157-
}
158-
159117
free_vid_mode_list();
160118
}
161119

162120
//////////////////////////////////////////////////////////////////////
163121
// Resetting device
164122
//////////////////////////////////////////////////////////////////////
165-
void CHW::Reset(HWND hwnd)
123+
void CHW::Reset(SDL_Window* hwnd)
166124
{
167125
BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);
168126

@@ -176,7 +134,7 @@ void CHW::Reset(HWND hwnd)
176134
UpdateViews();
177135

178136
updateWindowProps(hwnd);
179-
ShowWindow(hwnd, SW_SHOWNORMAL);
137+
SDL_ShowWindow(hwnd);
180138
}
181139

182140
void CHW::updateWindowProps(SDL_Window* m_sdlWnd)

src/utils/xrLC_Light/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
project(xrLC_Light)
2+
3+
list(APPEND DIRS
4+
"."
5+
)
6+
7+
add_dir("${DIRS}")
8+
9+
include_directories(
10+
${CMAKE_CURRENT_SOURCE_DIR}/../..
11+
${CMAKE_CURRENT_SOURCE_DIR}/../../../sdk/include
12+
)
13+
14+
list(APPEND ${PROJECT_NAME}__INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../Shader_xrLC.h")
15+
list(APPEND ${PROJECT_NAME}__SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../xrEngine/xrLoadSurface.cpp")
16+
#list(REMOVE_ITEM ${PROJECT_NAME}__SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/./LevelCompilerLoggerWindow.cpp")
17+
#list(REMOVE_ITEM ${PROJECT_NAME}__INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/./LevelCompilerLoggerWindow.hpp")
18+
19+
add_definitions(-D_USRDLL -DLEVEL_COMPILER -D_USE_MATH_DEFINES -DXRLC_LIGHT_EXPORTS -DFORCE_NO_EXCEPTIONS -DNO_XR_VDECLARATOR)
20+
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES})
21+
22+
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
23+
target_link_libraries(${PROJECT_NAME} xrCore xrCDB zlib xrLCUtil)

src/xrCDB/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ list(APPEND DIRS
66

77
add_dir("${DIRS}")
88

9-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include)
9+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include /usr/include/SDL2)
1010

1111
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES})
1212

src/xrCore/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ list(APPEND DIRS
1616

1717
add_dir("${DIRS}")
1818

19-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/pugixml/src ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include)
19+
include_directories(
20+
${CMAKE_CURRENT_SOURCE_DIR}/..
21+
${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/pugixml/src
22+
${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include
23+
/usr/include/SDL2
24+
)
2025

2126
add_definitions(-DXRCORE_EXPORTS)
2227
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES})

src/xrEngine/Device_Initialize.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,20 @@ void CRenderDevice::Initialize()
4848

4949
if (!m_sdlWnd)
5050
{
51-
m_sdlWnd = SDL_CreateWindow("S.T.A.L.K.E.R.: Call of Pripyat", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
52-
640, 480, SDL_WINDOW_BORDERLESS);
51+
Uint32 flags = SDL_WINDOW_BORDERLESS;
52+
53+
if (strstr(Core.Params, "-gl"))
54+
flags |= SDL_WINDOW_OPENGL;
55+
56+
m_sdlWnd = SDL_CreateWindow("S.T.A.L.K.E.R.: Call of Pripyat", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, flags);
5357

5458
if (!m_sdlWnd)
5559
Log("Unable to create window: %s", SDL_GetError());
5660

57-
m_sdlRndr = SDL_CreateRenderer(m_sdlWnd, -1, SDL_RENDERER_ACCELERATED);
61+
//m_sdlRndr = SDL_CreateRenderer(m_sdlWnd, -1, SDL_RENDERER_ACCELERATED);
5862

59-
SDL_RenderClear(m_sdlRndr);
60-
SDL_RenderPresent(m_sdlRndr);
63+
//SDL_RenderClear(m_sdlRndr);
64+
//SDL_RenderPresent(m_sdlRndr);
6165
}
6266
// Save window properties
6367

0 commit comments

Comments
 (0)