diff options
-rw-r--r-- | src/CMakeLists.txt | 15 | ||||
-rw-r--r-- | src/collision/Collision.cpp | 12 | ||||
-rw-r--r-- | src/core/ControllerConfig.cpp | 7 | ||||
-rw-r--r-- | src/modelinfo/BaseModelInfo.cpp | 2 | ||||
-rw-r--r-- | src/modelinfo/SimpleModelInfo.cpp | 3 | ||||
-rw-r--r-- | src/modelinfo/VehicleModelInfo.cpp | 32 | ||||
-rw-r--r-- | src/peds/PedAI.cpp | 8 | ||||
-rw-r--r-- | src/rw/VisibilityPlugins.cpp | 19 | ||||
-rw-r--r-- | src/rw/VisibilityPlugins.h | 1 |
9 files changed, 72 insertions, 27 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ad72eb56..f3d51b06 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -79,6 +79,21 @@ endif() target_compile_definitions(${EXECUTABLE} PRIVATE ) +option(${PROJECT}_WITH_SANITIZERS "Use UB sanitizers (better crash log)" OFF) +option(${PROJECT}_WITH_ASAN "Use Address sanitizer (better crash log)" OFF) + +if(${PROJECT}_WITH_SANITIZERS) + target_compile_options(${EXECUTABLE} PUBLIC + -fsanitize=undefined,float-divide-by-zero,integer,implicit-conversion,implicit-integer-truncation,implicit-integer-arithmetic-value-change,local-bounds,nullability + -g3 -fno-omit-frame-pointer) + target_link_options(${EXECUTABLE} PUBLIC -fsanitize=undefined,float-divide-by-zero,integer,implicit-conversion,implicit-integer-truncation,implicit-integer-arithmetic-value-change,local-bounds,nullability) +endif() + +if(${PROJECT}_WITH_ASAN) + target_compile_options(${EXECUTABLE} PUBLIC -fsanitize=address -g3 -fno-omit-frame-pointer) + target_link_options(${EXECUTABLE} PUBLIC -fsanitize=address) +endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") target_compile_options(${EXECUTABLE} PRIVATE diff --git a/src/collision/Collision.cpp b/src/collision/Collision.cpp index 45a15628..bead5183 100644 --- a/src/collision/Collision.cpp +++ b/src/collision/Collision.cpp @@ -2099,12 +2099,12 @@ CCollision::DistToLine(const CVector *l0, const CVector *l1, const CVector *poin float dot = DotProduct(*point - *l0, *l1 - *l0); // Between 0 and len we're above the line. // if not, calculate distance to endpoint - if(dot <= 0.0f) - return (*point - *l0).Magnitude(); - if(dot >= lensq) - return (*point - *l1).Magnitude(); + if(dot <= 0.0f) return (*point - *l0).Magnitude(); + if(dot >= lensq) return (*point - *l1).Magnitude(); // distance to line - return Sqrt((*point - *l0).MagnitudeSqr() - dot*dot/lensq); + float distSqr = (*point - *l0).MagnitudeSqr() - dot * dot / lensq; + if(distSqr <= 0.f) return 0.f; + return Sqrt(distSqr); } // same as above but also return the point on the line @@ -2571,4 +2571,4 @@ CCollision::DrawColModel_Coloured(const CMatrix &mat, const CColModel &colModel, RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); -}
\ No newline at end of file +} diff --git a/src/core/ControllerConfig.cpp b/src/core/ControllerConfig.cpp index 7e5e4c16..23e86a79 100644 --- a/src/core/ControllerConfig.cpp +++ b/src/core/ControllerConfig.cpp @@ -2755,9 +2755,10 @@ wchar *CControllerConfigManager::GetButtonComboText(e_ControllerAction action) void CControllerConfigManager::SetControllerKeyAssociatedWithAction(e_ControllerAction action, int32 key, eControllerType type) { ResetSettingOrder(action); + int numOfSettings = GetNumOfSettingsForAction(action); m_aSettings[action][type].m_Key = key; - m_aSettings[action][type].m_ContSetOrder = GetNumOfSettingsForAction(action) + 1; + m_aSettings[action][type].m_ContSetOrder = numOfSettings + 1; } int32 CControllerConfigManager::GetMouseButtonAssociatedWithAction(e_ControllerAction action) @@ -2767,8 +2768,10 @@ int32 CControllerConfigManager::GetMouseButtonAssociatedWithAction(e_ControllerA void CControllerConfigManager::SetMouseButtonAssociatedWithAction(e_ControllerAction action, int32 button) { + int numOfSettings = GetNumOfSettingsForAction(action); + m_aSettings[action][MOUSE].m_Key = button; - m_aSettings[action][MOUSE].m_ContSetOrder = GetNumOfSettingsForAction(action) + 1; + m_aSettings[action][MOUSE].m_ContSetOrder = numOfSettings + 1; } void CControllerConfigManager::ResetSettingOrder(e_ControllerAction action) diff --git a/src/modelinfo/BaseModelInfo.cpp b/src/modelinfo/BaseModelInfo.cpp index d0f868fa..765469b4 100644 --- a/src/modelinfo/BaseModelInfo.cpp +++ b/src/modelinfo/BaseModelInfo.cpp @@ -57,7 +57,7 @@ void CBaseModelInfo::SetTexDictionary(const char *name) { int slot = CTxdStore::FindTxdSlot(name); - if(slot < 0) + if(slot == -1) slot = CTxdStore::AddTxdSlot(name); m_txdSlot = slot; } diff --git a/src/modelinfo/SimpleModelInfo.cpp b/src/modelinfo/SimpleModelInfo.cpp index 8da3a86a..18eb7e5f 100644 --- a/src/modelinfo/SimpleModelInfo.cpp +++ b/src/modelinfo/SimpleModelInfo.cpp @@ -2,12 +2,11 @@ #include "General.h" #include "Camera.h" +#include "Renderer.h" #include "ModelInfo.h" #include "AnimManager.h" #include "custompipes.h" -#define LOD_DISTANCE (300.0f) - void CSimpleModelInfo::DeleteRwObject(void) { diff --git a/src/modelinfo/VehicleModelInfo.cpp b/src/modelinfo/VehicleModelInfo.cpp index dfd6519b..d31962ce 100644 --- a/src/modelinfo/VehicleModelInfo.cpp +++ b/src/modelinfo/VehicleModelInfo.cpp @@ -339,7 +339,7 @@ CVehicleModelInfo::SetAtomicRendererCB(RpAtomic *atomic, void *data) }else if(strstr(name, "_lo")){ RpClumpRemoveAtomic(clump, atomic); RpAtomicDestroy(atomic); - return atomic; // BUG: not done by gta + return atomic; // BUG: nil in gta }else if(strstr(name, "_vlo")) CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleReallyLowDetailCB); else @@ -402,21 +402,31 @@ CVehicleModelInfo::SetAtomicRendererCB_Boat(RpAtomic *atomic, void *data) { RpClump *clump; char *name; + bool alpha; clump = (RpClump*)data; name = GetFrameNodeName(RpAtomicGetFrame(atomic)); + alpha = false; + RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), HasAlphaMaterialCB, &alpha); if(strcmp(name, "boat_hi") == 0 || !CGeneral::faststrncmp(name, "extra", 5)) CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailCB_Boat); - else if(strstr(name, "_hi")) - CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailCB); - else if(strstr(name, "_lo")){ + else if(strstr(name, "_hi")){ + if(alpha) + CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_Boat); + else + CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailCB); + }else if(strstr(name, "_lo")){ RpClumpRemoveAtomic(clump, atomic); RpAtomicDestroy(atomic); return atomic; // BUG: not done by gta }else if(strstr(name, "_vlo")) - CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleReallyLowDetailCB_BigVehicle); - else - CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil); + CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleLoDetailCB_Boat); + else{ + if(alpha) + CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_Boat); + else + CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil); + } HideDamagedAtomicCB(atomic, nil); return atomic; } @@ -459,7 +469,7 @@ CVehicleModelInfo::SetAtomicRendererCB_RealHeli(RpAtomic *atomic, void *data) }else if(strstr(name, "_lo")){ RpClumpRemoveAtomic(clump, atomic); RpAtomicDestroy(atomic); - return atomic; // BUG: not done by gta + return atomic; // BUG: nil in gta }else if(strstr(name, "_vlo")) CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleReallyLowDetailCB); else @@ -629,9 +639,9 @@ CVehicleModelInfo::SetVehicleComponentFlags(RwFrame *frame, uint32 flags) SETFLAGS(ATOMIC_FLAG_FRONT); else if(flags & VEHICLE_FLAG_REAR && (handling->Flags & HANDLING_IS_VAN || (flags & (VEHICLE_FLAG_LEFT|VEHICLE_FLAG_RIGHT)) == 0)) SETFLAGS(ATOMIC_FLAG_REAR); - if(flags & VEHICLE_FLAG_LEFT) + else if(flags & VEHICLE_FLAG_LEFT) SETFLAGS(ATOMIC_FLAG_LEFT); - if(flags & VEHICLE_FLAG_RIGHT) + else if(flags & VEHICLE_FLAG_RIGHT) SETFLAGS(ATOMIC_FLAG_RIGHT); if(flags & VEHICLE_FLAG_REARDOOR) @@ -796,7 +806,7 @@ struct editableMatCBData RpMaterial* CVehicleModelInfo::GetEditableMaterialListCB(RpMaterial *material, void *data) { - static RwRGBA white = { 255, 255, 255, 255 }; + RwRGBA white = { 255, 255, 255, 255 }; const RwRGBA *col; editableMatCBData *cbdata; diff --git a/src/peds/PedAI.cpp b/src/peds/PedAI.cpp index c6415c7e..9802f968 100644 --- a/src/peds/PedAI.cpp +++ b/src/peds/PedAI.cpp @@ -3297,6 +3297,7 @@ void CPed::LineUpPedWithCar(PedLineUpPhase phase) { bool vehIsUpsideDown = false; + bool stillGettingInOut = false; int vehAnim; float seatPosMult = 0.0f; float currentZ; @@ -3549,8 +3550,8 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) if (m_pVehicleAnim && vehAnim != ANIM_VAN_GETIN_L && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE && vehAnim != ANIM_VAN_GETIN) { neededPos.z = autoZPos.z; m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - } else if (neededPos.z <= currentZ && m_pVehicleAnim && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE) { - adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); + } else if (neededPos.z < currentZ && m_pVehicleAnim && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE) { + adjustedTimeStep = Max(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = currentZ - (currentZ - neededPos.z) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep); @@ -3568,7 +3569,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) if (m_pVehicleAnim && (vehAnim == ANIM_CAR_GETIN_RHS || vehAnim == ANIM_CAR_GETIN_LOW_RHS || vehAnim == ANIM_CAR_GETIN_LHS || vehAnim == ANIM_CAR_GETIN_LOW_LHS || vehAnim == ANIM_CAR_QJACK || vehAnim == ANIM_VAN_GETIN_L || vehAnim == ANIM_VAN_GETIN)) { - adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); + adjustedTimeStep = Max(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = (neededPos.z - currentZ) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep) + currentZ; @@ -3580,7 +3581,6 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) } } - bool stillGettingInOut = false; if (CTimer::GetTimeInMilliseconds() < m_nPedStateTimer) stillGettingInOut = veh->m_vehType != VEHICLE_TYPE_BOAT || bOnBoat; diff --git a/src/rw/VisibilityPlugins.cpp b/src/rw/VisibilityPlugins.cpp index 871ef287..bdde5e33 100644 --- a/src/rw/VisibilityPlugins.cpp +++ b/src/rw/VisibilityPlugins.cpp @@ -454,7 +454,7 @@ CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_BigVehicle(RpAtomic *atomic) RpAtomic* CVisibilityPlugins::RenderVehicleHiDetailCB_Boat(RpAtomic *atomic) { - if(DistToCameraSq < ms_bigVehicleLod1Dist) + if(DistToCameraSq < ms_vehicleLod0Dist) RENDERCALLBACK(atomic); return atomic; } @@ -473,6 +473,23 @@ CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_Boat(RpAtomic *atomic) } RpAtomic* +CVisibilityPlugins::RenderVehicleLoDetailCB_Boat(RpAtomic *atomic) +{ + RpClump *clump; + int32 alpha; + + clump = RpAtomicGetClump(atomic); + if(DistToCameraSq >= ms_vehicleLod0Dist){ + alpha = GetClumpAlpha(clump); + if(alpha == 255) + RENDERCALLBACK(atomic); + else + RenderAlphaAtomic(atomic, alpha); + } + return atomic; +} + +RpAtomic* CVisibilityPlugins::RenderVehicleLowDetailCB_BigVehicle(RpAtomic *atomic) { RwFrame *clumpframe; diff --git a/src/rw/VisibilityPlugins.h b/src/rw/VisibilityPlugins.h index 13365c7a..9cdbc0c7 100644 --- a/src/rw/VisibilityPlugins.h +++ b/src/rw/VisibilityPlugins.h @@ -61,6 +61,7 @@ public: static RpAtomic *RenderVehicleHiDetailAlphaCB_BigVehicle(RpAtomic *atomic); static RpAtomic *RenderVehicleHiDetailCB_Boat(RpAtomic *atomic); static RpAtomic *RenderVehicleHiDetailAlphaCB_Boat(RpAtomic *atomic); + static RpAtomic *RenderVehicleLoDetailCB_Boat(RpAtomic *atomic); static RpAtomic *RenderVehicleLowDetailCB_BigVehicle(RpAtomic *atomic); static RpAtomic *RenderVehicleLowDetailAlphaCB_BigVehicle(RpAtomic *atomic); static RpAtomic *RenderVehicleReallyLowDetailCB(RpAtomic *atomic); |