Implement sf::Time
with <chrono>
This commit is contained in:
parent
41053f9983
commit
ebb2d9d186
@ -30,6 +30,8 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/Export.hpp>
|
#include <SFML/System/Export.hpp>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
@ -103,7 +105,7 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Int64 m_microseconds; //!< Time value stored as microseconds
|
std::chrono::microseconds m_microseconds; //!< Time value stored as microseconds
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -32,21 +32,21 @@ constexpr Time::Time() : m_microseconds(0)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr float Time::asSeconds() const
|
constexpr float Time::asSeconds() const
|
||||||
{
|
{
|
||||||
return static_cast<float>(static_cast<double>(m_microseconds) / 1000000.0);
|
return std::chrono::duration<float>(m_microseconds).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Int32 Time::asMilliseconds() const
|
constexpr Int32 Time::asMilliseconds() const
|
||||||
{
|
{
|
||||||
return static_cast<Int32>(m_microseconds / 1000);
|
return std::chrono::duration_cast<std::chrono::duration<Int32, std::milli>>(m_microseconds).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Int64 Time::asMicroseconds() const
|
constexpr Int64 Time::asMicroseconds() const
|
||||||
{
|
{
|
||||||
return m_microseconds;
|
return m_microseconds.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user