Skip to content

Commit 9ed80c8

Browse files
committed
Review
1 parent 747819d commit 9ed80c8

File tree

6 files changed

+27
-38
lines changed

6 files changed

+27
-38
lines changed

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,9 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
552552

553553
std::unique_ptr<CAnimBlendAssociation> GetAnimAssociation(CAnimBlendHierarchySAInterface* pHierarchyInterface);
554554

555-
void SetHasSyncedAnim(bool synced) noexcept { m_hasSyncedAnim = synced; };
556-
bool HasSyncedAnim() const noexcept { return m_hasSyncedAnim; };
555+
void SetHasSyncedAnim(bool synced) noexcept { m_hasSyncedAnim = synced; }
556+
bool HasSyncedAnim() const noexcept { return m_hasSyncedAnim; }
557+
557558
protected:
558559
// This constructor is for peds managed by a player. These are unknown to the ped manager.
559560
CClientPed(CClientManager* pManager, unsigned long ulModelID, ElementID ID, bool bIsLocalPlayer);
@@ -792,6 +793,6 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
792793

793794
std::shared_ptr<CClientModel> m_clientModel;
794795

795-
bool m_hasSyncedAnim;
796-
bool m_animationOverridedByClient;
796+
bool m_hasSyncedAnim{};
797+
bool m_animationOverridedByClient{};
797798
};

Server/mods/deathmatch/logic/CPed.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ enum eBone
105105

106106
struct SPlayerAnimData
107107
{
108-
std::string blockName;
109-
std::string animName;
108+
std::string blockName{};
109+
std::string animName{};
110110
int time{-1};
111111
bool loop{true};
112112
bool updatePosition{true};
@@ -120,22 +120,7 @@ struct SPlayerAnimData
120120
float progress{0.0f};
121121
float speed{1.0f};
122122

123-
SPlayerAnimData() = default;
124-
125-
SPlayerAnimData(const std::string& block, const std::string& anim, int time, bool loop, bool updatePos, bool interrupt, bool freeze, int blend,
126-
bool taskRestore, std::int64_t tick)
127-
: blockName(block),
128-
animName(anim),
129-
time(time),
130-
loop(loop),
131-
updatePosition(updatePos),
132-
interruptable(interrupt),
133-
freezeLastFrame(freeze),
134-
blendTime(blend),
135-
taskToBeRestoredOnAnimEnd(taskRestore),
136-
startedTick(tick),
137-
progress(0.0f),
138-
speed(1.0f){};
123+
bool IsAnimating() const noexcept { return !blockName.empty() && !animName.empty(); }
139124
};
140125

141126
class CWeapon
@@ -356,7 +341,7 @@ class CPed : public CElement
356341
bool m_bFrozen;
357342
bool m_bStealthAiming;
358343
CVehicle* m_pJackingVehicle;
359-
SPlayerAnimData m_animData;
344+
SPlayerAnimData m_animData{};
360345

361346
CVehicle* m_pVehicle;
362347
unsigned int m_uiVehicleSeat;

Server/mods/deathmatch/logic/CPedSync.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,20 @@ void CPedSync::OverrideSyncer(CPed* pPed, CPlayer* pPlayer, bool bPersist)
8282

8383
void CPedSync::UpdateAllSyncer()
8484
{
85+
auto currentTick = GetTickCount64_();
86+
8587
// Update all the ped's sync states
8688
for (auto iter = m_pPedManager->IterBegin(); iter != m_pPedManager->IterEnd(); iter++)
8789
{
90+
// Has the duration of the ped's animation already elapsed?
91+
const SPlayerAnimData& animData = (*iter)->GetAnimationData();
92+
if (animData.IsAnimating())
93+
{
94+
float deltaTime = currentTick - animData.startedTick;
95+
if (!animData.freezeLastFrame && animData.time > 0 && deltaTime >= animData.time)
96+
(*iter)->SetAnimationData({});
97+
}
98+
8899
// It is a ped, yet not a player
89100
if (IS_PED(*iter) && !IS_PLAYER(*iter))
90101
UpdateSyncer(*iter);

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4366,7 +4366,7 @@ bool CStaticFunctionDefinitions::SetPedAnimation(CElement* pElement, const SStri
43664366
pPed->SetChoking(false);
43674367

43684368
// Store anim data
4369-
pPed->SetAnimationData({blockName, animName, iTime, bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame, iBlend, bTaskToBeRestoredOnAnimEnd, GetTickCount64_()});
4369+
pPed->SetAnimationData(SPlayerAnimData{blockName, animName, iTime, bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame, iBlend, bTaskToBeRestoredOnAnimEnd, GetTickCount64_()});
43704370

43714371
BitStream.pBitStream->WriteString<unsigned char>(blockName);
43724372
BitStream.pBitStream->WriteString<unsigned char>(animName);

Server/mods/deathmatch/logic/packets/CEntityAddPacket.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -983,16 +983,7 @@ bool CEntityAddPacket::Write(NetBitStreamInterface& BitStream) const
983983
const SPlayerAnimData& animData = pPed->GetAnimationData();
984984

985985
// Contains animation data?
986-
bool animRunning = !animData.blockName.empty() && !animData.animName.empty();
987-
988-
// Is animation still running?
989-
float deltaTime = GetTickCount64_() - animData.startedTick;
990-
if (!animData.freezeLastFrame && animData.time > 0 && deltaTime >= animData.time)
991-
{
992-
animRunning = false;
993-
pPed->SetAnimationData({});
994-
}
995-
986+
bool animRunning = animData.IsAnimating();
996987
BitStream.WriteBit(animRunning);
997988

998989
if (animRunning)
@@ -1008,6 +999,7 @@ bool CEntityAddPacket::Write(NetBitStreamInterface& BitStream) const
1008999
BitStream.WriteBit(animData.taskToBeRestoredOnAnimEnd);
10091000

10101001
// Write progress & speed
1002+
float deltaTime = GetTickCount64_() - animData.startedTick;
10111003
BitStream.Write((deltaTime / animData.time) * animData.speed);
10121004
BitStream.Write(animData.speed);
10131005
}

Shared/sdk/net/bitstream.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,6 @@ enum class eBitStreamVersion : unsigned short
556556
// 2024-06-16
557557
PedSync_Revision,
558558

559-
// Ped animations synchronization
560-
// 2024-06-29
561-
AnimationsSync,
562-
563559
// Add "extendedwatercannons" to setWorldSpecialPropertyEnabled
564560
// 2024-06-30
565561
WorldSpecialProperty_TunnelWeatherBlend,
@@ -596,6 +592,10 @@ enum class eBitStreamVersion : unsigned short
596592
// 2024-30-12
597593
SetElementOnFire,
598594

595+
// Ped animations synchronization
596+
// 2025-01-01
597+
AnimationsSync,
598+
599599
// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
600600
// Make sure you only add things above this comment.
601601
Next,

0 commit comments

Comments
 (0)