1
0

Added helper functions AddSpeed, AddSpeedX, AddSpeedY, AddSpeedZ, AddPosition, AddPosX, AddPosY, AddPosZ. Made sure that all entites use these helper functions.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1299 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
keyboard.osh@gmail.com 2013-03-23 04:33:47 +00:00
parent f41b33ba80
commit b32a60106f
6 changed files with 107 additions and 24 deletions

View File

@ -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_Speed += a_AddSpeed;
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.z += a_AddSpeedZ;
m_bDirtySpeed = true;
WrapSpeed();
}

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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);