1
0

Refactored speed-setting to use a common function for all cases.

This commit is contained in:
madmaxoft 2014-06-14 17:10:53 +02:00
parent f8f7748a09
commit 3f009a7c9e
4 changed files with 43 additions and 92 deletions

View File

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

View File

@ -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 of the entity, measured in m / sec */
void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ);
/** 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(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);

View File

@ -1257,70 +1257,16 @@ 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)
void cPlayer::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
{
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);
}
super::DoSetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ);
void cPlayer::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
{
m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ);
WrapSpeed();
// Send the speed to the client so he actualy moves
m_ClientHandle->SendEntityVelocity(*this);
}
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);
}

View File

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