From 05c40db060809612e6d0bb3bee596c4c95ce758d Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 16 Jan 2015 13:49:22 +0000 Subject: Converted cPickupEntity to std::chrono --- src/Entities/Pickup.cpp | 18 +++++++++--------- src/Entities/Pickup.h | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index accb42a63..9f2609894 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -86,7 +86,7 @@ protected: cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) : cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2) - , m_Timer(0.f) + , m_Timer(0) , m_Item(a_Item) , m_bCollected(false) , m_bIsPlayerCreated(IsPlayerCreated) @@ -115,7 +115,7 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); // Notify clients of position - m_Timer += a_Dt.count(); + m_Timer += a_Dt; if (!m_bCollected) { @@ -141,9 +141,9 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) ) { m_bCollected = true; - m_Timer = 0; // We have to reset the timer. - m_Timer += a_Dt.count(); // In case we have to destroy the pickup in the same tick. - if (m_Timer > 500.f) + m_Timer = std::chrono::milliseconds(0); // We have to reset the timer. + m_Timer += a_Dt; // In case we have to destroy the pickup in the same tick. + if (m_Timer > std::chrono::milliseconds(500)) { Destroy(true); return; @@ -167,14 +167,14 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } else { - if (m_Timer > 500.f) // 0.5 second + if (m_Timer > std::chrono::milliseconds(500)) // 0.5 second { Destroy(true); return; } } - if (m_Timer > 1000 * 60 * 5) // 5 minutes + if (m_Timer > std::chrono::minutes(5)) // 5 minutes { Destroy(true); return; @@ -200,7 +200,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest) } // Two seconds if player created the pickup (vomiting), half a second if anything else - if (m_Timer < (m_bIsPlayerCreated ? 2000.f : 500.f)) + if (m_Timer < (m_bIsPlayerCreated ? std::chrono::seconds(2) : std::chrono::milliseconds(500))) { // LOG("Pickup %d cannot be collected by \"%s\", because it is not old enough.", m_UniqueID, a_Dest->GetName().c_str()); return false; // Not old enough @@ -234,7 +234,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest) // All of the pickup has been collected, schedule the pickup for destroying m_bCollected = true; } - m_Timer = 0; + m_Timer = std::chrono::milliseconds(0); return true; } diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index 67f2756ca..ed5949f37 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -37,10 +37,10 @@ public: virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; /** Returns the number of ticks that this entity has existed */ - int GetAge(void) const { return static_cast(m_Timer / 50); } // tolua_export + int GetAge(void) const { return std::chrono::duration_cast(m_Timer).count(); } // tolua_export /** Set the number of ticks that this entity has existed */ - void SetAge(int a_Age) { m_Timer = static_cast(a_Age * 50); } // tolua_export + void SetAge(int a_Age) { m_Timer = cTickTime(a_Age); } // tolua_export /** Returns true if the pickup has already been collected */ bool IsCollected(void) const { return m_bCollected; } // tolua_export @@ -51,7 +51,7 @@ public: private: /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */ - float m_Timer; + std::chrono::milliseconds m_Timer; cItem m_Item; -- cgit v1.2.3