From f9cac7a34f843d231e1cbbc65bf7db3887a9bed5 Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Thu, 26 Jul 2018 01:44:05 +0500 Subject: [PATCH] Various fixes and improvements: SDL_SCANCODE_LGUI replaced with SDL_SCANCODE_LALT xrGame/MainMenu.cpp: fixed mistake in condition Removed unnecessary casts Formatting xrRender/HW.cpp: I'm assuming that there should be check for depth stencil format --- src/Layers/xrRender/HW.cpp | 6 ++--- src/Layers/xrRenderDX10/dx10HW.cpp | 3 ++- src/xrEngine/device.cpp | 39 +++++++++++++++++++----------- src/xrEngine/line_edit_control.cpp | 17 ++++++------- src/xrEngine/line_editor.cpp | 6 ++--- src/xrEngine/main.cpp | 1 + src/xrGame/ActorInput.cpp | 6 ++--- src/xrGame/MainMenu.cpp | 4 +-- src/xrGame/attachable_item.cpp | 2 +- src/xrGame/ui/UIXmlInit.cpp | 5 ++-- 10 files changed, 50 insertions(+), 39 deletions(-) diff --git a/src/Layers/xrRender/HW.cpp b/src/Layers/xrRender/HW.cpp index a2b19d6f557..48c113a4e14 100644 --- a/src/Layers/xrRender/HW.cpp +++ b/src/Layers/xrRender/HW.cpp @@ -101,9 +101,9 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd) fDepth = selectDepthStencil(fTarget); } - if (D3DFMT_UNKNOWN == fTarget) + if (D3DFMT_UNKNOWN == fTarget || D3DFMT_UNKNOWN == fDepth) { - Msg("Failed to initialize graphics hardware.\n" + Log("Failed to initialize graphics hardware.\n" "Please try to restart the game.\n" "Can not find matching format for back buffer."); FlushLog(); @@ -143,7 +143,7 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd) } } else - Log("Couldn't get window information: %s", SDL_GetError()); + Log("! Couldn't get window information: ", SDL_GetError()); P.Windowed = bWindowed; diff --git a/src/Layers/xrRenderDX10/dx10HW.cpp b/src/Layers/xrRenderDX10/dx10HW.cpp index 097941cb333..17de8b5b09e 100644 --- a/src/Layers/xrRenderDX10/dx10HW.cpp +++ b/src/Layers/xrRenderDX10/dx10HW.cpp @@ -126,6 +126,7 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd) } else Log("Couldn't get window information: ", SDL_GetError()); + sd.Windowed = bWindowed; // Depth/stencil (DX10 don't need this?) @@ -138,7 +139,7 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd) UINT createDeviceFlags = 0; #ifdef DEBUG -// createDeviceFlags |= D3Dxx_CREATE_DEVICE_DEBUG; + // createDeviceFlags |= D3Dxx_CREATE_DEVICE_DEBUG; #endif HRESULT R; #ifdef USE_DX11 diff --git a/src/xrEngine/device.cpp b/src/xrEngine/device.cpp index 9f2c016883a..c44a2fa9899 100644 --- a/src/xrEngine/device.cpp +++ b/src/xrEngine/device.cpp @@ -230,9 +230,9 @@ void CRenderDevice::on_idle() } if (psDeviceFlags.test(rsStatistic)) - g_bEnableStatGather = TRUE; // XXX: why not use either rsStatistic or g_bEnableStatGather? + g_bEnableStatGather = true; // XXX: why not use either rsStatistic or g_bEnableStatGather? else - g_bEnableStatGather = FALSE; + g_bEnableStatGather = false; if (g_loading_events.size()) { @@ -505,17 +505,19 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason) if (bOn) { if (!Paused()) - bShowPauseString = editor() ? FALSE : + { + bShowPauseString = editor() ? FALSE : TRUE; #ifdef DEBUG - !xr_strcmp(reason, "li_pause_key_no_clip") ? FALSE : -#endif // DEBUG - TRUE; + if (xr_strcmp(reason, "li_pause_key_no_clip") == 0) + bShowPauseString = FALSE; +#endif + } if (bTimer && (!g_pGamePersistent || g_pGamePersistent->CanBePaused())) { - g_pauseMngr().Pause(TRUE); + g_pauseMngr().Pause(true); #ifdef DEBUG - if (!xr_strcmp(reason, "li_pause_key_no_clip")) - TimerGlobal.Pause(FALSE); + if (xr_strcmp(reason, "li_pause_key_no_clip") == 0) + TimerGlobal.Pause(false); #endif } if (bSound && GEnv.Sound) @@ -526,7 +528,7 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason) if (bTimer && g_pauseMngr().Paused()) { fTimeDelta = EPS_S + EPS_S; - g_pauseMngr().Pause(FALSE); + g_pauseMngr().Pause(false); } if (bSound) { @@ -545,7 +547,10 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason) BOOL CRenderDevice::Paused() { return g_pauseMngr().Paused(); } void CRenderDevice::OnWM_Activate(WPARAM wParam, LPARAM /*lParam*/) { - const BOOL isWndActive = (1 == wParam) ? TRUE : FALSE; + u16 fActive = LOWORD(wParam); + const BOOL fMinimized = (BOOL)HIWORD(wParam); + + const BOOL isWndActive = (fActive != WA_INACTIVE && !fMinimized) ? TRUE : FALSE; if (!editor() && !GEnv.isDedicatedServer && isWndActive) pInput->ClipCursor(true); @@ -589,10 +594,16 @@ CRenderDevice* get_device() { return &Device; } u32 script_time_global() { return Device.dwTimeGlobal; } u32 script_time_global_async() { return Device.TimerAsync_MMT(); } -SCRIPT_EXPORT(Device, (), { +SCRIPT_EXPORT(Device, (), +{ using namespace luabind; - module(luaState)[def("time_global", &script_time_global), def("time_global_async", &script_time_global_async), - def("device", &get_device), def("is_enough_address_space_available", &is_enough_address_space_available)]; + module(luaState) + [ + def("time_global", &script_time_global), + def("time_global_async", &script_time_global_async), + def("device", &get_device), + def("is_enough_address_space_available", &is_enough_address_space_available) + ]; }); CLoadScreenRenderer::CLoadScreenRenderer() : b_registered(false), b_need_user_input(false) {} diff --git a/src/xrEngine/line_edit_control.cpp b/src/xrEngine/line_edit_control.cpp index 65f1913e98d..7f0f4748986 100644 --- a/src/xrEngine/line_edit_control.cpp +++ b/src/xrEngine/line_edit_control.cpp @@ -125,13 +125,13 @@ void line_edit_control::update_key_states() { m_key_state.zero(); - 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()); + 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, SDL_GetModState() & KMOD_CAPS); } void line_edit_control::clear_states() @@ -489,7 +489,7 @@ void line_edit_control::on_frame() { update_key_states(); - u32 fr_time = Device.dwTimeContinual; + const auto fr_time = Device.dwTimeContinual; float dt = (fr_time - m_last_frame_time) * 0.001f; if (dt > 0.06666f) { @@ -774,7 +774,6 @@ void remove_spaces(pstr str) --i; if (i < str_size) - strncpy_s(str, str_size, new_str, i); } diff --git a/src/xrEngine/line_editor.cpp b/src/xrEngine/line_editor.cpp index 8dafa9aa6f8..6d2a4540892 100644 --- a/src/xrEngine/line_editor.cpp +++ b/src/xrEngine/line_editor.cpp @@ -13,7 +13,7 @@ namespace text_editor line_editor::line_editor(u32 str_buffer_size) : m_control(str_buffer_size) {} line_editor::~line_editor() {} void line_editor::on_frame() { m_control.on_frame(); } -void line_editor::IR_OnKeyboardPress(int dik) {m_control.on_key_press(dik); } -void line_editor::IR_OnKeyboardHold(int dik) {m_control.on_key_hold(dik); } -void line_editor::IR_OnKeyboardRelease(int dik) {m_control.on_key_release(dik); } +void line_editor::IR_OnKeyboardPress(int dik) { m_control.on_key_press(dik); } +void line_editor::IR_OnKeyboardHold(int dik) { m_control.on_key_hold(dik); } +void line_editor::IR_OnKeyboardRelease(int dik) { m_control.on_key_release(dik); } } // namespace text_editor diff --git a/src/xrEngine/main.cpp b/src/xrEngine/main.cpp index 6d964e92f27..3d5c03059ac 100644 --- a/src/xrEngine/main.cpp +++ b/src/xrEngine/main.cpp @@ -22,6 +22,7 @@ #include "Text_Console.h" #elif defined(LINUX) #define CTextConsole CConsole +#pragma todo("Implement text console or it's alternative") #endif #include "xrSASH.h" #include "xr_ioc_cmd.h" diff --git a/src/xrGame/ActorInput.cpp b/src/xrGame/ActorInput.cpp index aa519f8a0cd..dd133a62e09 100644 --- a/src/xrGame/ActorInput.cpp +++ b/src/xrGame/ActorInput.cpp @@ -534,7 +534,7 @@ void CActor::OnNextWeaponSlot() IR_OnKeyboardPress(kARTEFACT); } else - IR_OnKeyboardPress((EGameActions) (kWPN_1 + i)); + IR_OnKeyboardPress(kWPN_1 + i); return; } } @@ -570,7 +570,7 @@ void CActor::OnPrevWeaponSlot() IR_OnKeyboardPress(kARTEFACT); } else - IR_OnKeyboardPress((EGameActions) (kWPN_1 + i)); + IR_OnKeyboardPress(kWPN_1 + i); return; } } @@ -661,7 +661,7 @@ void CActor::NoClipFly(int cmd) float scale = 1.0f; if (pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT)) scale = 0.25f; - else if (pInput->iGetAsyncKeyState(SDL_SCANCODE_LGUI)) + else if (pInput->iGetAsyncKeyState(SDL_SCANCODE_LALT)) scale = 4.0f; switch (cmd) diff --git a/src/xrGame/MainMenu.cpp b/src/xrGame/MainMenu.cpp index 1c18a5bf48f..36daf51452a 100644 --- a/src/xrGame/MainMenu.cpp +++ b/src/xrGame/MainMenu.cpp @@ -346,8 +346,8 @@ void CMainMenu::IR_OnKeyboardPress(int dik) return; } - if (pInput->iGetAsyncKeyState(SDL_SCANCODE_LALT) || pInput->iGetAsyncKeyState(SDL_SCANCODE_RALT) - && pInput->iGetAsyncKeyState(SDL_SCANCODE_LGUI) || pInput->iGetAsyncKeyState(SDL_SCANCODE_RGUI)) + if ((pInput->iGetAsyncKeyState(SDL_SCANCODE_LALT) || pInput->iGetAsyncKeyState(SDL_SCANCODE_RALT)) + && (pInput->iGetAsyncKeyState(SDL_SCANCODE_LGUI) || pInput->iGetAsyncKeyState(SDL_SCANCODE_RGUI))) { IWantMyMouseBackScreamed = true; pInput->ClipCursor(false); diff --git a/src/xrGame/attachable_item.cpp b/src/xrGame/attachable_item.cpp index f40150e1f81..edff3556c76 100644 --- a/src/xrGame/attachable_item.cpp +++ b/src/xrGame/attachable_item.cpp @@ -137,7 +137,7 @@ void attach_adjust_mode_keyb(int dik) return; bool b_move = !!(pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT)); - bool b_rot = !!(pInput->iGetAsyncKeyState(SDL_SCANCODE_LGUI)); + bool b_rot = !!(pInput->iGetAsyncKeyState(SDL_SCANCODE_LALT)); int axis = -1; if (pInput->iGetAsyncKeyState(SDL_SCANCODE_Z)) diff --git a/src/xrGame/ui/UIXmlInit.cpp b/src/xrGame/ui/UIXmlInit.cpp index bffbe7f0f84..8e96d53ced0 100644 --- a/src/xrGame/ui/UIXmlInit.cpp +++ b/src/xrGame/ui/UIXmlInit.cpp @@ -345,7 +345,6 @@ bool CUIXmlInit::InitText(CUIXml& xml_doc, LPCSTR path, int index, CUILines* pLi return true; } //////////////////////////////////////////////////////////////////////////////////////////// -extern int keyname_to_dik(LPCSTR); bool CUIXmlInit::Init3tButton(CUIXml& xml_doc, LPCSTR path, int index, CUI3tButton* pWnd) { @@ -397,13 +396,13 @@ bool CUIXmlInit::Init3tButton(CUIXml& xml_doc, LPCSTR path, int index, CUI3tButt LPCSTR accel = xml_doc.ReadAttrib(path, index, "accel", NULL); if (accel) { - int acc = (int) keyname_to_dik(accel); + int acc = keyname_to_dik(accel); pWnd->SetAccelerator(acc, 0); } accel = xml_doc.ReadAttrib(path, index, "accel_ext", NULL); if (accel) { - int acc = (int) keyname_to_dik(accel); + int acc = keyname_to_dik(accel); pWnd->SetAccelerator(acc, 1); }