Onsens  1.0
This is C++ game about bitwise logic.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sf::Time Class Reference

Represents a time value. More...

#include <Time.hpp>

+ Collaboration diagram for sf::Time:

Public Member Functions

 Time ()
 Default constructor. More...
 
float asSeconds () const
 Return the time value as a number of seconds. More...
 
Int32 asMilliseconds () const
 Return the time value as a number of milliseconds. More...
 
Int64 asMicroseconds () const
 Return the time value as a number of microseconds. More...
 

Static Public Attributes

static const Time Zero
 Predefined "zero" time value. More...
 

Friends

SFML_SYSTEM_API Time seconds (float)
 
SFML_SYSTEM_API Time milliseconds (Int32)
 
SFML_SYSTEM_API Time microseconds (Int64)
 

Related Functions

(Note that these are not member functions.)

SFML_SYSTEM_API Time seconds (float amount)
 Construct a time value from a number of seconds. More...
 
SFML_SYSTEM_API Time milliseconds (Int32 amount)
 Construct a time value from a number of milliseconds. More...
 
SFML_SYSTEM_API Time microseconds (Int64 amount)
 Construct a time value from a number of microseconds. More...
 
SFML_SYSTEM_API bool operator== (Time left, Time right)
 Overload of == operator to compare two time values. More...
 
SFML_SYSTEM_API bool operator!= (Time left, Time right)
 Overload of != operator to compare two time values. More...
 
SFML_SYSTEM_API bool operator< (Time left, Time right)
 Overload of < operator to compare two time values. More...
 
SFML_SYSTEM_API bool operator> (Time left, Time right)
 Overload of > operator to compare two time values. More...
 
SFML_SYSTEM_API bool operator<= (Time left, Time right)
 Overload of <= operator to compare two time values. More...
 
SFML_SYSTEM_API bool operator>= (Time left, Time right)
 Overload of >= operator to compare two time values. More...
 
SFML_SYSTEM_API Time operator- (Time right)
 Overload of unary - operator to negate a time value. More...
 
SFML_SYSTEM_API Time operator+ (Time left, Time right)
 Overload of binary + operator to add two time values. More...
 
SFML_SYSTEM_API Timeoperator+= (Time &left, Time right)
 Overload of binary += operator to add/assign two time values. More...
 
SFML_SYSTEM_API Time operator- (Time left, Time right)
 Overload of binary - operator to subtract two time values. More...
 
SFML_SYSTEM_API Timeoperator-= (Time &left, Time right)
 Overload of binary -= operator to subtract/assign two time values. More...
 
SFML_SYSTEM_API Time operator* (Time left, float right)
 Overload of binary * operator to scale a time value. More...
 
SFML_SYSTEM_API Time operator* (Time left, Int64 right)
 Overload of binary * operator to scale a time value. More...
 
SFML_SYSTEM_API Time operator* (float left, Time right)
 Overload of binary * operator to scale a time value. More...
 
SFML_SYSTEM_API Time operator* (Int64 left, Time right)
 Overload of binary * operator to scale a time value. More...
 
SFML_SYSTEM_API Timeoperator*= (Time &left, float right)
 Overload of binary *= operator to scale/assign a time value. More...
 
SFML_SYSTEM_API Timeoperator*= (Time &left, Int64 right)
 Overload of binary *= operator to scale/assign a time value. More...
 
SFML_SYSTEM_API Time operator/ (Time left, float right)
 Overload of binary / operator to scale a time value. More...
 
SFML_SYSTEM_API Time operator/ (Time left, Int64 right)
 Overload of binary / operator to scale a time value. More...
 
SFML_SYSTEM_API Timeoperator/= (Time &left, float right)
 Overload of binary /= operator to scale/assign a time value. More...
 
SFML_SYSTEM_API Timeoperator/= (Time &left, Int64 right)
 Overload of binary /= operator to scale/assign a time value. More...
 
SFML_SYSTEM_API float operator/ (Time left, Time right)
 Overload of binary / operator to compute the ratio of two time values. More...
 
SFML_SYSTEM_API Time operator% (Time left, Time right)
 Overload of binary % operator to compute remainder of a time value. More...
 
