From da39624f1c694dbeaefc6762fd6867715cdb77bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Thu, 8 Oct 2020 00:21:44 +0300 Subject: Pad, BulletInfo, ProjectileInfo, fixes --- src/core/Camera.cpp | 2 +- src/core/EventList.cpp | 4 +- src/core/Frontend.cpp | 52 ++++---- src/core/Frontend.h | 6 +- src/core/Pad.cpp | 348 +++++++++++++++++++++++++++++++++++++++---------- src/core/Pad.h | 7 + src/core/Radar.cpp | 58 +-------- src/core/re3.cpp | 6 +- 8 files changed, 330 insertions(+), 153 deletions(-) (limited to 'src/core') diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 704e77b8..2fa81d24 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -1749,7 +1749,7 @@ CCamera::CamControl(void) if(PrevMode != Cams[ActiveCam].Mode || switchedFromObbe || Cams[ActiveCam].Mode == CCam::MODE_FOLLOWPED || Cams[ActiveCam].Mode == CCam::MODE_CAM_ON_A_STRING) - if(CPad::GetPad(0)->CycleCameraModeUpJustDown() && + if(CPad::GetPad(0)->CycleCameraModeJustDown() && !CReplay::IsPlayingBack() && (m_bLookingAtPlayer || WhoIsInControlOfTheCamera == CAMCONTROL_OBBE) && !m_WideScreenOn && diff --git a/src/core/EventList.cpp b/src/core/EventList.cpp index 7eb1e186..b22ddcb2 100644 --- a/src/core/EventList.cpp +++ b/src/core/EventList.cpp @@ -10,6 +10,8 @@ #include "main.h" #include "Accident.h" +// --MIAMI: file done + int32 CEventList::ms_nFirstFreeSlotIndex; CEvent gaEvent[NUMEVENTS]; @@ -57,6 +59,7 @@ CEventList::Update(void) } } +// ok void CEventList::RegisterEvent(eEventType type, eEventEntity entityType, CEntity *ent, CPed *criminal, int32 timeout) { @@ -195,7 +198,6 @@ CEventList::FindClosestEvent(eEventType type, CVector posn, int32 *event) return found; } -// --MIAMI: Done void CEventList::ReportCrimeForEvent(eEventType type, size_t crimeId, bool copsDontCare) { diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index eee8b4b2..59649e93 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -352,7 +352,7 @@ CMenuManager::CMenuManager() m_PrefsUseVibration = 0; m_PrefsShowHud = 1; m_PrefsRadarMode = 0; - field_10 = 0; + m_DisplayControllerOnFoot = false; m_bShutDownFrontEndRequested = false; m_bStartUpFrontEndRequested = false; pEditString = nil; @@ -950,6 +950,13 @@ CMenuManager::DrawStandardMenus(bool activeScreen) break; } break; + // This one is still in enum and ProcessOnOffMenuOptions, but removed from other places + case MENUACTION_CTRLDISPLAY: + if (m_DisplayControllerOnFoot) + rightText = TheText.Get("FEC_ONF"); + else + rightText = TheText.Get("FEC_INC"); + break; #endif case MENUACTION_FRAMESYNC: rightText = TheText.Get(m_PrefsVsyncDisp ? "FEM_ON" : "FEM_OFF"); @@ -4206,6 +4213,7 @@ CMenuManager::ProcessUserInput(uint8 goDown, uint8 goUp, uint8 optionSelected, u } } +// --MIAMI: Done void CMenuManager::ProcessOnOffMenuOptions() { @@ -4213,78 +4221,78 @@ CMenuManager::ProcessOnOffMenuOptions() #ifdef LEGACY_MENU_OPTIONS case MENUACTION_CTRLVIBRATION: m_PrefsUseVibration = !m_PrefsUseVibration; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); break; case MENUACTION_CTRLCONFIG: CPad::GetPad(0)->Mode++; if (CPad::GetPad(0)->Mode > 3) CPad::GetPad(0)->Mode = 0; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); break; #endif + case MENUACTION_INVERTPADY: + CPad::bInvertLook4Pad = !CPad::bInvertLook4Pad; + SaveSettings(); // FIX: Why don't SaveSettings? Because of it's an hidden option? :( + break; + case MENUACTION_CTRLDISPLAY: + m_DisplayControllerOnFoot = !m_DisplayControllerOnFoot; + break; case MENUACTION_FRAMESYNC: m_PrefsVsyncDisp = !m_PrefsVsyncDisp; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); - SaveSettings(); + SaveSettings(); // FIX: Again... This makes me very unhappy break; case MENUACTION_FRAMELIMIT: m_PrefsFrameLimiter = !m_PrefsFrameLimiter; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); SaveSettings(); break; case MENUACTION_TRAILS: CMBlur::BlurOn = !CMBlur::BlurOn; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); SaveSettings(); - if (CMBlur::BlurOn) - CMBlur::MotionBlurOpen(Scene.camera); - else - CMBlur::MotionBlurClose(); break; case MENUACTION_SUBTITLES: m_PrefsShowSubtitles = !m_PrefsShowSubtitles; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); SaveSettings(); break; #ifndef ASPECT_RATIO_SCALE case MENUACTION_WIDESCREEN: m_PrefsUseWideScreen = !m_PrefsUseWideScreen; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); SaveSettings(); break; #endif + case MENUACTION_LEGENDS: + m_PrefsShowLegends = !m_PrefsShowLegends; + break; + case MENUACTION_HUD: + m_PrefsShowHud = !m_PrefsShowHud; + SaveSettings(); + break; +#ifdef LEGACY_MENU_OPTIONS case MENUACTION_SETDBGFLAG: CTheScripts::InvertDebugFlag(); - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); break; case MENUACTION_SWITCHBIGWHITEDEBUGLIGHT: gbBigWhiteDebugLightSwitchedOn = !gbBigWhiteDebugLightSwitchedOn; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); break; case MENUACTION_COLLISIONPOLYS: gbShowCollisionPolys = !gbShowCollisionPolys; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); break; +#endif case MENUACTION_SHOWHEADBOB: TheCamera.m_bHeadBob = !TheCamera.m_bHeadBob; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); SaveSettings(); break; case MENUACTION_INVVERT: MousePointerStateHelper.bInvertVertically = !MousePointerStateHelper.bInvertVertically; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); SaveSettings(); break; case MENUACTION_DYNAMICACOUSTIC: m_PrefsDMA = !m_PrefsDMA; DMAudio.SetDynamicAcousticModelingStatus(m_PrefsDMA); - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); SaveSettings(); break; case MENUACTION_MOUSESTEER: - CVehicle::m_bDisableMouseSteering = !CVehicle::m_bDisableMouseSteering; - DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); - SaveSettings(); + if (m_ControlMethod == CONTROL_STANDARD) { + CVehicle::m_bDisableMouseSteering = !CVehicle::m_bDisableMouseSteering; + SaveSettings(); + } break; } } diff --git a/src/core/Frontend.h b/src/core/Frontend.h index 6cd58e7d..0dab83a4 100644 --- a/src/core/Frontend.h +++ b/src/core/Frontend.h @@ -207,8 +207,8 @@ enum eMenuAction MENUACTION_YES, MENUACTION_NO, MENUACTION_CHANGEMENU, - MENUACTION_UNK5, MENUACTION_INVERTPADY, + MENUACTION_CTRLDISPLAY, MENUACTION_FRAMESYNC, MENUACTION_FRAMELIMIT, MENUACTION_TRAILS, @@ -466,7 +466,7 @@ public: bool m_PrefsUseVibration; bool m_PrefsShowHud; int32 m_PrefsRadarMode; - uint8 field_10; + bool m_DisplayControllerOnFoot; bool m_bShutDownFrontEndRequested; bool m_bStartUpFrontEndRequested; int32 m_KeyPressedCode; @@ -702,4 +702,4 @@ VALIDATE_SIZE(CMenuManager, 0x688); extern CMenuManager FrontEndMenuManager; extern CMenuScreen aScreens[]; -#endif \ No newline at end of file +#endif diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index 36e14e55..785927ce 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -54,6 +54,8 @@ #include "libpad.h" #endif +// --MIAMI: file done except Mobile(see TODOs) and PS2 stuff + CPad Pads[MAX_PADS]; #ifdef GTA_PS2 u_long128 pad_dma_buf[scePadDmaBufferMax] __attribute__((aligned(64))); @@ -66,7 +68,9 @@ bool CPad::bDisplayNoControllerMessage; bool CPad::bObsoleteControllerMessage; bool CPad::bOldDisplayNoControllerMessage; bool CPad::m_bMapPadOneToPadTwo; +bool CPad::m_bDebugCamPCOn; bool CPad::bHasPlayerCheated; +bool CPad::bInvertLook4Pad; #ifdef GTA_PS2 unsigned char act_direct[6]; unsigned char act_align[6]; @@ -93,6 +97,74 @@ extern bool gbFastTime; extern bool gGravityCheat; #endif +void SpecialCarCheats() +{ + if ( !CVehicle::bCheat9 ) + { + ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_INFERNUS))->m_wheelScale *= 1.3f; + ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_CHEETAH))->m_wheelScale *= 1.3f; + ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_PHEONIX))->m_wheelScale *= 1.3f; + ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_DELUXO))->m_wheelScale *= 1.3f; + mod_HandlingManager.GetHandlingData(HANDLING_LANDSTAL)->Transmission.fEngineAcceleration *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_PATRIOT)->Transmission.fEngineAcceleration *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_BOBCAT)->Transmission.fEngineAcceleration *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_BFINJECT)->Transmission.fEngineAcceleration *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_RANCHER)->Transmission.fEngineAcceleration *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_DESPERAD)->Transmission.fEngineAcceleration *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_DELUXO)->Transmission.fEngineAcceleration *= 2.0f; + + mod_HandlingManager.GetHandlingData(HANDLING_BAGGAGE)->Transmission.fEngineAcceleration *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_BAGGAGE)->Transmission.fMaxVelocity *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_BAGGAGE)->Transmission.InitGearRatios(); + + mod_HandlingManager.GetHandlingData(HANDLING_GOLFCART)->Transmission.fEngineAcceleration *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_GOLFCART)->Transmission.fMaxVelocity *= 2.0f; + mod_HandlingManager.GetHandlingData(HANDLING_GOLFCART)->Transmission.InitGearRatios(); + + mod_HandlingManager.GetHandlingData(HANDLING_STINGER)->fCollisionDamageMultiplier *= 0.25f; + mod_HandlingManager.GetHandlingData(HANDLING_STINGER)->fMass *= 2.5f; + mod_HandlingManager.GetHandlingData(HANDLING_STINGER)->fTurnMass *= 4.0f; + + mod_HandlingManager.GetHandlingData(HANDLING_BANSHEE)->fCollisionDamageMultiplier *= 0.25f; + mod_HandlingManager.GetHandlingData(HANDLING_BANSHEE)->fMass *= 2.5f; + mod_HandlingManager.GetHandlingData(HANDLING_BANSHEE)->fTurnMass *= 4.0f; + + mod_HandlingManager.GetHandlingData(HANDLING_SABRETUR)->fCollisionDamageMultiplier *= 0.25f; + mod_HandlingManager.GetHandlingData(HANDLING_SABRETUR)->fMass *= 2.5f; + mod_HandlingManager.GetHandlingData(HANDLING_SABRETUR)->fTurnMass *= 4.0f; + + mod_HandlingManager.GetHandlingData(HANDLING_COMET)->fCollisionDamageMultiplier *= 0.25f; + mod_HandlingManager.GetHandlingData(HANDLING_COMET)->fMass *= 2.5f; + mod_HandlingManager.GetHandlingData(HANDLING_COMET)->fTurnMass *= 4.0f; + + mod_HandlingManager.GetHandlingData(HANDLING_DELUXO)->fCollisionDamageMultiplier *= 0.25f; + mod_HandlingManager.GetHandlingData(HANDLING_DELUXO)->fMass *= 2.5f; + mod_HandlingManager.GetHandlingData(HANDLING_DELUXO)->fTurnMass *= 4.0f; + CHud::SetHelpMessage(TheText.Get("CHEAT1"), true); + CVehicle::bCheat9 = true; + CPad::bHasPlayerCheated = true; + } +} + +void PickUpChicksCheat() +{ + if ( FindPlayerVehicle() && (FindPlayerVehicle()->IsCar() || FindPlayerVehicle()->IsBike()) ) + { + CVehicle *vehicle = FindPlayerVehicle(); + if ( FindPlayerVehicle()->m_vehType == 5 ) + { + if ( vehicle->pPassengers[0] ) + vehicle->pPassengers[0]->SetObjective(OBJECTIVE_LEAVE_CAR, vehicle); + } + CPed* someoneElse = (CPed*)CWorld::TestSphereAgainstWorld(vehicle->GetPosition(), 6.0f, FindPlayerPed(), false, false, true, false, false, false); + if ( someoneElse && someoneElse->m_nPedState != PED_DRIVING ) + { + CHud::SetHelpMessage(TheText.Get("CHEAT1"), true); + someoneElse->SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, vehicle); + } + } +} + void WeaponCheat1() { CHud::SetHelpMessage(TheText.Get("CHEAT2"), true); @@ -127,6 +199,11 @@ void WeaponCheat1() CStreaming::SetModelIsDeletable(MI_RUGER); CStreaming::SetModelIsDeletable(MI_SNIPERRIFLE); CStreaming::SetModelIsDeletable(MI_FLAMETHROWER); +#ifdef MOBILE_IMPROVEMENTS + if (FindPlayerVehicle()) { + FindPlayerPed()->RemoveWeaponWhenEnteringVehicle(); + } +#endif } void WeaponCheat2() @@ -162,6 +239,11 @@ void WeaponCheat2() CStreaming::SetModelIsDeletable(MI_M4); CStreaming::SetModelIsDeletable(MI_LASERSCOPE); CStreaming::SetModelIsDeletable(MI_ROCKETLAUNCHER); +#ifdef MOBILE_IMPROVEMENTS + if (FindPlayerVehicle()) { + FindPlayerPed()->RemoveWeaponWhenEnteringVehicle(); + } +#endif } void WeaponCheat3() @@ -197,6 +279,12 @@ void WeaponCheat3() CStreaming::SetModelIsDeletable(MI_LASERSCOPE); CStreaming::SetModelIsDeletable(MI_MINIGUN); CStreaming::SetModelIsDeletable(MI_MINIGUN2); + +#ifdef MOBILE_IMPROVEMENTS + if (FindPlayerVehicle()) { + FindPlayerPed()->RemoveWeaponWhenEnteringVehicle(); + } +#endif } void HealthCheat() @@ -213,6 +301,7 @@ void HealthCheat() } } +// TODO(Miami): this is HELLA different on mobile, although it mostly has debug oriented things like player exiting it's current car and enters spawned one etc. void VehicleCheat(int model) { CHud::SetHelpMessage(TheText.Get("CHEAT1"), true); @@ -232,7 +321,7 @@ void VehicleCheat(int model) #ifdef FIX_BUGS CAutomobile* vehicle = new CAutomobile(model, RANDOM_VEHICLE); #else - CAutomobile* vehicle = new CAutomobile(MI_RHINO, MISSION_VEHICLE); + CAutomobile* vehicle = new CAutomobile(model, MISSION_VEHICLE); #endif if (vehicle != nil) { CVector pos = ThePaths.m_pathNodes[node].GetPosition(); @@ -249,6 +338,7 @@ void VehicleCheat(int model) CPad::bHasPlayerCheated = true; } + void BlowUpCarsCheat() { CHud::SetHelpMessage(TheText.Get("CHEAT1"), true); @@ -262,7 +352,8 @@ void BlowUpCarsCheat() void ChangePlayerCheat() { - int modelId; + // I don't know wtf is going on in here... + int modelId, anotherModelId; if (FindPlayerPed()->IsPedInControl() && CModelInfo::GetModelInfo("player", nil)) { CHud::SetHelpMessage(TheText.Get("CHEAT1"), true); @@ -270,21 +361,22 @@ void ChangePlayerCheat() AssocGroupId AnimGrp = ped->m_animGroup; do { - do - modelId = CGeneral::GetRandomNumberInRange(0, MI_WFYG2+1); - while (!CModelInfo::GetModelInfo(modelId)); - } while (modelId == MI_TAXI_D); + do { + modelId = CGeneral::GetRandomNumberInRange(0, MI_PGA); + anotherModelId = modelId+1; + } while (!CModelInfo::GetModelInfo(anotherModelId)); + } while (anotherModelId >= MI_SPECIAL01 && anotherModelId <= MI_SPECIAL04 || modelId == MI_TAXI_D); - uint8 flags = CStreaming::ms_aInfoForModel[modelId].m_flags; + uint8 flags = CStreaming::ms_aInfoForModel[anotherModelId].m_flags; ped->DeleteRwObject(); - CStreaming::RequestModel(modelId, STREAMFLAGS_DEPENDENCY| STREAMFLAGS_DONT_REMOVE); + CStreaming::RequestModel(anotherModelId, STREAMFLAGS_DEPENDENCY| STREAMFLAGS_DONT_REMOVE); CStreaming::LoadAllRequestedModels(false); ped->m_modelIndex = -1; - ped->SetModelIndex(modelId); + ped->SetModelIndex(anotherModelId); ped->m_animGroup = AnimGrp; - if (modelId != MI_PLAYER) { + if (modelId != -1) { if (!(flags & STREAMFLAGS_DONT_REMOVE)) - CStreaming::SetModelIsDeletable(modelId); + CStreaming::SetModelIsDeletable(anotherModelId); } } } @@ -426,11 +518,6 @@ void StrongGripCheat() CPad::bHasPlayerCheated = true; } -void NastyLimbsCheat() -{ - CPed::bNastyLimbsCheat = !CPed::bNastyLimbsCheat; -} - void FannyMagnetCheat() { CHud::SetHelpMessage(TheText.Get("CHEAT1"), true); @@ -578,6 +665,7 @@ void FlyingFishCheat(void) { CHud::SetHelpMessage(TheText.Get("CHEAT1"), true); CVehicle::bCheat8 = !CVehicle::bCheat8; + CPad::bHasPlayerCheated = true; } void DoShowChaseStatCheat(void) { @@ -655,6 +743,8 @@ void CPad::Initialise(void) bObsoleteControllerMessage = false; bOldDisplayNoControllerMessage = false; bDisplayNoControllerMessage = false; + m_bMapPadOneToPadTwo = false; + m_bDebugCamPCOn = false; } #endif @@ -687,9 +777,9 @@ void CPad::Clear(bool bResetPlayerControls) if ( bResetPlayerControls ) DisablePlayerControls = PLAYERCONTROL_ENABLED; + JustOutOfFrontend = 0; bApplyBrakes = false; - for ( int32 i = 0; i < HORNHISTORY_SIZE; i++ ) bHornHistory[i] = false; @@ -715,6 +805,14 @@ void CPad::ClearMouseHistory() OldMouseControllerState.Clear(); } +// unused +void CPad::ClearKeyBoardHistory() +{ + NewKeyState.Clear(); + OldKeyState.Clear(); + TempKeyState.Clear(); +} + CMouseControllerState::CMouseControllerState() { LMB = 0; @@ -1113,9 +1211,6 @@ void CPad::AddToCheatString(char c) else if ( !_CHEATCMP("T33L1413") ) StrongGripCheat(); - // "S1CD13TR1X" - SQUARE L1 CIRCLE DOWN L1 R1 TRIANGLE RIGHT L1 CROSS - else if ( !_CHEATCMP("X1RT31DC1S") ) - NastyLimbsCheat(); #undef _CHEATCMP } #endif @@ -1132,6 +1227,7 @@ int Cheat_strncmp(char* sourceStr, char* origCheatStr) return 0; } +// TODO(Miami): Mobile has changed some of the cheats to include debugging things void CPad::AddToPCCheatString(char c) { for (int32 i = ARRAY_SIZE(KeyBoardCheatString) - 2; i >= 0; i--) @@ -1406,6 +1502,16 @@ void CPad::AddToPCCheatString(char c) KeyBoardCheatString[0] = ' '; BackToTheFuture(); } + // LOADSOFLITTLETHINGS + else if (!Cheat_strncmp(KeyBoardCheatString, "VLUJUoHSU_VTMo`J]bV")) { + KeyBoardCheatString[0] = ' '; + SpecialCarCheats(); + } + // HOPINGIRL + else if (!Cheat_strncmp(KeyBoardCheatString, "OWPH[dSVI")) { + KeyBoardCheatString[0] = ' '; + PickUpChicksCheat(); + } //CERTAINDEATH else if (!Cheat_strncmp(KeyBoardCheatString, "KYHFQiLHU]RK")) { KeyBoardCheatString[0] = ' '; @@ -1422,10 +1528,6 @@ void CPad::AddToPCCheatString(char c) FannyMagnetCheat(); } - // "NASTYLIMBSCHEAT" - if (!_CHEATCMP("TAEHCSBMILYTSAN")) - NastyLimbsCheat(); - #ifdef KANGAROO_CHEAT // "KANGAROO" if (!_CHEATCMP("OORAGNAK")) @@ -1879,6 +1981,9 @@ void CPad::Update(int16 pad) if ( !bDisplayNoControllerMessage ) CGame::bDemoMode = false; + + if ( JustOutOfFrontend != 0 ) + --JustOutOfFrontend; } void CPad::DoCheats(void) @@ -1963,7 +2068,6 @@ CPad *CPad::GetPad(int32 pad) #define CURMODE (Mode) #endif - int16 CPad::GetSteeringLeftRight(void) { if ( ArePlayerControlsDisabled() ) @@ -2126,7 +2230,6 @@ int16 CPad::GetPedWalkLeftRight(void) return 0; } - int16 CPad::GetPedWalkUpDown(void) { if ( ArePlayerControlsDisabled() ) @@ -2190,6 +2293,36 @@ int16 CPad::GetAnalogueUpDown(void) return 0; } +int16 CPad::GetAnalogueLeftRight(void) +{ + switch (CURMODE) + { + case 0: + case 2: + { + int16 axis = NewState.LeftStickX; + int16 dpad = (NewState.DPadRight - NewState.DPadLeft) / 2; + + if ( Abs(axis) > Abs(dpad) ) + return axis; + else + return dpad; + + break; + } + + case 1: + case 3: + { + return NewState.LeftStickX; + + break; + } + } + + return 0; +} + bool CPad::GetLookLeft(void) { if ( ArePlayerControlsDisabled() ) @@ -2301,7 +2434,6 @@ bool CPad::HornJustDown(void) return false; } - bool CPad::GetCarGunFired(void) { if ( ArePlayerControlsDisabled() ) @@ -2432,6 +2564,10 @@ bool CPad::GetExitVehicle(void) if ( ArePlayerControlsDisabled() ) return false; + + if ( JustOutOfFrontend != 0 ) + return false; + switch (CURMODE) { case 0: @@ -2459,6 +2595,9 @@ bool CPad::ExitVehicleJustDown(void) if ( ArePlayerControlsDisabled() ) return false; + if ( JustOutOfFrontend != 0 ) + return false; + switch (CURMODE) { case 0: @@ -2585,6 +2724,53 @@ int16 CPad::GetAccelerate(void) return 0; } +bool CPad::CycleCameraModeJustDown(void) +{ + bool result; + switch (CURMODE) + { + case 0: + case 2: + case 3: + { + result = !!(NewState.Select && !OldState.Select); + + break; + } + + case 1: + { + result = !!(NewState.DPadUp && !OldState.DPadUp); + + break; + } + default: + { + result = false; + break; + } + } + + if (!result) + { + switch (CURMODE) + { + case 1: + { + result = !!(NewState.DPadDown && !OldState.DPadDown); + break; + } + default: + { + result = false; + break; + } + } + } + + return result; +} + bool CPad::CycleCameraModeUpJustDown(void) { switch (CURMODE) @@ -2672,7 +2858,6 @@ bool CPad::ChangeStationJustDown(void) return false; } - bool CPad::CycleWeaponLeftJustDown(void) { if ( ArePlayerControlsDisabled() ) @@ -2831,23 +3016,23 @@ bool CPad::ShiftTargetRightJustDown(void) if ( ArePlayerControlsDisabled() ) return false; - return !!(NewState.RightShoulder2 && !OldState.RightShoulder2); + return !!(NewState.LeftShoulder1 && !OldState.LeftShoulder1) || !!(NewState.RightShoulder2 && !OldState.RightShoulder2); } bool CPad::GetAnaloguePadUp(void) { static int16 oldfStickY = 0; - int16 Y = CPad::GetPad(0)->GetAnalogueUpDown(); + int16 leftStickY = CPad::GetPad(0)->GetLeftStickY(); - if ( Y < 0 && oldfStickY >= 0 ) + if ( leftStickY < -15 && oldfStickY >= -5 ) { - oldfStickY = Y; + oldfStickY = leftStickY; return true; } else { - oldfStickY = Y; + oldfStickY = leftStickY; return false; } } @@ -2856,16 +3041,16 @@ bool CPad::GetAnaloguePadDown(void) { static int16 oldfStickY = 0; - int16 Y = CPad::GetPad(0)->GetAnalogueUpDown(); + int16 leftStickY = CPad::GetPad(0)->GetLeftStickY(); - if ( Y > 0 && oldfStickY <= 0 ) + if ( leftStickY > 15 && oldfStickY <= 5 ) { - oldfStickY = Y; + oldfStickY = leftStickY; return true; } else { - oldfStickY = Y; + oldfStickY = leftStickY; return false; } } @@ -2874,16 +3059,16 @@ bool CPad::GetAnaloguePadLeft(void) { static int16 oldfStickX = 0; - int16 X = CPad::GetPad(0)->GetPedWalkLeftRight(); + int16 leftStickX = CPad::GetPad(0)->GetLeftStickX(); - if ( X < 0 && oldfStickX >= 0 ) + if ( leftStickX < -15 && oldfStickX >= -5 ) { - oldfStickX = X; + oldfStickX = leftStickX; return true; } else { - oldfStickX = X; + oldfStickX = leftStickX; return false; } } @@ -2892,16 +3077,16 @@ bool CPad::GetAnaloguePadRight(void) { static int16 oldfStickX = 0; - int16 X = CPad::GetPad(0)->GetPedWalkLeftRight(); + int16 leftStickX = CPad::GetPad(0)->GetLeftStickX(); - if ( X > 0 && oldfStickX <= 0 ) + if ( leftStickX > 15 && oldfStickX <= 5 ) { - oldfStickX = X; + oldfStickX = leftStickX; return true; } else { - oldfStickX = X; + oldfStickX = leftStickX; return false; } } @@ -2914,7 +3099,7 @@ bool CPad::GetAnaloguePadLeftJustUp(void) if ( X == 0 && oldfStickX < 0 ) { - oldfStickX = X; + oldfStickX = 0; return true; } @@ -2934,7 +3119,7 @@ bool CPad::GetAnaloguePadRightJustUp(void) if ( X == 0 && oldfStickX > 0 ) { - oldfStickX = X; + oldfStickX = 0; return true; } @@ -3040,23 +3225,35 @@ int16 CPad::SniperModeLookLeftRight(void) int16 axis = NewState.LeftStickX; int16 dpad = (NewState.DPadRight - NewState.DPadLeft) / 2; - if ( Abs(axis) > Abs(dpad) ) - return axis; - else + if ( Abs(axis) > Abs(dpad) ) { + if ( Abs(axis) > 35.0f ) { + return (axis > 0.f ? axis - 35.f : axis + 35.f) * 1.3763441f; + } else { + return 0; + } + } else return dpad; } int16 CPad::SniperModeLookUpDown(void) { int16 axis = NewState.LeftStickY; -#ifdef FIX_BUGS - axis = -axis; -#endif - int16 dpad = (NewState.DPadUp - NewState.DPadDown) / 2; + int16 dpad; - if ( Abs(axis) > Abs(dpad) ) - return axis; - else + if (CPad::bInvertLook4Pad) { + axis = -axis; + dpad = (NewState.DPadDown - NewState.DPadUp) / 2; + } else { + dpad = (NewState.DPadUp - NewState.DPadDown) / 2; + } + + if ( Abs(axis) > Abs(dpad) ) { + if ( Abs(axis) > 35.0f ) { + return (axis > 0.f ? axis - 35.f : axis + 35.f) * 1.3763441f; + } else { + return 0; + } + } else return dpad; } @@ -3079,9 +3276,8 @@ int16 CPad::LookAroundUpDown(void) { int16 axis = GetPad(0)->NewState.RightStickY; -#ifdef FIX_BUGS - axis = -axis; -#endif + if (CPad::bInvertLook4Pad) + axis = -axis; if ( Abs(axis) > 85 && !GetLookBehindForPed() ) return (int16) ( (axis + ( ( axis > 0 ) ? -85 : 85) ) @@ -3094,7 +3290,6 @@ int16 CPad::LookAroundUpDown(void) return 0; } - void CPad::ResetAverageWeapon(void) { AverageWeapon = GetWeapon(); @@ -3103,6 +3298,9 @@ void CPad::ResetAverageWeapon(void) void CPad::PrintErrorMessage(void) { + if (TheCamera.m_WideScreenOn) + return; + if ( bDisplayNoControllerMessage && !CGame::playingIntro && !FrontEndMenuManager.m_bMenuActive ) { CSprite2d::DrawRect(CRect(SCREEN_STRETCH_X(20.0f), SCREEN_SCALE_FROM_BOTTOM(130.0f), SCREEN_STRETCH_FROM_RIGHT(20.0f), SCREEN_SCALE_Y(140.0f)), CRGBA(50, 50, 50, 210)); @@ -3153,26 +3351,30 @@ void CPad::ResetCheats(void) { CWeather::ReleaseWeather(); + gbFastTime = false; CPopulation::ms_bGivePedsWeapons = false; - - CPed::bNastyLimbsCheat = false; - CPed::bFannyMagnetCheat = false; - CPed::bPedCheat2 = false; - CPed::bPedCheat3 = false; + CTimer::SetTimeScale(1.0f); CVehicle::bWheelsOnlyCheat = false; CVehicle::bAllDodosCheat = false; CVehicle::bCheat3 = false; CVehicle::bCheat4 = false; CVehicle::bCheat5 = false; + CVehicle::bAllTaxisHaveNitro = false; + CVehicle::bHoverCheat = false; CVehicle::bCheat8 = false; + CVehicle::bCheat9 = false; + CVehicle::bCheat10 = false; gbBlackCars = false; gbPinkCars = false; + CCarCtrl::bMadDriversCheat = false; CTrafficLights::bGreenLightsCheat = false; CStats::ShowChaseStatOnScreen = 0; - gbFastTime = false; - CTimer::SetTimeScale(1.0f); + CPed::bNastyLimbsCheat = false; + CPed::bFannyMagnetCheat = false; + CPed::bPedCheat3 = false; + } char *CPad::EditString(char *pStr, int32 nSize) @@ -3377,3 +3579,13 @@ int32 *CPad::EditCodesForControls(int32 *pRsKeys, int32 nSize) return pRsKeys; } + +void CPad::FixPadsAfterSave(void) +{ + UpdatePads(); + if ( bObsoleteControllerMessage ) + { + bObsoleteControllerMessage = false; + GetPad(0)->Phase = 0; + } +} \ No newline at end of file diff --git a/src/core/Pad.h b/src/core/Pad.h index cde2d3c5..01f5bb9b 100644 --- a/src/core/Pad.h +++ b/src/core/Pad.h @@ -158,6 +158,7 @@ public: uint8 ShakeFreq; bool bHornHistory[HORNHISTORY_SIZE]; uint8 iCurrHornHistory; + int8 JustOutOfFrontend; int8 bApplyBrakes; char CheatString[12]; int32 LastTimeTouched; @@ -174,7 +175,9 @@ public: static bool bObsoleteControllerMessage; static bool bOldDisplayNoControllerMessage; static bool m_bMapPadOneToPadTwo; + static bool m_bDebugCamPCOn; static bool bHasPlayerCheated; + static bool bInvertLook4Pad; static CKeyboardState OldKeyState; static CKeyboardState NewKeyState; @@ -190,6 +193,7 @@ public: #endif void Clear(bool bResetPlayerControls); void ClearMouseHistory(); + void ClearKeyBoardHistory(); void UpdateMouse(); CControllerState ReconcileTwoControllersInput(CControllerState const &State1, CControllerState const &State2); void StartShake(int16 nDur, uint8 nFreq); @@ -219,6 +223,7 @@ public: int16 GetPedWalkLeftRight(void); int16 GetPedWalkUpDown(void); int16 GetAnalogueUpDown(void); + int16 GetAnalogueLeftRight(void); bool GetLookLeft(void); bool GetLookRight(void); bool GetLookBehindForCar(void); @@ -234,6 +239,7 @@ public: int32 GetWeapon(void); bool WeaponJustDown(void); int16 GetAccelerate(void); + bool CycleCameraModeJustDown(void); bool CycleCameraModeUpJustDown(void); bool CycleCameraModeDownJustDown(void); bool ChangeStationJustDown(void); @@ -261,6 +267,7 @@ public: int16 LookAroundLeftRight(void); int16 LookAroundUpDown(void); void ResetAverageWeapon(void); + static void FixPadsAfterSave(void); static void PrintErrorMessage(void); static void ResetCheats(void); static char *EditString(char *pStr, int32 nSize); diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index b9fc369d..5317040f 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -750,9 +750,7 @@ void CRadar::DrawBlips() void CRadar::DrawMap() { if (!TheCamera.m_WideScreenOn && CHud::m_Wants_To_Draw_Hud) { -#if 1 // from VC CalculateCachedSinCos(); -#endif if (FindPlayerVehicle()) { float speed = FindPlayerSpeed().Magnitude(); if (speed < RADAR_MIN_SPEED) @@ -1366,33 +1364,8 @@ void CRadar::TransformRealWorldToTexCoordSpace(CVector2D &out, const CVector2D & void CRadar::TransformRadarPointToRealWorldSpace(CVector2D &out, const CVector2D &in) { float s, c; -#if 1 s = -cachedSin; c = cachedCos; -#else - // Original code - - s = -Sin(TheCamera.GetForward().Heading()); - c = Cos(TheCamera.GetForward().Heading()); - - if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN || TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED) { - s = 0.0f; - c = 1.0f; - } - else if (TheCamera.GetLookDirection() != LOOKING_FORWARD) { - CVector forward; - - if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_1STPERSON) { - forward = TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity->GetForward(); - forward.Normalise(); // a bit useless... - } - else - forward = TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity->GetPosition() - TheCamera.Cams[TheCamera.ActiveCam].SourceBeforeLookBehind; - - s = -Sin(forward.Heading()); - c = Cos(forward.Heading()); - } -#endif out.x = s * in.y + c * in.x; out.y = c * in.y - s * in.x; @@ -1419,35 +1392,8 @@ void CRadar::TransformRadarPointToScreenSpace(CVector2D &out, const CVector2D &i void CRadar::TransformRealWorldPointToRadarSpace(CVector2D &out, const CVector2D &in) { float s, c; -#if 1 s = cachedSin; c = cachedCos; -#else - // Original code - - float s, c; - if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN || TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED) { - s = 0.0f; - c = 1.0f; - } - else if (TheCamera.GetLookDirection() == LOOKING_FORWARD) { - s = Sin(TheCamera.GetForward().Heading()); - c = Cos(TheCamera.GetForward().Heading()); - } - else { - CVector forward; - - if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_1STPERSON) { - forward = TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity->GetForward(); - forward.Normalise(); // a bit useless... - } - else - forward = TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity->GetPosition() - TheCamera.Cams[TheCamera.ActiveCam].SourceBeforeLookBehind; - - s = Sin(forward.Heading()); - c = Cos(forward.Heading()); - } -#endif float x = (in.x - vec2DRadarOrigin.x) * (1.0f / m_radarRange); float y = (in.y - vec2DRadarOrigin.y) * (1.0f / m_radarRange); @@ -1534,10 +1480,10 @@ CRadar::ToggleTargetMarker(float x, float y) if (!ms_RadarTrace[nextBlip].m_bInUse) break; } -#ifdef FIX_BUGS + if (nextBlip == NUMRADARBLIPS) return; -#endif + ms_RadarTrace[nextBlip].m_eBlipType = BLIP_COORD; ms_RadarTrace[nextBlip].m_nColor = 0x333333FF; ms_RadarTrace[nextBlip].m_bDim = 1; diff --git a/src/core/re3.cpp b/src/core/re3.cpp index 1393314c..2e112442 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -100,7 +100,8 @@ void FastWeatherCheat(); void OnlyRenderWheelsCheat(); void ChittyChittyBangBangCheat(); void StrongGripCheat(); -void NastyLimbsCheat(); +void SpecialCarCheats(); +void PickUpChicksCheat(); DebugMenuEntry *carCol1; DebugMenuEntry *carCol2; @@ -370,7 +371,8 @@ DebugMenuPopulate(void) DebugMenuAddCmd("Cheats", "Only render wheels", OnlyRenderWheelsCheat); DebugMenuAddCmd("Cheats", "Chitty chitty bang bang", ChittyChittyBangBangCheat); DebugMenuAddCmd("Cheats", "Strong grip", StrongGripCheat); - DebugMenuAddCmd("Cheats", "Nasty limbs", NastyLimbsCheat); + DebugMenuAddCmd("Cheats", "Special car", SpecialCarCheats); + DebugMenuAddCmd("Cheats", "Pickup chicks", PickUpChicksCheat); static int spawnCarId = MI_LANDSTAL; e = DebugMenuAddVar("Spawn", "Spawn Car ID", &spawnCarId, nil, 1, MI_LANDSTAL, MI_VICECHEE, carnames); -- cgit v1.2.3 From d590fdddf6ba938bdc2f59e2c0d2e3fc9713f67a Mon Sep 17 00:00:00 2001 From: Andrew Udvare Date: Tue, 29 Sep 2020 20:39:18 -0400 Subject: macOS support; thanks to @MrYadro This should support ARM64 and x86-64. -target flag based on information from https://developer.apple.com/documentation/xcode/building_a_universal_macos_binary#3618377. --- src/core/CdStreamPosix.cpp | 73 +++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 24 deletions(-) (limited to 'src/core') diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index e114a29a..895143a4 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,30 @@ #define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) #define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) +#ifdef __APPLE__ +#define COMPAT_SEM_T sem_t * +int compat_sem_init(sem_t **ptr, __attribute__((unused)) int x, __attribute__((unused)) int y) { + *ptr = sem_open("/semaphore", O_CREAT, 0644, 1); + return *ptr == SEM_FAILED ? -1 : 0; +} +int compat_sem_post(sem_t **sem) { + return sem_post(*sem); +} +int compat_sem_wait(sem_t **sem) { + return sem_wait(*sem); +} +int compat_sem_destroy(sem_t **sem, const char * name) { + sem_close(*sem); + sem_unlink(name); +} +#else +#define COMPAT_SEM_T sem_t +#define compat_sem_post sem_post +#define compat_sem_destroy(x, y) sem_destroy(x) +#define compat_sem_init sem_init +#define compat_sem_wait sem_wait +#endif + // #define ONE_THREAD_PER_CHANNEL // Don't use if you're not on SSD/Flash. (Also you may want to benefit from this via using all channels in Streaming.cpp) bool flushStream[MAX_CDCHANNELS]; @@ -35,11 +60,11 @@ struct CdReadInfo int32 nStatus; #ifdef ONE_THREAD_PER_CHANNEL int8 nThreadStatus; // 0: created 1:initalized 2:abort now - pthread_t pChannelThread; - sem_t pStartSemaphore; + pthread_t pChannelThread; + COMPAT_SEM_T pStartSemaphore; #endif - sem_t pDoneSemaphore; // used for CdStreamSync - int32 hFile; + COMPAT_SEM_T pDoneSemaphore; // used for CdStreamSync + int32 hFile; }; char gCdImageNames[MAX_CDIMAGES+1][64]; @@ -51,7 +76,7 @@ char *gImgNames[MAX_CDIMAGES]; #ifndef ONE_THREAD_PER_CHANNEL pthread_t _gCdStreamThread; -sem_t gCdStreamSema; // released when we have new thing to read(so channel is set) +COMPAT_SEM_T gCdStreamSema; // released when we have new thing to read(so channel is set) int8 gCdStreamThreadStatus; // 0: created 1:initalized 2:abort now Queue gChannelRequestQ; bool _gbCdStreamOverlapped; @@ -76,7 +101,7 @@ CdStreamInitThread(void) gChannelRequestQ.tail = 0; gChannelRequestQ.size = gNumChannels + 1; ASSERT(gChannelRequestQ.items != nil ); - status = sem_init(&gCdStreamSema, 0, 0); + status = compat_sem_init(&gCdStreamSema, 0, 0); #endif @@ -91,7 +116,7 @@ CdStreamInitThread(void) { for ( int32 i = 0; i < gNumChannels; i++ ) { - status = sem_init(&gpReadInfo[i].pDoneSemaphore, 0, 0); + status = compat_sem_init(&gpReadInfo[i].pDoneSemaphore, 0, 0); if (status == -1) { @@ -100,7 +125,7 @@ CdStreamInitThread(void) return; } #ifdef ONE_THREAD_PER_CHANNEL - status = sem_init(&gpReadInfo[i].pStartSemaphore, 0, 0); + status = compat_sem_init(&gpReadInfo[i].pStartSemaphore, 0, 0); if (status == -1) { @@ -214,13 +239,13 @@ CdStreamShutdown(void) // Destroying semaphores and free(gpReadInfo) will be done at threads #ifndef ONE_THREAD_PER_CHANNEL gCdStreamThreadStatus = 2; - sem_post(&gCdStreamSema); + compat_sem_post(&gCdStreamSema); #endif #ifdef ONE_THREAD_PER_CHANNEL for ( int32 i = 0; i < gNumChannels; i++ ) { gpReadInfo[i].nThreadStatus = 2; - sem_post(&gpReadInfo[i].pStartSemaphore); + compat_sem_post(&gpReadInfo[i].pStartSemaphore); } #endif } @@ -254,10 +279,10 @@ CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size) #ifndef ONE_THREAD_PER_CHANNEL AddToQueue(&gChannelRequestQ, channel); - if ( sem_post(&gCdStreamSema) != 0 ) + if ( compat_sem_post(&gCdStreamSema) != 0 ) printf("Signal Sema Error\n"); #else - if ( sem_post(&gpReadInfo[channel].pStartSemaphore) != 0 ) + if ( compat_sem_post(&gpReadInfo[channel].pStartSemaphore) != 0 ) printf("Signal Sema Error\n"); #endif @@ -332,7 +357,7 @@ CdStreamSync(int32 channel) { pChannel->bLocked = true; - sem_wait(&pChannel->pDoneSemaphore); + compat_sem_wait(&pChannel->pDoneSemaphore); } pChannel->bReading = false; @@ -383,12 +408,12 @@ void *CdStreamThread(void *param) #ifndef ONE_THREAD_PER_CHANNEL while (gCdStreamThreadStatus != 2) { - sem_wait(&gCdStreamSema); + compat_sem_wait(&gCdStreamSema); int32 channel = GetFirstInQueue(&gChannelRequestQ); #else int channel = *((int*)param); while (gpReadInfo[channel].nThreadStatus != 2){ - sem_wait(&gpReadInfo[channel].pStartSemaphore); + compat_sem_wait(&gpReadInfo[channel].pStartSemaphore); #endif ASSERT( channel < gNumChannels ); @@ -437,22 +462,22 @@ void *CdStreamThread(void *param) if ( pChannel->bLocked ) { - sem_post(&pChannel->pDoneSemaphore); + compat_sem_post(&pChannel->pDoneSemaphore); } pChannel->bReading = false; } #ifndef ONE_THREAD_PER_CHANNEL - for ( int32 i = 0; i < gNumChannels; i++ ) - { - sem_destroy(&gpReadInfo[i].pDoneSemaphore); - } - sem_destroy(&gCdStreamSema); + for ( int32 i = 0; i < gNumChannels; i++ ) + { + compat_sem_destroy(&gpReadInfo[i].pDoneSemaphore, "/semaphoredone"); + } + compat_sem_destroy(&gCdStreamSema, "/semaphore"); free(gChannelRequestQ.items); #else - sem_destroy(&gpReadInfo[channel].pStartSemaphore); - sem_destroy(&gpReadInfo[channel].pDoneSemaphore); + compat_sem_destroy(&gpReadInfo[channel].pStartSemaphore, "/semaphorestart"); + compat_sem_destroy(&gpReadInfo[channel].pDoneSemaphore, "/semaphoredone"); #endif - free(gpReadInfo); + free(gpReadInfo); pthread_exit(nil); } -- cgit v1.2.3 From 2bb29a50b79a4f9a126823b6e359ae07cbf9bf5c Mon Sep 17 00:00:00 2001 From: Andrew Udvare Date: Thu, 1 Oct 2020 03:21:06 -0400 Subject: core/CdStreamPosix: switch to named semaphores to support macOS macOS does not support unnamed semaphores. The functions return ENOSYS. --- src/core/CdStreamPosix.cpp | 87 ++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 54 deletions(-) (limited to 'src/core') diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index 895143a4..3d9316c9 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -22,30 +21,6 @@ #define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) #define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) -#ifdef __APPLE__ -#define COMPAT_SEM_T sem_t * -int compat_sem_init(sem_t **ptr, __attribute__((unused)) int x, __attribute__((unused)) int y) { - *ptr = sem_open("/semaphore", O_CREAT, 0644, 1); - return *ptr == SEM_FAILED ? -1 : 0; -} -int compat_sem_post(sem_t **sem) { - return sem_post(*sem); -} -int compat_sem_wait(sem_t **sem) { - return sem_wait(*sem); -} -int compat_sem_destroy(sem_t **sem, const char * name) { - sem_close(*sem); - sem_unlink(name); -} -#else -#define COMPAT_SEM_T sem_t -#define compat_sem_post sem_post -#define compat_sem_destroy(x, y) sem_destroy(x) -#define compat_sem_init sem_init -#define compat_sem_wait sem_wait -#endif - // #define ONE_THREAD_PER_CHANNEL // Don't use if you're not on SSD/Flash. (Also you may want to benefit from this via using all channels in Streaming.cpp) bool flushStream[MAX_CDCHANNELS]; @@ -60,11 +35,11 @@ struct CdReadInfo int32 nStatus; #ifdef ONE_THREAD_PER_CHANNEL int8 nThreadStatus; // 0: created 1:initalized 2:abort now - pthread_t pChannelThread; - COMPAT_SEM_T pStartSemaphore; + pthread_t pChannelThread; + sem_t *pStartSemaphore; #endif - COMPAT_SEM_T pDoneSemaphore; // used for CdStreamSync - int32 hFile; + sem_t *pDoneSemaphore; // used for CdStreamSync + int32 hFile; }; char gCdImageNames[MAX_CDIMAGES+1][64]; @@ -76,7 +51,7 @@ char *gImgNames[MAX_CDIMAGES]; #ifndef ONE_THREAD_PER_CHANNEL pthread_t _gCdStreamThread; -COMPAT_SEM_T gCdStreamSema; // released when we have new thing to read(so channel is set) +sem_t *gCdStreamSema; // released when we have new thing to read(so channel is set) int8 gCdStreamThreadStatus; // 0: created 1:initalized 2:abort now Queue gChannelRequestQ; bool _gbCdStreamOverlapped; @@ -101,11 +76,11 @@ CdStreamInitThread(void) gChannelRequestQ.tail = 0; gChannelRequestQ.size = gNumChannels + 1; ASSERT(gChannelRequestQ.items != nil ); - status = compat_sem_init(&gCdStreamSema, 0, 0); + gCdStreamSema = sem_open("/semaphore_cd_stream", O_CREAT, 0644, 1); #endif - if (status == -1) { + if (gCdStreamSema == SEM_FAILED) { CDTRACE("failed to create stream semaphore"); ASSERT(0); return; @@ -116,18 +91,18 @@ CdStreamInitThread(void) { for ( int32 i = 0; i < gNumChannels; i++ ) { - status = compat_sem_init(&gpReadInfo[i].pDoneSemaphore, 0, 0); + gpReadInfo[i].pDoneSemaphore = sem_open("/semaphore_done", O_CREAT, 0644, 1); - if (status == -1) + if (gpReadInfo[i].pDoneSemaphore == SEM_FAILED) { CDTRACE("failed to create sync semaphore"); ASSERT(0); return; } #ifdef ONE_THREAD_PER_CHANNEL - status = compat_sem_init(&gpReadInfo[i].pStartSemaphore, 0, 0); + gpReadInfo[i].pStartSemaphore = sem_open("/semaphore_start", O_CREAT, 0644, 1); - if (status == -1) + if (gpReadInfo[i].pStartSemaphore == SEM_FAILED) { CDTRACE("failed to create start semaphore"); ASSERT(0); @@ -160,7 +135,7 @@ CdStreamInitThread(void) return; } #else - debug("Using seperate streaming threads for each channel\n"); + debug("Using separate streaming threads for each channel\n"); #endif } @@ -239,13 +214,13 @@ CdStreamShutdown(void) // Destroying semaphores and free(gpReadInfo) will be done at threads #ifndef ONE_THREAD_PER_CHANNEL gCdStreamThreadStatus = 2; - compat_sem_post(&gCdStreamSema); + sem_post(gCdStreamSema); #endif #ifdef ONE_THREAD_PER_CHANNEL for ( int32 i = 0; i < gNumChannels; i++ ) { gpReadInfo[i].nThreadStatus = 2; - compat_sem_post(&gpReadInfo[i].pStartSemaphore); + sem_post(&gpReadInfo[i].pStartSemaphore); } #endif } @@ -279,10 +254,10 @@ CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size) #ifndef ONE_THREAD_PER_CHANNEL AddToQueue(&gChannelRequestQ, channel); - if ( compat_sem_post(&gCdStreamSema) != 0 ) + if ( sem_post(gCdStreamSema) != 0 ) printf("Signal Sema Error\n"); #else - if ( compat_sem_post(&gpReadInfo[channel].pStartSemaphore) != 0 ) + if ( sem_post(&gpReadInfo[channel].pStartSemaphore) != 0 ) printf("Signal Sema Error\n"); #endif @@ -357,7 +332,7 @@ CdStreamSync(int32 channel) { pChannel->bLocked = true; - compat_sem_wait(&pChannel->pDoneSemaphore); + sem_wait(pChannel->pDoneSemaphore); } pChannel->bReading = false; @@ -408,12 +383,12 @@ void *CdStreamThread(void *param) #ifndef ONE_THREAD_PER_CHANNEL while (gCdStreamThreadStatus != 2) { - compat_sem_wait(&gCdStreamSema); + sem_wait(gCdStreamSema); int32 channel = GetFirstInQueue(&gChannelRequestQ); #else int channel = *((int*)param); while (gpReadInfo[channel].nThreadStatus != 2){ - compat_sem_wait(&gpReadInfo[channel].pStartSemaphore); + sem_wait(&gpReadInfo[channel].pStartSemaphore); #endif ASSERT( channel < gNumChannels ); @@ -462,22 +437,26 @@ void *CdStreamThread(void *param) if ( pChannel->bLocked ) { - compat_sem_post(&pChannel->pDoneSemaphore); + sem_post(pChannel->pDoneSemaphore); } pChannel->bReading = false; } #ifndef ONE_THREAD_PER_CHANNEL - for ( int32 i = 0; i < gNumChannels; i++ ) - { - compat_sem_destroy(&gpReadInfo[i].pDoneSemaphore, "/semaphoredone"); - } - compat_sem_destroy(&gCdStreamSema, "/semaphore"); - free(gChannelRequestQ.items); + for ( int32 i = 0; i < gNumChannels; i++ ) + { + sem_close(gpReadInfo[i].pDoneSemaphore); + sem_unlink("/semaphore_done"); + } + sem_close(gCdStreamSema); + sem_unlink("/semaphore_cd_stream"); + free(gChannelRequestQ.items); #else - compat_sem_destroy(&gpReadInfo[channel].pStartSemaphore, "/semaphorestart"); - compat_sem_destroy(&gpReadInfo[channel].pDoneSemaphore, "/semaphoredone"); + sem_close(gpReadInfo[channel].pStartSemaphore); + sem_unlink("/semaphore_start"); + sem_close(gpReadInfo[channel].pDoneSemaphore); + sem_unlink("/semaphore_done"); #endif - free(gpReadInfo); + free(gpReadInfo); pthread_exit(nil); } -- cgit v1.2.3 From 1a3e254b6c5fc79433d84f89273a5a983f30af8e Mon Sep 17 00:00:00 2001 From: Andrew Udvare Date: Thu, 1 Oct 2020 20:45:38 -0400 Subject: CdStreamPosix: fix type issues --- src/core/CdStreamPosix.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index 3d9316c9..40000f03 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -163,7 +163,7 @@ CdStreamInit(int32 numChannels) debug("Using no buffered loading for streaming\n"); } */ - void *pBuffer = (void *)RwMallocAlign(CDSTREAM_SECTOR_SIZE, fsInfo.f_bsize); + void *pBuffer = (void *)RwMallocAlign(CDSTREAM_SECTOR_SIZE, (RwUInt32)fsInfo.f_bsize); ASSERT( pBuffer != nil ); gNumImages = 0; @@ -205,7 +205,7 @@ GetGTA3ImgSize(void) return 0; } ok: - return statbuf.st_size; + return (uint32)statbuf.st_size; } void -- cgit v1.2.3 From fec01aeff1daa891d754bd249f053652788d6f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sun, 4 Oct 2020 22:39:54 +0300 Subject: Fix some sanitizer errors, improve POSIX streamer --- src/core/CdStreamPosix.cpp | 288 ++++++++++++++++++++++++--------------------- src/core/FileLoader.cpp | 4 + src/core/FileMgr.cpp | 10 +- src/core/Streaming.cpp | 121 +++++++++++++++++++ src/core/common.h | 2 +- 5 files changed, 282 insertions(+), 143 deletions(-) (limited to 'src/core') diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index 40000f03..04a5de4b 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -34,9 +34,9 @@ struct CdReadInfo bool bReading; int32 nStatus; #ifdef ONE_THREAD_PER_CHANNEL - int8 nThreadStatus; // 0: created 1:initalized 2:abort now - pthread_t pChannelThread; - sem_t *pStartSemaphore; + int8 nThreadStatus; // 0: created 1:priority set up 2:abort now + pthread_t pChannelThread; + sem_t *pStartSemaphore; #endif sem_t *pDoneSemaphore; // used for CdStreamSync int32 hFile; @@ -52,7 +52,7 @@ char *gImgNames[MAX_CDIMAGES]; #ifndef ONE_THREAD_PER_CHANNEL pthread_t _gCdStreamThread; sem_t *gCdStreamSema; // released when we have new thing to read(so channel is set) -int8 gCdStreamThreadStatus; // 0: created 1:initalized 2:abort now +int8 gCdStreamThreadStatus; // 0: created 1:priority set up 2:abort now Queue gChannelRequestQ; bool _gbCdStreamOverlapped; #endif @@ -69,15 +69,14 @@ void CdStreamInitThread(void) { int status; - + char semName[20]; #ifndef ONE_THREAD_PER_CHANNEL gChannelRequestQ.items = (int32 *)calloc(gNumChannels + 1, sizeof(int32)); gChannelRequestQ.head = 0; gChannelRequestQ.tail = 0; gChannelRequestQ.size = gNumChannels + 1; ASSERT(gChannelRequestQ.items != nil ); - gCdStreamSema = sem_open("/semaphore_cd_stream", O_CREAT, 0644, 1); -#endif + gCdStreamSema = sem_open("/semaphore_cd_stream", O_CREAT, 0644, 1); if (gCdStreamSema == SEM_FAILED) { @@ -85,33 +84,35 @@ CdStreamInitThread(void) ASSERT(0); return; } - +#endif if ( gNumChannels > 0 ) { for ( int32 i = 0; i < gNumChannels; i++ ) { - gpReadInfo[i].pDoneSemaphore = sem_open("/semaphore_done", O_CREAT, 0644, 1); + sprintf(semName,"/semaphore_done%d",i); + gpReadInfo[i].pDoneSemaphore = sem_open(semName, O_CREAT, 0644, 1); - if (gpReadInfo[i].pDoneSemaphore == SEM_FAILED) + if (gpReadInfo[i].pDoneSemaphore == SEM_FAILED) { CDTRACE("failed to create sync semaphore"); ASSERT(0); return; } #ifdef ONE_THREAD_PER_CHANNEL - gpReadInfo[i].pStartSemaphore = sem_open("/semaphore_start", O_CREAT, 0644, 1); + sprintf(semName,"/semaphore_start%d",i); + gpReadInfo[i].pStartSemaphore = sem_open(semName, O_CREAT, 0644, 1); - if (gpReadInfo[i].pStartSemaphore == SEM_FAILED) + if (gpReadInfo[i].pStartSemaphore == SEM_FAILED) { CDTRACE("failed to create start semaphore"); ASSERT(0); return; } - gpReadInfo[i].nThreadStatus = 0; + gpReadInfo[i].nThreadStatus = 0; int *channelI = (int*)malloc(sizeof(int)); *channelI = i; - status = pthread_create(&gpReadInfo[i].pChannelThread, NULL, CdStreamThread, (void*)channelI); + status = pthread_create(&gpReadInfo[i].pChannelThread, NULL, CdStreamThread, (void*)channelI); if (status == -1) { @@ -124,32 +125,32 @@ CdStreamInitThread(void) } #ifndef ONE_THREAD_PER_CHANNEL - debug("Using one streaming thread for all channels\n"); - status = pthread_create(&_gCdStreamThread, NULL, CdStreamThread, nil); - gCdStreamThreadStatus = 0; - - if (status == -1) - { - CDTRACE("failed to create sync thread"); - ASSERT(0); - return; - } + debug("Using one streaming thread for all channels\n"); + gCdStreamThreadStatus = 0; + status = pthread_create(&_gCdStreamThread, NULL, CdStreamThread, nil); + + if (status == -1) + { + CDTRACE("failed to create sync thread"); + ASSERT(0); + return; + } #else - debug("Using separate streaming threads for each channel\n"); + debug("Using separate streaming threads for each channel\n"); #endif } void CdStreamInit(int32 numChannels) { - struct statvfs fsInfo; - - if((statvfs("models/gta3.img", &fsInfo)) < 0) - { - CDTRACE("can't get filesystem info"); - ASSERT(0); - return; - } + struct statvfs fsInfo; + + if((statvfs("models/gta3.img", &fsInfo)) < 0) + { + CDTRACE("can't get filesystem info"); + ASSERT(0); + return; + } #ifdef __linux__ _gdwCdStreamFlags = O_RDONLY | O_NOATIME; #else @@ -185,26 +186,26 @@ uint32 GetGTA3ImgSize(void) { ASSERT( gImgFiles[0] > 0 ); - struct stat statbuf; + struct stat statbuf; - char path[PATH_MAX]; - realpath(gImgNames[0], path); - if (stat(path, &statbuf) == -1) { + char path[PATH_MAX]; + realpath(gImgNames[0], path); + if (stat(path, &statbuf) == -1) { // Try case-insensitivity char* real = casepath(gImgNames[0], false); if (real) { realpath(real, path); free(real); - if (stat(path, &statbuf) != -1) + if (stat(path, &statbuf) != -1) goto ok; } - CDTRACE("can't get size of gta3.img"); - ASSERT(0); - return 0; - } -ok: + CDTRACE("can't get size of gta3.img"); + ASSERT(0); + return 0; + } + ok: return (uint32)statbuf.st_size; } @@ -213,15 +214,13 @@ CdStreamShutdown(void) { // Destroying semaphores and free(gpReadInfo) will be done at threads #ifndef ONE_THREAD_PER_CHANNEL - gCdStreamThreadStatus = 2; - sem_post(gCdStreamSema); -#endif - -#ifdef ONE_THREAD_PER_CHANNEL - for ( int32 i = 0; i < gNumChannels; i++ ) { - gpReadInfo[i].nThreadStatus = 2; - sem_post(&gpReadInfo[i].pStartSemaphore); - } + gCdStreamThreadStatus = 2; + sem_post(gCdStreamSema); +#else + for ( int32 i = 0; i < gNumChannels; i++ ) { + gpReadInfo[i].nThreadStatus = 2; + sem_post(gpReadInfo[i].pStartSemaphore); + } #endif } @@ -243,25 +242,28 @@ CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size) pChannel->hFile = hImage - 1; - if ( pChannel->nSectorsToRead != 0 || pChannel->bReading ) - return STREAM_NONE; + if ( pChannel->nSectorsToRead != 0 || pChannel->bReading ) { + flushStream[channel] = 1; + CdStreamSync(channel); + //return STREAM_NONE; + } - pChannel->nStatus = STREAM_NONE; - pChannel->nSectorOffset = _GET_OFFSET(offset); - pChannel->nSectorsToRead = size; - pChannel->pBuffer = buffer; - pChannel->bLocked = 0; + pChannel->nStatus = STREAM_NONE; + pChannel->nSectorOffset = _GET_OFFSET(offset); + pChannel->nSectorsToRead = size; + pChannel->pBuffer = buffer; + pChannel->bLocked = 0; #ifndef ONE_THREAD_PER_CHANNEL - AddToQueue(&gChannelRequestQ, channel); - if ( sem_post(gCdStreamSema) != 0 ) - printf("Signal Sema Error\n"); + AddToQueue(&gChannelRequestQ, channel); + if ( sem_post(gCdStreamSema) != 0 ) + printf("Signal Sema Error\n"); #else - if ( sem_post(&gpReadInfo[channel].pStartSemaphore) != 0 ) - printf("Signal Sema Error\n"); + if ( sem_post(pChannel->pStartSemaphore) != 0 ) + printf("Signal Sema Error\n"); #endif - return STREAM_SUCCESS; + return STREAM_SUCCESS; } int32 @@ -272,29 +274,29 @@ CdStreamGetStatus(int32 channel) ASSERT( pChannel != nil ); #ifdef ONE_THREAD_PER_CHANNEL - if (pChannel->nThreadStatus == 2) - return STREAM_NONE; + if (pChannel->nThreadStatus == 2) + return STREAM_NONE; #else - if (gCdStreamThreadStatus == 2) - return STREAM_NONE; + if (gCdStreamThreadStatus == 2) + return STREAM_NONE; #endif - if ( pChannel->bReading ) - return STREAM_READING; + if ( pChannel->bReading ) + return STREAM_READING; - if ( pChannel->nSectorsToRead != 0 ) - return STREAM_WAITING; + if ( pChannel->nSectorsToRead != 0 ) + return STREAM_WAITING; - if ( pChannel->nStatus != STREAM_NONE ) - { - int32 status = pChannel->nStatus; + if ( pChannel->nStatus != STREAM_NONE ) + { + int32 status = pChannel->nStatus; - pChannel->nStatus = STREAM_NONE; + pChannel->nStatus = STREAM_NONE; - return status; - } + return status; + } - return STREAM_NONE; + return STREAM_NONE; } int32 @@ -314,30 +316,34 @@ CdStreamSync(int32 channel) if (flushStream[channel]) { #ifdef ONE_THREAD_PER_CHANNEL pChannel->nSectorsToRead = 0; - pthread_kill(gpReadInfo[channel].pChannelThread, SIGINT); + pthread_kill(pChannel->pChannelThread, SIGINT); + if (pChannel->bReading) { + pChannel->bLocked = true; + sem_wait(pChannel->pDoneSemaphore); + } #else + pChannel->nSectorsToRead = 0; if (pChannel->bReading) { - pChannel->nSectorsToRead = 0; + pChannel->bLocked = true; pthread_kill(_gCdStreamThread, SIGINT); - } else { - pChannel->nSectorsToRead = 0; + sem_wait(pChannel->pDoneSemaphore); } #endif pChannel->bReading = false; flushStream[channel] = false; - return STREAM_NONE; + return STREAM_NONE; } - if ( pChannel->nSectorsToRead != 0 ) - { - pChannel->bLocked = true; + if ( pChannel->nSectorsToRead != 0 ) + { + pChannel->bLocked = true; - sem_wait(pChannel->pDoneSemaphore); - } + sem_wait(pChannel->pDoneSemaphore); + } - pChannel->bReading = false; + pChannel->bReading = false; - return pChannel->nStatus; + return pChannel->nStatus; } void @@ -382,53 +388,52 @@ void *CdStreamThread(void *param) debug("Created cdstream thread\n"); #ifndef ONE_THREAD_PER_CHANNEL - while (gCdStreamThreadStatus != 2) { + while (gCdStreamThreadStatus != 2) { sem_wait(gCdStreamSema); - int32 channel = GetFirstInQueue(&gChannelRequestQ); + int32 channel = GetFirstInQueue(&gChannelRequestQ); #else - int channel = *((int*)param); - while (gpReadInfo[channel].nThreadStatus != 2){ - sem_wait(&gpReadInfo[channel].pStartSemaphore); + int channel = *((int*)param); + while (gpReadInfo[channel].nThreadStatus != 2){ + sem_wait(gpReadInfo[channel].pStartSemaphore); #endif - ASSERT( channel < gNumChannels ); CdReadInfo *pChannel = &gpReadInfo[channel]; ASSERT( pChannel != nil ); -#ifdef ONE_THREAD_PER_CHANNEL - if (gpReadInfo[channel].nThreadStatus == 0){ - gpReadInfo[channel].nThreadStatus = 1; -#else - if (gCdStreamThreadStatus == 0){ - gCdStreamThreadStatus = 1; -#endif - -#ifdef __linux__ - pid_t tid = syscall(SYS_gettid); - int ret = setpriority(PRIO_PROCESS, tid, getpriority(PRIO_PROCESS, getpid()) + 1); -#endif - } - // spurious wakeup or we sent interrupt signal for flushing if(pChannel->nSectorsToRead == 0) - continue; + continue; pChannel->bReading = true; + // Not standard POSIX :shrug: +#ifdef __linux__ +#ifdef ONE_THREAD_PER_CHANNEL + if (gpReadInfo[channel].nThreadStatus == 0){ + gpReadInfo[channel].nThreadStatus = 1; +#else + if (gCdStreamThreadStatus == 0){ + gCdStreamThreadStatus = 1; +#endif + pid_t tid = syscall(SYS_gettid); + int ret = setpriority(PRIO_PROCESS, tid, getpriority(PRIO_PROCESS, getpid()) + 1); + } +#endif if ( pChannel->nStatus == STREAM_NONE ) { - ASSERT(pChannel->hFile >= 0); - ASSERT(pChannel->pBuffer != nil ); + ASSERT(pChannel->hFile >= 0); + ASSERT(pChannel->pBuffer != nil ); lseek(pChannel->hFile, pChannel->nSectorOffset * CDSTREAM_SECTOR_SIZE, SEEK_SET); - if (read(pChannel->hFile, pChannel->pBuffer, pChannel->nSectorsToRead * CDSTREAM_SECTOR_SIZE) == -1) { + if (read(pChannel->hFile, pChannel->pBuffer, pChannel->nSectorsToRead * CDSTREAM_SECTOR_SIZE) == -1) { // pChannel->nSectorsToRead == 0 at this point means we wanted to flush channel - pChannel->nStatus = pChannel->nSectorsToRead == 0 ? STREAM_NONE : STREAM_ERROR; - } else { - pChannel->nStatus = STREAM_NONE; - } + // STREAM_WAITING is a little hack to make CStreaming not process this data + pChannel->nStatus = pChannel->nSectorsToRead == 0 ? STREAM_WAITING : STREAM_ERROR; + } else { + pChannel->nStatus = STREAM_NONE; + } } - + #ifndef ONE_THREAD_PER_CHANNEL RemoveFirstInQueue(&gChannelRequestQ); #endif @@ -437,26 +442,33 @@ void *CdStreamThread(void *param) if ( pChannel->bLocked ) { - sem_post(pChannel->pDoneSemaphore); + sem_post(pChannel->pDoneSemaphore); } pChannel->bReading = false; } + char semName[20]; #ifndef ONE_THREAD_PER_CHANNEL - for ( int32 i = 0; i < gNumChannels; i++ ) - { - sem_close(gpReadInfo[i].pDoneSemaphore); - sem_unlink("/semaphore_done"); - } - sem_close(gCdStreamSema); - sem_unlink("/semaphore_cd_stream"); - free(gChannelRequestQ.items); + for ( int32 i = 0; i < gNumChannels; i++ ) + { + sem_close(gpReadInfo[i].pDoneSemaphore); + sprintf(semName,"/semaphore_done%d",i); + sem_unlink(semName); + } + sem_close(gCdStreamSema); + sem_unlink("/semaphore_cd_stream"); + free(gChannelRequestQ.items); #else - sem_close(gpReadInfo[channel].pStartSemaphore); - sem_unlink("/semaphore_start"); - sem_close(gpReadInfo[channel].pDoneSemaphore); - sem_unlink("/semaphore_done"); + sem_close(gpReadInfo[channel].pStartSemaphore); + sprintf(semName,"/semaphore_start%d",channel); + sem_unlink(semName); + + sem_close(gpReadInfo[channel].pDoneSemaphore); + sprintf(semName,"/semaphore_done%d",channel); + sem_unlink(semName); #endif - free(gpReadInfo); + if (gpReadInfo) + free(gpReadInfo); + gpReadInfo = nil; pthread_exit(nil); } @@ -473,7 +485,7 @@ CdStreamAddImage(char const *path) char* real = casepath(path, false); if (real) { - gImgFiles[gNumImages] = open(real, _gdwCdStreamFlags); + gImgFiles[gNumImages] = open(real, _gdwCdStreamFlags); free(real); } } @@ -506,8 +518,10 @@ CdStreamGetImageName(int32 cd) void CdStreamRemoveImages(void) { - for ( int32 i = 0; i < gNumChannels; i++ ) + for ( int32 i = 0; i < gNumChannels; i++ ) { + flushStream[i] = 1; CdStreamSync(i); + } for ( int32 i = 0; i < gNumImages; i++ ) { diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index 635192ea..da678fd3 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -1052,7 +1052,11 @@ CFileLoader::Load2dEffect(const char *line) &effect->attractor.dir.z, &probability); effect->attractor.type = flags; +#ifdef FIX_BUGS + effect->attractor.probability = clamp(probability, 0, 255); +#else effect->attractor.probability = probability; +#endif break; case EFFECT_PED_ATTRACTOR: sscanf(line, "%d %f %f %f %d %d %d %d %d %d %f %f %f %f %f %f", diff --git a/src/core/FileMgr.cpp b/src/core/FileMgr.cpp index 4477a190..d3695cb4 100644 --- a/src/core/FileMgr.cpp +++ b/src/core/FileMgr.cpp @@ -142,17 +142,17 @@ static size_t myfread(void *buf, size_t elt, size_t n, int fd) { if(myfiles[fd].isText){ - char *p; + unsigned char *p; size_t i; int c; n *= elt; - p = (char*)buf; + p = (unsigned char*)buf; for(i = 0; i < n; i++){ c = myfgetc(fd); if(c == EOF) break; - *p++ = c; + *p++ = (unsigned char)c; } return i / elt; } @@ -163,12 +163,12 @@ static size_t myfwrite(void *buf, size_t elt, size_t n, int fd) { if(myfiles[fd].isText){ - char *p; + unsigned char *p; size_t i; int c; n *= elt; - p = (char*)buf; + p = (unsigned char*)buf; for(i = 0; i < n; i++){ c = *p++; myfputc(c, fd); diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index d296496e..1651f5b3 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -46,7 +46,11 @@ CStreamingInfo CStreaming::ms_endRequestedList; int32 CStreaming::ms_oldSectorX; int32 CStreaming::ms_oldSectorY; int32 CStreaming::ms_streamingBufferSize; +#ifndef ONE_THREAD_PER_CHANNEL int8 *CStreaming::ms_pStreamingBuffer[2]; +#else +int8 *CStreaming::ms_pStreamingBuffer[4]; +#endif size_t CStreaming::ms_memoryUsed; CStreamingChannel CStreaming::ms_channel[2]; int32 CStreaming::ms_channelError; @@ -197,6 +201,10 @@ CStreaming::Init2(void) ms_pStreamingBuffer[0] = (int8*)RwMallocAlign(ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE, CDSTREAM_SECTOR_SIZE); ms_streamingBufferSize /= 2; ms_pStreamingBuffer[1] = ms_pStreamingBuffer[0] + ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE; +#ifdef ONE_THREAD_PER_CHANNEL + ms_pStreamingBuffer[2] = (int8*)RwMallocAlign(ms_streamingBufferSize*2*CDSTREAM_SECTOR_SIZE, CDSTREAM_SECTOR_SIZE); + ms_pStreamingBuffer[3] = ms_pStreamingBuffer[2] + ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE; +#endif debug("Streaming buffer size is %d sectors", ms_streamingBufferSize); // PC only, figure out how much memory we got @@ -2196,6 +2204,110 @@ CStreaming::LoadRequestedModels(void) } } + +// Let's load models first, then process it. Unfortunately processing models are still single-threaded. +// Currently only supported on POSIX streamer. +#ifdef ONE_THREAD_PER_CHANNEL +void +CStreaming::LoadAllRequestedModels(bool priority) +{ + static bool bInsideLoadAll = false; + int imgOffset, streamId, status; + int i; + uint32 posn, size; + + if(bInsideLoadAll) + return; + bInsideLoadAll = true; + + FlushChannels(); + imgOffset = GetCdImageOffset(CdStreamGetLastPosn()); + + int streamIds[ARRAY_SIZE(ms_pStreamingBuffer)]; + int streamSizes[ARRAY_SIZE(ms_pStreamingBuffer)]; + int streamPoses[ARRAY_SIZE(ms_pStreamingBuffer)]; + bool first = true; + int processI = 0; + + while (true) { + // Enumerate files and start reading + for (int i=0; i (uint32)ms_streamingBufferSize) { + if (i + 1 == ARRAY_SIZE(ms_pStreamingBuffer)) + continue; + else if (!first && streamIds[i+1] != -1) + continue; + } else { + if (i != 0 && streamIds[i-1] != -1 && streamSizes[i-1] > (uint32)ms_streamingBufferSize) + continue; + } + ms_aInfoForModel[streamId].RemoveFromList(); + DecrementRef(streamId); + + streamIds[i] = streamId; + streamSizes[i] = size; + streamPoses[i] = posn; + CdStreamRead(i, ms_pStreamingBuffer[i], imgOffset+posn, size); + processI = i; + } else { + ms_aInfoForModel[streamId].RemoveFromList(); + DecrementRef(streamId); + + ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_LOADED; + streamIds[i] = -1; + } + } else + streamIds[i] = -1; + } + + first = false; + + // Now process + if (streamIds[processI] == -1) + break; + + // Try again on error + while (CdStreamSync(processI) != STREAM_NONE) { + CdStreamRead(processI, ms_pStreamingBuffer[processI], imgOffset+streamPoses[processI], streamSizes[processI]); + } + ms_aInfoForModel[streamIds[processI]].m_loadState = STREAMSTATE_READING; + + MakeSpaceFor(streamSizes[processI] * CDSTREAM_SECTOR_SIZE); + ConvertBufferToObject(ms_pStreamingBuffer[processI], streamIds[processI]); + if(ms_aInfoForModel[streamIds[processI]].m_loadState == STREAMSTATE_STARTED) + FinishLoadingLargeFile(ms_pStreamingBuffer[processI], streamIds[processI]); + + if(streamIds[processI] < STREAM_OFFSET_TXD){ + CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(streamIds[processI]); + if(mi->IsSimple()) + mi->m_alpha = 255; + } + streamIds[processI] = -1; + } + + ms_bLoadingBigModel = false; + for(i = 0; i < 4; i++){ + ms_channel[1].streamIds[i] = -1; + ms_channel[1].offsets[i] = -1; + } + ms_channel[1].state = CHANNELSTATE_IDLE; + bInsideLoadAll = false; +} +#else void CStreaming::LoadAllRequestedModels(bool priority) { @@ -2256,6 +2368,7 @@ CStreaming::LoadAllRequestedModels(bool priority) ms_channel[1].state = CHANNELSTATE_IDLE; bInsideLoadAll = false; } +#endif void CStreaming::FlushChannels(void) @@ -2287,6 +2400,14 @@ CStreaming::FlushRequestList(void) next = si->m_next; RemoveModel(si - ms_aInfoForModel); } +#ifndef _WIN32 + if(ms_channel[0].state == CHANNELSTATE_READING) { + flushStream[0] = 1; + } + if(ms_channel[1].state == CHANNELSTATE_READING) { + flushStream[1] = 1; + } +#endif FlushChannels(); } diff --git a/src/core/common.h b/src/core/common.h index 16d32b32..c4c133fa 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -106,7 +106,7 @@ typedef uint16_t wchar; inline uint32 dpb(uint32 b, uint32 p, uint32 s, uint32 w) { uint32 m = MASK(p,s); - return w & ~m | b<

Date: Sat, 3 Oct 2020 16:17:24 +0200 Subject: Fix unsigned comparison in CStreaming::MakeSpaceFor(int32 size) --- src/core/Streaming.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index 1651f5b3..ddde4664 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -2936,10 +2936,15 @@ CStreaming::DeleteRwObjectsNotInFrustumInSectorList(CPtrList &list, size_t mem) void CStreaming::MakeSpaceFor(int32 size) { - // BUG: ms_memoryAvailable can be uninitialized - // the code still happens to work in that case because ms_memoryAvailable is unsigned - // but it's not nice.... - +#ifdef FIX_BUGS +#define MB (1024 * 1024) + if(ms_memoryAvailable == 0) { + extern size_t _dwMemAvailPhys; + ms_memoryAvailable = (_dwMemAvailPhys - 10 * MB) / 2; + if(ms_memoryAvailable < 65 * MB) ms_memoryAvailable = 65 * MB; + } +#undef MB +#endif while(ms_memoryUsed >= ms_memoryAvailable - size) if(!RemoveLeastUsedModel(STREAMFLAGS_20)){ DeleteRwObjectsBehindCamera(ms_memoryAvailable - size); -- cgit v1.2.3 From 73a3e9d5bb3a12812926b487a17c36dd4381ebc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Thu, 8 Oct 2020 21:46:00 +0300 Subject: Fixes, some thanks to ASan --- src/core/Pad.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index aa6e5cc8..b723eb1d 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -3209,7 +3209,7 @@ int16 CPad::SniperModeLookLeftRight(void) if ( Abs(axis) > Abs(dpad) ) { if ( Abs(axis) > 35.0f ) { - return (axis > 0.f ? axis - 35.f : axis + 35.f) * 1.3763441f; + return (axis > 0.f ? axis - 35.f : axis + 35.f) * (128.f / (128 - 35)); } else { return 0; } @@ -3231,7 +3231,7 @@ int16 CPad::SniperModeLookUpDown(void) if ( Abs(axis) > Abs(dpad) ) { if ( Abs(axis) > 35.0f ) { - return (axis > 0.f ? axis - 35.f : axis + 35.f) * 1.3763441f; + return (axis > 0.f ? axis - 35.f : axis + 35.f) * (128.f / (128 - 35)); } else { return 0; } @@ -3573,4 +3573,4 @@ void CPad::FixPadsAfterSave(void) bObsoleteControllerMessage = false; GetPad(0)->Phase = 0; } -} \ No newline at end of file +} -- cgit v1.2.3 From ed82c55475f4cda6d1ed0644ea1609e08b5b0e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Fri, 9 Oct 2020 02:19:49 +0300 Subject: Fix POSIX streaming --- src/core/CdStreamPosix.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index 04a5de4b..a6ab62bc 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -240,14 +240,17 @@ CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size) CdReadInfo *pChannel = &gpReadInfo[channel]; ASSERT( pChannel != nil ); - pChannel->hFile = hImage - 1; if ( pChannel->nSectorsToRead != 0 || pChannel->bReading ) { + if (pChannel->nSectorOffset == _GET_OFFSET(offset) && pChannel->nSectorsToRead >= size) + return STREAM_SUCCESS; + flushStream[channel] = 1; CdStreamSync(channel); //return STREAM_NONE; } + pChannel->hFile = hImage - 1; pChannel->nStatus = STREAM_NONE; pChannel->nSectorOffset = _GET_OFFSET(offset); pChannel->nSectorsToRead = size; @@ -316,7 +319,7 @@ CdStreamSync(int32 channel) if (flushStream[channel]) { #ifdef ONE_THREAD_PER_CHANNEL pChannel->nSectorsToRead = 0; - pthread_kill(pChannel->pChannelThread, SIGINT); + pthread_kill(pChannel->pChannelThread, SIGUSR1); if (pChannel->bReading) { pChannel->bLocked = true; sem_wait(pChannel->pDoneSemaphore); @@ -325,8 +328,9 @@ CdStreamSync(int32 channel) pChannel->nSectorsToRead = 0; if (pChannel->bReading) { pChannel->bLocked = true; - pthread_kill(_gCdStreamThread, SIGINT); + pthread_kill(_gCdStreamThread, SIGUSR1); sem_wait(pChannel->pDoneSemaphore); + } #endif pChannel->bReading = false; -- cgit v1.2.3