summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorkeyboard.osh@gmail.com <keyboard.osh@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-22 07:33:10 +0100
committerkeyboard.osh@gmail.com <keyboard.osh@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-22 07:33:10 +0100
commit39e4bd323914143408120fc914fd1c52557baac6 (patch)
tree434530690980e923d6b989b494e9fa9a4c6699ac /source
parentDelayedFluidSimulator: optimized block storage for large amounts of blocks. (diff)
downloadcuberite-39e4bd323914143408120fc914fd1c52557baac6.tar
cuberite-39e4bd323914143408120fc914fd1c52557baac6.tar.gz
cuberite-39e4bd323914143408120fc914fd1c52557baac6.tar.bz2
cuberite-39e4bd323914143408120fc914fd1c52557baac6.tar.lz
cuberite-39e4bd323914143408120fc914fd1c52557baac6.tar.xz
cuberite-39e4bd323914143408120fc914fd1c52557baac6.tar.zst
cuberite-39e4bd323914143408120fc914fd1c52557baac6.zip
Diffstat (limited to 'source')
-rw-r--r--source/Entity.cpp132
-rw-r--r--source/Entity.h32
-rw-r--r--source/FallingBlock.cpp6
-rw-r--r--source/Mobs/AggressiveMonster.cpp2
-rw-r--r--source/Mobs/Monster.cpp86
-rw-r--r--source/Pawn.cpp20
-rw-r--r--source/Pawn.h2
-rw-r--r--source/Pickup.cpp52
-rw-r--r--source/Player.cpp58
-rw-r--r--source/Player.h2
10 files changed, 257 insertions, 135 deletions
diff --git a/source/Entity.cpp b/source/Entity.cpp
index 418543fb1..799d5073c 100644
--- a/source/Entity.cpp
+++ b/source/Entity.cpp
@@ -31,9 +31,16 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z)
, m_ChunkY(0)
, m_ChunkZ(0)
, m_Pos(a_X, a_Y, a_Z)
- , m_bDirtyPosition(true)
, m_bDirtyOrientation(true)
+ , m_bDirtyPosition(true)
+ , m_bDirtySpeed(true)
, m_bDestroyed(false)
+ , m_LastPosX( 0.0 )
+ , m_LastPosY( 0.0 )
+ , m_LastPosZ( 0.0 )
+ , m_TimeLastTeleportPacket(0)
+ , m_TimeLastMoveReltPacket(0)
+ , m_TimeLastSpeedPacket(0)
, m_EntityType(a_EntityType)
, m_World(NULL)
, m_bRemovedFromChunk(false)
@@ -127,6 +134,18 @@ void cEntity::WrapRotation()
while (m_Rot.y < -180.f) m_Rot.y+=360.f;
}
+void cEntity::WrapSpeed()
+{
+ //There shoudn't be a need for flipping the flag on because this function is called
+ //after any update, so the flag is already turned on
+ if (m_Speed.x > 20.0f) m_Speed.x = 20.0f;
+ else if (m_Speed.x < -20.0f) m_Speed.x = -20.0f;
+ if (m_Speed.y > 20.0f) m_Speed.y = 20.0f;
+ else if (m_Speed.y < -20.0f) m_Speed.y = -20.0f;
+ if (m_Speed.z > 20.0f) m_Speed.z = 20.0f;
+ else if (m_Speed.z < -20.0f) m_Speed.z = -20.0f;
+}
+
@@ -243,6 +262,73 @@ void cEntity::Tick(float a_Dt, MTRand & a_TickRandom)
+void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
+{
+ if (m_bDirtyOrientation && !m_bDirtyPosition)
+ {
+ //LOGD("Sending (rot,yaw,roll) = (%f,%f,%f)",m_Rot.x,m_Rot.y,m_Rot.z);
+ m_World->BroadcastEntLook(*this,a_Exclude);
+ m_World->BroadcastEntHeadLook(*this,a_Exclude);
+ m_bDirtyOrientation = false;
+ }
+
+ if (m_bDirtyPosition)
+ {
+ float DiffX = (float)(GetPosX() - m_LastPosX);
+ 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
+ )
+ {
+ //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();
+ m_LastPosX = GetPosX();
+ m_LastPosY = GetPosY();
+ m_LastPosZ = GetPosZ();
+ m_bDirtyPosition = false;
+ }
+ else
+ {
+ if ((m_World->GetWorldAge() - m_TimeLastMoveReltPacket > 60)) // Send relative movement every 3 seconds
+ {
+ //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);
+ m_World->BroadcastEntRelMoveLook(*this, (char)(DiffX * 32), (char)(DiffY * 32), (char)(DiffZ * 32),a_Exclude);
+ m_bDirtyOrientation = false;
+ }
+ 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();
+ m_LastPosX = GetPosX();
+ m_LastPosY = GetPosY();
+ m_LastPosZ = GetPosZ();
+ m_bDirtyPosition = false;
+ }
+ }
+ }
+ //We need to keep updating the clients when there is movement or if there was a change in speed and after 1 tick
+ if( (m_Speed.SqrLength() > 0.0004f || m_bDirtySpeed) && (m_World->GetWorldAge() - m_TimeLastSpeedPacket >= 1))
+ {
+ m_World->BroadcastEntVelocity(*this,a_Exclude);
+ m_bDirtySpeed = false;
+ m_TimeLastSpeedPacket = m_World->GetWorldAge();
+ }
+}
+
+
+
+
+
void cEntity::AttachTo(cEntity * a_AttachTo)
{
if (m_AttachedTo == a_AttachTo)
@@ -334,15 +420,48 @@ void cEntity::SetRoll(double a_Roll)
void cEntity::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
{
m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ);
+ m_bDirtySpeed = true;
+ WrapSpeed();
}
+void cEntity::SetSpeedX(double a_SpeedX)
+{
+ m_Speed.x = a_SpeedX;
+ m_bDirtySpeed = true;
+ WrapSpeed();
+}
+
+
+
+
+void cEntity::SetSpeedY(double a_SpeedY)
+{
+ m_Speed.y = a_SpeedY;
+ m_bDirtySpeed = true;
+ WrapSpeed();
+}
+
+
+
+
+void cEntity::SetSpeedZ(double a_SpeedZ)
+{
+ m_Speed.z = a_SpeedZ;
+ m_bDirtySpeed = true;
+ WrapSpeed();
+}
+
+
+
void cEntity::AddSpeed(const Vector3d & a_AddSpeed)
{
m_Speed += a_AddSpeed;
+ m_bDirtySpeed = true;
+ WrapSpeed();
}
@@ -365,17 +484,6 @@ Vector3d cEntity::GetLookVector(void) const
//////////////////////////////////////////////////////////////////////////
// Set position
-void cEntity::SetPosition(const Vector3d & a_Pos)
-{
- m_Pos = a_Pos;
- MoveToCorrectChunk();
- m_bDirtyPosition = true;
-}
-
-
-
-
-
void cEntity::SetPosition(double a_PosX, double a_PosY, double a_PosZ)
{
m_Pos.Set(a_PosX, a_PosY, a_PosZ);
diff --git a/source/Entity.h b/source/Entity.h
index cdcf57a98..b7789c627 100644
--- a/source/Entity.h
+++ b/source/Entity.h
@@ -127,13 +127,16 @@ public:
void SetPosY (double a_PosY);
void SetPosZ (double a_PosZ);
void SetPosition(double a_PosX, double a_PosY, double a_PosZ);
- void SetPosition(const Vector3d & a_Pos);
+ void SetPosition(const Vector3d & a_Pos) { SetPosition(a_Pos.x,a_Pos.y,a_Pos.z);}
void SetRot (const Vector3f & a_Rot);
void SetRotation(double a_Rotation);
void SetPitch (double a_Pitch);
void SetRoll (double a_Roll);
void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ);
- void SetSpeed (const Vector3d & a_Speed) { m_Speed = a_Speed; }
+ void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x,a_Speed.y,a_Speed.z); }
+ void SetSpeedX (double a_SpeedX);
+ void SetSpeedY (double a_SpeedY);
+ void SetSpeedZ (double a_SpeedZ);
void AddSpeed(const Vector3d & a_AddSpeed);
@@ -153,6 +156,9 @@ public:
Needs to have a default implementation due to Lua bindings.
*/
virtual void SpawnOn(cClientHandle & a_Client) {ASSERT(!"SpawnOn() unimplemented!"); }
+
+ //Updates clients of changes in the entity.
+ virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = NULL);
/// Attaches to the specified entity; detaches from any previous one first
void AttachTo(cEntity * a_AttachTo);
@@ -160,7 +166,11 @@ public:
/// Detaches from the currently attached entity, if any
void Detach(void);
+ //Makes sure rotation is not over the specified range.
void WrapRotation();
+
+ //Makes speed is not over 20. Max speed is 20 blocks / second
+ void WrapSpeed();
// tolua_begin
@@ -192,13 +202,17 @@ protected:
cReferenceManager* m_References;
int m_ChunkX, m_ChunkY, m_ChunkZ;
- Vector3d m_Pos;
+
+ //Flags that signal that we haven't updated the clients with the latest.
+ bool m_bDirtyOrientation;
bool m_bDirtyPosition;
+ bool m_bDirtySpeed;
- Vector3d m_Rot;
- bool m_bDirtyOrientation;
-
- Vector3d m_Speed;
+ //Last Position.
+ double m_LastPosX, m_LastPosY, m_LastPosZ;
+
+ //This variables keep track of the last time a packet was sent
+ Int64 m_TimeLastTeleportPacket,m_TimeLastMoveReltPacket,m_TimeLastSpeedPacket; // In ticks
bool m_bDestroyed;
bool m_bRemovedFromChunk;
@@ -219,6 +233,10 @@ protected:
void AddReference( cEntity*& a_EntityPtr );
void ReferencedBy( cEntity*& a_EntityPtr );
void Dereference( cEntity*& a_EntityPtr );
+private:
+ Vector3d m_Speed;
+ Vector3d m_Rot;
+ Vector3d m_Pos;
} ; // tolua_export
typedef std::list<cEntity *> cEntityList;
diff --git a/source/FallingBlock.cpp b/source/FallingBlock.cpp
index 8ad313bb9..9fbf498e2 100644
--- a/source/FallingBlock.cpp
+++ b/source/FallingBlock.cpp
@@ -43,13 +43,13 @@ void cFallingBlock::SpawnOn(cClientHandle & a_ClientHandle)
void cFallingBlock::Tick(float a_Dt, MTRand & a_TickRandom)
{
float MilliDt = a_Dt * 0.001f;
- m_Speed.y -= MilliDt * 9.8f;
- m_Pos.y += m_Speed.y * MilliDt;
+ SetSpeedY(GetSpeedY() - (MilliDt * 9.8f));
+ SetPosY(GetPosY() + (GetSpeedY() * MilliDt));
// GetWorld()->BroadcastTeleportEntity(*this); // Test position
int BlockX = (int)m_OriginalPosition.x;
- int BlockY = (int)(m_Pos.y - 0.5);
+ int BlockY = (int)(GetPosY() - 0.5);
int BlockZ = (int)m_OriginalPosition.z;
if (BlockY < 0)
diff --git a/source/Mobs/AggressiveMonster.cpp b/source/Mobs/AggressiveMonster.cpp
index 14c3135be..0a5461837 100644
--- a/source/Mobs/AggressiveMonster.cpp
+++ b/source/Mobs/AggressiveMonster.cpp
@@ -39,7 +39,7 @@ void cAggressiveMonster::InStateChasing(float a_Dt, MTRand & a_TickRandom)
}
}
- Vector3f Pos = Vector3f( m_Pos );
+ Vector3f Pos = Vector3f( GetPosition() );
Vector3f Their = Vector3f( m_Target->GetPosition() );
if ((Their - Pos).Length() <= m_AttackRange)
{
diff --git a/source/Mobs/Monster.cpp b/source/Mobs/Monster.cpp
index a2819a0bd..e8d8f7571 100644
--- a/source/Mobs/Monster.cpp
+++ b/source/Mobs/Monster.cpp
@@ -76,7 +76,7 @@ void cMonster::MoveToPosition( const Vector3f & a_Position )
bool cMonster::ReachedDestination()
{
- Vector3f Distance = (m_Destination) - Vector3f( m_Pos );
+ Vector3f Distance = (m_Destination) - GetPosition();
if( Distance.SqrLength() < 2.f )
return true;
@@ -106,20 +106,20 @@ void cMonster::Tick(float a_Dt, MTRand & a_TickRandom)
if (m_bMovingToDestination)
{
- Vector3f Pos( m_Pos );
+ Vector3f Pos( GetPosition() );
Vector3f Distance = m_Destination - Pos;
if( !ReachedDestination() )
{
Distance.y = 0;
Distance.Normalize();
Distance *= 3;
- m_Speed.x = Distance.x;
- m_Speed.z = Distance.z;
+ SetSpeedX( Distance.x );
+ SetSpeedZ( Distance.z );
if (m_EMState == ESCAPING)
{ //Runs Faster when escaping :D otherwise they just walk away
- m_Speed.x *= 2.f;
- m_Speed.z *= 2.f;
+ SetSpeedX (GetSpeedX() * 2.f);
+ SetSpeedZ (GetSpeedZ() * 2.f);
}
}
else
@@ -127,25 +127,23 @@ void cMonster::Tick(float a_Dt, MTRand & a_TickRandom)
m_bMovingToDestination = false;
}
- if( m_Speed.SqrLength() > 0.f )
+ if( GetSpeed().SqrLength() > 0.f )
{
if( m_bOnGround )
{
- Vector3f NormSpeed = m_Speed.NormalizeCopy();
- Vector3f NextBlock = Vector3f( m_Pos ) + NormSpeed;
+ Vector3f NormSpeed = Vector3f(GetSpeed()).NormalizeCopy();
+ Vector3f NextBlock = Vector3f( GetPosition() ) + NormSpeed;
double NextHeight = (double)GetWorld()->GetHeight( (int)NextBlock.x, (int)NextBlock.z );
- if( NextHeight > m_Pos.y - 1.2 && NextHeight - m_Pos.y < 2.5 )
+ if( NextHeight > (GetPosY() - 1.0) && (NextHeight - GetPosY()) < 2.5 )
{
m_bOnGround = false;
- m_Speed.y = 7.f; // Jump!!
+ SetSpeedY(5.f); // Jump!!
}
}
}
}
-
- ReplicateMovement();
- Vector3d Distance = m_Destination - Vector3f( m_Pos );
+ Vector3d Distance = m_Destination - GetPosition();
if (Distance.SqrLength() > 0.1f)
{
double Rotation, Pitch;
@@ -154,7 +152,11 @@ void cMonster::Tick(float a_Dt, MTRand & a_TickRandom)
SetRotation( Rotation );
SetPitch( Pitch );
}
-
+
+ HandlePhysics(a_Dt);
+ BroadcastMovementUpdate();
+ MoveToCorrectChunk();
+
switch (m_EMState)
{
case IDLE:
@@ -182,7 +184,7 @@ void cMonster::Tick(float a_Dt, MTRand & a_TickRandom)
-
+//Not used. Will remove later when we implement the AI.
void cMonster::ReplicateMovement()
{
if (m_bDirtyOrientation && !m_bDirtyPosition)
@@ -237,59 +239,59 @@ void cMonster::HandlePhysics(float a_Dt)
if( m_bOnGround ) // check if it's still on the ground
{
cWorld* World = GetWorld();
- if( World->GetBlock( (int)m_Pos.x, (int)m_Pos.y -1, (int)m_Pos.z ) == E_BLOCK_AIR )
+ if( World->GetBlock( (int)GetPosX(), (int)GetPosY() -1, (int)GetPosZ() ) == E_BLOCK_AIR )
{
m_bOnGround = false;
}
- if( World->GetBlock( (int)m_Pos.x, (int)m_Pos.y, (int)m_Pos.z ) != E_BLOCK_AIR ) // If in ground itself, push it out
+ if( World->GetBlock( (int)GetPosX(), (int)GetPosY(), (int)GetPosZ() ) != E_BLOCK_AIR ) // If in ground itself, push it out
{
m_bOnGround = true;
- m_Pos.y += 0.2;
+ SetPosY(GetPosY() + 0.2);
m_bDirtyPosition = true;
}
- m_Speed.x *= 0.7f/(1+a_Dt);
- if( fabs(m_Speed.x) < 0.05 ) m_Speed.x = 0;
- m_Speed.z *= 0.7f/(1+a_Dt);
- if( fabs(m_Speed.z) < 0.05 ) m_Speed.z = 0;
+ SetSpeedX(GetSpeedX() * 0.7f/(1+a_Dt));
+ if( fabs(GetSpeedX()) < 0.05 ) SetSpeedX(0);
+ SetSpeedZ(GetSpeedZ() * 0.7f/(1+a_Dt));
+ if( fabs(GetSpeedZ()) < 0.05 ) SetSpeedZ(0);
}
if( !m_bOnGround )
{
float Gravity = -9.81f*a_Dt;
- m_Speed.y += Gravity;
+ SetSpeedY(GetSpeedY() + Gravity);
}
- if( m_Speed.SqrLength() > 0.f )
+ if( GetSpeed().SqrLength() > 0.f )
{
cTracer Tracer( GetWorld() );
- int Ret = Tracer.Trace( m_Pos, m_Speed, 2 );
+ int Ret = Tracer.Trace( GetPosition(), GetSpeed(), 2 );
if( Ret ) // Oh noez! we hit something
{
// Set to hit position
- if( (Tracer.RealHit - Vector3f(m_Pos)).SqrLength() <= ( m_Speed * a_Dt ).SqrLength() )
+ if( (Tracer.RealHit - GetPosition()).SqrLength() <= ( GetSpeed() * a_Dt ).SqrLength() )
{
if( Ret == 1 )
{
- if( Tracer.HitNormal.x != 0.f ) m_Speed.x = 0.f;
- if( Tracer.HitNormal.y != 0.f ) m_Speed.y = 0.f;
- if( Tracer.HitNormal.z != 0.f ) m_Speed.z = 0.f;
+ if( Tracer.HitNormal.x != 0.f ) SetSpeedX(0.f);
+ if( Tracer.HitNormal.y != 0.f ) SetSpeedY(0.f);
+ if( Tracer.HitNormal.z != 0.f ) SetSpeedZ(0.f);
if( Tracer.HitNormal.y > 0 ) // means on ground
{
m_bOnGround = true;
}
}
- m_Pos = Tracer.RealHit;
- m_Pos += Tracer.HitNormal * 0.2f;
-
+ SetPosition(Tracer.RealHit);
+ SetPosX(GetPosX() + (Tracer.HitNormal.x * 0.5f));
+ SetPosZ(GetPosZ() + (Tracer.HitNormal.z * 0.5f));
}
else
- m_Pos += m_Speed*a_Dt;
+ SetPosition(GetPosition() + (GetSpeed()*a_Dt));
}
else
{ // We didn't hit anything, so move =]
- m_Pos += m_Speed*a_Dt;
+ SetPosition(GetPosition() + (GetSpeed()*a_Dt));
}
m_bDirtyPosition = true;
@@ -303,7 +305,7 @@ void cMonster::HandlePhysics(float a_Dt)
void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
{
super::DoTakeDamage(a_TDI);
- if((m_SoundHurt != "") && (m_Health > 0)) m_World->BroadcastSoundEffect(m_SoundHurt, (int)(m_Pos.x * 8), (int)(m_Pos.y * 8), (int)(m_Pos.z * 8), 1.0f, 0.8f);
+ if((m_SoundHurt != "") && (m_Health > 0)) m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
if (a_TDI.Attacker != NULL)
{
m_Target = a_TDI.Attacker;
@@ -318,7 +320,7 @@ void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
void cMonster::KilledBy(cPawn * a_Killer)
{
super::KilledBy(a_Killer);
- if(m_SoundHurt != "") m_World->BroadcastSoundEffect(m_SoundDeath, (int)(m_Pos.x * 8), (int)(m_Pos.y * 8), (int)(m_Pos.z * 8), 1.0f, 0.8f);
+ if(m_SoundHurt != "") m_World->BroadcastSoundEffect(m_SoundDeath, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
m_DestroyTimer = 0;
}
@@ -396,7 +398,7 @@ void cMonster::CheckEventLostPlayer(MTRand & a_TickRandom)
if (m_Target != NULL)
{
pos = m_Target->GetPosition();
- if ((pos - m_Pos).Length() > m_SightDistance || LineOfSight.Trace(m_Pos,(pos - m_Pos), (int)(pos - m_Pos).Length()))
+ if ((pos - GetPosition()).Length() > m_SightDistance || LineOfSight.Trace(GetPosition(),(pos - GetPosition()), (int)(pos - GetPosition()).Length()))
{
EventLosePlayer();
}
@@ -451,8 +453,8 @@ void cMonster::InStateIdle(float a_Dt, MTRand & a_TickRandom)
Dist.z = (float)((a_TickRandom.randInt() % 11) - 5);
if ((Dist.SqrLength() > 2) && (rem >= 3))
{
- m_Destination.x = (float)(m_Pos.x + Dist.x);
- m_Destination.z = (float)(m_Pos.z + Dist.z);
+ m_Destination.x = (float)(GetPosX() + Dist.x);
+ m_Destination.z = (float)(GetPosZ() + Dist.z);
m_Destination.y = (float)GetWorld()->GetHeight((int)m_Destination.x, (int)m_Destination.z) + 1.2f;
MoveToPosition(m_Destination);
}
@@ -483,7 +485,7 @@ void cMonster::InStateEscaping(float a_Dt, MTRand & a_TickRandom)
if (m_Target != NULL)
{
- Vector3d newloc = m_Pos;
+ Vector3d newloc = GetPosition();
newloc.x = (m_Target->GetPosition().x < newloc.x)? (newloc.x + m_SightDistance): (newloc.x - m_SightDistance);
newloc.z = (m_Target->GetPosition().z < newloc.z)? (newloc.z + m_SightDistance): (newloc.z - m_SightDistance);
MoveToPosition(newloc);
@@ -518,7 +520,7 @@ void cMonster::Attack(float a_Dt)
// Checks for Players close by and if they are visible return the closest
cPlayer * cMonster::FindClosestPlayer(void)
{
- return m_World->FindClosestPlayer(m_Pos, m_SightDistance);
+ return m_World->FindClosestPlayer(GetPosition(), m_SightDistance);
}
diff --git a/source/Pawn.cpp b/source/Pawn.cpp
index d0546eccc..c1b8d6683 100644
--- a/source/Pawn.cpp
+++ b/source/Pawn.cpp
@@ -19,10 +19,6 @@ cPawn::cPawn(eEntityType a_EntityType)
: cEntity(a_EntityType, 0, 0, 0)
, m_Health(1)
, m_MaxHealth(1)
- , m_LastPosX( 0.0 )
- , m_LastPosY( 0.0 )
- , m_LastPosZ( 0.0 )
- , m_TimeLastTeleportPacket(0)
, m_bBurnable(true)
, m_MetaData(NORMAL)
{
@@ -74,9 +70,9 @@ void cPawn::TakeDamage(eDamageType a_DamageType, cPawn * a_Attacker, int a_RawDa
TDI.RawDamage = a_RawDamage;
TDI.FinalDamage = a_FinalDamage;
Vector3d Heading;
- Heading.x = sin(m_Rot.x);
+ Heading.x = sin(GetRotation());
Heading.y = 0.4; // TODO: adjust the amount of "up" knockback when testing
- Heading.z = cos(m_Rot.x);
+ Heading.z = cos(GetRotation());
TDI.Knockback = Heading * a_KnockbackAmount;
DoTakeDamage(TDI);
}
@@ -134,7 +130,7 @@ void cPawn::KilledBy(cPawn * a_Killer)
// Drop loot:
cItems Drops;
GetDrops(Drops, a_Killer);
- m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z);
+ m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ());
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_DEAD);
}
@@ -321,9 +317,9 @@ void cPawn::SetMetaData(MetaData a_MetaData)
//----Change Entity MetaData
void cPawn::CheckMetaDataBurn()
{
- BLOCKTYPE Block = GetWorld()->GetBlock((int) m_Pos.x, (int) m_Pos.y, (int) m_Pos.z);
- BLOCKTYPE BlockAbove = GetWorld()->GetBlock((int) m_Pos.x, (int) m_Pos.y + 1, (int) m_Pos.z);
- BLOCKTYPE BlockBelow = GetWorld()->GetBlock((int) m_Pos.x, (int) m_Pos.y - 1, (int) m_Pos.z);
+ BLOCKTYPE Block = GetWorld()->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ());
+ BLOCKTYPE BlockAbove = GetWorld()->GetBlock((int) GetPosX(), (int) GetPosY() + 1, (int) GetPosZ());
+ BLOCKTYPE BlockBelow = GetWorld()->GetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ());
if (
(GetMetaData() == BURNING) &&
@@ -359,8 +355,8 @@ void cPawn::InStateBurning(float a_Dt)
return;
}
- BLOCKTYPE Block = GetWorld()->GetBlock((int)m_Pos.x, (int)m_Pos.y, (int)m_Pos.z);
- BLOCKTYPE BlockAbove = GetWorld()->GetBlock((int)m_Pos.x, (int)m_Pos.y + 1, (int)m_Pos.z);
+ BLOCKTYPE Block = GetWorld()->GetBlock((int)GetPosX(), (int)GetPosY(), (int)GetPosZ());
+ BLOCKTYPE BlockAbove = GetWorld()->GetBlock((int)GetPosX(), (int)GetPosY() + 1, (int)GetPosZ());
m_FireDamageInterval = 0;
TakeDamage(dtOnFire, NULL, 1, 0);
diff --git a/source/Pawn.h b/source/Pawn.h
index f9b2d4555..9ddc61296 100644
--- a/source/Pawn.h
+++ b/source/Pawn.h
@@ -163,8 +163,6 @@ protected:
MetaData m_MetaData;
- double m_LastPosX, m_LastPosY, m_LastPosZ;
- Int64 m_TimeLastTeleportPacket; // In ticks
}; // tolua_export
diff --git a/source/Pickup.cpp b/source/Pickup.cpp
index d27a2aba7..5775782f5 100644
--- a/source/Pickup.cpp
+++ b/source/Pickup.cpp
@@ -33,7 +33,7 @@ cPickup::cPickup(int a_MicroPosX, int a_MicroPosY, int a_MicroPosZ, const cItem
, m_Item(a_Item)
, m_bCollected( false )
{
- m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ);
+ SetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ);
}
@@ -80,7 +80,7 @@ void cPickup::Tick(float a_Dt, MTRand & a_TickRandom)
return;
}
- if (m_Pos.y < -8) // Out of this world and no more visible!
+ if (GetPosY() < -8) // Out of this world and no more visible!
{
Destroy();
return;
@@ -108,15 +108,15 @@ void cPickup::HandlePhysics(float a_Dt)
if (m_bOnGround) // check if it's still on the ground
{
- int BlockX = (m_Pos.x < 0) ? (int)m_Pos.x - 1 : (int)m_Pos.x;
- int BlockZ = (m_Pos.z < 0) ? (int)m_Pos.z - 1 : (int)m_Pos.z;
- char BlockBelow = World->GetBlock(BlockX, (int)m_Pos.y - 1, BlockZ);
+ int BlockX = (GetPosX() < 0) ? (int)GetPosX() - 1 : (int)GetPosX();
+ int BlockZ = (GetPosZ() < 0) ? (int)GetPosZ() - 1 : (int)GetPosZ();
+ char BlockBelow = World->GetBlock(BlockX, (int)GetPosY() - 1, BlockZ);
if (BlockBelow == E_BLOCK_AIR || IsBlockWater(BlockBelow))
{
m_bOnGround = false;
}
- char Block = World->GetBlock(BlockX, (int)m_Pos.y - (int)m_bOnGround, BlockZ );
- char BlockIn = World->GetBlock(BlockX, (int)m_Pos.y, BlockZ );
+ char Block = World->GetBlock(BlockX, (int)GetPosY() - (int)m_bOnGround, BlockZ );
+ char BlockIn = World->GetBlock(BlockX, (int)GetPosY(), BlockZ );
if( IsBlockLava(Block) || Block == E_BLOCK_FIRE
|| IsBlockLava(BlockIn) || BlockIn == E_BLOCK_FIRE)
@@ -129,17 +129,17 @@ void cPickup::HandlePhysics(float a_Dt)
if( BlockIn != E_BLOCK_AIR && !IsBlockWater(BlockIn) ) // If in ground itself, push it out
{
m_bOnGround = true;
- m_Pos.y += 0.2;
+ SetPosY(GetPosY() + 0.2);
m_bReplicated = false;
}
- m_Speed.x *= 0.7f / (1 + a_Dt);
- if (fabs(m_Speed.x) < 0.05) m_Speed.x = 0;
- m_Speed.z *= 0.7f / (1 + a_Dt);
- if (fabs(m_Speed.z) < 0.05) m_Speed.z = 0;
+ SetSpeedX(GetSpeedX() * 0.7f/(1+a_Dt));
+ if( fabs(GetSpeedX()) < 0.05 ) SetSpeedX(0);
+ SetSpeedZ(GetSpeedZ() * 0.7f/(1+a_Dt));
+ if( fabs(GetSpeedZ()) < 0.05 ) SetSpeedZ(0);
}
// get flowing direction
- Direction WaterDir = World->GetWaterSimulator()->GetFlowingDirection((int) m_Pos.x - 1, (int) m_Pos.y, (int) m_Pos.z - 1);
+ Direction WaterDir = World->GetWaterSimulator()->GetFlowingDirection((int) GetSpeedX() - 1, (int) GetSpeedY(), (int) GetSpeedZ() - 1);
m_WaterSpeed *= 0.9f; //Keep old speed but lower it
@@ -176,10 +176,10 @@ void cPickup::HandlePhysics(float a_Dt)
{
Gravity = -3;
}
- m_Speed.y += Gravity;
+ SetSpeedY(GetSpeedY() + Gravity);
// Set to hit position
- m_ResultingSpeed += m_Speed;
+ m_ResultingSpeed += GetSpeed();
/*
LOGD("Pickup #%d speed: {%.03f, %.03f, %.03f}, pos {%.02f, %.02f, %.02f}",
@@ -190,38 +190,38 @@ void cPickup::HandlePhysics(float a_Dt)
*/
cTracer Tracer(GetWorld());
- int Ret = Tracer.Trace(m_Pos, m_Speed, 2);
+ int Ret = Tracer.Trace(GetPosition(), GetSpeed(), 2);
if (Ret) // Oh noez! we hit something
{
- if ((Tracer.RealHit - Vector3f(m_Pos)).SqrLength() <= ( m_ResultingSpeed * a_Dt ).SqrLength())
+ if ((Tracer.RealHit - Vector3f(GetPosition())).SqrLength() <= ( m_ResultingSpeed * a_Dt ).SqrLength())
{
m_bReplicated = false; // It's only interesting to replicate when we actually hit something...
if (Ret == 1)
{
- if (Tracer.HitNormal.x != 0.f ) m_Speed.x = 0.f;
- if (Tracer.HitNormal.y != 0.f ) m_Speed.y = 0.f;
- if (Tracer.HitNormal.z != 0.f ) m_Speed.z = 0.f;
+ if( Tracer.HitNormal.x != 0.f ) SetSpeedX(0.f);
+ if( Tracer.HitNormal.y != 0.f ) SetSpeedY(0.f);
+ if( Tracer.HitNormal.z != 0.f ) SetSpeedZ(0.f);
if (Tracer.HitNormal.y > 0) // means on ground
{
m_bOnGround = true;
}
}
- m_Pos = Tracer.RealHit;
- m_Pos += Tracer.HitNormal * 0.2f;
+ SetPosition(Tracer.RealHit);
+ SetPosition(GetPosition() + (Tracer.HitNormal * 0.2f));
}
else
- m_Pos += m_ResultingSpeed * a_Dt;
+ SetPosition(GetPosition() + (m_ResultingSpeed*a_Dt));
}
else
{ // We didn't hit anything, so move =]
- m_Pos += m_ResultingSpeed * a_Dt;
+ SetPosition(GetPosition() + (m_ResultingSpeed*a_Dt));
}
}
// Usable for debugging
- SetPosition(m_Pos.x, m_Pos.y, m_Pos.z);
+ //SetPosition(m_Pos.x, m_Pos.y, m_Pos.z);
}
@@ -255,7 +255,7 @@ bool cPickup::CollectedBy(cPlayer * a_Dest)
{
cItems Pickup;
Pickup.push_back(cItem(m_Item));
- m_World->SpawnItemPickups(Pickup, m_Pos.x, m_Pos.y, m_Pos.z);
+ m_World->SpawnItemPickups(Pickup, GetPosX(), GetPosY(), GetPosZ());
}
return true;
}
diff --git a/source/Player.cpp b/source/Player.cpp
index 2e05fed26..cde975afd 100644
--- a/source/Player.cpp
+++ b/source/Player.cpp
@@ -80,17 +80,17 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
if (!LoadFromDisk())
{
m_Inventory.Clear();
- m_Pos.x = cRoot::Get()->GetDefaultWorld()->GetSpawnX();
- m_Pos.y = cRoot::Get()->GetDefaultWorld()->GetSpawnY();
- m_Pos.z = cRoot::Get()->GetDefaultWorld()->GetSpawnZ();
+ SetPosX(cRoot::Get()->GetDefaultWorld()->GetSpawnX());
+ SetPosY(cRoot::Get()->GetDefaultWorld()->GetSpawnY());
+ SetPosZ(cRoot::Get()->GetDefaultWorld()->GetSpawnZ());
LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
- a_PlayerName.c_str(), m_Pos.x, m_Pos.y, m_Pos.z
+ a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
);
}
- m_LastJumpHeight = (float)(m_Pos.y);
- m_LastGroundHeight = (float)(m_Pos.y);
- m_Stance = m_Pos.y + 1.62;
+ m_LastJumpHeight = (float)(GetPosY());
+ m_LastGroundHeight = (float)(GetPosY());
+ m_Stance = GetPosY() + 1.62;
}
@@ -267,9 +267,9 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
if (!m_bTouchGround)
{
- if(m_Pos.y > m_LastJumpHeight) m_LastJumpHeight = (float)m_Pos.y;
+ if(GetPosY() > m_LastJumpHeight) m_LastJumpHeight = (float)GetPosY();
cWorld* World = GetWorld();
- char BlockID = World->GetBlock( float2int(m_Pos.x), float2int(m_Pos.y), float2int(m_Pos.z) );
+ char BlockID = World->GetBlock( float2int(GetPosX()), float2int(GetPosY()), float2int(GetPosZ()) );
if( BlockID != E_BLOCK_AIR )
{
// LOGD("TouchGround set to true by server");
@@ -278,22 +278,22 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
if( BlockID == E_BLOCK_WATER || BlockID == E_BLOCK_STATIONARY_WATER || BlockID == E_BLOCK_LADDER || BlockID == E_BLOCK_VINES )
{
// LOGD("Water / Ladder / Torch");
- m_LastGroundHeight = (float)m_Pos.y;
+ m_LastGroundHeight = (float)GetPosY();
}
}
if (m_bTouchGround)
{
- float Dist = (float)(m_LastGroundHeight - floor(m_Pos.y));
+ float Dist = (float)(m_LastGroundHeight - floor(GetPosY()));
int Damage = (int)(Dist - 3.f);
if(m_LastJumpHeight > m_LastGroundHeight) Damage++;
- m_LastJumpHeight = (float)m_Pos.y;
+ m_LastJumpHeight = (float)GetPosY();
if (Damage > 0)
{
super::TakeDamage(dtFalling, NULL, Damage, Damage, 0);
}
- m_LastGroundHeight = (float)m_Pos.y;
+ m_LastGroundHeight = (float)GetPosY();
}
}
@@ -391,7 +391,7 @@ void cPlayer::KilledBy(cPawn * a_Killer)
}
Items[i].Empty();
}
- m_World->SpawnItemPickups(Pickups, m_Pos.x, m_Pos.y, m_Pos.z, 10);
+ m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10);
SaveToDisk(); // Save it, yeah the world is a tough place !
}
@@ -424,7 +424,7 @@ double cPlayer::GetEyeHeight()
Vector3d cPlayer::GetEyePosition()
{
- return Vector3d( m_Pos.x, m_Stance, m_Pos.z );
+ return Vector3d( GetPosX(), m_Stance, GetPosZ() );
}
@@ -558,7 +558,7 @@ void cPlayer::TeleportTo(double a_PosX, double a_PosY, double a_PosZ)
void cPlayer::MoveTo( const Vector3d & a_NewPos )
{
- if ((a_NewPos.y < -990) && (m_Pos.y > -100))
+ if ((a_NewPos.y < -990) && (GetPosY() > -100))
{
// When attached to an entity, the client sends position packets with weird coords:
// Y = -999 and X, Z = attempting to create speed, usually up to 0.03
@@ -952,17 +952,17 @@ bool cPlayer::LoadFromDisk()
Json::Value & JSON_PlayerPosition = root["position"];
if (JSON_PlayerPosition.size() == 3)
{
- m_Pos.x = JSON_PlayerPosition[(unsigned int)0].asDouble();
- m_Pos.y = JSON_PlayerPosition[(unsigned int)1].asDouble();
- m_Pos.z = JSON_PlayerPosition[(unsigned int)2].asDouble();
+ SetPosX(JSON_PlayerPosition[(unsigned int)0].asDouble());
+ SetPosY(JSON_PlayerPosition[(unsigned int)1].asDouble());
+ SetPosZ(JSON_PlayerPosition[(unsigned int)2].asDouble());
}
Json::Value & JSON_PlayerRotation = root["rotation"];
if (JSON_PlayerRotation.size() == 3)
{
- m_Rot.x = (float)JSON_PlayerRotation[(unsigned int)0].asDouble();
- m_Rot.y = (float)JSON_PlayerRotation[(unsigned int)1].asDouble();
- m_Rot.z = (float)JSON_PlayerRotation[(unsigned int)2].asDouble();
+ SetRotation ((float)JSON_PlayerRotation[(unsigned int)0].asDouble());
+ SetPitch ((float)JSON_PlayerRotation[(unsigned int)1].asDouble());
+ SetRoll ((float)JSON_PlayerRotation[(unsigned int)2].asDouble());
}
m_Health = (short)root.get("health", 0 ).asInt();
@@ -976,7 +976,7 @@ bool cPlayer::LoadFromDisk()
m_LoadedWorldName = root.get("world", "world").asString();
LOGD("Player \"%s\" was read from file, spawning at {%.2f, %.2f, %.2f} in world \"%s\"",
- m_PlayerName.c_str(), m_Pos.x, m_Pos.y, m_Pos.z, m_LoadedWorldName.c_str()
+ m_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ(), m_LoadedWorldName.c_str()
);
return true;
@@ -992,14 +992,14 @@ bool cPlayer::SaveToDisk()
// create the JSON data
Json::Value JSON_PlayerPosition;
- JSON_PlayerPosition.append( Json::Value( m_Pos.x ) );
- JSON_PlayerPosition.append( Json::Value( m_Pos.y ) );
- JSON_PlayerPosition.append( Json::Value( m_Pos.z ) );
+ JSON_PlayerPosition.append( Json::Value( GetPosX() ) );
+ JSON_PlayerPosition.append( Json::Value( GetPosY() ) );
+ JSON_PlayerPosition.append( Json::Value( GetPosZ() ) );
Json::Value JSON_PlayerRotation;
- JSON_PlayerRotation.append( Json::Value( m_Rot.x ) );
- JSON_PlayerRotation.append( Json::Value( m_Rot.y ) );
- JSON_PlayerRotation.append( Json::Value( m_Rot.z ) );
+ JSON_PlayerRotation.append( Json::Value( GetRotation() ) );
+ JSON_PlayerRotation.append( Json::Value( GetPitch() ) );
+ JSON_PlayerRotation.append( Json::Value( GetRoll() ) );
Json::Value JSON_Inventory;
m_Inventory.SaveToJson( JSON_Inventory );
diff --git a/source/Player.h b/source/Player.h
index 45f3a3226..7d825eec4 100644
--- a/source/Player.h
+++ b/source/Player.h
@@ -61,7 +61,7 @@ public:
double GetEyeHeight(); // tolua_export
Vector3d GetEyePosition(); // tolua_export
inline bool IsOnGround(void) const {return m_bTouchGround; } // tolua_export
- inline const double GetStance(void) const { return m_Pos.y + 1.62; } // tolua_export // TODO: Proper stance when crouching etc.
+ inline const double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc.
inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export
inline const cInventory & GetInventory(void) const { return m_Inventory; }