1
0

Converted cPickupEntity to std::chrono

This commit is contained in:
Tycho 2015-01-16 13:49:22 +00:00
parent 8dc9cf0c76
commit 05c40db060
2 changed files with 12 additions and 12 deletions

View File

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

View File

@ -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<int>(m_Timer / 50); } // tolua_export
int GetAge(void) const { return std::chrono::duration_cast<cTickTime>(m_Timer).count(); } // tolua_export
/** Set the number of ticks that this entity has existed */
void SetAge(int a_Age) { m_Timer = static_cast<float>(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;