summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Entities/ArrowEntity.cpp4
-rw-r--r--src/Entities/Entity.cpp5
-rw-r--r--src/Vector3.h14
3 files changed, 20 insertions, 3 deletions
diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp
index db9dc781a..c76c710ef 100644
--- a/src/Entities/ArrowEntity.cpp
+++ b/src/Entities/ArrowEntity.cpp
@@ -69,7 +69,9 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const
void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace)
{
Vector3d Hit = a_HitPos;
- Hit += GetSpeed() / 700; // Make arrow sink into block a little
+ Vector3d SinkMovement = GetSpeed() / 800;
+ SinkMovement.Clamp(0.001, 0.001, 0.001, 0.05, 0.05, 0.05);
+ Hit += SinkMovement; // Make arrow sink into block a little
super::OnHitSolidBlock(Hit, a_HitFace);
int X = (int)floor(Hit.x), Y = (int)floor(Hit.y), Z = (int)floor(Hit.z);
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index f4e89367b..1683aa209 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -255,7 +255,8 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R
void cEntity::SetYawFromSpeed(void)
{
- if ((abs(m_Speed.x) < std::numeric_limits<double>::epsilon()) && (abs(m_Speed.z) < std::numeric_limits<double>::epsilon()))
+ const double EPS = 0.0000001;
+ if ((abs(m_Speed.x) < EPS) && (abs(m_Speed.z) < EPS))
{
// atan2() may overflow or is undefined, pick any number
SetYaw(0);
@@ -1235,7 +1236,7 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
if (GetWorld()->GetWorldAge() % 2 == 0)
{
double SpeedSqr = GetSpeed().SqrLength();
- if (SpeedSqr < std::numeric_limits<double>::epsilon())
+ if (SpeedSqr == 0.0)
{
// Speed is zero, send this to clients once only as well as an absolute position
if (!m_bHasSentNoSpeed)
diff --git a/src/Vector3.h b/src/Vector3.h
index 5faac1457..762fdfd71 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -274,6 +274,14 @@ public:
return (a_X - x) / (a_OtherEnd.x - x);
}
+ /** Clamps each value in the vector to within a specified range */
+ inline void Clamp(T a_MinX, T a_MinY, T a_MinZ, T a_MaxX, T a_MaxY, T a_MaxZ)
+ {
+ x = Clamp(x, (T)copysign(a_MinX, x), (T)copysign(a_MaxX, x));
+ y = Clamp(y, (T)copysign(a_MinY, y), (T)copysign(a_MaxY, y));
+ z = Clamp(z, (T)copysign(a_MinZ, z), (T)copysign(a_MaxZ, z));
+ }
+
/** The max difference between two coords for which the coords are assumed equal. */
static const double EPS;
@@ -288,6 +296,12 @@ protected:
{
return (a_Value < 0) ? -a_Value : a_Value;
}
+
+ /** Clamp X to the specified range. */
+ T Clamp(T a_Value, T a_Min, T a_Max)
+ {
+ return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value);
+ }
};
// tolua_end