From d4f90259b8cd3e5d90dd419930c8635105ea4d0f Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 28 May 2014 16:12:10 +0200 Subject: Fix Y-Position from arrow entity. --- src/Entities/ArrowEntity.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 8d2569125..fbc535e63 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -19,6 +19,7 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a m_bIsCollected(false), m_HitBlockPos(Vector3i(0, 0, 0)) { + SetPosY(GetPosY() + a_Creator->GetHeight() - 0.1000000014901161); SetSpeed(a_Speed); SetMass(0.1); SetYawFromSpeed(); -- cgit v1.2.3 From e7a7c45c3681e90cb9ab13d16935aae9860f1077 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 28 May 2014 16:39:59 +0200 Subject: Add throw sound and fix arrow server crash. --- src/Entities/ArrowEntity.cpp | 5 ++++- src/Entities/ThrownSnowballEntity.cpp | 4 ---- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index fbc535e63..769750bd4 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -19,7 +19,10 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a m_bIsCollected(false), m_HitBlockPos(Vector3i(0, 0, 0)) { - SetPosY(GetPosY() + a_Creator->GetHeight() - 0.1000000014901161); + if (a_Creator != NULL) + { + SetPosY(GetPosY() + a_Creator->GetHeight() - 0.1000000014901161); + } SetSpeed(a_Speed); SetMass(0.1); SetYawFromSpeed(); diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp index 427f630f7..cefc3433c 100644 --- a/src/Entities/ThrownSnowballEntity.cpp +++ b/src/Entities/ThrownSnowballEntity.cpp @@ -36,10 +36,6 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & { TotalDamage = 3; } - else if (MobType == cMonster::mtEnderDragon) - { - TotalDamage = 1; - } } // TODO: If entity is Ender Crystal, destroy it a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); -- cgit v1.2.3 From 92d9ab0f6dbd5e6d9b23ed309daa473b00c70ebb Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 30 May 2014 22:25:57 +0200 Subject: Wrong arrow commit. --- src/Entities/ArrowEntity.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 769750bd4..8d2569125 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -19,10 +19,6 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a m_bIsCollected(false), m_HitBlockPos(Vector3i(0, 0, 0)) { - if (a_Creator != NULL) - { - SetPosY(GetPosY() + a_Creator->GetHeight() - 0.1000000014901161); - } SetSpeed(a_Speed); SetMass(0.1); SetYawFromSpeed(); -- cgit v1.2.3 From ee50790398791c38e563eee04cf12780fab74baf Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 16 Jun 2014 15:12:50 +0100 Subject: Merge branch 'master' of github.com:mc-server/MCServer --- src/Entities/Entity.cpp | 38 ++++++++++++++++++-------------------- src/Entities/Entity.h | 35 +++++++++++++++++++++++++---------- src/Entities/Player.cpp | 30 +++++++++++++++++++++++++++++- src/Entities/Player.h | 11 +++++++++-- 4 files changed, 81 insertions(+), 33 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8f736a269..ee7ce06ac 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -179,14 +179,9 @@ void cEntity::WrapRotation(void) void cEntity::WrapSpeed(void) { - // There shoudn't be a need for flipping the flag on because this function is called - // after any update, so the flag is already turned on - if (m_Speed.x > 78.0f) m_Speed.x = 78.0f; - else if (m_Speed.x < -78.0f) m_Speed.x = -78.0f; - if (m_Speed.y > 78.0f) m_Speed.y = 78.0f; - else if (m_Speed.y < -78.0f) m_Speed.y = -78.0f; - if (m_Speed.z > 78.0f) m_Speed.z = 78.0f; - else if (m_Speed.z < -78.0f) m_Speed.z = -78.0f; + m_Speed.x = Clamp(m_Speed.x, -78.0, 78.0); + m_Speed.y = Clamp(m_Speed.y, -78.0, 78.0); + m_Speed.z = Clamp(m_Speed.z, -78.0, 78.0); } @@ -1076,6 +1071,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 +1434,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 +1442,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 +1450,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 +1458,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 85ad42d54..2df66e353 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -215,11 +215,22 @@ public: void SetYaw (double a_Yaw); // In degrees, normalizes to [-180, +180) void SetPitch (double a_Pitch); // In degrees, normalizes to [-180, +180) void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180) - void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); - void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } - void SetSpeedX (double a_SpeedX); - void SetSpeedY (double a_SpeedY); - 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); void AddPosX (double a_AddPosX); @@ -429,6 +440,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; @@ -486,11 +500,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); @@ -506,9 +524,6 @@ private: /** Measured in degrees, [-180, +180) */ double m_HeadYaw; - /** Measured in meter/second (m/s) */ - Vector3d m_Speed; - /** Measured in degrees, [-180, +180) */ Vector3d m_Rot; diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index feb09b5d2..fdc0bb390 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -22,6 +22,12 @@ #include "inifile/iniFile.h" #include "json/json.h" +// 6000 ticks or 5 minutes +#define PLAYER_INVENTORY_SAVE_INTERVAL 6000 + +// 1000 = once per second +#define PLAYER_LIST_TIME_MS 1000 + @@ -64,6 +70,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_BowCharge(0) , m_FloaterID(-1) , m_Team(NULL) + , m_TicksUntilNextSave(PLAYER_INVENTORY_SAVE_INTERVAL) { LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", a_PlayerName.c_str(), a_Client->GetIPString().c_str(), @@ -250,7 +257,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) // Send Player List (Once per m_LastPlayerListTime/1000 ms) cTimer t1; - if (m_LastPlayerListTime + cPlayer::PLAYER_LIST_TIME_MS <= t1.GetNowTime()) + if (m_LastPlayerListTime + PLAYER_LIST_TIME_MS <= t1.GetNowTime()) { m_World->SendPlayerList(this); m_LastPlayerListTime = t1.GetNowTime(); @@ -260,6 +267,16 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) { m_LastGroundHeight = (float)GetPosY(); } + + if (m_TicksUntilNextSave == 0) + { + SaveToDisk(); + m_TicksUntilNextSave = PLAYER_INVENTORY_SAVE_INTERVAL; + } + else + { + m_TicksUntilNextSave--; + } } @@ -1257,6 +1274,17 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const void cPlayer::ForceSetSpeed(const Vector3d & a_Speed) { SetSpeed(a_Speed); +} + + + + + +void cPlayer::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) +{ + super::DoSetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ); + + // Send the speed to the client so he actualy moves m_ClientHandle->SendEntityVelocity(*this); } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 83b9ad593..b2142a18b 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -194,7 +194,8 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); - /** Forces the player to move in the given direction. */ + /** Forces the player to move in the given direction. + @deprecated Use SetSpeed instead. */ void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export /** Tries to move to a new position, with attachment-related checks (y == -999) */ @@ -461,7 +462,6 @@ protected: cItem m_DraggingItem; long long m_LastPlayerListTime; - static const unsigned short PLAYER_LIST_TIME_MS = 1000; // 1000 = once per second cClientHandle * m_ClientHandle; @@ -512,6 +512,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); @@ -539,6 +542,10 @@ protected: Set by a right click on unoccupied bed, unset by a time fast forward or teleport */ bool m_bIsInBed; + /** How long till the player's inventory will be saved + Default save interval is #defined in PLAYER_INVENTORY_SAVE_INTERVAL */ + unsigned int m_TicksUntilNextSave; + } ; // tolua_export -- cgit v1.2.3 From e8143de01bff31f9e153949d7ab5b0df82629541 Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 19 Jun 2014 01:49:56 -0700 Subject: Nullify deleted pointers. --- src/Entities/Player.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index fdc0bb390..e1e03fded 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -146,6 +146,7 @@ cPlayer::~cPlayer(void) m_ClientHandle = NULL; delete m_InventoryWindow; + m_InventoryWindow = NULL; LOGD("Player %p deleted", this); } -- cgit v1.2.3