Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Jan 1, 2025
1 parent 747819d commit 9ed80c8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 38 deletions.
9 changes: 5 additions & 4 deletions Client/mods/deathmatch/logic/CClientPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,9 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

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

void SetHasSyncedAnim(bool synced) noexcept { m_hasSyncedAnim = synced; };
bool HasSyncedAnim() const noexcept { return m_hasSyncedAnim; };
void SetHasSyncedAnim(bool synced) noexcept { m_hasSyncedAnim = synced; }
bool HasSyncedAnim() const noexcept { return m_hasSyncedAnim; }

protected:
// This constructor is for peds managed by a player. These are unknown to the ped manager.
CClientPed(CClientManager* pManager, unsigned long ulModelID, ElementID ID, bool bIsLocalPlayer);
Expand Down Expand Up @@ -792,6 +793,6 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

std::shared_ptr<CClientModel> m_clientModel;

bool m_hasSyncedAnim;
bool m_animationOverridedByClient;
bool m_hasSyncedAnim{};
bool m_animationOverridedByClient{};
};
23 changes: 4 additions & 19 deletions Server/mods/deathmatch/logic/CPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ enum eBone

struct SPlayerAnimData
{
std::string blockName;
std::string animName;
std::string blockName{};
std::string animName{};
int time{-1};
bool loop{true};
bool updatePosition{true};
Expand All @@ -120,22 +120,7 @@ struct SPlayerAnimData
float progress{0.0f};
float speed{1.0f};

SPlayerAnimData() = default;

SPlayerAnimData(const std::string& block, const std::string& anim, int time, bool loop, bool updatePos, bool interrupt, bool freeze, int blend,
bool taskRestore, std::int64_t tick)
: blockName(block),
animName(anim),
time(time),
loop(loop),
updatePosition(updatePos),
interruptable(interrupt),
freezeLastFrame(freeze),
blendTime(blend),
taskToBeRestoredOnAnimEnd(taskRestore),
startedTick(tick),
progress(0.0f),
speed(1.0f){};
bool IsAnimating() const noexcept { return !blockName.empty() && !animName.empty(); }
};

class CWeapon
Expand Down Expand Up @@ -356,7 +341,7 @@ class CPed : public CElement
bool m_bFrozen;
bool m_bStealthAiming;
CVehicle* m_pJackingVehicle;
SPlayerAnimData m_animData;
SPlayerAnimData m_animData{};

CVehicle* m_pVehicle;
unsigned int m_uiVehicleSeat;
Expand Down
11 changes: 11 additions & 0 deletions Server/mods/deathmatch/logic/CPedSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,20 @@ void CPedSync::OverrideSyncer(CPed* pPed, CPlayer* pPlayer, bool bPersist)

void CPedSync::UpdateAllSyncer()
{
auto currentTick = GetTickCount64_();

// Update all the ped's sync states
for (auto iter = m_pPedManager->IterBegin(); iter != m_pPedManager->IterEnd(); iter++)
{
// Has the duration of the ped's animation already elapsed?
const SPlayerAnimData& animData = (*iter)->GetAnimationData();
if (animData.IsAnimating())
{
float deltaTime = currentTick - animData.startedTick;
if (!animData.freezeLastFrame && animData.time > 0 && deltaTime >= animData.time)
(*iter)->SetAnimationData({});
}

// It is a ped, yet not a player
if (IS_PED(*iter) && !IS_PLAYER(*iter))
UpdateSyncer(*iter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4366,7 +4366,7 @@ bool CStaticFunctionDefinitions::SetPedAnimation(CElement* pElement, const SStri
pPed->SetChoking(false);

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

BitStream.pBitStream->WriteString<unsigned char>(blockName);
BitStream.pBitStream->WriteString<unsigned char>(animName);
Expand Down
12 changes: 2 additions & 10 deletions Server/mods/deathmatch/logic/packets/CEntityAddPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,16 +983,7 @@ bool CEntityAddPacket::Write(NetBitStreamInterface& BitStream) const
const SPlayerAnimData& animData = pPed->GetAnimationData();

// Contains animation data?
bool animRunning = !animData.blockName.empty() && !animData.animName.empty();

// Is animation still running?
float deltaTime = GetTickCount64_() - animData.startedTick;
if (!animData.freezeLastFrame && animData.time > 0 && deltaTime >= animData.time)
{
animRunning = false;
pPed->SetAnimationData({});
}

bool animRunning = animData.IsAnimating();
BitStream.WriteBit(animRunning);

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

// Write progress & speed
float deltaTime = GetTickCount64_() - animData.startedTick;
BitStream.Write((deltaTime / animData.time) * animData.speed);
BitStream.Write(animData.speed);
}
Expand Down
8 changes: 4 additions & 4 deletions Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,6 @@ enum class eBitStreamVersion : unsigned short
// 2024-06-16
PedSync_Revision,

// Ped animations synchronization
// 2024-06-29
AnimationsSync,

// Add "extendedwatercannons" to setWorldSpecialPropertyEnabled
// 2024-06-30
WorldSpecialProperty_TunnelWeatherBlend,
Expand Down Expand Up @@ -596,6 +592,10 @@ enum class eBitStreamVersion : unsigned short
// 2024-30-12
SetElementOnFire,

// Ped animations synchronization
// 2025-01-01
AnimationsSync,

// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
// Make sure you only add things above this comment.
Next,
Expand Down

0 comments on commit 9ed80c8

Please sign in to comment.