summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Entities/Entity.cpp27
-rw-r--r--src/Entities/Entity.h39
-rw-r--r--src/Entities/Player.cpp58
-rw-r--r--src/Entities/Player.h13
4 files changed, 44 insertions, 93 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 8f736a269..76bd11406 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1076,6 +1076,17 @@ void cEntity::SetSwimState(cChunk & a_Chunk)
+void cEntity::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
+{
+ m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ);
+
+ WrapSpeed();
+}
+
+
+
+
+
void cEntity::HandleAir(void)
{
// Ref.: http://www.minecraftwiki.net/wiki/Chunk_format
@@ -1428,9 +1439,7 @@ 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);
-
- WrapSpeed();
+ DoSetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ);
}
@@ -1438,9 +1447,7 @@ void cEntity::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
void cEntity::SetSpeedX(double a_SpeedX)
{
- m_Speed.x = a_SpeedX;
-
- WrapSpeed();
+ SetSpeed(a_SpeedX, m_Speed.y, m_Speed.z);
}
@@ -1448,9 +1455,7 @@ void cEntity::SetSpeedX(double a_SpeedX)
void cEntity::SetSpeedY(double a_SpeedY)
{
- m_Speed.y = a_SpeedY;
-
- WrapSpeed();
+ SetSpeed(m_Speed.x, a_SpeedY, m_Speed.z);
}
@@ -1458,9 +1463,7 @@ void cEntity::SetSpeedY(double a_SpeedY)
void cEntity::SetSpeedZ(double a_SpeedZ)
{
- m_Speed.z = a_SpeedZ;
-
- WrapSpeed();
+ SetSpeed(m_Speed.x, m_Speed.y, a_SpeedZ);
}
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index fed856b30..cb35db43b 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -217,21 +217,21 @@ public:
void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180)
// tolua_end
- /** Measured in meter/second (m/s) */
- Vector3d m_Speed;
-
// tolua_begin
- /** Sets the speed of the entity and moves them in the given speed. */
- virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ);
- /** Sets the speed of the entity and moves them in the given speed. */
- void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); }
-
- /** Sets the speed for the X axis */
- virtual void SetSpeedX (double a_SpeedX);
- /** Sets the speed for the Y axis */
- virtual void SetSpeedY (double a_SpeedY);
- /** Sets the speed for the Z axis */
- virtual void SetSpeedZ (double a_SpeedZ);
+ /** Sets the speed of the entity, measured in m / sec */
+ void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ);
+
+ /** Sets the speed of the entity, measured in m / sec */
+ void SetSpeed(const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); }
+
+ /** Sets the speed in the X axis, leaving the other speed components intact. Measured in m / sec. */
+ void SetSpeedX(double a_SpeedX);
+
+ /** Sets the speed in the Y axis, leaving the other speed components intact. Measured in m / sec. */
+ void SetSpeedY(double a_SpeedY);
+
+ /** Sets the speed in the Z axis, leaving the other speed components intact. Measured in m / sec. */
+ void SetSpeedZ(double a_SpeedZ);
void SetWidth (double a_Width);
@@ -442,6 +442,9 @@ protected:
static cCriticalSection m_CSCount;
static int m_EntityCount;
+ /** Measured in meter/second (m/s) */
+ Vector3d m_Speed;
+
int m_UniqueID;
int m_Health;
@@ -499,11 +502,15 @@ protected:
/// Time, in ticks, since the last damage dealt by the void. Reset to zero when moving out of the void.
int m_TicksSinceLastVoidDamage;
-
+
+ /** Does the actual speed-setting. The default implementation just sets the member variable value;
+ overrides can provide further processing, such as forcing players to move at the given speed. */
+ virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ);
+
virtual void Destroyed(void) {} // Called after the entity has been destroyed
/** Called in each tick to handle air-related processing i.e. drowning */
- virtual void HandleAir();
+ virtual void HandleAir(void);
/** Called once per tick to set IsSwimming and IsSubmerged */
virtual void SetSwimState(cChunk & a_Chunk);
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 33b339f8e..f1e0aad7e 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1257,30 +1257,15 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const
void cPlayer::ForceSetSpeed(const Vector3d & a_Speed)
{
SetSpeed(a_Speed);
- m_ClientHandle->SendEntityVelocity(*this);
-}
-
-
-
-
-
-void cPlayer::SetSpeed(const Vector3d & a_Speed)
-{
- m_Speed.Set(a_Speed.x, a_Speed.y, a_Speed.z);
- WrapSpeed();
-
- // Send the speed to the client so he actualy moves
- m_ClientHandle->SendEntityVelocity(*this);
}
-void cPlayer::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
+void cPlayer::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
{
- m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ);
- WrapSpeed();
+ super::DoSetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ);
// Send the speed to the client so he actualy moves
m_ClientHandle->SendEntityVelocity(*this);
@@ -1290,45 +1275,6 @@ void cPlayer::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
-void cPlayer::SetSpeedX(double a_SpeedX)
-{
- m_Speed.x = a_SpeedX;
- WrapSpeed();
-
- // Send the speed to the client so he actualy moves
- m_ClientHandle->SendEntityVelocity(*this);
-}
-
-
-
-
-
-void cPlayer::SetSpeedY(double a_SpeedY)
-{
- m_Speed.y = a_SpeedY;
- WrapSpeed();
-
- // Send the speed to the client so he actualy moves
- m_ClientHandle->SendEntityVelocity(*this);
-}
-
-
-
-
-
-void cPlayer::SetSpeedZ(double a_SpeedZ)
-{
- m_Speed.z = a_SpeedZ;
- WrapSpeed();
-
- // Send the speed to the client so he actualy moves
- m_ClientHandle->SendEntityVelocity(*this);
-}
-
-
-
-
-
void cPlayer::MoveTo( const Vector3d & a_NewPos )
{
if ((a_NewPos.y < -990) && (GetPosY() > -100))
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 165963e6e..325ff9005 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -195,17 +195,9 @@ public:
void LoginSetGameMode(eGameMode a_GameMode);
/** Forces the player to move in the given direction.
- * @deprecated Use SetSpeed instead.
- */
+ @deprecated Use SetSpeed instead. */
void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export
- /** Sets the speed of the player and moves them in the given speed. */
- void SetSpeed (const Vector3d & a_Speed);
- virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ) override;
- virtual void SetSpeedX (double a_SpeedX) override;
- virtual void SetSpeedY (double a_SpeedY) override;
- virtual void SetSpeedZ (double a_SpeedZ) override;
-
/** Tries to move to a new position, with attachment-related checks (y == -999) */
void MoveTo(const Vector3d & a_NewPos); // tolua_export
@@ -521,6 +513,9 @@ protected:
+ /** Sets the speed and sends it to the client, so that they are forced to move so. */
+ virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override;
+
void ResolvePermissions(void);
void ResolveGroups(void);