From 6be526924dd248d8bffa2f22de3f99727d4a3ea7 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Thu, 14 Jul 2016 19:52:14 +0300 Subject: [PATCH] Add the option to specify a header and payload when tracking player position changes. --- source/Core.hpp | 5 +++++ source/CoreEvents.cpp | 12 ++++++++++-- source/CoreUtils.cpp | 3 +++ source/Entity/Player.cpp | 31 +++++++++++++++++++++++++++++++ source/Entity/Player.hpp | 17 ++++++++++++++++- 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/source/Core.hpp b/source/Core.hpp index 8dae439b..3594f259 100644 --- a/source/Core.hpp +++ b/source/Core.hpp @@ -222,6 +222,11 @@ protected: // ---------------------------------------------------------------------------------------- SQInteger mTrackPosition; + SQInteger mTrackHeading; + + // ---------------------------------------------------------------------------------------- + Int32 mTrackPositionHeader; + Object mTrackPositionPayload; // ---------------------------------------------------------------------------------------- Int32 mLastWeapon; diff --git a/source/CoreEvents.cpp b/source/CoreEvents.cpp index 2dc6d11f..7ef82159 100644 --- a/source/CoreEvents.cpp +++ b/source/CoreEvents.cpp @@ -712,7 +712,7 @@ void Core::EmitPlayerHeading(Int32 player_id, Float32 old_heading, Float32 new_h void Core::EmitPlayerPosition(Int32 player_id) { PlayerInst & _player = m_Players.at(player_id); - Emit(_player.mOnPosition); + Emit(_player.mOnPosition, _player.mTrackPositionHeader, _player.mTrackPositionPayload); Emit(mOnPlayerPosition, _player.mObj); } @@ -909,7 +909,15 @@ void Core::EmitPlayerUpdate(Int32 player_id, vcmpPlayerUpdate update_type) if (!EpsEq(heading, inst.mLastHeading)) { // Trigger the event specific to this change - EmitPlayerHeading(player_id, inst.mLastHeading, heading); + if (inst.mTrackHeading != 0) + { + EmitPlayerHeading(player_id, inst.mLastHeading, heading); + // Should we decrease the tracked position changes? + if (inst.mTrackHeading) + { + --inst.mTrackHeading; + } + } // Update the tracked value inst.mLastHeading = heading; } diff --git a/source/CoreUtils.cpp b/source/CoreUtils.cpp index f7a23316..86c0cd80 100644 --- a/source/CoreUtils.cpp +++ b/source/CoreUtils.cpp @@ -54,6 +54,9 @@ void Core::ResetInst(PlayerInst & inst) inst.mID = -1; inst.mFlags = ENF_DEFAULT; inst.mTrackPosition = 0; + inst.mTrackHeading = 0; + inst.mTrackPositionHeader = 0; + inst.mTrackPositionPayload.Release(); inst.mLastWeapon = -1; inst.mLastHealth = 0.0; inst.mLastArmour = 0.0; diff --git a/source/Entity/Player.cpp b/source/Entity/Player.cpp index 49657669..cf46c275 100644 --- a/source/Entity/Player.cpp +++ b/source/Entity/Player.cpp @@ -1311,6 +1311,35 @@ void CPlayer::SetTrackPosition(SQInteger num) const Core::Get().GetPlayer(m_ID).mTrackPosition = num; } +// ------------------------------------------------------------------------------------------------ +void CPlayer::SetTrackPositionEx(SQInteger num, Int32 header, const Object & payload) const +{ + // Validate the managed identifier + Validate(); + // Assign the requested information + Core::Get().GetPlayer(m_ID).mTrackPosition = num; + Core::Get().GetPlayer(m_ID).mTrackPositionHeader = header; + Core::Get().GetPlayer(m_ID).mTrackPositionPayload = payload; +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CPlayer::GetTrackHeading() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetPlayer(m_ID).mTrackHeading; +} + +// ------------------------------------------------------------------------------------------------ +void CPlayer::SetTrackHeading(SQInteger num) const +{ + // Validate the managed identifier + Validate(); + // Assign the requested information + Core::Get().GetPlayer(m_ID).mTrackHeading = num; +} + // ------------------------------------------------------------------------------------------------ Int32 CPlayer::GetLastWeapon() const { @@ -2223,6 +2252,7 @@ void Register_CPlayer(HSQUIRRELVM vm) .Prop(_SC("Spec"), &CPlayer::GetSpectator, &CPlayer::SetSpectator) .Prop(_SC("Authority"), &CPlayer::GetAuthority, &CPlayer::SetAuthority) .Prop(_SC("TrackPosition"), &CPlayer::GetTrackPosition, &CPlayer::SetTrackPosition) + .Prop(_SC("TrackHeading"), &CPlayer::GetTrackHeading, &CPlayer::SetTrackHeading) .Prop(_SC("LastWeapon"), &CPlayer::GetLastWeapon) .Prop(_SC("LastHealth"), &CPlayer::GetLastHealth) .Prop(_SC("LastArmor"), &CPlayer::GetLastArmour) @@ -2268,6 +2298,7 @@ void Register_CPlayer(HSQUIRRELVM vm) .Func(_SC("PlaySound"), &CPlayer::PlaySound) .Func(_SC("GetMsgPrefix"), &CPlayer::GetMessagePrefix) .Func(_SC("SetMsgPrefix"), &CPlayer::SetMessagePrefix) + .Func(_SC("SetTrackPosition"), &CPlayer::SetTrackPositionEx) .Func(_SC("StreamByte"), &CPlayer::StreamByte) .Func(_SC("StreamShort"), &CPlayer::StreamShort) .Func(_SC("StreamInt"), &CPlayer::StreamInt) diff --git a/source/Entity/Player.hpp b/source/Entity/Player.hpp index 1a8e7d6e..e3ee61a4 100644 --- a/source/Entity/Player.hpp +++ b/source/Entity/Player.hpp @@ -761,10 +761,25 @@ public: SQInteger GetTrackPosition() const; /* -------------------------------------------------------------------------------------------- - * Retrieve the amount of tracked position changes for the managed player entity. + * Modify the amount of tracked position changes for the managed player entity. */ void SetTrackPosition(SQInteger num) const; + /* -------------------------------------------------------------------------------------------- + * Modify the amount of tracked position changes for the managed player entity. + */ + void SetTrackPositionEx(SQInteger num, Int32 header, const Object & payload) const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the amount of tracked heading changes for the managed player entity. + */ + SQInteger GetTrackHeading() const; + + /* -------------------------------------------------------------------------------------------- + * Modify the amount of tracked heading changes for the managed player entity. + */ + void SetTrackHeading(SQInteger num) const; + /* -------------------------------------------------------------------------------------------- * Retrieve the last known weapon for the managed player entity. */