From d341b9b91c1f07ae47d11b06b26dad4b5318211c Mon Sep 17 00:00:00 2001 From: Ilya Orlov Date: Thu, 5 Jul 2018 15:44:07 +0300 Subject: [PATCH] xrEngine: fix build with SDL2 --- src/CMakeLists.txt | 2 +- src/Layers/xrRender/HW.h | 4 +- src/Layers/xrRender/r__dsgraph_build.cpp | 4 +- src/Layers/xrRenderDX10/dx10HW.cpp | 53 ++--- src/Layers/xrRenderGL/glHW.cpp | 72 ++---- src/utils/xrLC_Light/CMakeLists.txt | 23 ++ src/xrCDB/CMakeLists.txt | 2 +- src/xrCore/CMakeLists.txt | 7 +- src/xrEngine/Device_Initialize.cpp | 14 +- src/xrEngine/FDemoRecord.cpp | 60 ++--- src/xrEngine/IInputReceiver.cpp | 4 +- src/xrEngine/Render.h | 2 +- src/xrEngine/XR_IOConsole_callback.cpp | 57 ++--- src/xrEngine/line_edit_control.cpp | 291 ++++++++++++----------- src/xrEngine/line_edit_control.h | 4 +- src/xrEngine/stdafx.h | 2 +- src/xrEngine/xr_input.cpp | 254 +------------------- src/xrEngine/xr_input.h | 24 +- src/xrPhysics/CMakeLists.txt | 1 + 19 files changed, 293 insertions(+), 587 deletions(-) create mode 100644 src/utils/xrLC_Light/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d73dd225fa1..9f602efae34 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,7 @@ add_subdirectory(Layers) add_subdirectory(xrAICore) add_subdirectory(xrCDB) add_subdirectory(xrCore) -#add_subdirectory(xrEngine) +add_subdirectory(xrEngine) #add_subdirectory(xrGame) #add_subdirectory(xrNetServer) add_subdirectory(xrParticles) diff --git a/src/Layers/xrRender/HW.h b/src/Layers/xrRender/HW.h index 1d7194de6eb..02d3ca0431f 100644 --- a/src/Layers/xrRender/HW.h +++ b/src/Layers/xrRender/HW.h @@ -68,9 +68,9 @@ class CHW CHWCaps Caps; - HWND m_hWnd; + SDL_Window* m_hWnd; HDC m_hDC; - HGLRC m_hRC; + SDL_GLContext m_hRC; #elif defined(USE_DX11) public: IDXGIFactory1* m_pFactory = nullptr; diff --git a/src/Layers/xrRender/r__dsgraph_build.cpp b/src/Layers/xrRender/r__dsgraph_build.cpp index 36095bc9a66..d8a525b45f5 100644 --- a/src/Layers/xrRender/r__dsgraph_build.cpp +++ b/src/Layers/xrRender/r__dsgraph_build.cpp @@ -804,7 +804,7 @@ void D3DXRenderBase::DestroyHW() HW.DestroyDevice(); } -void D3DXRenderBase::Reset(HWND hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2) +void D3DXRenderBase::Reset(SDL_Window *hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2) { #if defined(DEBUG) && !defined(USE_OGL) _SHOW_REF("*ref -CRenderDevice::ResetTotal: DeviceREF:", HW.pDevice); @@ -901,7 +901,7 @@ void D3DXRenderBase::OnDeviceCreate(const char* shName) } } -void D3DXRenderBase::Create(HWND hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool move_window) +void D3DXRenderBase::Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool move_window) { HW.CreateDevice(hWnd, move_window); #if defined(USE_OGL) diff --git a/src/Layers/xrRenderDX10/dx10HW.cpp b/src/Layers/xrRenderDX10/dx10HW.cpp index 69c5855e01e..6abb2fd2b0b 100644 --- a/src/Layers/xrRenderDX10/dx10HW.cpp +++ b/src/Layers/xrRenderDX10/dx10HW.cpp @@ -64,7 +64,7 @@ void CHW::DestroyD3D() _RELEASE(m_pFactory); } -void CHW::CreateDevice(SDL_Window* hWnd, bool move_window) +void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window) { m_move_window = move_window; CreateD3D(); @@ -196,7 +196,7 @@ void CHW::CreateDevice(SDL_Window* hWnd, bool move_window) Msg("* Texture memory: %d M", memory / (1024 * 1024)); //Msg("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice)) / 100.f); #ifndef _EDITOR - updateWindowProps(m_hWnd); + updateWindowProps(m_sdlWnd); fill_vid_mode_list(this); #endif } @@ -240,7 +240,7 @@ void CHW::DestroyDevice() ////////////////////////////////////////////////////////////////////// // Resetting device ////////////////////////////////////////////////////////////////////// -void CHW::Reset(HWND hwnd) +void CHW::Reset(SDL_Window* m_sdlWnd) { DXGI_SWAP_CHAIN_DESC& cd = m_ChainDesc; BOOL bWindowed = !psDeviceFlags.is(rsFullscreen); @@ -265,8 +265,8 @@ void CHW::Reset(HWND hwnd) cd.BufferCount, desc.Width, desc.Height, desc.Format, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH)); UpdateViews(); - updateWindowProps(hwnd); - ShowWindow(hwnd, SW_SHOWNORMAL); + updateWindowProps(m_sdlWnd); + SDL_ShowWindow(m_sdlWnd); } D3DFORMAT CHW::selectDepthStencil(D3DFORMAT /*fTarget*/) @@ -352,7 +352,7 @@ BOOL CHW::support(D3DFORMAT fmt, DWORD type, DWORD usage) return TRUE; } -void CHW::updateWindowProps(HWND m_hWnd) +void CHW::updateWindowProps(SDL_Window* m_sdlWnd) { bool bWindowed = !psDeviceFlags.is(rsFullscreen); @@ -362,11 +362,8 @@ void CHW::updateWindowProps(HWND m_hWnd) { if (m_move_window) { - 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); + if (NULL != strstr(Core.Params, "-draw_borders")) + SDL_SetWindowBordered(m_sdlWnd, SDL_TRUE); // When moving from fullscreen to windowed mode, it is important to // adjust the window size after recreating the device rather than // beforehand to ensure that you get the window size you want. For @@ -376,45 +373,29 @@ void CHW::updateWindowProps(HWND m_hWnd) // changed to 1024x768, because windows cannot be larger than the // desktop. - RECT m_rcWindowBounds; - float fYOffset = 0.f; bool centerScreen = false; - if (strstr(Core.Params, "-center_screen")) + if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen")) centerScreen = true; + SDL_SetWindowSize(m_sdlWnd, m_ChainDesc.BufferDesc.Width, m_ChainDesc.BufferDesc.Height); + if (centerScreen) { - RECT DesktopRect; - GetClientRect(GetDesktopWindow(), &DesktopRect); - - 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); + SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); } else { - 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_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME); + SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED); + } } } else { - SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE); + SDL_ShowWindow(m_sdlWnd); } - SetForegroundWindow(m_hWnd); + if (!GEnv.isDedicatedServer) + SDL_SetWindowGrab(m_sdlWnd, SDL_TRUE); } struct uniqueRenderingMode diff --git a/src/Layers/xrRenderGL/glHW.cpp b/src/Layers/xrRenderGL/glHW.cpp index 5a3ad9cbf99..aa02fd50d92 100644 --- a/src/Layers/xrRenderGL/glHW.cpp +++ b/src/Layers/xrRenderGL/glHW.cpp @@ -41,72 +41,39 @@ CHW::~CHW() {} ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -void CHW::CreateDevice(HWND hWnd, bool move_window) +void CHW::CreateDevice(SDL_Window *hWnd, bool move_window) { m_hWnd = hWnd; m_move_window = move_window; R_ASSERT(m_hWnd); - PIXELFORMATDESCRIPTOR pfd = - { - sizeof(PIXELFORMATDESCRIPTOR), - 1, - PFD_DRAW_TO_WINDOW | - PFD_SUPPORT_OPENGL | - PFD_DOUBLEBUFFER, // Flags - PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette. - 32, // Color depth of the framebuffer. - 0, 0, 0, 0, 0, 0, - 0, - 0, - 0, - 0, 0, 0, 0, - 24, // Number of bits for the depthbuffer - 8, // Number of bits for the stencilbuffer - 0, // Number of Aux buffers in the framebuffer. - PFD_MAIN_PLANE, - 0, - 0, 0, 0 - }; - // Get the device context - m_hDC = GetDC(m_hWnd); - if (m_hDC == nullptr) + Uint32 pixelFormat = SDL_GetWindowPixelFormat(m_hWnd); + if (SDL_PIXELFORMAT_UNKNOWN == pixelFormat) { - Msg("Could not get device context."); + Msg("Could not get pixel format: %s", SDL_GetError()); return; } - // Choose the closest pixel format - int iPixelFormat = ChoosePixelFormat(m_hDC, &pfd); - if (iPixelFormat == 0) - { - Msg("No pixel format found."); - return; - } + //TODO Choose the closest pixel format - // Apply the pixel format to the device context - if (!SetPixelFormat(m_hDC, iPixelFormat, &pfd)) - { - Msg("Could not set pixel format."); - return; - } + //TODO Apply the pixel format to the device context // Create the context - m_hRC = wglCreateContext(m_hDC); + m_hRC = SDL_GL_CreateContext(m_hWnd); if (m_hRC == nullptr) { - Msg("Could not create drawing context."); + Msg("Could not create drawing context: %s", SDL_GetError()); return; } // Make the new context the current context for this thread // NOTE: This assumes the thread calling Create() is the only // thread that will use the context. - if (!wglMakeCurrent(m_hDC, m_hRC)) + if (SDL_GL_MakeCurrent(m_hWnd, m_hRC) != 0) { - Msg("Could not make context current."); + Msg("Could not make context current. %s", SDL_GetError()); return; } @@ -139,30 +106,21 @@ void CHW::DestroyDevice() { if (m_hRC) { - if (!wglMakeCurrent(nullptr, nullptr)) - Msg("Could not release drawing context."); + if (SDL_GL_MakeCurrent(nullptr, nullptr) != 0) + Msg("Could not release drawing context: %s", SDL_GetError()); - if (!wglDeleteContext(m_hRC)) - Msg("Could not delete context."); + SDL_GL_DeleteContext(m_hRC); m_hRC = nullptr; } - if (m_hDC) - { - if (!ReleaseDC(m_hWnd, m_hDC)) - Msg("Could not release device context."); - - m_hDC = nullptr; - } - free_vid_mode_list(); } ////////////////////////////////////////////////////////////////////// // Resetting device ////////////////////////////////////////////////////////////////////// -void CHW::Reset(HWND hwnd) +void CHW::Reset(SDL_Window* hwnd) { BOOL bWindowed = !psDeviceFlags.is(rsFullscreen); @@ -176,7 +134,7 @@ void CHW::Reset(HWND hwnd) UpdateViews(); updateWindowProps(hwnd); - ShowWindow(hwnd, SW_SHOWNORMAL); + SDL_ShowWindow(hwnd); } void CHW::updateWindowProps(SDL_Window* m_sdlWnd) diff --git a/src/utils/xrLC_Light/CMakeLists.txt b/src/utils/xrLC_Light/CMakeLists.txt new file mode 100644 index 00000000000..03e99a7f170 --- /dev/null +++ b/src/utils/xrLC_Light/CMakeLists.txt @@ -0,0 +1,23 @@ +project(xrLC_Light) + +list(APPEND DIRS + "." + ) + +add_dir("${DIRS}") + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/../.. + ${CMAKE_CURRENT_SOURCE_DIR}/../../../sdk/include + ) + +list(APPEND ${PROJECT_NAME}__INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../Shader_xrLC.h") +list(APPEND ${PROJECT_NAME}__SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../xrEngine/xrLoadSurface.cpp") +#list(REMOVE_ITEM ${PROJECT_NAME}__SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/./LevelCompilerLoggerWindow.cpp") +#list(REMOVE_ITEM ${PROJECT_NAME}__INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/./LevelCompilerLoggerWindow.hpp") + +add_definitions(-D_USRDLL -DLEVEL_COMPILER -D_USE_MATH_DEFINES -DXRLC_LIGHT_EXPORTS -DFORCE_NO_EXCEPTIONS -DNO_XR_VDECLARATOR) +add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") +target_link_libraries(${PROJECT_NAME} xrCore xrCDB zlib xrLCUtil) diff --git a/src/xrCDB/CMakeLists.txt b/src/xrCDB/CMakeLists.txt index 0b0aefc7489..9b9ffc42154 100644 --- a/src/xrCDB/CMakeLists.txt +++ b/src/xrCDB/CMakeLists.txt @@ -6,7 +6,7 @@ list(APPEND DIRS add_dir("${DIRS}") -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include /usr/include/SDL2) add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES}) diff --git a/src/xrCore/CMakeLists.txt b/src/xrCore/CMakeLists.txt index 6d7c0398aaf..d7d36ccf772 100644 --- a/src/xrCore/CMakeLists.txt +++ b/src/xrCore/CMakeLists.txt @@ -16,7 +16,12 @@ list(APPEND DIRS add_dir("${DIRS}") -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/pugixml/src ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include) +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/.. + ${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/pugixml/src + ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include + /usr/include/SDL2 +) add_definitions(-DXRCORE_EXPORTS) add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES}) diff --git a/src/xrEngine/Device_Initialize.cpp b/src/xrEngine/Device_Initialize.cpp index 764a5554049..935c23543e4 100644 --- a/src/xrEngine/Device_Initialize.cpp +++ b/src/xrEngine/Device_Initialize.cpp @@ -48,16 +48,20 @@ void CRenderDevice::Initialize() if (!m_sdlWnd) { - m_sdlWnd = SDL_CreateWindow("S.T.A.L.K.E.R.: Call of Pripyat", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - 640, 480, SDL_WINDOW_BORDERLESS); + Uint32 flags = SDL_WINDOW_BORDERLESS; + + if (strstr(Core.Params, "-gl")) + flags |= SDL_WINDOW_OPENGL; + + m_sdlWnd = SDL_CreateWindow("S.T.A.L.K.E.R.: Call of Pripyat", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, flags); if (!m_sdlWnd) Log("Unable to create window: %s", SDL_GetError()); - m_sdlRndr = SDL_CreateRenderer(m_sdlWnd, -1, SDL_RENDERER_ACCELERATED); + //m_sdlRndr = SDL_CreateRenderer(m_sdlWnd, -1, SDL_RENDERER_ACCELERATED); - SDL_RenderClear(m_sdlRndr); - SDL_RenderPresent(m_sdlRndr); + //SDL_RenderClear(m_sdlRndr); + //SDL_RenderPresent(m_sdlRndr); } // Save window properties diff --git a/src/xrEngine/FDemoRecord.cpp b/src/xrEngine/FDemoRecord.cpp index 41738896563..d552a20d52d 100644 --- a/src/xrEngine/FDemoRecord.cpp +++ b/src/xrEngine/FDemoRecord.cpp @@ -307,7 +307,7 @@ BOOL CDemoRecord::ProcessCam(SCamEffectorInfo& info) } else { - if (IR_GetKeyState(DIK_F1)) + if (IR_GetKeyState(SDL_SCANCODE_F1)) { pApp->pFontSystem->SetColor(color_rgba(255, 0, 0, 255)); pApp->pFontSystem->SetAligment(CGameFont::alCenter); @@ -337,17 +337,17 @@ BOOL CDemoRecord::ProcessCam(SCamEffectorInfo& info) float speed = m_fSpeed1, ang_speed = m_fAngSpeed1; - if (IR_GetKeyState(DIK_LSHIFT)) + if (IR_GetKeyState(SDL_SCANCODE_LSHIFT)) { speed = m_fSpeed0; ang_speed = m_fAngSpeed0; } - else if (IR_GetKeyState(DIK_LALT)) + else if (IR_GetKeyState(SDL_SCANCODE_LALT)) { speed = m_fSpeed2; ang_speed = m_fAngSpeed2; } - else if (IR_GetKeyState(DIK_LCONTROL)) + else if (IR_GetKeyState(SDL_SCANCODE_LCTRL)) { speed = m_fSpeed3; ang_speed = m_fAngSpeed3; @@ -402,7 +402,7 @@ BOOL CDemoRecord::ProcessCam(SCamEffectorInfo& info) void CDemoRecord::IR_OnKeyboardPress(int dik) { - if (dik == DIK_MULTIPLY) + if (dik == SDL_SCANCODE_KP_MULTIPLY) m_b_redirect_input_to_level = !m_b_redirect_input_to_level; if (m_b_redirect_input_to_level) @@ -410,21 +410,21 @@ void CDemoRecord::IR_OnKeyboardPress(int dik) g_pGameLevel->IR_OnKeyboardPress(dik); return; } - if (dik == DIK_GRAVE) + if (dik == SDL_SCANCODE_GRAVE) Console->Show(); - if (dik == DIK_SPACE) + if (dik == SDL_SCANCODE_SPACE) RecordKey(); - if (dik == DIK_BACK) + if (dik == SDL_SCANCODE_BACKSPACE) MakeCubemap(); - if (dik == DIK_F11) - MakeLevelMapScreenshot(IR_GetKeyState(DIK_LCONTROL)); - if (dik == DIK_F12) + if (dik == SDL_SCANCODE_F11) + MakeLevelMapScreenshot(IR_GetKeyState(SDL_SCANCODE_LCTRL)); + if (dik == SDL_SCANCODE_F12) MakeScreenshot(); - if (dik == DIK_ESCAPE) + if (dik == SDL_SCANCODE_ESCAPE) fLifeTime = -1; #ifdef DEBUG // ndef MASTER_GOLD // Xottab_DUTY: Teleport to demo cam in Debug configuration - if (dik == DIK_RETURN) + if (dik == SDL_SCANCODE_RETURN) { if (g_pGameLevel->CurrentEntity()) { @@ -434,7 +434,7 @@ void CDemoRecord::IR_OnKeyboardPress(int dik) } #endif - if (dik == DIK_PAUSE) + if (dik == SDL_SCANCODE_PAUSE) Device.Pause(!Device.Paused(), TRUE, TRUE, "demo_record"); } @@ -457,41 +457,41 @@ void CDemoRecord::IR_OnKeyboardHold(int dik) switch (dik) { - case DIK_A: - case DIK_NUMPAD1: - case DIK_LEFT: + case SDL_SCANCODE_A: + case SDL_SCANCODE_KP_1: + case SDL_SCANCODE_LEFT: vT_delta.x -= 1.0f; break; // Slide Left - case DIK_D: - case DIK_NUMPAD3: - case DIK_RIGHT: + case SDL_SCANCODE_D: + case SDL_SCANCODE_KP_3: + case SDL_SCANCODE_RIGHT: vT_delta.x += 1.0f; break; // Slide Right - case DIK_S: + case SDL_SCANCODE_S: vT_delta.y -= 1.0f; break; // Slide Down - case DIK_W: + case SDL_SCANCODE_W: vT_delta.y += 1.0f; break; // Slide Up // rotate - case DIK_NUMPAD2: + case SDL_SCANCODE_KP_2: vR_delta.x -= 1.0f; break; // Pitch Down - case DIK_NUMPAD8: + case SDL_SCANCODE_KP_8: vR_delta.x += 1.0f; break; // Pitch Up - case DIK_E: - case DIK_NUMPAD6: + case SDL_SCANCODE_E: + case SDL_SCANCODE_KP_6: vR_delta.y += 1.0f; break; // Turn Left - case DIK_Q: - case DIK_NUMPAD4: + case SDL_SCANCODE_Q: + case SDL_SCANCODE_KP_4: vR_delta.y -= 1.0f; break; // Turn Right - case DIK_NUMPAD9: + case SDL_SCANCODE_KP_9: vR_delta.z -= 2.0f; break; // Turn Right - case DIK_NUMPAD7: + case SDL_SCANCODE_KP_7: vR_delta.z += 2.0f; break; // Turn Right } diff --git a/src/xrEngine/IInputReceiver.cpp b/src/xrEngine/IInputReceiver.cpp index 62542fc410e..cce4498a2c2 100644 --- a/src/xrEngine/IInputReceiver.cpp +++ b/src/xrEngine/IInputReceiver.cpp @@ -32,8 +32,8 @@ void IInputReceiver::IR_OnDeactivate(void) for (i = 0; i < CInput::COUNT_MOUSE_BUTTONS; i++) if (IR_GetBtnState(i)) IR_OnMouseRelease(i); - IR_OnMouseStop(DIMOFS_X, 0); - IR_OnMouseStop(DIMOFS_Y, 0); + //IR_OnMouseStop(DIMOFS_X, 0); + //IR_OnMouseStop(DIMOFS_Y, 0); } void IInputReceiver::IR_OnActivate(void) {} diff --git a/src/xrEngine/Render.h b/src/xrEngine/Render.h index dc615a9cc1b..7d8be3680bc 100644 --- a/src/xrEngine/Render.h +++ b/src/xrEngine/Render.h @@ -5,7 +5,7 @@ #include "vis_common.h" #include "Include/xrRender/FactoryPtr.h" #include "xrCore/xr_resource.h" -#include "SDL.h" +#include class IUIShader; typedef FactoryPtr wm_shader; diff --git a/src/xrEngine/XR_IOConsole_callback.cpp b/src/xrEngine/XR_IOConsole_callback.cpp index f58a9dfc9da..092d19c8d8d 100644 --- a/src/xrEngine/XR_IOConsole_callback.cpp +++ b/src/xrEngine/XR_IOConsole_callback.cpp @@ -11,36 +11,37 @@ #include "line_editor.h" #include "xr_input.h" #include "xr_ioc_cmd.h" +#include "SDL.h" void CConsole::Register_callbacks() { - ec().assign_callback(DIK_PRIOR, text_editor::ks_free, Callback(this, &CConsole::Prev_log)); - ec().assign_callback(DIK_NEXT, text_editor::ks_free, Callback(this, &CConsole::Next_log)); - ec().assign_callback(DIK_PRIOR, text_editor::ks_Ctrl, Callback(this, &CConsole::Begin_log)); - ec().assign_callback(DIK_NEXT, text_editor::ks_Ctrl, Callback(this, &CConsole::End_log)); + ec().assign_callback(SDL_SCANCODE_PAGEUP, text_editor::ks_free, Callback(this, &CConsole::Prev_log)); + ec().assign_callback(SDL_SCANCODE_PAGEDOWN, text_editor::ks_free, Callback(this, &CConsole::Next_log)); + ec().assign_callback(SDL_SCANCODE_PAGEUP, text_editor::ks_Ctrl, Callback(this, &CConsole::Begin_log)); + ec().assign_callback(SDL_SCANCODE_PAGEDOWN, text_editor::ks_Ctrl, Callback(this, &CConsole::End_log)); - ec().assign_callback(DIK_TAB, text_editor::ks_free, Callback(this, &CConsole::Find_cmd)); - ec().assign_callback(DIK_TAB, text_editor::ks_Shift, Callback(this, &CConsole::Find_cmd_back)); - ec().assign_callback(DIK_TAB, text_editor::ks_Alt, Callback(this, &CConsole::GamePause)); + ec().assign_callback(SDL_SCANCODE_TAB, text_editor::ks_free, Callback(this, &CConsole::Find_cmd)); + ec().assign_callback(SDL_SCANCODE_TAB, text_editor::ks_Shift, Callback(this, &CConsole::Find_cmd_back)); + ec().assign_callback(SDL_SCANCODE_TAB, text_editor::ks_Alt, Callback(this, &CConsole::GamePause)); - ec().assign_callback(DIK_UP, text_editor::ks_free, Callback(this, &CConsole::Prev_tip)); - ec().assign_callback(DIK_DOWN, text_editor::ks_free, Callback(this, &CConsole::Next_tip)); - ec().assign_callback(DIK_UP, text_editor::ks_Ctrl, Callback(this, &CConsole::Prev_cmd)); - ec().assign_callback(DIK_DOWN, text_editor::ks_Ctrl, Callback(this, &CConsole::Next_cmd)); + ec().assign_callback(SDL_SCANCODE_UP, text_editor::ks_free, Callback(this, &CConsole::Prev_tip)); + ec().assign_callback(SDL_SCANCODE_DOWN, text_editor::ks_free, Callback(this, &CConsole::Next_tip)); + ec().assign_callback(SDL_SCANCODE_UP, text_editor::ks_Ctrl, Callback(this, &CConsole::Prev_cmd)); + ec().assign_callback(SDL_SCANCODE_DOWN, text_editor::ks_Ctrl, Callback(this, &CConsole::Next_cmd)); - ec().assign_callback(DIK_HOME, text_editor::ks_Alt, Callback(this, &CConsole::Begin_tips)); - ec().assign_callback(DIK_END, text_editor::ks_Alt, Callback(this, &CConsole::End_tips)); - ec().assign_callback(DIK_PRIOR, text_editor::ks_Alt, Callback(this, &CConsole::PageUp_tips)); - ec().assign_callback(DIK_NEXT, text_editor::ks_Alt, Callback(this, &CConsole::PageDown_tips)); + ec().assign_callback(SDL_SCANCODE_HOME, text_editor::ks_Alt, Callback(this, &CConsole::Begin_tips)); + ec().assign_callback(SDL_SCANCODE_END, text_editor::ks_Alt, Callback(this, &CConsole::End_tips)); + ec().assign_callback(SDL_SCANCODE_PAGEUP, text_editor::ks_Alt, Callback(this, &CConsole::PageUp_tips)); + ec().assign_callback(SDL_SCANCODE_PAGEDOWN, text_editor::ks_Alt, Callback(this, &CConsole::PageDown_tips)); - ec().assign_callback(DIK_RETURN, text_editor::ks_free, Callback(this, &CConsole::Execute_cmd)); - ec().assign_callback(DIK_NUMPADENTER, text_editor::ks_free, Callback(this, &CConsole::Execute_cmd)); + ec().assign_callback(SDL_SCANCODE_RETURN, text_editor::ks_free, Callback(this, &CConsole::Execute_cmd)); + ec().assign_callback(SDL_SCANCODE_KP_ENTER, text_editor::ks_free, Callback(this, &CConsole::Execute_cmd)); - ec().assign_callback(DIK_ESCAPE, text_editor::ks_free, Callback(this, &CConsole::Hide_cmd_esc)); - ec().assign_callback(DIK_GRAVE, text_editor::ks_free, Callback(this, &CConsole::Hide_cmd)); + ec().assign_callback(SDL_SCANCODE_ESCAPE, text_editor::ks_free, Callback(this, &CConsole::Hide_cmd_esc)); + ec().assign_callback(SDL_SCANCODE_GRAVE, text_editor::ks_free, Callback(this, &CConsole::Hide_cmd)); } -void CConsole::Prev_log() // DIK_PRIOR=PAGE_UP +void CConsole::Prev_log() // SDL_SCANCODE_PRIOR=PAGE_UP { scroll_delta++; if (scroll_delta > int(LogFile.size()) - 1) @@ -49,7 +50,7 @@ void CConsole::Prev_log() // DIK_PRIOR=PAGE_UP } } -void CConsole::Next_log() // DIK_NEXT=PAGE_DOWN +void CConsole::Next_log() // SDL_SCANCODE_NEXT=PAGE_DOWN { scroll_delta--; if (scroll_delta < 0) @@ -68,7 +69,7 @@ void CConsole::End_log() // PAGE_DOWN+Ctrl scroll_delta = 0; } -void CConsole::Find_cmd() // DIK_TAB +void CConsole::Find_cmd() // SDL_SCANCODE_TAB { shared_str out_str; @@ -79,7 +80,7 @@ void CConsole::Find_cmd() // DIK_TAB } } -void CConsole::Find_cmd_back() // DIK_TAB+shift +void CConsole::Find_cmd_back() // SDL_SCANCODE_TAB+shift { LPCSTR edt = ec().str_edit(); LPCSTR radmin_cmd_name = "ra "; @@ -101,19 +102,19 @@ void CConsole::Find_cmd_back() // DIK_TAB+shift } } -void CConsole::Prev_cmd() // DIK_UP + Ctrl +void CConsole::Prev_cmd() // SDL_SCANCODE_UP + Ctrl { prev_cmd_history_idx(); SelectCommand(); } -void CConsole::Next_cmd() // DIK_DOWN + Ctrl +void CConsole::Next_cmd() // SDL_SCANCODE_DOWN + Ctrl { next_cmd_history_idx(); SelectCommand(); } -void CConsole::Prev_tip() // DIK_UP +void CConsole::Prev_tip() // SDL_SCANCODE_UP { if (xr_strlen(ec().str_edit()) == 0) { @@ -124,7 +125,7 @@ void CConsole::Prev_tip() // DIK_UP prev_selected_tip(); } -void CConsole::Next_tip() // DIK_DOWN + Ctrl +void CConsole::Next_tip() // SDL_SCANCODE_DOWN + Ctrl { if (xr_strlen(ec().str_edit()) == 0) { @@ -160,7 +161,7 @@ void CConsole::PageDown_tips() check_next_selected_tip(); } -void CConsole::Execute_cmd() // DIK_RETURN, DIK_NUMPADENTER +void CConsole::Execute_cmd() // SDL_SCANCODE_RETURN, SDL_SCANCODE_KP_ENTER { if (0 <= m_select_tip && m_select_tip < (int)m_tips.size()) { diff --git a/src/xrEngine/line_edit_control.cpp b/src/xrEngine/line_edit_control.cpp index 7e8adc728d5..14b358d855b 100644 --- a/src/xrEngine/line_edit_control.cpp +++ b/src/xrEngine/line_edit_control.cpp @@ -12,6 +12,7 @@ #include "xrCore/buffer_vector.h" #include "Common/object_broker.h" #include "xr_input.h" +#include "SDL.h" #include "edit_actions.h" @@ -72,7 +73,7 @@ line_edit_control::line_edit_control(u32 str_buffer_size) m_buf2 = nullptr; m_buf3 = nullptr; - for (u32 i = 0; i < DIK_COUNT; ++i) + for (u32 i = 0; i < SDL_SCANCODE_COUNT; ++i) m_actions[i] = nullptr; init(str_buffer_size); @@ -124,12 +125,12 @@ void line_edit_control::update_key_states() { m_key_state.zero(); - set_key_state(ks_LShift, !!pInput->iGetAsyncKeyState(DIK_LSHIFT)); - set_key_state(ks_RShift, !!pInput->iGetAsyncKeyState(DIK_RSHIFT)); - set_key_state(ks_LCtrl, !!pInput->iGetAsyncKeyState(DIK_LCONTROL)); - set_key_state(ks_RCtrl, !!pInput->iGetAsyncKeyState(DIK_RCONTROL)); - set_key_state(ks_LAlt, !!pInput->iGetAsyncKeyState(DIK_LALT)); - set_key_state(ks_RAlt, !!pInput->iGetAsyncKeyState(DIK_RALT)); + set_key_state(ks_LShift, !!pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT)); + set_key_state(ks_RShift, !!pInput->iGetAsyncKeyState(SDL_SCANCODE_RSHIFT)); + set_key_state(ks_LCtrl, !!pInput->iGetAsyncKeyState(SDL_SCANCODE_LCTRL)); + set_key_state(ks_RCtrl, !!pInput->iGetAsyncKeyState(SDL_SCANCODE_RCTRL)); + set_key_state(ks_LAlt, !!pInput->iGetAsyncKeyState(SDL_SCANCODE_LALT)); + set_key_state(ks_RAlt, !!pInput->iGetAsyncKeyState(SDL_SCANCODE_RALT)); set_key_state(ks_CapsLock, text_editor::get_caps_lock_state()); } @@ -190,7 +191,7 @@ void line_edit_control::init(u32 str_buffer_size, init_mode mode) clear_states(); - for (u32 i = 0; i < DIK_COUNT; ++i) + for (u32 i = 0; i < SDL_SCANCODE_COUNT; ++i) { xr_delete(m_actions[i]); m_actions[i] = nullptr; @@ -198,164 +199,164 @@ void line_edit_control::init(u32 str_buffer_size, init_mode mode) if (mode == im_read_only) { - assign_callback(DIK_A, ks_Ctrl, Callback(this, &line_edit_control::select_all_buf)); - assign_callback(DIK_C, ks_Ctrl, Callback(this, &line_edit_control::copy_to_clipboard)); - assign_callback(DIK_INSERT, ks_Ctrl, Callback(this, &line_edit_control::copy_to_clipboard)); + assign_callback(SDL_SCANCODE_A, ks_Ctrl, Callback(this, &line_edit_control::select_all_buf)); + assign_callback(SDL_SCANCODE_C, ks_Ctrl, Callback(this, &line_edit_control::copy_to_clipboard)); + assign_callback(SDL_SCANCODE_INSERT, ks_Ctrl, Callback(this, &line_edit_control::copy_to_clipboard)); - assign_callback(DIK_HOME, ks_free, Callback(this, &line_edit_control::move_pos_home)); - assign_callback(DIK_END, ks_free, Callback(this, &line_edit_control::move_pos_end)); - assign_callback(DIK_LEFT, ks_free, Callback(this, &line_edit_control::move_pos_left)); - assign_callback(DIK_RIGHT, ks_free, Callback(this, &line_edit_control::move_pos_right)); - assign_callback(DIK_LEFT, ks_Ctrl, Callback(this, &line_edit_control::move_pos_left_word)); - assign_callback(DIK_RIGHT, ks_Ctrl, Callback(this, &line_edit_control::move_pos_right_word)); + assign_callback(SDL_SCANCODE_HOME, ks_free, Callback(this, &line_edit_control::move_pos_home)); + assign_callback(SDL_SCANCODE_END, ks_free, Callback(this, &line_edit_control::move_pos_end)); + assign_callback(SDL_SCANCODE_LEFT, ks_free, Callback(this, &line_edit_control::move_pos_left)); + assign_callback(SDL_SCANCODE_RIGHT, ks_free, Callback(this, &line_edit_control::move_pos_right)); + assign_callback(SDL_SCANCODE_LEFT, ks_Ctrl, Callback(this, &line_edit_control::move_pos_left_word)); + assign_callback(SDL_SCANCODE_RIGHT, ks_Ctrl, Callback(this, &line_edit_control::move_pos_right_word)); } else { assign_char_pairs(mode); - assign_callback(DIK_INSERT, ks_free, Callback(this, &line_edit_control::flip_insert_mode)); - assign_callback(DIK_A, ks_Ctrl, Callback(this, &line_edit_control::select_all_buf)); - assign_callback(DIK_Z, ks_Ctrl, Callback(this, &line_edit_control::undo_buf)); + assign_callback(SDL_SCANCODE_INSERT, ks_free, Callback(this, &line_edit_control::flip_insert_mode)); + assign_callback(SDL_SCANCODE_A, ks_Ctrl, Callback(this, &line_edit_control::select_all_buf)); + assign_callback(SDL_SCANCODE_Z, ks_Ctrl, Callback(this, &line_edit_control::undo_buf)); - assign_callback(DIK_C, ks_Ctrl, Callback(this, &line_edit_control::copy_to_clipboard)); - assign_callback(DIK_V, ks_Ctrl, Callback(this, &line_edit_control::paste_from_clipboard)); - assign_callback(DIK_X, ks_Ctrl, Callback(this, &line_edit_control::cut_to_clipboard)); + assign_callback(SDL_SCANCODE_C, ks_Ctrl, Callback(this, &line_edit_control::copy_to_clipboard)); + assign_callback(SDL_SCANCODE_V, ks_Ctrl, Callback(this, &line_edit_control::paste_from_clipboard)); + assign_callback(SDL_SCANCODE_X, ks_Ctrl, Callback(this, &line_edit_control::cut_to_clipboard)); - assign_callback(DIK_INSERT, ks_Ctrl, Callback(this, &line_edit_control::copy_to_clipboard)); - assign_callback(DIK_INSERT, ks_Shift, Callback(this, &line_edit_control::paste_from_clipboard)); - assign_callback(DIK_DELETE, ks_Shift, Callback(this, &line_edit_control::cut_to_clipboard)); + assign_callback(SDL_SCANCODE_INSERT, ks_Ctrl, Callback(this, &line_edit_control::copy_to_clipboard)); + assign_callback(SDL_SCANCODE_INSERT, ks_Shift, Callback(this, &line_edit_control::paste_from_clipboard)); + assign_callback(SDL_SCANCODE_DELETE, ks_Shift, Callback(this, &line_edit_control::cut_to_clipboard)); - assign_callback(DIK_HOME, ks_free, Callback(this, &line_edit_control::move_pos_home)); - assign_callback(DIK_END, ks_free, Callback(this, &line_edit_control::move_pos_end)); - assign_callback(DIK_LEFT, ks_free, Callback(this, &line_edit_control::move_pos_left)); - assign_callback(DIK_RIGHT, ks_free, Callback(this, &line_edit_control::move_pos_right)); - assign_callback(DIK_LEFT, ks_Ctrl, Callback(this, &line_edit_control::move_pos_left_word)); - assign_callback(DIK_RIGHT, ks_Ctrl, Callback(this, &line_edit_control::move_pos_right_word)); + assign_callback(SDL_SCANCODE_HOME, ks_free, Callback(this, &line_edit_control::move_pos_home)); + assign_callback(SDL_SCANCODE_END, ks_free, Callback(this, &line_edit_control::move_pos_end)); + assign_callback(SDL_SCANCODE_LEFT, ks_free, Callback(this, &line_edit_control::move_pos_left)); + assign_callback(SDL_SCANCODE_RIGHT, ks_free, Callback(this, &line_edit_control::move_pos_right)); + assign_callback(SDL_SCANCODE_LEFT, ks_Ctrl, Callback(this, &line_edit_control::move_pos_left_word)); + assign_callback(SDL_SCANCODE_RIGHT, ks_Ctrl, Callback(this, &line_edit_control::move_pos_right_word)); - assign_callback(DIK_BACK, ks_free, Callback(this, &line_edit_control::delete_selected_back)); - assign_callback(DIK_DELETE, ks_free, Callback(this, &line_edit_control::delete_selected_forward)); - assign_callback(DIK_BACK, ks_Ctrl, Callback(this, &line_edit_control::delete_word_back)); - assign_callback(DIK_DELETE, ks_Ctrl, Callback(this, &line_edit_control::delete_word_forward)); + assign_callback(SDL_SCANCODE_BACKSPACE, ks_free, Callback(this, &line_edit_control::delete_selected_back)); + assign_callback(SDL_SCANCODE_DELETE, ks_free, Callback(this, &line_edit_control::delete_selected_forward)); + assign_callback(SDL_SCANCODE_BACKSPACE, ks_Ctrl, Callback(this, &line_edit_control::delete_word_back)); + assign_callback(SDL_SCANCODE_DELETE, ks_Ctrl, Callback(this, &line_edit_control::delete_word_forward)); - assign_callback(DIK_LSHIFT, ks_Ctrl, Callback(this, &line_edit_control::SwitchKL)); - assign_callback(DIK_LSHIFT, ks_Alt, Callback(this, &line_edit_control::SwitchKL)); + assign_callback(SDL_SCANCODE_LSHIFT, ks_Ctrl, Callback(this, &line_edit_control::SwitchKL)); + assign_callback(SDL_SCANCODE_LSHIFT, ks_Alt, Callback(this, &line_edit_control::SwitchKL)); } // if mode - create_key_state(DIK_LSHIFT, ks_LShift); - create_key_state(DIK_RSHIFT, ks_RShift); - create_key_state(DIK_LCONTROL, ks_LCtrl); - create_key_state(DIK_RCONTROL, ks_RCtrl); - create_key_state(DIK_LALT, ks_LAlt); - create_key_state(DIK_RALT, ks_RAlt); + create_key_state(SDL_SCANCODE_LSHIFT, ks_LShift); + create_key_state(SDL_SCANCODE_RSHIFT, ks_RShift); + create_key_state(SDL_SCANCODE_LCTRL, ks_LCtrl); + create_key_state(SDL_SCANCODE_RCTRL, ks_RCtrl); + create_key_state(SDL_SCANCODE_LALT, ks_LAlt); + create_key_state(SDL_SCANCODE_RALT, ks_RAlt); } void line_edit_control::assign_char_pairs(init_mode mode) { - create_char_pair(DIK_NUMPAD0, '0', '0'); - create_char_pair(DIK_NUMPAD1, '1', '1'); - create_char_pair(DIK_NUMPAD2, '2', '2'); - create_char_pair(DIK_NUMPAD3, '3', '3'); - create_char_pair(DIK_NUMPAD4, '4', '4'); - create_char_pair(DIK_NUMPAD5, '5', '5'); - create_char_pair(DIK_NUMPAD6, '6', '6'); - create_char_pair(DIK_NUMPAD7, '7', '7'); - create_char_pair(DIK_NUMPAD8, '8', '8'); - create_char_pair(DIK_NUMPAD9, '9', '9'); + create_char_pair(SDL_SCANCODE_KP_0, '0', '0'); + create_char_pair(SDL_SCANCODE_KP_1, '1', '1'); + create_char_pair(SDL_SCANCODE_KP_2, '2', '2'); + create_char_pair(SDL_SCANCODE_KP_3, '3', '3'); + create_char_pair(SDL_SCANCODE_KP_4, '4', '4'); + create_char_pair(SDL_SCANCODE_KP_5, '5', '5'); + create_char_pair(SDL_SCANCODE_KP_6, '6', '6'); + create_char_pair(SDL_SCANCODE_KP_7, '7', '7'); + create_char_pair(SDL_SCANCODE_KP_8, '8', '8'); + create_char_pair(SDL_SCANCODE_KP_9, '9', '9'); if (mode == im_number_only) { - create_char_pair(DIK_0, '0', '0'); - create_char_pair(DIK_1, '1', '1'); - create_char_pair(DIK_2, '2', '2'); - create_char_pair(DIK_3, '3', '3'); - create_char_pair(DIK_4, '4', '4'); - create_char_pair(DIK_5, '5', '5'); - create_char_pair(DIK_6, '6', '6'); - create_char_pair(DIK_7, '7', '7'); - create_char_pair(DIK_8, '8', '8'); - create_char_pair(DIK_9, '9', '9'); - create_char_pair(DIK_NUMPADMINUS, '-', '-'); - create_char_pair(DIK_MINUS, '-', '-'); - create_char_pair(DIK_NUMPADPLUS, '+', '+'); - create_char_pair(DIK_EQUALS, '+', '+'); + create_char_pair(SDL_SCANCODE_0, '0', '0'); + create_char_pair(SDL_SCANCODE_1, '1', '1'); + create_char_pair(SDL_SCANCODE_2, '2', '2'); + create_char_pair(SDL_SCANCODE_3, '3', '3'); + create_char_pair(SDL_SCANCODE_4, '4', '4'); + create_char_pair(SDL_SCANCODE_5, '5', '5'); + create_char_pair(SDL_SCANCODE_6, '6', '6'); + create_char_pair(SDL_SCANCODE_7, '7', '7'); + create_char_pair(SDL_SCANCODE_8, '8', '8'); + create_char_pair(SDL_SCANCODE_9, '9', '9'); + create_char_pair(SDL_SCANCODE_KP_MINUS, '-', '-'); + create_char_pair(SDL_SCANCODE_MINUS, '-', '-'); + create_char_pair(SDL_SCANCODE_KP_PLUS, '+', '+'); + create_char_pair(SDL_SCANCODE_EQUALS, '+', '+'); return; } if (mode != im_file_name_mode) { - create_char_pair(DIK_0, '0', ')', true); - create_char_pair(DIK_1, '1', '!', true); - create_char_pair(DIK_2, '2', '@', true); - create_char_pair(DIK_3, '3', '#', true); - create_char_pair(DIK_4, '4', '$', true); - create_char_pair(DIK_5, '5', '%', true); - create_char_pair(DIK_6, '6', '^', true); - create_char_pair(DIK_7, '7', '&', true); - create_char_pair(DIK_8, '8', '*', true); - create_char_pair(DIK_9, '9', '(', true); - - create_char_pair(DIK_BACKSLASH, '\\', '|', true); - create_char_pair(DIK_LBRACKET, '[', '{', true); - create_char_pair(DIK_RBRACKET, ']', '}', true); - create_char_pair(DIK_APOSTROPHE, '\'', '\"', true); - create_char_pair(DIK_COMMA, ',', '<', true); - create_char_pair(DIK_PERIOD, '.', '>', true); - create_char_pair(DIK_EQUALS, '=', '+', true); - create_char_pair(DIK_SEMICOLON, ';', ':', true); - create_char_pair(DIK_SLASH, '/', '?', true); - - create_char_pair(DIK_NUMPADSTAR, '*', '*'); - create_char_pair(DIK_NUMPADSLASH, '/', '/'); + create_char_pair(SDL_SCANCODE_0, '0', ')', true); + create_char_pair(SDL_SCANCODE_1, '1', '!', true); + create_char_pair(SDL_SCANCODE_2, '2', '@', true); + create_char_pair(SDL_SCANCODE_3, '3', '#', true); + create_char_pair(SDL_SCANCODE_4, '4', '$', true); + create_char_pair(SDL_SCANCODE_5, '5', '%', true); + create_char_pair(SDL_SCANCODE_6, '6', '^', true); + create_char_pair(SDL_SCANCODE_7, '7', '&', true); + create_char_pair(SDL_SCANCODE_8, '8', '*', true); + create_char_pair(SDL_SCANCODE_9, '9', '(', true); + + create_char_pair(SDL_SCANCODE_BACKSLASH, '\\', '|', true); + create_char_pair(SDL_SCANCODE_LEFTBRACKET, '[', '{', true); + create_char_pair(SDL_SCANCODE_RIGHTBRACKET, ']', '}', true); + create_char_pair(SDL_SCANCODE_APOSTROPHE, '\'', '\"', true); + create_char_pair(SDL_SCANCODE_COMMA, ',', '<', true); + create_char_pair(SDL_SCANCODE_PERIOD, '.', '>', true); + create_char_pair(SDL_SCANCODE_EQUALS, '=', '+', true); + create_char_pair(SDL_SCANCODE_SEMICOLON, ';', ':', true); + create_char_pair(SDL_SCANCODE_SLASH, '/', '?', true); + + create_char_pair(SDL_SCANCODE_KP_MULTIPLY, '*', '*'); + create_char_pair(SDL_SCANCODE_KP_DIVIDE, '/', '/'); } else { - create_char_pair(DIK_0, '0', '0'); - create_char_pair(DIK_1, '1', '1'); - create_char_pair(DIK_2, '2', '2'); - create_char_pair(DIK_3, '3', '3'); - create_char_pair(DIK_4, '4', '4'); - create_char_pair(DIK_5, '5', '5'); - create_char_pair(DIK_6, '6', '6'); - create_char_pair(DIK_7, '7', '7'); - create_char_pair(DIK_8, '8', '8'); - create_char_pair(DIK_9, '9', '9'); + create_char_pair(SDL_SCANCODE_0, '0', '0'); + create_char_pair(SDL_SCANCODE_1, '1', '1'); + create_char_pair(SDL_SCANCODE_2, '2', '2'); + create_char_pair(SDL_SCANCODE_3, '3', '3'); + create_char_pair(SDL_SCANCODE_4, '4', '4'); + create_char_pair(SDL_SCANCODE_5, '5', '5'); + create_char_pair(SDL_SCANCODE_6, '6', '6'); + create_char_pair(SDL_SCANCODE_7, '7', '7'); + create_char_pair(SDL_SCANCODE_8, '8', '8'); + create_char_pair(SDL_SCANCODE_9, '9', '9'); } - create_char_pair(DIK_NUMPADMINUS, '-', '-'); - create_char_pair(DIK_NUMPADPLUS, '+', '+'); - create_char_pair(DIK_NUMPADPERIOD, '.', '.'); - - create_char_pair(DIK_MINUS, '-', '_', true); - create_char_pair(DIK_SPACE, ' ', ' '); - create_char_pair(DIK_GRAVE, '`', '~', true); - - create_char_pair(DIK_A, 'a', 'A', true); - create_char_pair(DIK_B, 'b', 'B', true); - create_char_pair(DIK_C, 'c', 'C', true); - create_char_pair(DIK_D, 'd', 'D', true); - create_char_pair(DIK_E, 'e', 'E', true); - create_char_pair(DIK_F, 'f', 'F', true); - create_char_pair(DIK_G, 'g', 'G', true); - create_char_pair(DIK_H, 'h', 'H', true); - create_char_pair(DIK_I, 'i', 'I', true); - create_char_pair(DIK_J, 'j', 'J', true); - create_char_pair(DIK_K, 'k', 'K', true); - create_char_pair(DIK_L, 'l', 'L', true); - create_char_pair(DIK_M, 'm', 'M', true); - create_char_pair(DIK_N, 'n', 'N', true); - create_char_pair(DIK_O, 'o', 'O', true); - create_char_pair(DIK_P, 'p', 'P', true); - create_char_pair(DIK_Q, 'q', 'Q', true); - create_char_pair(DIK_R, 'r', 'R', true); - create_char_pair(DIK_S, 's', 'S', true); - create_char_pair(DIK_T, 't', 'T', true); - create_char_pair(DIK_U, 'u', 'U', true); - create_char_pair(DIK_V, 'v', 'V', true); - create_char_pair(DIK_W, 'w', 'W', true); - create_char_pair(DIK_X, 'x', 'X', true); - create_char_pair(DIK_Y, 'y', 'Y', true); - create_char_pair(DIK_Z, 'z', 'Z', true); + create_char_pair(SDL_SCANCODE_KP_MINUS, '-', '-'); + create_char_pair(SDL_SCANCODE_KP_PLUS, '+', '+'); + create_char_pair(SDL_SCANCODE_KP_PERIOD, '.', '.'); + + create_char_pair(SDL_SCANCODE_MINUS, '-', '_', true); + create_char_pair(SDL_SCANCODE_SPACE, ' ', ' '); + create_char_pair(SDL_SCANCODE_GRAVE, '`', '~', true); + + create_char_pair(SDL_SCANCODE_A, 'a', 'A', true); + create_char_pair(SDL_SCANCODE_B, 'b', 'B', true); + create_char_pair(SDL_SCANCODE_C, 'c', 'C', true); + create_char_pair(SDL_SCANCODE_D, 'd', 'D', true); + create_char_pair(SDL_SCANCODE_E, 'e', 'E', true); + create_char_pair(SDL_SCANCODE_F, 'f', 'F', true); + create_char_pair(SDL_SCANCODE_G, 'g', 'G', true); + create_char_pair(SDL_SCANCODE_H, 'h', 'H', true); + create_char_pair(SDL_SCANCODE_I, 'i', 'I', true); + create_char_pair(SDL_SCANCODE_J, 'j', 'J', true); + create_char_pair(SDL_SCANCODE_K, 'k', 'K', true); + create_char_pair(SDL_SCANCODE_L, 'l', 'L', true); + create_char_pair(SDL_SCANCODE_M, 'm', 'M', true); + create_char_pair(SDL_SCANCODE_N, 'n', 'N', true); + create_char_pair(SDL_SCANCODE_O, 'o', 'O', true); + create_char_pair(SDL_SCANCODE_P, 'p', 'P', true); + create_char_pair(SDL_SCANCODE_Q, 'q', 'Q', true); + create_char_pair(SDL_SCANCODE_R, 'r', 'R', true); + create_char_pair(SDL_SCANCODE_S, 's', 'S', true); + create_char_pair(SDL_SCANCODE_T, 't', 'T', true); + create_char_pair(SDL_SCANCODE_U, 'u', 'U', true); + create_char_pair(SDL_SCANCODE_V, 'v', 'V', true); + create_char_pair(SDL_SCANCODE_W, 'w', 'W', true); + create_char_pair(SDL_SCANCODE_X, 'x', 'X', true); + create_char_pair(SDL_SCANCODE_Y, 'y', 'Y', true); + create_char_pair(SDL_SCANCODE_Z, 'z', 'Z', true); } void line_edit_control::create_key_state(u32 const dik, key_state state) @@ -380,7 +381,7 @@ void line_edit_control::create_char_pair(u32 const dik, char c, char c_shift, bo void line_edit_control::assign_callback(u32 const dik, key_state state, Callback const& callback) { - VERIFY(dik < DIK_COUNT); + VERIFY(dik < SDL_SCANCODE_COUNT); Base* prev_action = m_actions[dik]; m_actions[dik] = new text_editor::callback_base(callback, state); m_actions[dik]->on_assign(prev_action); @@ -406,7 +407,7 @@ void line_edit_control::set_edit(pcstr str) void line_edit_control::on_key_press(int dik) { - if (DIK_COUNT <= dik) + if (SDL_SCANCODE_COUNT <= dik) { return; } @@ -426,7 +427,7 @@ void line_edit_control::on_key_press(int dik) m_actions[dik]->on_key_press(this); } // =========== - if (dik == DIK_LCONTROL || dik == DIK_RCONTROL) + if (dik == SDL_SCANCODE_LCTRL || dik == SDL_SCANCODE_RCTRL) { m_mark = false; } @@ -456,13 +457,13 @@ void line_edit_control::on_key_hold(int dik) update_bufs(); switch (dik) { - case DIK_TAB: - case DIK_LSHIFT: - case DIK_RSHIFT: - case DIK_LCONTROL: - case DIK_RCONTROL: - case DIK_LALT: - case DIK_RALT: return; break; + case SDL_SCANCODE_TAB: + case SDL_SCANCODE_LSHIFT: + case SDL_SCANCODE_RSHIFT: + case SDL_SCANCODE_LCTRL: + case SDL_SCANCODE_RCTRL: + case SDL_SCANCODE_LALT: + case SDL_SCANCODE_RALT: return; break; } if (m_repeat_mode && m_last_key_time > 5.0f * g_console_sensitive) diff --git a/src/xrEngine/line_edit_control.h b/src/xrEngine/line_edit_control.h index 351a3fc08e2..cf7079a479f 100644 --- a/src/xrEngine/line_edit_control.h +++ b/src/xrEngine/line_edit_control.h @@ -121,9 +121,9 @@ class ENGINE_API line_edit_control private: enum { - DIK_COUNT = 256 + SDL_SCANCODE_COUNT = 256 }; - Base* m_actions[DIK_COUNT]; + Base* m_actions[SDL_SCANCODE_COUNT]; char* m_edit_str; char* m_undo_buf; diff --git a/src/xrEngine/stdafx.h b/src/xrEngine/stdafx.h index c400d046729..b5194c3d3ea 100644 --- a/src/xrEngine/stdafx.h +++ b/src/xrEngine/stdafx.h @@ -28,7 +28,7 @@ #include "xrCDB/xrXRC.h" -#include "xrSound/sound.h" +#include "xrSound/Sound.h" extern ENGINE_API CInifile* pGameIni; diff --git a/src/xrEngine/xr_input.cpp b/src/xrEngine/xr_input.cpp index 838a98f12ea..b70572534dd 100644 --- a/src/xrEngine/xr_input.cpp +++ b/src/xrEngine/xr_input.cpp @@ -42,23 +42,13 @@ CInput::CInput(BOOL bExclusive, int deviceForInit) g_exclusive = !!bExclusive; Log("Starting INPUT device..."); - pDI = NULL; - pMouse = NULL; - //=====================Mouse - mouse_property.mouse_dt = 25; ZeroMemory(mouseState, sizeof(mouseState)); ZeroMemory(KBState, sizeof(KBState)); ZeroMemory(timeStamp, sizeof(timeStamp)); ZeroMemory(timeSave, sizeof(timeStamp)); ZeroMemory(offs, sizeof(offs)); - //if (SDL_Init(SDL_INIT_EVERYTHING) != 0) - //{ - // Log("Unable to initialize SDL: %s", SDL_GetError()); - //} - - xrDebug::SetDialogHandler(on_error_dialog); #ifdef ENGINE_BUILD @@ -75,58 +65,6 @@ CInput::~CInput(void) Device.seqAppDeactivate.Remove(this); Device.seqAppActivate.Remove(this); #endif - //_______________________ - - // Unacquire and release the device's interfaces - if (pMouse) - { - pMouse->Unacquire(); - _RELEASE(pMouse); - } - - _SHOW_REF("Input: ", pDI); - //SDL_Quit(); - _RELEASE(pDI); -} - -//----------------------------------------------------------------------------- -// Name: CreateInputDevice() -// Desc: Create a DirectInput device. -//----------------------------------------------------------------------------- -HRESULT CInput::CreateInputDevice( - LPDIRECTINPUTDEVICE8* device, GUID guidDevice, const DIDATAFORMAT* pdidDataFormat, u32 dwFlags, u32 buf_size) -{ - // Obtain an interface to the input device - //. CHK_DX( pDI->CreateDeviceEx( guidDevice, IID_IDirectInputDevice8, (void**)device, NULL ) ); - CHK_DX(pDI->CreateDevice(guidDevice, /*IID_IDirectInputDevice8,*/ device, NULL)); - - // Set the device data format. Note: a data format specifies which - // controls on a device we are interested in, and how they should be - // reported. - CHK_DX((*device)->SetDataFormat(pdidDataFormat)); - - // Set the cooperativity level to let DirectInput know how this device - // should interact with the system and with other DirectInput applications. - //if (!Device.editor()) - //{ - // HRESULT _hr = (*device)->SetCooperativeLevel(RDEVICE.m_sdlWnd, dwFlags); - // if (FAILED(_hr) && (_hr == E_NOTIMPL)) - // Msg("! INPUT: Can't set coop level. Emulation???"); - // else - // R_CHK(_hr); - //} - - // setup the buffer size for the keyboard data - DIPROPDWORD dipdw; - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = buf_size; - - CHK_DX((*device)->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph)); - - return S_OK; } //----------------------------------------------------------------------- @@ -138,14 +76,10 @@ void CInput::DumpStatistics(IGameFont& font, IPerformanceAlert* alert) void CInput::SetAllAcquire(BOOL bAcquire) { - if (pMouse) - bAcquire ? pMouse->Acquire() : pMouse->Unacquire(); } void CInput::SetMouseAcquire(BOOL bAcquire) { - if (pMouse) - bAcquire ? pMouse->Acquire() : pMouse->Unacquire(); } void CInput::SetKBDAcquire(BOOL bAcquire) {} //----------------------------------------------------------------------- @@ -276,23 +210,6 @@ void CInput::ClipCursor(bool clip) // void CInput::MouseUpdate(SDL_Event *event) void CInput::MouseUpdate() { - HRESULT hr; - DWORD dwElements = MOUSEBUFFERSIZE; - DIDEVICEOBJECTDATA od[MOUSEBUFFERSIZE]; - - VERIFY(pMouse); - - hr = pMouse->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), &od[0], &dwElements, 0); - if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED)) - { - hr = pMouse->Acquire(); - if (hr != S_OK) - return; - hr = pMouse->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), &od[0], &dwElements, 0); - if (hr != S_OK) - return; - }; - #ifndef _EDITOR if (Device.dwPrecacheFrame) return; @@ -307,179 +224,14 @@ void CInput::MouseUpdate() mouse_prev[5] = mouseState[5]; mouse_prev[6] = mouseState[6]; mouse_prev[7] = mouseState[7]; - - offs[0] = offs[1] = offs[2] = 0; - for (u32 i = 0; i < dwElements; i++) - { - switch (od[i].dwOfs) - { - case DIMOFS_X: - offs[0] += od[i].dwData; - timeStamp[0] = od[i].dwTimeStamp; - break; - case DIMOFS_Y: - offs[1] += od[i].dwData; - timeStamp[1] = od[i].dwTimeStamp; - break; - case DIMOFS_Z: - offs[2] += od[i].dwData; - timeStamp[2] = od[i].dwTimeStamp; - break; - case DIMOFS_BUTTON0: - if (od[i].dwData & 0x80) - { - mouseState[0] = TRUE; - cbStack.back()->IR_OnMousePress(0); - } - if (!(od[i].dwData & 0x80)) - { - mouseState[0] = FALSE; - cbStack.back()->IR_OnMouseRelease(0); - } - break; - case DIMOFS_BUTTON1: - if (od[i].dwData & 0x80) - { - mouseState[1] = TRUE; - cbStack.back()->IR_OnMousePress(1); - } - if (!(od[i].dwData & 0x80)) - { - mouseState[1] = FALSE; - cbStack.back()->IR_OnMouseRelease(1); - } - break; - case DIMOFS_BUTTON2: - if (od[i].dwData & 0x80) - { - mouseState[2] = TRUE; - cbStack.back()->IR_OnMousePress(2); - } - if (!(od[i].dwData & 0x80)) - { - mouseState[2] = FALSE; - cbStack.back()->IR_OnMouseRelease(2); - } - break; - case DIMOFS_BUTTON3: - if (od[i].dwData & 0x80) - { - mouseState[3] = TRUE; - cbStack.back()->IR_OnKeyboardPress(0xED + 103); - } - if (!(od[i].dwData & 0x80)) - { - mouseState[3] = FALSE; - cbStack.back()->IR_OnKeyboardRelease(0xED + 103); - } - break; - case DIMOFS_BUTTON4: - if (od[i].dwData & 0x80) - { - mouseState[4] = TRUE; - cbStack.back()->IR_OnKeyboardPress(0xED + 104); - } - if (!(od[i].dwData & 0x80)) - { - mouseState[4] = FALSE; - cbStack.back()->IR_OnKeyboardRelease(0xED + 104); - } - break; - case DIMOFS_BUTTON5: - if (od[i].dwData & 0x80) - { - mouseState[5] = TRUE; - cbStack.back()->IR_OnKeyboardPress(0xED + 105); - } - if (!(od[i].dwData & 0x80)) - { - mouseState[5] = FALSE; - cbStack.back()->IR_OnKeyboardRelease(0xED + 105); - } - break; - case DIMOFS_BUTTON6: - if (od[i].dwData & 0x80) - { - mouseState[6] = TRUE; - cbStack.back()->IR_OnKeyboardPress(0xED + 106); - } - if (!(od[i].dwData & 0x80)) - { - mouseState[6] = FALSE; - cbStack.back()->IR_OnKeyboardRelease(0xED + 106); - } - break; - case DIMOFS_BUTTON7: - if (od[i].dwData & 0x80) - { - mouseState[7] = TRUE; - cbStack.back()->IR_OnKeyboardPress(0xED + 107); - } - if (!(od[i].dwData & 0x80)) - { - mouseState[7] = FALSE; - cbStack.back()->IR_OnKeyboardRelease(0xED + 107); - } - break; - } - } - - // Giperion: double check mouse buttons state - DIMOUSESTATE2 MouseState; - hr = pMouse->GetDeviceState(sizeof(MouseState), &MouseState); - - auto RecheckMouseButtonFunc = [&](int i) { - if (MouseState.rgbButtons[i] & 0x80 && mouseState[i] == FALSE) - { - mouseState[i] = TRUE; - cbStack.back()->IR_OnMousePress(i); - } - else if (!(MouseState.rgbButtons[i] & 0x80) && mouseState[i] == TRUE) - { - mouseState[i] = FALSE; - cbStack.back()->IR_OnMouseRelease(i); - } - }; - - if (hr == S_OK) - { - RecheckMouseButtonFunc(0); - RecheckMouseButtonFunc(1); - RecheckMouseButtonFunc(2); - } - //-Giperion - - auto isButtonOnHold = [&](int i) { - if (mouseState[i] && mouse_prev[i]) - cbStack.back()->IR_OnMouseHold(i); - }; - - isButtonOnHold(0); - isButtonOnHold(1); - isButtonOnHold(2); - - if (dwElements) - { - if (offs[0] || offs[1]) - cbStack.back()->IR_OnMouseMove(offs[0], offs[1]); - if (offs[2]) - cbStack.back()->IR_OnMouseWheel(offs[2]); - } - else - { - if (timeStamp[1] && ((dwCurTime - timeStamp[1]) >= mouse_property.mouse_dt)) - cbStack.back()->IR_OnMouseStop(DIMOFS_Y, timeStamp[1] = 0); - if (timeStamp[0] && ((dwCurTime - timeStamp[0]) >= mouse_property.mouse_dt)) - cbStack.back()->IR_OnMouseStop(DIMOFS_X, timeStamp[0] = 0); - } } //------------------------------------------------------- void CInput::iCapture(IInputReceiver* p) { VERIFY(p); - if (pMouse) - MouseUpdate(); + + MouseUpdate(); // change focus if (!cbStack.empty()) @@ -602,7 +354,7 @@ IInputReceiver* CInput::CurrentIR() return NULL; } -void CInput::unacquire() { if (pMouse) pMouse->Unacquire(); } +void CInput::unacquire() {} void CInput::acquire(const bool& exclusive) { diff --git a/src/xrEngine/xr_input.h b/src/xrEngine/xr_input.h index 9f7b5343883..969de97e911 100644 --- a/src/xrEngine/xr_input.h +++ b/src/xrEngine/xr_input.h @@ -2,7 +2,6 @@ #define __XR_INPUT__ #define DIRECTINPUT_VERSION 0x0800 -#include #include class ENGINE_API IInputReceiver; @@ -28,19 +27,7 @@ class ENGINE_API CInput COUNT_MOUSE_AXIS = 3, COUNT_KB_BUTTONS = 256 }; - struct sxr_mouse - { - DIDEVCAPS capabilities; - DIDEVICEINSTANCE deviceInfo; - DIDEVICEOBJECTINSTANCE objectInfo; - u32 mouse_dt; - }; - struct sxr_key - { - DIDEVCAPS capabilities; - DIDEVICEINSTANCE deviceInfo; - DIDEVICEOBJECTINSTANCE objectInfo; - }; + struct InputStatistics { CStatTimer FrameTime; @@ -51,9 +38,7 @@ class ENGINE_API CInput private: BENCH_SEC_SCRAMBLEMEMBER1 - LPDIRECTINPUT8 pDI; // The DInput object - LPDIRECTINPUTDEVICE8 pMouse; // The DIDevice7 interface - //---------------------- + u32 timeStamp[COUNT_MOUSE_AXIS]; u32 timeSave[COUNT_MOUSE_AXIS]; int offs[COUNT_MOUSE_AXIS]; @@ -61,9 +46,6 @@ class ENGINE_API CInput //---------------------- BOOL KBState[COUNT_KB_BUTTONS]; - HRESULT CreateInputDevice( - LPDIRECTINPUTDEVICE8* device, GUID guidDevice, const DIDATAFORMAT* pdidDataFormat, u32 dwFlags, u32 buf_size); - xr_vector cbStack; @@ -74,8 +56,6 @@ class ENGINE_API CInput InputStatistics stats; public: - sxr_mouse mouse_property; - sxr_key key_property; u32 dwCurTime; const InputStatistics& GetStats() const { return stats; } diff --git a/src/xrPhysics/CMakeLists.txt b/src/xrPhysics/CMakeLists.txt index 304049b0536..1e743d2e2ec 100644 --- a/src/xrPhysics/CMakeLists.txt +++ b/src/xrPhysics/CMakeLists.txt @@ -12,6 +12,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/ode/include ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include + /usr/include/SDL2 ) list(REMOVE_ITEM ${PROJECT_NAME}__SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tri-colliderknoopc/dcTriListCollider.cpp")