SFML_SYSTEM_API Timeoperator%= (Time &left, Time right)
 Overload of binary %= operator to compute/assign remainder of a time value. More...
 

Detailed Description

Represents a time value.

sf::Time encapsulates a time value in a flexible way.

It allows to define a time value either as a number of seconds, milliseconds or microseconds. It also works the other way round: you can read a time value as either a number of seconds, milliseconds or microseconds.

By using such a flexible interface, the API doesn't impose any fixed type or resolution for time values, and let the user choose its own favorite representation.

Time values support the usual mathematical operations: you can add or subtract two times, multiply or divide a time by a number, compare two times, etc.

Since they represent a time span and not an absolute time value, times can also be negative.

Usage example:

sf::Time t1 = sf::seconds(0.1f);
Int32 milli = t1.asMilliseconds(); // 100
sf::Time t2 = sf::milliseconds(30);
Int64 micro = t2.asMicroseconds(); // 30000
sf::Time t3 = sf::microseconds(-800000);
float sec = t3.asSeconds(); // -0.8
Represents a time value.
Definition: Time.hpp:41
Int64 asMicroseconds() const
Return the time value as a number of microseconds.
Int32 asMilliseconds() const
Return the time value as a number of milliseconds.
float asSeconds() const
Return the time value as a number of seconds.
signed long long Int64
Definition: Config.hpp:229
signed int Int32
Definition: Config.hpp:221
void update(sf::Time elapsed)
{
position += speed * elapsed.asSeconds();
}
update(sf::milliseconds(100));
See also
sf::Clock

Definition at line 40 of file Time.hpp.

Constructor & Destructor Documentation

◆ Time()

sf::Time::Time ( )

Default constructor.

Sets the time value to zero.

Member Function Documentation

◆ asMicroseconds()

Int64 sf::Time::asMicroseconds ( ) const

Return the time value as a number of microseconds.

Returns
Time in microseconds
See also
asSeconds, asMilliseconds

◆ asMilliseconds()

Int32 sf::Time::asMilliseconds ( ) const

Return the time value as a number of milliseconds.

Returns
Time in milliseconds
See also
asSeconds, asMicroseconds

◆ asSeconds()

float sf::Time::asSeconds ( ) const

Return the time value as a number of seconds.

Returns
Time in seconds
See also
asMilliseconds, asMicroseconds
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ microseconds() [1/2]

SFML_SYSTEM_API Time microseconds ( Int64  amount)
related

Construct a time value from a number of microseconds.

Parameters
amountNumber of microseconds
Returns
Time value constructed from the amount of microseconds
See also
seconds, milliseconds

◆ microseconds [2/2]

SFML_SYSTEM_API Time microseconds ( Int64  )
friend

◆ milliseconds() [1/2]

SFML_SYSTEM_API Time milliseconds ( Int32  amount)
related

Construct a time value from a number of milliseconds.

Parameters
amountNumber of milliseconds
Returns
Time value constructed from the amount of milliseconds
See also
seconds, microseconds

◆ milliseconds [2/2]

SFML_SYSTEM_API Time milliseconds ( Int32  )
friend

◆ operator!=()

SFML_SYSTEM_API bool operator!= ( Time  left,
Time  right 
)
related

Overload of != operator to compare two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
True if both time values are different

◆ operator%()

SFML_SYSTEM_API Time operator% ( Time  left,
Time  right 
)
related

Overload of binary % operator to compute remainder of a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
left modulo right

◆ operator%=()

SFML_SYSTEM_API Time & operator%= ( Time left,
Time  right 
)
related

Overload of binary %= operator to compute/assign remainder of a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
left modulo right

◆ operator*() [1/4]

SFML_SYSTEM_API Time operator* ( float  left,
Time  right 
)
related

Overload of binary * operator to scale a time value.

Parameters
leftLeft operand (a number)
rightRight operand (a time)
Returns
left multiplied by right

◆ operator*() [2/4]

SFML_SYSTEM_API Time operator* ( Int64  left,
Time  right 
)
related

Overload of binary * operator to scale a time value.

Parameters
leftLeft operand (a number)
rightRight operand (a time)
Returns
left multiplied by right

◆ operator*() [3/4]

SFML_SYSTEM_API Time operator* ( Time  left,
float  right 
)
related

