diff options
author | madmaxoft <github@xoft.cz> | 2013-08-26 22:27:28 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-08-26 22:27:28 +0200 |
commit | 71cfb8fcd2a037feef0a2a2efe8e1bcb81f7750c (patch) | |
tree | fb040996e565cda6596e83875e756273ed1db065 /source | |
parent | Arrows get loaded from MCA. (diff) | |
download | cuberite-71cfb8fcd2a037feef0a2a2efe8e1bcb81f7750c.tar cuberite-71cfb8fcd2a037feef0a2a2efe8e1bcb81f7750c.tar.gz cuberite-71cfb8fcd2a037feef0a2a2efe8e1bcb81f7750c.tar.bz2 cuberite-71cfb8fcd2a037feef0a2a2efe8e1bcb81f7750c.tar.lz cuberite-71cfb8fcd2a037feef0a2a2efe8e1bcb81f7750c.tar.xz cuberite-71cfb8fcd2a037feef0a2a2efe8e1bcb81f7750c.tar.zst cuberite-71cfb8fcd2a037feef0a2a2efe8e1bcb81f7750c.zip |
Diffstat (limited to 'source')
-rw-r--r-- | source/Entities/Entity.cpp | 45 | ||||
-rw-r--r-- | source/Entities/ProjectileEntity.cpp | 12 | ||||
-rw-r--r-- | source/Entities/ProjectileEntity.h | 1 |
3 files changed, 39 insertions, 19 deletions
diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 65860118a..608f5a73b 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -481,7 +481,7 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { // TODO Add collision detection with entities. - a_Dt /= 1000; + a_Dt /= 1000; // Convert from msec to sec Vector3d NextPos = Vector3d(GetPosX(),GetPosY(),GetPosZ()); Vector3d NextSpeed = Vector3d(GetSpeedX(),GetSpeedY(),GetSpeedZ()); 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... - cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX,BlockZ); + cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); if (NextChunk != NULL) { int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); @@ -516,11 +516,12 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } else { - //Push out entity. + // Push out entity. m_bOnGround = true; NextPos.y += 0.2; - LOGD("Entity #%d (%s) is inside a block at {%d,%d,%d}", - m_UniqueID, GetClass(), BlockX, BlockY, BlockZ); + LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}", + m_UniqueID, GetClass(), BlockX, BlockY, BlockZ + ); } if (!m_bOnGround) @@ -528,34 +529,40 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) float fallspeed; 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) { - NextSpeed.y *= 0.05; //Reduce overall falling speed - fallspeed = 0; //No falling. + NextSpeed.y *= 0.05; // Reduce overall falling speed + fallspeed = 0; // No falling. } else { - //Normal gravity + // Normal gravity fallspeed = m_Gravity * a_Dt; } NextSpeed.y += fallspeed; } else { - //Friction + // Friction if (NextSpeed.SqrLength() > 0.0004f) { - NextSpeed.x *= 0.7f/(1+a_Dt); - if ( fabs(NextSpeed.x) < 0.05 ) NextSpeed.x = 0; - NextSpeed.z *= 0.7f/(1+a_Dt); - if ( fabs(NextSpeed.z) < 0.05 ) NextSpeed.z = 0; + NextSpeed.x *= 0.7f / (1 + a_Dt); + if (fabs(NextSpeed.x) < 0.05) + { + 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 - //might have different speed modifiers according to terrain. + // 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. if (BlockIn == E_BLOCK_COBWEB) { NextSpeed.x *= 0.25; @@ -1032,9 +1039,9 @@ void cEntity::SetMass(double a_Mass) } else { - //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 - //less than 1g as long as is NOT equal or less than zero. + // 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 + // less than 1g as long as is NOT equal or less than zero. m_Mass = 0.001; } } diff --git a/source/Entities/ProjectileEntity.cpp b/source/Entities/ProjectileEntity.cpp index 66d9409f5..552a61c42 100644 --- a/source/Entities/ProjectileEntity.cpp +++ b/source/Entities/ProjectileEntity.cpp @@ -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) { a_Client.SendSpawnObject(*this, pkArrow, 0, 0, 0); diff --git a/source/Entities/ProjectileEntity.h b/source/Entities/ProjectileEntity.h index cf107e15b..345730d19 100644 --- a/source/Entities/ProjectileEntity.h +++ b/source/Entities/ProjectileEntity.h @@ -127,6 +127,7 @@ protected: double m_DamageCoeff; // cEntity overrides: + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; // tolua_begin |