Skip to content

Commit 80a6056

Browse files
committed
Better way of floats comparison
1 parent d318adf commit 80a6056

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct SLastSyncedPedData
105105
CVector vPosition;
106106
CVector vVelocity;
107107
float fRotation;
108-
float cameraRotation;
108+
float cameraRotation{};
109109
bool bOnFire;
110110
bool bIsInWater;
111111
bool isReloadingWeapon;

Client/mods/deathmatch/logic/CPedSync.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void CPedSync::WritePedInformation(NetBitStreamInterface* pBitStream, CClientPed
335335
ucFlags |= 0x80;
336336

337337
std::uint8_t flags2{};
338-
if (pPed->GetCameraRotation() != pPed->m_LastSyncedData->cameraRotation && pBitStream->Can(eBitStreamVersion::PedSync_CameraRotation))
338+
if (!IsNearlyEqual(pPed->GetCameraRotation(), pPed->m_LastSyncedData->cameraRotation) && pBitStream->Can(eBitStreamVersion::PedSync_CameraRotation))
339339
flags2 |= 0x01;
340340

341341
// Do we really have to sync this ped?

Shared/sdk/SharedUtil.Math.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,9 @@ namespace SharedUtil
113113
{
114114
return std::uniform_real_distribution<float>{minRange, maxRange}(randomEngine);
115115
}
116+
117+
inline bool IsNearlyEqual(float a, float b, float epsilon = std::numeric_limits<float>().epsilon()) noexcept
118+
{
119+
return std::fabs(a - b) <= epsilon;
120+
}
116121
} // namespace SharedUtil

0 commit comments

Comments
 (0)