Overload of binary * operator to scale a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a number)
Returns
left multiplied by right

◆ operator*() [4/4]

SFML_SYSTEM_API Time operator* ( Time  left,
Int64  right 
)
related

Overload of binary * operator to scale a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a number)
Returns
left multiplied by right

◆ operator*=() [1/2]

SFML_SYSTEM_API Time & operator*= ( Time left,
float  right 
)
related

Overload of binary *= operator to scale/assign a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a number)
Returns
left multiplied by right

◆ operator*=() [2/2]

SFML_SYSTEM_API Time & operator*= ( Time left,
Int64  right 
)
related

Overload of binary *= operator to scale/assign a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a number)
Returns
left multiplied by right

◆ operator+()

SFML_SYSTEM_API Time operator+ ( Time  left,
Time  right 
)
related

Overload of binary + operator to add two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
Sum of the two times values

◆ operator+=()

SFML_SYSTEM_API Time & operator+= ( Time left,
Time  right 
)
related

Overload of binary += operator to add/assign two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
Sum of the two times values

◆ operator-() [1/2]

SFML_SYSTEM_API Time operator- ( Time  left,
Time  right 
)
related

Overload of binary - operator to subtract two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
Difference of the two times values

◆ operator-() [2/2]

SFML_SYSTEM_API Time operator- ( Time  right)
related

Overload of unary - operator to negate a time value.

Parameters
rightRight operand (a time)
Returns
Opposite of the time value

◆ operator-=()

SFML_SYSTEM_API Time & operator-= ( Time left,
Time  right 
)
related

Overload of binary -= operator to subtract/assign two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
Difference of the two times values

◆ operator/() [1/3]

SFML_SYSTEM_API Time operator/ ( Time  left,
float  right 
)
related

Overload of binary / operator to scale a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a number)
Returns
left divided by right

◆ operator/() [2/3]

SFML_SYSTEM_API Time operator/ ( Time  left,
Int64  right 
)
related

Overload of binary / operator to scale a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a number)
Returns
left divided by right

◆ operator/() [3/3]

SFML_SYSTEM_API float operator/ ( Time  left,
Time  right 
)
related

Overload of binary / operator to compute the ratio of two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
left divided by right

◆ operator/=() [1/2]

SFML_SYSTEM_API Time & operator/= ( Time left,
float  right 
)
related

Overload of binary /= operator to scale/assign a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a number)
Returns
left divided by right

◆ operator/=() [2/2]

SFML_SYSTEM_API Time & operator/= ( Time left,
Int64  right 
)
related

Overload of binary /= operator to scale/assign a time value.

Parameters
leftLeft operand (a time)
rightRight operand (a number)
Returns
left divided by right

◆ operator<()

SFML_SYSTEM_API bool operator< ( Time  left,
Time  right 
)
related

Overload of < operator to compare two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
True if left is lesser than right

◆ operator<=()

SFML_SYSTEM_API bool operator<= ( Time  left,
Time  right 
)
related

Overload of <= operator to compare two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
True if left is lesser or equal than right

◆ operator==()

SFML_SYSTEM_API bool operator== ( Time  left,
Time  right 
)
related

Overload of == operator to compare two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
True if both time values are equal

◆ operator>()

SFML_SYSTEM_API bool operator> ( Time  left,
Time  right 
)
related

Overload of > operator to compare two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
True if left is greater than right

◆ operator>=()

SFML_SYSTEM_API bool operator>= ( Time  left,
Time  right 
)
related

Overload of >= operator to compare two time values.

Parameters
leftLeft operand (a time)
rightRight operand (a time)
Returns
True if left is greater or equal than right

◆ seconds() [1/2]

SFML_SYSTEM_API Time seconds ( float  amount)
related

Construct a time value from a number of seconds.

Parameters
amountNumber of seconds
Returns
Time value constructed from the amount of seconds
See also
milliseconds, microseconds

◆ seconds [2/2]

SFML_SYSTEM_API Time seconds ( float  )
friend

Member Data Documentation

◆ Zero

const Time sf::Time::Zero
static

Predefined "zero" time value.

Definition at line 85 of file Time.hpp.


The documentation for this class was generated from the following file: