summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Entity.cpp94
-rw-r--r--source/Entity.h11
-rw-r--r--source/FallingBlock.cpp4
-rw-r--r--source/Mobs/Monster.cpp10
-rw-r--r--source/Pickup.cpp10
-rw-r--r--source/Player.cpp2
6 files changed, 107 insertions, 24 deletions
diff --git a/source/Entity.cpp b/source/Entity.cpp
index 799d5073c..bec32e74c 100644
--- a/source/Entity.cpp
+++ b/source/Entity.cpp
@@ -278,12 +278,10 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
float DiffY = (float)(GetPosY() - m_LastPosY);
float DiffZ = (float)(GetPosZ() - m_LastPosZ);
float SqrDist = DiffX * DiffX + DiffY * DiffY + DiffZ * DiffZ;
- if (
- (SqrDist > 16) // 4 blocks is max Relative Move. 16 = 4 ^ 2
- || (m_World->GetWorldAge() - m_TimeLastTeleportPacket > 400) // Send an absolute position every 20 seconds
- )
+
+ // 4 blocks is max Relative Move. 16 = 4 ^ 2. Send an absolute position every 20 seconds
+ if ((SqrDist > 16) || (m_World->GetWorldAge() - m_TimeLastTeleportPacket > 400))
{
- //LOGD("Teleported from (%f,%f,%f) to (%f,%f,%f); Distance square: %f",m_LastPosX,m_LastPosY,m_LastPosZ, m_Pos.x,m_Pos.y,m_Pos.z,SqrDist );
m_World->BroadcastEntHeadLook(*this,a_Exclude);
m_World->BroadcastTeleportEntity(*this,a_Exclude);
m_TimeLastTeleportPacket = m_World->GetWorldAge();
@@ -294,9 +292,9 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
}
else
{
- if ((m_World->GetWorldAge() - m_TimeLastMoveReltPacket > 60)) // Send relative movement every 3 seconds
+ // Send relative movement every 3 seconds
+ if ((m_World->GetWorldAge() - m_TimeLastMoveReltPacket > 60))
{
- //LOGD("Moved from (%f,%f,%f) to (%f,%f,%f)",m_LastPosX,m_LastPosY,m_LastPosZ, m_Pos.x,m_Pos.y,m_Pos.z );
if (m_bDirtyOrientation)
{
m_World->BroadcastEntHeadLook(*this,a_Exclude);
@@ -305,7 +303,6 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
}
else
{
- m_World->BroadcastEntHeadLook(*this,a_Exclude);
m_World->BroadcastEntRelMove(*this, (char)(DiffX * 32), (char)(DiffY * 32), (char)(DiffZ * 32),a_Exclude);
}
m_TimeLastMoveReltPacket = m_World->GetWorldAge();
@@ -457,9 +454,86 @@ void cEntity::SetSpeedZ(double a_SpeedZ)
-void cEntity::AddSpeed(const Vector3d & a_AddSpeed)
+void cEntity::AddPosX(double a_AddPosX)
+{
+ m_Pos.x += a_AddPosX;
+ MoveToCorrectChunk();
+ m_bDirtyPosition = true;
+}
+
+
+
+
+void cEntity::AddPosY(double a_AddPosY)
+{
+ m_Pos.y += a_AddPosY;
+ MoveToCorrectChunk();
+ m_bDirtyPosition = true;
+}
+
+
+
+
+void cEntity::AddPosZ(double a_AddPosZ)
+{
+ m_Pos.z += a_AddPosZ;
+ MoveToCorrectChunk();
+ m_bDirtyPosition = true;
+}
+
+
+
+
+void cEntity::AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ)
+{
+ m_Pos.x += a_AddPosX;
+ m_Pos.y += a_AddPosY;
+ m_Pos.z += a_AddPosZ;
+ MoveToCorrectChunk();
+ m_bDirtyPosition = true;
+}
+
+
+
+
+void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ)
+{
+ m_Speed.x += a_AddSpeedX;
+ m_Speed.y += a_AddSpeedY;
+ m_Speed.z += a_AddSpeedZ;
+ m_bDirtySpeed = true;
+ WrapSpeed();
+}
+
+
+
+
+
+void cEntity::AddSpeedX(double a_AddSpeedX)
+{
+ m_Speed.x += a_AddSpeedX;
+ m_bDirtySpeed = true;
+ WrapSpeed();
+}
+
+
+
+
+
+void cEntity::AddSpeedY(double a_AddSpeedY)
+{
+ m_Speed.y += a_AddSpeedY;
+ m_bDirtySpeed = true;
+ WrapSpeed();
+}
+
+
+
+
+
+void cEntity::AddSpeedZ(double a_AddSpeedZ)
{
- m_Speed += a_AddSpeed;
+ m_Speed.z += a_AddSpeedZ;
m_bDirtySpeed = true;
WrapSpeed();
}
diff --git a/source/Entity.h b/source/Entity.h
index b7789c627..e40827cf4 100644
--- a/source/Entity.h
+++ b/source/Entity.h
@@ -138,7 +138,16 @@ public:
void SetSpeedY (double a_SpeedY);
void SetSpeedZ (double a_SpeedZ);
- void AddSpeed(const Vector3d & a_AddSpeed);
+ void AddPosX (double a_AddPosX);
+ void AddPosY (double a_AddPosY);
+ void AddPosZ (double a_AddPosZ);
+ void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ);
+ void AddPosition(const Vector3d & a_AddPos) { AddPosition(a_AddPos.x,a_AddPos.y,a_AddPos.z);}
+ void AddSpeed (double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ);
+ void AddSpeed (const Vector3d & a_AddSpeed) { AddSpeed(a_AddSpeed.x,a_AddSpeed.y,a_AddSpeed.z);}
+ void AddSpeedX (double a_AddSpeedX);
+ void AddSpeedY (double a_AddSpeedY);
+ void AddSpeedZ (double a_AddSpeedZ);
// tolua_end
diff --git a/source/FallingBlock.cpp b/source/FallingBlock.cpp
index 9fbf498e2..5edae6283 100644
--- a/source/FallingBlock.cpp
+++ b/source/FallingBlock.cpp
@@ -43,8 +43,8 @@ void cFallingBlock::SpawnOn(cClientHandle & a_ClientHandle)
void cFallingBlock::Tick(float a_Dt, MTRand & a_TickRandom)
{
float MilliDt = a_Dt * 0.001f;
- SetSpeedY(GetSpeedY() - (MilliDt * 9.8f));
- SetPosY(GetPosY() + (GetSpeedY() * MilliDt));
+ AddSpeedY(MilliDt * -9.8f);
+ AddPosY(GetSpeedY() * MilliDt);
// GetWorld()->BroadcastTeleportEntity(*this); // Test position
diff --git a/source/Mobs/Monster.cpp b/source/Mobs/Monster.cpp
index e8d8f7571..8867c7e60 100644
--- a/source/Mobs/Monster.cpp
+++ b/source/Mobs/Monster.cpp
@@ -142,7 +142,11 @@ void cMonster::Tick(float a_Dt, MTRand & a_TickRandom)
}
}
}
-
+
+ HandlePhysics(a_Dt);
+ BroadcastMovementUpdate();
+ MoveToCorrectChunk();
+
Vector3d Distance = m_Destination - GetPosition();
if (Distance.SqrLength() > 0.1f)
{
@@ -153,10 +157,6 @@ void cMonster::Tick(float a_Dt, MTRand & a_TickRandom)
SetPitch( Pitch );
}
- HandlePhysics(a_Dt);
- BroadcastMovementUpdate();
- MoveToCorrectChunk();
-
switch (m_EMState)
{
case IDLE:
diff --git a/source/Pickup.cpp b/source/Pickup.cpp
index 5775782f5..16e68b3ee 100644
--- a/source/Pickup.cpp
+++ b/source/Pickup.cpp
@@ -129,7 +129,7 @@ void cPickup::HandlePhysics(float a_Dt)
if( BlockIn != E_BLOCK_AIR && !IsBlockWater(BlockIn) ) // If in ground itself, push it out
{
m_bOnGround = true;
- SetPosY(GetPosY() + 0.2);
+ AddPosY(0.2);
m_bReplicated = false;
}
SetSpeedX(GetSpeedX() * 0.7f/(1+a_Dt));
@@ -176,7 +176,7 @@ void cPickup::HandlePhysics(float a_Dt)
{
Gravity = -3;
}
- SetSpeedY(GetSpeedY() + Gravity);
+ AddSpeedY(Gravity);
// Set to hit position
m_ResultingSpeed += GetSpeed();
@@ -209,15 +209,15 @@ void cPickup::HandlePhysics(float a_Dt)
}
}
SetPosition(Tracer.RealHit);
- SetPosition(GetPosition() + (Tracer.HitNormal * 0.2f));
+ AddPosition(Tracer.HitNormal * 0.2f);
}
else
- SetPosition(GetPosition() + (m_ResultingSpeed*a_Dt));
+ AddPosition(m_ResultingSpeed*a_Dt);
}
else
{ // We didn't hit anything, so move =]
- SetPosition(GetPosition() + (m_ResultingSpeed*a_Dt));
+ AddPosition(m_ResultingSpeed*a_Dt);
}
}
// Usable for debugging
diff --git a/source/Player.cpp b/source/Player.cpp
index cde975afd..d20db5067 100644
--- a/source/Player.cpp
+++ b/source/Player.cpp
@@ -165,7 +165,7 @@ void cPlayer::Tick(float a_Dt, MTRand & a_TickRandom)
}
super::Tick(a_Dt, a_TickRandom);
-
+ //TODO: Change this to use the BroadcastMovementUpdate function
if (m_bDirtyOrientation && !m_bDirtyPosition)
{
m_World->BroadcastEntLook(*this, m_ClientHandle);