From bc1e7dbde6852a3cc0f564b6c505273f7b30e470 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 8 Jun 2016 16:53:16 +0300 Subject: [PATCH] Implement the option to specify how many times you want to allow intensive entity events to be forwarded to script callbacks. Also expose several properties for the vehicle entity type that I forgot about. --- source/Core.hpp | 7 ++++ source/CoreEvents.cpp | 38 +++++++++++++---- source/CoreUtils.cpp | 3 ++ source/Entity/Player.cpp | 19 +++++++++ source/Entity/Player.hpp | 10 +++++ source/Entity/Vehicle.cpp | 88 +++++++++++++++++++++++++++++++++++++++ source/Entity/Vehicle.hpp | 45 ++++++++++++++++++++ 7 files changed, 202 insertions(+), 8 deletions(-) diff --git a/source/Core.hpp b/source/Core.hpp index 1b5aba34..946a9871 100644 --- a/source/Core.hpp +++ b/source/Core.hpp @@ -219,6 +219,9 @@ protected: CPlayer * mInst; Object mObj; + // ---------------------------------------------------------------------------------------- + SQInteger mTrackPosition; + // ---------------------------------------------------------------------------------------- Int32 mLastWeapon; Float32 mLastHealth; @@ -312,6 +315,10 @@ protected: CVehicle * mInst; Object mObj; + // ---------------------------------------------------------------------------------------- + SQInteger mTrackPosition; + SQInteger mTrackRotation; + // ---------------------------------------------------------------------------------------- Int32 mLastPrimaryColour; Int32 mLastSecondaryColour; diff --git a/source/CoreEvents.cpp b/source/CoreEvents.cpp index 9d8862cf..7e347a0c 100644 --- a/source/CoreEvents.cpp +++ b/source/CoreEvents.cpp @@ -921,7 +921,15 @@ void Core::EmitPlayerUpdate(Int32 player_id, vcmpPlayerUpdate update_type) if (pos != inst.mLastPosition) { // Trigger the event specific to this change - EmitPlayerPosition(player_id); + if (inst.mTrackPosition != 0) + { + EmitPlayerPosition(player_id); + // Should we decrease the tracked position changes? + if (inst.mTrackPosition) + { + --inst.mTrackPosition; + } + } // Update the tracked value inst.mLastPosition = pos; } @@ -980,7 +988,15 @@ void Core::EmitVehicleUpdate(Int32 vehicle_id, vcmpVehicleUpdate update_type) case vcmpVehicleUpdatePosition: { // Trigger the event specific to this change - EmitVehiclePosition(vehicle_id); + if (inst.mTrackPosition != 0) + { + EmitVehiclePosition(vehicle_id); + // Should we decrease the tracked position changes? + if (inst.mTrackPosition) + { + --inst.mTrackPosition; + } + } // Update the tracked value _Func->GetVehiclePosition(vehicle_id, &inst.mLastPosition.x, &inst.mLastPosition.y, &inst.mLastPosition.z); @@ -1019,13 +1035,19 @@ void Core::EmitVehicleUpdate(Int32 vehicle_id, vcmpVehicleUpdate update_type) } break; case vcmpVehicleUpdateRotation: { - Quaternion rot; - // Obtain the current position of this instance - _Func->GetVehicleRotation(vehicle_id, &rot.x, &rot.y, &rot.z, &rot.w); // Trigger the event specific to this change - EmitVehicleRotation(vehicle_id); - // Update the tracked value - inst.mLastRotation = rot; + if (inst.mTrackRotation != 0) + { + EmitVehicleRotation(vehicle_id); + // Should we decrease the tracked rotation changes? + if (inst.mTrackRotation) + { + --inst.mTrackRotation; + } + } + // Obtain the current rotation of this instance + _Func->GetVehicleRotation(vehicle_id, &inst.mLastRotation.x, &inst.mLastRotation.y, + &inst.mLastRotation.z, &inst.mLastRotation.w); } break; default: { diff --git a/source/CoreUtils.cpp b/source/CoreUtils.cpp index b443e482..f7a23316 100644 --- a/source/CoreUtils.cpp +++ b/source/CoreUtils.cpp @@ -53,6 +53,7 @@ void Core::ResetInst(PlayerInst & inst) { inst.mID = -1; inst.mFlags = ENF_DEFAULT; + inst.mTrackPosition = 0; inst.mLastWeapon = -1; inst.mLastHealth = 0.0; inst.mLastArmour = 0.0; @@ -66,6 +67,8 @@ void Core::ResetInst(VehicleInst & inst) { inst.mID = -1; inst.mFlags = ENF_DEFAULT; + inst.mTrackPosition = 0; + inst.mTrackRotation = 0; inst.mLastPrimaryColour = -1; inst.mLastSecondaryColour = -1; inst.mLastHealth = 0.0; diff --git a/source/Entity/Player.cpp b/source/Entity/Player.cpp index 88c03b9a..2124a21c 100644 --- a/source/Entity/Player.cpp +++ b/source/Entity/Player.cpp @@ -1174,6 +1174,24 @@ void CPlayer::SetMessagePrefix(Uint32 index, CSStr prefix) mMessagePrefixes[index].assign(prefix); } +// ------------------------------------------------------------------------------------------------ +SQInteger CPlayer::GetTrackPosition() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetPlayer(m_ID).mTrackPosition; +} + +// ------------------------------------------------------------------------------------------------ +void CPlayer::SetTrackPosition(SQInteger num) const +{ + // Validate the managed identifier + Validate(); + // Assign the requested information + Core::Get().GetPlayer(m_ID).mTrackPosition = num; +} + // ------------------------------------------------------------------------------------------------ Int32 CPlayer::GetLastWeapon() const { @@ -2075,6 +2093,7 @@ void Register_CPlayer(HSQUIRRELVM vm) .Prop(_SC("Away"), &CPlayer::IsAway) .Prop(_SC("Spec"), &CPlayer::GetSpectator, &CPlayer::SetSpectator) .Prop(_SC("Authority"), &CPlayer::GetAuthority, &CPlayer::SetAuthority) + .Prop(_SC("TrackPosition"), &CPlayer::GetTrackPosition, &CPlayer::SetTrackPosition) .Prop(_SC("LastWeapon"), &CPlayer::GetLastWeapon) .Prop(_SC("LastHealth"), &CPlayer::GetLastHealth) .Prop(_SC("LastArmour"), &CPlayer::GetLastArmour) diff --git a/source/Entity/Player.hpp b/source/Entity/Player.hpp index 371324f6..df690893 100644 --- a/source/Entity/Player.hpp +++ b/source/Entity/Player.hpp @@ -715,6 +715,16 @@ public: */ void SetMessagePrefix(Uint32 index, CSStr prefix); + /* -------------------------------------------------------------------------------------------- + * Retrieve the amount of tracked position changes for the managed player entity. + */ + SQInteger GetTrackPosition() const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the amount of tracked position changes for the managed player entity. + */ + void SetTrackPosition(SQInteger num) const; + /* -------------------------------------------------------------------------------------------- * Retrieve the last known weapon for the managed player entity. */ diff --git a/source/Entity/Vehicle.cpp b/source/Entity/Vehicle.cpp index 6fb8a40a..2fa23a84 100644 --- a/source/Entity/Vehicle.cpp +++ b/source/Entity/Vehicle.cpp @@ -984,6 +984,87 @@ bool CVehicle::Embark(CPlayer & player, Int32 slot, bool allocate, bool warp) co != vcmpErrorRequestDenied); } +// ------------------------------------------------------------------------------------------------ +SQInteger CVehicle::GetTrackPosition() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetVehicle(m_ID).mTrackPosition; +} + +// ------------------------------------------------------------------------------------------------ +void CVehicle::SetTrackPosition(SQInteger num) const +{ + // Validate the managed identifier + Validate(); + // Assign the requested information + Core::Get().GetVehicle(m_ID).mTrackPosition = num; +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CVehicle::GetTrackRotation() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetVehicle(m_ID).mTrackRotation; +} + +// ------------------------------------------------------------------------------------------------ +void CVehicle::SetTrackRotation(SQInteger num) const +{ + // Validate the managed identifier + Validate(); + // Assign the requested information + Core::Get().GetVehicle(m_ID).mTrackRotation = num; +} + +// ------------------------------------------------------------------------------------------------ +Int32 CVehicle::GetLastPrimaryColour() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetVehicle(m_ID).mLastPrimaryColour; +} + +// ------------------------------------------------------------------------------------------------ +Int32 CVehicle::GetLastSecondaryColour() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetVehicle(m_ID).mLastSecondaryColour; +} + +// ------------------------------------------------------------------------------------------------ +Float32 CVehicle::GetLastHealth() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetVehicle(m_ID).mLastHealth; +} + +// ------------------------------------------------------------------------------------------------ +const Vector3 & CVehicle::GetLastPosition() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetVehicle(m_ID).mLastPosition; +} + +// ------------------------------------------------------------------------------------------------ +const Quaternion & CVehicle::GetLastRotation() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetVehicle(m_ID).mLastRotation; +} + // ------------------------------------------------------------------------------------------------ Float32 CVehicle::GetPositionX() const { @@ -1678,6 +1759,13 @@ void Register_CVehicle(HSQUIRRELVM vm) .Prop(_SC("HorizontalTurretRotation"), &CVehicle::GetHorizontalTurretRotation) .Prop(_SC("VerTurretRotation"), &CVehicle::GetVerticalTurretRotation) .Prop(_SC("VerticalTurretRotation"), &CVehicle::GetVerticalTurretRotation) + .Prop(_SC("TrackPosition"), &CVehicle::GetTrackPosition, &CVehicle::SetTrackPosition) + .Prop(_SC("TrackRotation"), &CVehicle::GetTrackRotation, &CVehicle::SetTrackRotation) + .Prop(_SC("LastPrimaryColour"), &CVehicle::GetLastPrimaryColour) + .Prop(_SC("LastSecondaryColour"), &CVehicle::GetLastSecondaryColour) + .Prop(_SC("LastHealth"), &CVehicle::GetLastHealth) + .Prop(_SC("LastPosition"), &CVehicle::GetLastPosition) + .Prop(_SC("LastRotation"), &CVehicle::GetLastRotation) .Prop(_SC("PosX"), &CVehicle::GetPositionX, &CVehicle::SetPositionX) .Prop(_SC("PosY"), &CVehicle::GetPositionY, &CVehicle::SetPositionY) .Prop(_SC("PosZ"), &CVehicle::GetPositionZ, &CVehicle::SetPositionZ) diff --git a/source/Entity/Vehicle.hpp b/source/Entity/Vehicle.hpp index 9c42e550..36530119 100644 --- a/source/Entity/Vehicle.hpp +++ b/source/Entity/Vehicle.hpp @@ -590,6 +590,51 @@ public: */ bool Embark(CPlayer & player, Int32 slot, bool allocate, bool warp) const; + /* -------------------------------------------------------------------------------------------- + * Retrieve the amount of tracked position changes for the managed vehicle entity. + */ + SQInteger GetTrackPosition() const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the amount of tracked position changes for the managed vehicle entity. + */ + void SetTrackPosition(SQInteger num) const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the amount of tracked rotation changes for the managed vehicle entity. + */ + SQInteger GetTrackRotation() const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the amount of tracked rotation changes for the managed vehicle entity. + */ + void SetTrackRotation(SQInteger num) const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the last known primary color for the managed vehicle entity. + */ + Int32 GetLastPrimaryColour() const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the last known secondary color for the managed vehicle entity. + */ + Int32 GetLastSecondaryColour() const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the last known health for the managed vehicle entity. + */ + Float32 GetLastHealth() const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the last known position for the managed player entity. + */ + const Vector3 & GetLastPosition() const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the last known rotation for the managed player entity. + */ + const Quaternion & GetLastRotation() const; + /* -------------------------------------------------------------------------------------------- * Retrieve the position on the x axis of the managed vehicle entity. */