From 07ca09574072b303064eafb2751f8f83c865f083 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 4 May 2020 09:10:47 +0100 Subject: Improve entity position updates (#4701) * Make puking pickups fly nicer * Improve entity position updates * Move determination of whether a delta is too big for a packet into the protocol handlers + Less jittery movement + Generalise CollectEntity to take any entity --- src/Entities/Player.cpp | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 46a1606d0..3f2ab21c1 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -681,6 +681,24 @@ void cPlayer::AddFoodExhaustion(double a_Exhaustion) +void cPlayer::TossItems(const cItems & a_Items) +{ + if (IsGameModeSpectator()) // Players can't toss items in spectator + { + return; + } + + m_Stats.AddValue(statItemsDropped, static_cast(a_Items.Size())); + + const auto Speed = (GetLookVector() + Vector3d(0, 0.2, 0)) * 6; // A dash of height and a dollop of speed + const auto Position = GetEyePosition() - Vector3d(0, 0.2, 0); // Correct for eye-height weirdness + m_World->SpawnItemPickups(a_Items, Position, Speed, true); // 'true' because created by player +} + + + + + void cPlayer::StartEating(void) { // Set the timer: @@ -1647,11 +1665,10 @@ void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) // ask plugins to allow teleport to the new position. if (!cRoot::Get()->GetPluginManager()->CallHookEntityTeleport(*this, m_LastPosition, Vector3d(a_PosX, a_PosY, a_PosZ))) { - ResetPosition({a_PosX, a_PosY, a_PosZ}); + SetPosition({a_PosX, a_PosY, a_PosZ}); FreezeInternal(GetPosition(), false); m_bIsTeleporting = true; - m_World->BroadcastTeleportEntity(*this, GetClientHandle()); m_ClientHandle->SendPlayerMoveLook(); } } @@ -2017,25 +2034,6 @@ void cPlayer::TossPickup(const cItem & a_Item) -void cPlayer::TossItems(const cItems & a_Items) -{ - if (IsGameModeSpectator()) // Players can't toss items in spectator - { - return; - } - - m_Stats.AddValue(statItemsDropped, static_cast(a_Items.Size())); - - double vX = 0, vY = 0, vZ = 0; - EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); - vY = -vY * 2 + 1.f; - m_World->SpawnItemPickups(a_Items, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player -} - - - - - void cPlayer::DoMoveToWorld(const cEntity::sWorldChangeInfo & a_WorldChangeInfo) { ASSERT(a_WorldChangeInfo.m_NewWorld != nullptr); -- cgit v1.2.3