From 7a469d870d229420970b62b0070df51aa080537f Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 6 Aug 2017 15:14:45 +0300 Subject: [PATCH] Attempt to fix (or make it easy to be fixed) the spectating crash. --- source/Entity/Player.cpp | 44 +++++++++++++++++++++++++++++----------- source/Entity/Player.hpp | 17 +++++++++++++++- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/source/Entity/Player.cpp b/source/Entity/Player.cpp index 75937797..2a7e21e9 100644 --- a/source/Entity/Player.cpp +++ b/source/Entity/Player.cpp @@ -1346,21 +1346,39 @@ LightObj & CPlayer::GetSpectator() const } // ------------------------------------------------------------------------------------------------ -void CPlayer::SetSpectator(CPlayer * target) const +void CPlayer::SetSpectator(CPlayer & target) const { // Validate the managed identifier Validate(); - // See if the given target is null - if (target == nullptr) - { - // Spectate an invalid player - _Func->SetPlayerSpectateTarget(m_ID, -1); - } - else - { - // Spectate the given target - _Func->SetPlayerSpectateTarget(m_ID, target->GetID()); - } + // Spectate the given target + _Func->SetPlayerSpectateTarget(m_ID, target.GetID()); +} + +// ------------------------------------------------------------------------------------------------ +SQInteger CPlayer::GetSpectatorID() const +{ + // Validate the managed identifier + Validate(); + // Retrieve the identifier of the player + return _Func->GetPlayerSpectateTarget(m_ID); +} + +// ------------------------------------------------------------------------------------------------ +void CPlayer::SetSpectatorID(SQInteger id) const +{ + // Validate the managed identifier + Validate(); + // Spectate the given target + _Func->SetPlayerSpectateTarget(m_ID, id); +} + +// ------------------------------------------------------------------------------------------------ +void CPlayer::SpectateNone() const +{ + // Validate the managed identifier + Validate(); + // Spectate the given target + _Func->SetPlayerSpectateTarget(m_ID, -1); } // ------------------------------------------------------------------------------------------------ @@ -2501,6 +2519,7 @@ void Register_CPlayer(HSQUIRRELVM vm) .Prop(_SC("TouchedObject"), &CPlayer::StandingOnObject) .Prop(_SC("Away"), &CPlayer::IsAway) .Prop(_SC("Spec"), &CPlayer::GetSpectator, &CPlayer::SetSpectator) + .Prop(_SC("SpecID"), &CPlayer::GetSpectatorID, &CPlayer::SetSpectatorID) .Prop(_SC("CollideAreas"), &CPlayer::GetCollideAreas, &CPlayer::SetCollideAreas) .Prop(_SC("Authority"), &CPlayer::GetAuthority, &CPlayer::SetAuthority) .Prop(_SC("TrackPosition"), &CPlayer::GetTrackPosition, &CPlayer::SetTrackPosition) @@ -2548,6 +2567,7 @@ void Register_CPlayer(HSQUIRRELVM vm) .Func(_SC("StripWeapons"), &CPlayer::StripWeapons) .Func(_SC("RestoreCamera"), &CPlayer::RestoreCamera) .Func(_SC("Spectating"), &CPlayer::GetSpectator) + .Func(_SC("SpectateNone"), &CPlayer::SpectateNone) .Func(_SC("Spectate"), &CPlayer::SetSpectator) .Func(_SC("Redirect"), &CPlayer::Redirect) .Func(_SC("PlaySound"), &CPlayer::PlaySound) diff --git a/source/Entity/Player.hpp b/source/Entity/Player.hpp index e20038f2..c595ee3e 100644 --- a/source/Entity/Player.hpp +++ b/source/Entity/Player.hpp @@ -727,7 +727,22 @@ public: /* -------------------------------------------------------------------------------------------- * Set the managed player entity to spectate the specified player entity. */ - void SetSpectator(CPlayer * target) const; + void SetSpectator(CPlayer & target) const; + + /* -------------------------------------------------------------------------------------------- + * Retrieve the identifier of the player that the managed player entity is spectating. + */ + SQInteger GetSpectatorID() const; + + /* -------------------------------------------------------------------------------------------- + * Set the managed player entity to spectate the specified player entity. + */ + void SetSpectatorID(SQInteger id) const; + + /* -------------------------------------------------------------------------------------------- + * Set the managed player entity to spectate no one. + */ + void SpectateNone() const; /* -------------------------------------------------------------------------------------------- * Redirect the managed player entity to the specified server.