From ad6094ca1d9b54b32ae8153c771e8e6f9308103a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Fri, 24 Jul 2020 20:43:51 +0300 Subject: [PATCH] 90% fixes, 10% skel refactoring --- src/control/Garages.cpp | 3 +++ src/core/Frontend.cpp | 7 ------- src/core/Pad.cpp | 19 ++++++++++++++++--- src/modelinfo/VehicleModelInfo.cpp | 4 ++++ src/peds/PedAttractor.cpp | 10 +++++----- src/render/Font.cpp | 12 ++++++++++++ src/skel/crossplatform.h | 30 +++++++++++++++++++++++------- src/skel/glfw/glfw.cpp | 21 ++++++++++++++++++++- src/skel/platform.h | 5 +++++ src/skel/win/win.cpp | 7 ++++++- src/skel/win/win.h | 26 ++------------------------ src/vehicles/CarGen.cpp | 10 ++++++++-- 12 files changed, 104 insertions(+), 50 deletions(-) diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index 6b4ceb80..e7b5ebe6 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -137,6 +137,9 @@ void CGarages::Init(void) MessageStartTime = 0; PlayerInGarage = false; BombsAreFree = false; +#ifdef FIX_BUGS + RespraysAreFree = false; +#endif CarsCollected = 0; BankVansCollected = 0; PoliceCarsCollected = 0; diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index e5776459..06744ac2 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -5155,13 +5155,10 @@ CMenuManager::SwitchMenuOnAndOff() m_bMenuActive = !m_bMenuActive; if (m_bMenuActive) { -#if defined RW_D3D9 || defined RWLIBS if (_InputMouseNeedsExclusive()) { _InputShutdownMouse(); _InputInitialiseMouse(false); } -#endif - Initialise(); LoadAllTextures(); } else { @@ -5173,12 +5170,10 @@ CMenuManager::SwitchMenuOnAndOff() DoRWStuffEndOfFrame(); DoRWStuffStartOfFrame(0, 0, 0, 0, 0, 0, 255); DoRWStuffEndOfFrame(); -#if defined RW_D3D9 || defined RWLIBS if (_InputMouseNeedsExclusive()) { _InputShutdownMouse(); _InputInitialiseMouse(true); } -#endif #ifdef PS2_LIKE_MENU bottomBarActive = false; @@ -5223,12 +5218,10 @@ CMenuManager::SwitchMenuOnAndOff() m_bMenuActive = true; m_OnlySaveMenu = true; -#if defined RW_D3D9 || defined RWLIBS if (_InputMouseNeedsExclusive()) { _InputShutdownMouse(); _InputInitialiseMouse(false); } -#endif Initialise(); LoadAllTextures(); diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index 685256e3..8043bb6c 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -722,9 +722,9 @@ CMouseControllerState CMousePointerStateHelper::GetMouseSetUp() void CPad::UpdateMouse() { +#if defined RW_D3D9 || defined RWLIBS if ( IsForegroundApp() ) { -#if defined RW_D3D9 || defined RWLIBS if ( PSGLOBAL(mouse) == nil ) _InputInitialiseMouse(!FrontEndMenuManager.m_bMenuActive && _InputMouseNeedsExclusive()); @@ -761,7 +761,10 @@ void CPad::UpdateMouse() OldMouseControllerState = NewMouseControllerState; NewMouseControllerState = PCTempMouseControllerState; } + } #else + if ( IsForegroundApp() && PSGLOBAL(cursorIsInWindow) ) + { double xpos = 1.0f, ypos; glfwGetCursorPos(PSGLOBAL(window), &xpos, &ypos); if (xpos == 0.f) @@ -799,8 +802,8 @@ void CPad::UpdateMouse() OldMouseControllerState = NewMouseControllerState; NewMouseControllerState = PCTempMouseControllerState; -#endif } +#endif } CControllerState CPad::ReconcileTwoControllersInput(CControllerState const &State1, CControllerState const &State2) @@ -1451,6 +1454,13 @@ void CPad::UpdatePads(void) #else CapturePad(0); #endif + + // Improve keyboard input latency part 1 +#ifdef FIX_BUGS + OldKeyState = NewKeyState; + NewKeyState = TempKeyState; +#endif + #ifdef DETECT_PAD_INPUT_SWITCH if (GetPad(0)->PCTempJoyState.CheckForInput()) IsAffectedByController = true; @@ -1472,7 +1482,7 @@ void CPad::UpdatePads(void) if ( bUpdate ) { GetPad(0)->Update(0); - GetPad(1)->Update(0); + // GetPad(1)->Update(0); // not in VC } #if defined(MASTER) && !defined(XINPUT) @@ -1480,8 +1490,11 @@ void CPad::UpdatePads(void) GetPad(1)->OldState.Clear(); #endif + // Improve keyboard input latency part 2 +#ifndef FIX_BUGS OldKeyState = NewKeyState; NewKeyState = TempKeyState; +#endif } void CPad::ProcessPCSpecificStuff(void) diff --git a/src/modelinfo/VehicleModelInfo.cpp b/src/modelinfo/VehicleModelInfo.cpp index d5396d12..11f78495 100644 --- a/src/modelinfo/VehicleModelInfo.cpp +++ b/src/modelinfo/VehicleModelInfo.cpp @@ -689,7 +689,11 @@ ChooseComponent(int32 rule, int32 comps) return COMPRULE_COMPN(comps, n-1); return -1; case 4: +#ifdef FIX_BUGS + return CGeneral::GetRandomNumberInRange(0, 6); +#else return CGeneral::GetRandomNumberInRange(0, 5); +#endif } return -1; } diff --git a/src/peds/PedAttractor.cpp b/src/peds/PedAttractor.cpp index d69f2684..9f77f2a4 100644 --- a/src/peds/PedAttractor.cpp +++ b/src/peds/PedAttractor.cpp @@ -137,8 +137,8 @@ void CPedAttractorManager::RemoveIceCreamVanEffects(C2dEffect* pEffect) for (std::vector::const_iterator assoc = vVehicleToEffect.cbegin(); assoc != vVehicleToEffect.cend();) { if (assoc->GetVehicle() != pVehicle) return; - int total = 0; - for (int j = 0; j < NUM_ATTRACTORS_FOR_ICECREAM_VAN; j++) { + uint32 total = 0; + for (uint32 j = 0; j < NUM_ATTRACTORS_FOR_ICECREAM_VAN; j++) { if (FindAssociatedAttractor(assoc->GetEffect(j), vIceCreamAttractors)) total++; } @@ -355,13 +355,13 @@ bool CPedAttractor::BroadcastArrival(CPed* pPed) bool CPedAttractor::BroadcastDeparture(CPed* pPed) { int qid = -1; - for (int i = 0; i < vWaitingQueue.size(); i++){ + for (uint32 i = 0; i < vWaitingQueue.size(); i++){ if (vWaitingQueue[i] == pPed) qid = i; } if (qid < 0) return false; - for (int i = qid + 1; i < vWaitingQueue.size(); i++) { + for (uint32 i = qid + 1; i < vWaitingQueue.size(); i++) { CVector pos; float heading; float time; @@ -401,7 +401,7 @@ bool CPedAttractor::BroadcastDeparture(CPed* pPed) bool CPedShelterAttractor::BroadcastDeparture(CPed* pPed) { int qid = -1; - for (int i = 0; i < vWaitingQueue.size(); i++) { + for (uint32 i = 0; i < vWaitingQueue.size(); i++) { if (vWaitingQueue[i] == pPed) qid = i; } diff --git a/src/render/Font.cpp b/src/render/Font.cpp index a3ead932..1e60083b 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -1133,7 +1133,11 @@ CFont::ParseToken(wchar *s) case 'r': SetColor(CRGBA(255, 150, 225, 255)); Details.anonymous_23 = true; break; case 't': SetColor(CRGBA(86, 212, 146, 255)); Details.anonymous_23 = true; break; case 'w': SetColor(CRGBA(175, 175, 175, 255)); Details.anonymous_23 = true; break; +#ifdef FIX_BUGS + case 'x': SetColor(CRGBA(0, 255, 255, 255)); Details.anonymous_23 = true; break; +#else case 'x': SetColor(CRGBA(132, 146, 197, 255)); Details.anonymous_23 = true; break; +#endif case 'y': SetColor(CRGBA(255, 227, 79, 255)); Details.anonymous_23 = true; break; } while(*s != '~') s++; @@ -1208,11 +1212,19 @@ CFont::ParseToken(wchar* str, CRGBA &color, bool &flash, bool &bold) color.g = 175; color.b = 175; break; +#ifdef FIX_BUGS + case 'x': + color.r = 0; + color.g = 255; + color.b = 255; + break; +#else case 'x': color.r = 132; color.g = 146; color.b = 197; break; +#endif case 'y': color.r = 255; color.g = 227; diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h index 678d3ec4..066570be 100644 --- a/src/skel/crossplatform.h +++ b/src/skel/crossplatform.h @@ -3,19 +3,34 @@ // This is the common include for platform/renderer specific skeletons(glfw.cpp, win.cpp etc.) and using cross platform things (like Windows directories wrapper, platform specific global arrays etc.) // Functions that's different on glfw and win but have same signature, should be located on platform.h. +enum eWinVersion +{ + OS_WIN95 = 0, + OS_WIN98, + OS_WINNT, + OS_WIN2000, + OS_WINXP, +}; + #ifdef _WIN32 -// This only has as Windows header, which is lighter (as long as WITHWINDOWS isn't defined / isn't included). + +// As long as WITHWINDOWS isn't defined / isn't included, include , which is lighter. +#ifndef _INC_WINDOWS + #ifdef _WIN64 + #define _ARM64_ + #else + #define _X86_ + #endif + #include +#endif +#if defined RW_D3D9 || defined RWLIBS #include "win.h" +#endif extern DWORD _dwOperatingSystemVersion; + #else char *strupr(char *str); char *strlwr(char *str); -enum { - OS_WIN98, - OS_WIN2000, - OS_WINNT, - OS_WINXP, -}; enum { LANG_OTHER, @@ -42,6 +57,7 @@ typedef struct RwBool fullScreen; RwV2d lastMousePos; double mouseWheel; // glfw doesn't cache it + bool cursorIsInWindow; RwInt8 joy1id; RwInt8 joy2id; } diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index a0a5a171..9a4f2188 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -282,6 +282,7 @@ psInitialize(void) RsGlobal.ps = &PsGlobal; PsGlobal.fullScreen = FALSE; + PsGlobal.cursorIsInWindow = TRUE; PsGlobal.joy1id = -1; PsGlobal.joy2id = -1; @@ -790,6 +791,7 @@ void keypressCB(GLFWwindow* window, int key, int scancode, int action, int mods) void resizeCB(GLFWwindow* window, int width, int height); void scrollCB(GLFWwindow* window, double xoffset, double yoffset); void cursorCB(GLFWwindow* window, double xpos, double ypos); +void cursorEnterCB(GLFWwindow* window, int entered); void joysChangeCB(int jid, int event); bool IsThisJoystickBlacklisted(int i) @@ -831,6 +833,17 @@ long _InputInitialiseMouse(bool exclusive) return 0; } +void _InputShutdownMouse() +{ + // Not needed +} + +bool _InputMouseNeedsExclusive() +{ + // That was the cause of infamous mouse bug on Win. Not supported on glfw anyway + return false; +} + void psPostRWinit(void) { RwVideoMode vm; @@ -840,6 +853,7 @@ void psPostRWinit(void) glfwSetWindowSizeCallback(PSGLOBAL(window), resizeCB); glfwSetScrollCallback(PSGLOBAL(window), scrollCB); glfwSetCursorPosCallback(PSGLOBAL(window), cursorCB); + glfwSetCursorEnterCallback(PSGLOBAL(window), cursorEnterCB); glfwSetJoystickCallback(joysChangeCB); _InputInitialiseJoys(); @@ -1345,13 +1359,18 @@ _InputTranslateShiftKeyUpDown(RsKeyCodes *rs) { RsKeyboardEventHandler(rshiftStatus ? rsKEYDOWN : rsKEYUP, &(*rs = rsRSHIFT)); } -// TODO this only works in frontend(and luckily only frontend use this), maybe because of glfw knows that mouse pos is > 32000 in game?? +// TODO this only works in frontend(and luckily only frontend use this). Fun fact: if I get pos manually in game, glfw reports that it's > 32000 void cursorCB(GLFWwindow* window, double xpos, double ypos) { FrontEndMenuManager.m_nMouseTempPosX = xpos; FrontEndMenuManager.m_nMouseTempPosY = ypos; } +void +cursorEnterCB(GLFWwindow* window, int entered) { + PSGLOBAL(cursorIsInWindow) = !!entered; +} + /* ***************************************************************************** */ diff --git a/src/skel/platform.h b/src/skel/platform.h index 7f36d8b7..806c0a73 100644 --- a/src/skel/platform.h +++ b/src/skel/platform.h @@ -1,6 +1,8 @@ #ifndef PLATFORM_H #define PLATFORM_H +// Functions that's different on glfw/win etc. but have same signature (but if a function only used in win.cpp you can keep in win.h) + #include "rwcore.h" #include "skeleton.h" @@ -36,6 +38,9 @@ extern RwBool psNativeTextureSupport(void); extern void _InputTranslateShiftKeyUpDown(RsKeyCodes* rs); extern long _InputInitialiseMouse(bool exclusive); // returns HRESULT on Windows actually +extern void _InputShutdownMouse(); +extern bool _InputMouseNeedsExclusive(); +extern void _InputInitialiseJoys(); extern void HandleExit(); diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index f8e5c38e..a2673ccb 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -2883,8 +2883,13 @@ void _InputShutdownMouse() SAFE_RELEASE(PSGLOBAL(mouse)); } -BOOL _InputMouseNeedsExclusive(void) +bool _InputMouseNeedsExclusive(void) { + // FIX: I don't know why R* needed that, but it causes infamous mouse bug on modern systems. + // Probably DirectInput bug, since Acquire() and GetDeviceState() reports everything A-OK. +#ifdef FIX_BUGS + return false; +#endif RwVideoMode vm; RwEngineGetVideoModeInfo(&vm, GcurSelVM); diff --git a/src/skel/win/win.h b/src/skel/win/win.h index 9427822d..4b2001f8 100644 --- a/src/skel/win/win.h +++ b/src/skel/win/win.h @@ -1,5 +1,5 @@ -// DON'T include directly. crossplatform.h includes this if you're on Windows. +// DON'T include directly. crossplatform.h includes this if you're using D3D9 backend(win.cpp). #if (!defined(_PLATFORM_WIN_H)) #define _PLATFORM_WIN_H @@ -8,25 +8,6 @@ #define RSREGSETBREAKALLOC(_name) /* No op */ #endif /* (!defined(RSREGSETBREAKALLOC)) */ -#ifndef _INC_WINDOWS - #ifdef _WIN64 - #define _AMD64_ - #else - #define _X86_ - #endif - #include -#endif - -enum eWinVersion -{ - OS_WIN95 = 0, - OS_WIN98, - OS_WINNT, - OS_WIN2000, - OS_WINXP, -}; - - #ifdef __DINPUT_INCLUDED__ /* platform specfic global data */ typedef struct @@ -87,19 +68,16 @@ extern "C" { #endif /* __cplusplus */ -#ifdef __DINPUT_INCLUDED__ extern LRESULT CALLBACK MainWndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam); +#ifdef __DINPUT_INCLUDED__ HRESULT _InputInitialise(); HRESULT CapturePad(RwInt32 padID); -void _InputInitialiseJoys(); void _InputAddJoyStick(LPDIRECTINPUTDEVICE8 lpDevice, INT num); HRESULT _InputAddJoys(); HRESULT _InputGetMouseState(DIMOUSESTATE2 *state); void _InputShutdown(); -void _InputShutdownMouse(); -BOOL _InputMouseNeedsExclusive(); BOOL CALLBACK _InputEnumDevicesCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext ); BOOL _InputTranslateKey(RsKeyCodes *rs, UINT flag, UINT key); BOOL _InputTranslateShiftKey(RsKeyCodes *rs, UINT key, BOOLEAN bDown); diff --git a/src/vehicles/CarGen.cpp b/src/vehicles/CarGen.cpp index 4b83cc81..84a19b82 100644 --- a/src/vehicles/CarGen.cpp +++ b/src/vehicles/CarGen.cpp @@ -32,7 +32,7 @@ void CCarGenerator::SwitchOff() void CCarGenerator::SwitchOn() { - m_nUsesRemaining = -1; + m_nUsesRemaining = 255; m_nTimer = CalcNextGen(); ++CTheCarGenerators::CurrentActiveCount; } @@ -141,8 +141,14 @@ void CCarGenerator::DoInternalProcessing() } CVisibilityPlugins::SetClumpAlpha(pVehicle->GetClump(), 0); m_nVehicleHandle = CPools::GetVehiclePool()->GetIndex(pVehicle); - if (m_nUsesRemaining < -1) /* I don't think this is a correct comparasion */ + /* I don't think this is a correct comparasion */ +#ifdef FIX_BUGS + if (m_nUsesRemaining != 0) --m_nUsesRemaining; +#else + if (m_nUsesRemaining < -1) + --m_nUsesRemaining; +#endif m_nTimer = CalcNextGen(); if (m_nUsesRemaining == 0) --CTheCarGenerators::CurrentActiveCount;