From 7f5cf417de5e83641e6aa0998cc9dc8b377346b6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 23 Apr 2014 21:06:46 +0100 Subject: Some change to Entity.cpp * Added comments to BroadcastMovementUpdate() and the collision tracer --- src/Entities/Player.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 2df0711b4..ba4353478 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -76,11 +76,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cTimer t1; m_LastPlayerListTime = t1.GetNowTime(); - - m_TimeLastTeleportPacket = 0; m_PlayerName = a_PlayerName; - m_bDirtyPosition = true; // So chunks are streamed to player at spawn if (!LoadFromDisk()) { @@ -208,25 +205,22 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) m_BowCharge += 1; } - //handle updating experience + // Handle updating experience if (m_bDirtyExperience) { SendExperience(); } - if (m_bDirtyPosition) + if ((GetPosition() - m_LastPos).SqrLength() != 0.0) // Change in position from last tick? { // Apply food exhaustion from movement: ApplyFoodExhaustionFromMovement(); cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this); - BroadcastMovementUpdate(m_ClientHandle); m_ClientHandle->StreamChunks(); } - else - { - BroadcastMovementUpdate(m_ClientHandle); - } + + BroadcastMovementUpdate(m_ClientHandle); if (m_Health > 0) // make sure player is alive { @@ -1592,10 +1586,7 @@ bool cPlayer::LoadFromDisk() SetPosX(JSON_PlayerPosition[(unsigned int)0].asDouble()); SetPosY(JSON_PlayerPosition[(unsigned int)1].asDouble()); SetPosZ(JSON_PlayerPosition[(unsigned int)2].asDouble()); - m_LastPosX = GetPosX(); - m_LastPosY = GetPosY(); - m_LastPosZ = GetPosZ(); - m_LastFoodPos = GetPosition(); + m_LastPos = GetPosition(); } Json::Value & JSON_PlayerRotation = root["rotation"]; @@ -1858,9 +1849,8 @@ void cPlayer::ApplyFoodExhaustionFromMovement() } // Calculate the distance travelled, update the last pos: - Vector3d Movement(GetPosition() - m_LastFoodPos); + Vector3d Movement(GetPosition() - m_LastPos); Movement.y = 0; // Only take XZ movement into account - m_LastFoodPos = GetPosition(); // If riding anything, apply no food exhaustion if (m_AttachedTo != NULL) -- cgit v1.2.3 From 15767badac8f1832dad93afa39b4678f611ce697 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 26 Apr 2014 23:52:18 +0100 Subject: A tiny speed improvement in ApplyFoodExhaustion() --- src/Entities/Player.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index a7b1dd74e..b43205226 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1848,16 +1848,16 @@ void cPlayer::ApplyFoodExhaustionFromMovement() { return; } - - // Calculate the distance travelled, update the last pos: - Vector3d Movement(GetPosition() - m_LastPos); - Movement.y = 0; // Only take XZ movement into account - + // If riding anything, apply no food exhaustion if (m_AttachedTo != NULL) { return; } + + // Calculate the distance travelled, update the last pos: + Vector3d Movement(GetPosition() - m_LastPos); + Movement.y = 0; // Only take XZ movement into account // Apply the exhaustion based on distance travelled: double BaseExhaustion = Movement.Length(); -- cgit v1.2.3 From 1df7dbe7c91953c2413908b846649e884b7ac53c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 5 May 2014 23:45:35 +0100 Subject: Suggestions'd --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index bcbf58623..d63e5461a 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -212,7 +212,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) SendExperience(); } - if ((GetPosition() - m_LastPos).SqrLength() != 0.0) // Change in position from last tick? + if (!(GetPosition() - m_LastPos).Equals(Vector3d(0, 0, 0))) // Change in position from last tick? { // Apply food exhaustion from movement: ApplyFoodExhaustionFromMovement(); -- cgit v1.2.3 From cca8376a0127a3e1711ed46d7e5491750135e715 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 6 May 2014 19:38:01 +0100 Subject: Suggestions'd #2 --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index d63e5461a..6ac11c270 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -212,7 +212,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) SendExperience(); } - if (!(GetPosition() - m_LastPos).Equals(Vector3d(0, 0, 0))) // Change in position from last tick? + if (GetPosition() != m_LastPos) // Change in position from last tick? { // Apply food exhaustion from movement: ApplyFoodExhaustionFromMovement(); -- cgit v1.2.3