1
0

Debug: arrow log their position in each tick

This commit is contained in:
madmaxoft 2013-08-26 22:27:28 +02:00
parent 4bbade9fc6
commit 71cfb8fcd2
3 changed files with 39 additions and 19 deletions

View File

@ -481,7 +481,7 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
{ {
// TODO Add collision detection with entities. // TODO Add collision detection with entities.
a_Dt /= 1000; a_Dt /= 1000; // Convert from msec to sec
Vector3d NextPos = Vector3d(GetPosX(),GetPosY(),GetPosZ()); Vector3d NextPos = Vector3d(GetPosX(),GetPosY(),GetPosZ());
Vector3d NextSpeed = Vector3d(GetSpeedX(),GetSpeedY(),GetSpeedZ()); Vector3d NextSpeed = Vector3d(GetSpeedX(),GetSpeedY(),GetSpeedZ());
int BlockX = (int) floor(NextPos.x); int BlockX = (int) floor(NextPos.x);
@ -497,7 +497,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
} }
// Make sure we got the correct chunk and a valid one. No one ever knows... // Make sure we got the correct chunk and a valid one. No one ever knows...
cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX,BlockZ); cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ);
if (NextChunk != NULL) if (NextChunk != NULL)
{ {
int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width);
@ -516,11 +516,12 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
} }
else else
{ {
//Push out entity. // Push out entity.
m_bOnGround = true; m_bOnGround = true;
NextPos.y += 0.2; NextPos.y += 0.2;
LOGD("Entity #%d (%s) is inside a block at {%d,%d,%d}", LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}",
m_UniqueID, GetClass(), BlockX, BlockY, BlockZ); m_UniqueID, GetClass(), BlockX, BlockY, BlockZ
);
} }
if (!m_bOnGround) if (!m_bOnGround)
@ -528,34 +529,40 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
float fallspeed; float fallspeed;
if (IsBlockWater(BlockIn)) if (IsBlockWater(BlockIn))
{ {
fallspeed = -3.0f * a_Dt; //Fall slower in water. fallspeed = -3.0f * a_Dt; // Fall slower in water.
} }
else if (BlockIn == E_BLOCK_COBWEB) else if (BlockIn == E_BLOCK_COBWEB)
{ {
NextSpeed.y *= 0.05; //Reduce overall falling speed NextSpeed.y *= 0.05; // Reduce overall falling speed
fallspeed = 0; //No falling. fallspeed = 0; // No falling.
} }
else else
{ {
//Normal gravity // Normal gravity
fallspeed = m_Gravity * a_Dt; fallspeed = m_Gravity * a_Dt;
} }
NextSpeed.y += fallspeed; NextSpeed.y += fallspeed;
} }
else else
{ {
//Friction // Friction
if (NextSpeed.SqrLength() > 0.0004f) if (NextSpeed.SqrLength() > 0.0004f)
{ {
NextSpeed.x *= 0.7f/(1+a_Dt); NextSpeed.x *= 0.7f / (1 + a_Dt);
if ( fabs(NextSpeed.x) < 0.05 ) NextSpeed.x = 0; if (fabs(NextSpeed.x) < 0.05)
NextSpeed.z *= 0.7f/(1+a_Dt); {
if ( fabs(NextSpeed.z) < 0.05 ) NextSpeed.z = 0; NextSpeed.x = 0;
}
NextSpeed.z *= 0.7f / (1 + a_Dt);
if (fabs(NextSpeed.z) < 0.05)
{
NextSpeed.z = 0;
}
} }
} }
//Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
//might have different speed modifiers according to terrain. // might have different speed modifiers according to terrain.
if (BlockIn == E_BLOCK_COBWEB) if (BlockIn == E_BLOCK_COBWEB)
{ {
NextSpeed.x *= 0.25; NextSpeed.x *= 0.25;
@ -1032,9 +1039,9 @@ void cEntity::SetMass(double a_Mass)
} }
else else
{ {
//Make sure that mass is not zero. 1g is the default because we // Make sure that mass is not zero. 1g is the default because we
//have to choose a number. It's perfectly legal to have a mass // have to choose a number. It's perfectly legal to have a mass
//less than 1g as long as is NOT equal or less than zero. // less than 1g as long as is NOT equal or less than zero.
m_Mass = 0.001; m_Mass = 0.001;
} }
} }

View File

@ -115,6 +115,18 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const
void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
// DEBUG:
LOGD("Arrow %d: {%.02f, %.02f, %.02f}", m_UniqueID, GetPosX(), GetPosY(), GetPosZ());
}
void cArrowEntity::SpawnOn(cClientHandle & a_Client) void cArrowEntity::SpawnOn(cClientHandle & a_Client)
{ {
a_Client.SendSpawnObject(*this, pkArrow, 0, 0, 0); a_Client.SendSpawnObject(*this, pkArrow, 0, 0, 0);

View File

@ -127,6 +127,7 @@ protected:
double m_DamageCoeff; double m_DamageCoeff;
// cEntity overrides: // cEntity overrides:
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void SpawnOn(cClientHandle & a_Client) override; virtual void SpawnOn(cClientHandle & a_Client) override;
// tolua_begin // tolua_begin