Added the sf::Time class
This commit is contained in:
parent
e775bd0169
commit
4116ad033c
58 changed files with 880 additions and 227 deletions
|
@ -30,6 +30,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundStream.hpp>
|
||||
#include <SFML/System/Mutex.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -121,10 +122,10 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the total duration of the music
|
||||
///
|
||||
/// \return Music duration, in milliseconds
|
||||
/// \return Music duration
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 GetDuration() const;
|
||||
Time GetDuration() const;
|
||||
|
||||
protected :
|
||||
|
||||
|
@ -144,10 +145,10 @@ protected :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the current playing position in the stream source
|
||||
///
|
||||
/// \param timeOffset New playing position, in milliseconds
|
||||
/// \param timeOffset New playing position, from the beginning of the music
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void OnSeek(Uint32 timeOffset);
|
||||
virtual void OnSeek(Time timeOffset);
|
||||
|
||||
private :
|
||||
|
||||
|
@ -161,7 +162,7 @@ private :
|
|||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
priv::SoundFile* myFile; ///< Sound file
|
||||
Uint32 myDuration; ///< Music duration, in milliseconds
|
||||
Time myDuration; ///< Music duration
|
||||
std::vector<Int16> mySamples; ///< Temporary buffer of samples
|
||||
Mutex myMutex; ///< Mutex protecting the data
|
||||
};
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundSource.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
|
@ -144,12 +145,12 @@ public :
|
|||
/// The playing position can be changed when the sound is
|
||||
/// either paused or playing.
|
||||
///
|
||||
/// \param timeOffset New playing position, in milliseconds
|
||||
/// \param timeOffset New playing position, from the beginning of the sound
|
||||
///
|
||||
/// \see GetPlayingOffset
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetPlayingOffset(Uint32 timeOffset);
|
||||
void SetPlayingOffset(Time timeOffset);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the audio buffer attached to the sound
|
||||
|
@ -172,12 +173,12 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current playing position of the sound
|
||||
///
|
||||
/// \return Current playing position, in milliseconds
|
||||
/// \return Current playing position, from the beginning of the sound
|
||||
///
|
||||
/// \see SetPlayingOffset
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 GetPlayingOffset() const;
|
||||
Time GetPlayingOffset() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current status of the sound (stopped, paused, playing)
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
@ -212,12 +213,12 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the total duration of the sound
|
||||
///
|
||||
/// \return Sound duration, in milliseconds
|
||||
/// \return Sound duration
|
||||
///
|
||||
/// \see GetSampleRate, GetChannelCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 GetDuration() const;
|
||||
Time GetDuration() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of assignment operator
|
||||
|
@ -280,7 +281,7 @@ private :
|
|||
////////////////////////////////////////////////////////////
|
||||
unsigned int myBuffer; ///< OpenAL buffer identifier
|
||||
std::vector<Int16> mySamples; ///< Samples buffer
|
||||
Uint32 myDuration; ///< Sound duration, in milliseconds
|
||||
Time myDuration; ///< Sound duration
|
||||
mutable SoundList mySounds; ///< List of sounds that are using this buffer
|
||||
};
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundSource.hpp>
|
||||
#include <SFML/System/Thread.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
|
@ -131,22 +132,22 @@ public :
|
|||
/// The playing position can be changed when the stream is
|
||||
/// either paused or playing.
|
||||
///
|
||||
/// \param timeOffset New playing position, in milliseconds
|
||||
/// \param timeOffset New playing position, from the beginning of the stream
|
||||
///
|
||||
/// \see GetPlayingOffset
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetPlayingOffset(Uint32 timeOffset);
|
||||
void SetPlayingOffset(Time timeOffset);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current playing position of the stream
|
||||
///
|
||||
/// \return Current playing position, in milliseconds
|
||||
/// \return Current playing position, from the beginning of the stream
|
||||
///
|
||||
/// \see SetPlayingOffset
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 GetPlayingOffset() const;
|
||||
Time GetPlayingOffset() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set whether or not the stream should loop after reaching the end
|
||||
|
@ -232,10 +233,10 @@ private :
|
|||
/// This function must be overriden by derived classes to
|
||||
/// allow random seeking into the stream source.
|
||||
///
|
||||
/// \param timeOffset New playing position, in milliseconds
|
||||
/// \param timeOffset New playing position, relative to the beginning of the stream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void OnSeek(Uint32 timeOffset) = 0;
|
||||
virtual void OnSeek(Time timeOffset) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Fill a new buffer with audio samples, and append
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <SFML/Network/TcpSocket.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -264,19 +265,19 @@ public :
|
|||
/// This function tries to connect to the server so it may take
|
||||
/// a while to complete, especially if the server is not
|
||||
/// reachable. To avoid blocking your application for too long,
|
||||
/// you can use a timeout. The default value, 0, means that the
|
||||
/// you can use a timeout. The default value, Time::Zero, means that the
|
||||
/// system timeout will be used (which is usually pretty long).
|
||||
///
|
||||
/// \param server Name or address of the FTP server to connect to
|
||||
/// \param port Port used for the connection
|
||||
/// \param timeout Maximum time to wait, in milliseconds
|
||||
/// \param timeout Maximum time to wait
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \see Disconnect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Response Connect(const IpAddress& server, unsigned short port = 21, Uint32 timeout = 0);
|
||||
Response Connect(const IpAddress& server, unsigned short port = 21, Time timeout = Time::Zero);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Close the connection with the server
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <SFML/Network/IpAddress.hpp>
|
||||
#include <SFML/Network/TcpSocket.hpp>
|
||||
#include <map>
|
||||
|
@ -377,16 +378,16 @@ public :
|
|||
/// Warning: this function waits for the server's response and may
|
||||
/// not return instantly; use a thread if you don't want to block your
|
||||
/// application, or use a timeout to limit the time to wait. A value
|
||||
/// of 0 means that the client will use the system defaut timeout
|
||||
/// of Time::Zero means that the client will use the system defaut timeout
|
||||
/// (which is usually pretty long).
|
||||
///
|
||||
/// \param request Request to send
|
||||
/// \param timeout Maximum time to wait, in milliseconds
|
||||
/// \param timeout Maximum time to wait
|
||||
///
|
||||
/// \return Server's response
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Response SendRequest(const Request& request, Uint32 timeout = 0);
|
||||
Response SendRequest(const Request& request, Time timeout = Time::Zero);
|
||||
|
||||
private :
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
@ -168,14 +169,14 @@ public :
|
|||
/// to be possibly stuck waiting in case there is a problem; this
|
||||
/// limit is deactivated by default.
|
||||
///
|
||||
/// \param timeout Maximum time to wait, in milliseconds
|
||||
/// \param timeout Maximum time to wait
|
||||
///
|
||||
/// \return Public IP address of the computer
|
||||
///
|
||||
/// \see GetLocalAddress
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static IpAddress GetPublicAddress(Uint32 timeout = 0);
|
||||
static IpAddress GetPublicAddress(Time timeout = Time::Zero);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -111,14 +112,14 @@ public :
|
|||
/// If you use a timeout and no socket is ready before the timeout
|
||||
/// is over, the function returns false.
|
||||
///
|
||||
/// \param timeout Maximum time to wait, in milliseconds (use 0 for infinity)
|
||||
/// \param timeout Maximum time to wait, (use Time::Zero for infinity)
|
||||
///
|
||||
/// \return True if there are sockets ready, false otherwise
|
||||
///
|
||||
/// \see IsReady
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Wait(Uint32 timeout = 0);
|
||||
bool Wait(Time timeout = Time::Zero);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Test a socket to know if it is ready to receive data
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Socket.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -99,14 +100,14 @@ public :
|
|||
///
|
||||
/// \param remoteAddress Address of the remote peer
|
||||
/// \param remotePort Port of the remote peer
|
||||
/// \param timeout Optional maximum time to wait, in milliseconds
|
||||
/// \param timeout Optional maximum time to wait
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see Disconnect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status Connect(const IpAddress& remoteAddress, unsigned short remotePort, Uint32 timeout = 0);
|
||||
Status Connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Disconnect the socket from its remote peer
|
||||
|
|
|
@ -29,12 +29,13 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility class for manipulating time
|
||||
/// \brief Utility class that measures the elapsed time
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Clock
|
||||
|
@ -50,31 +51,34 @@ public :
|
|||
Clock();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the time elapsed
|
||||
/// \brief Get the elapsed time
|
||||
///
|
||||
/// This function returns the time elapsed since the last call
|
||||
/// to Reset() (or the construction of the instance if Reset()
|
||||
/// to Restart() (or the construction of the instance if Restart()
|
||||
/// has not been called).
|
||||
///
|
||||
/// \return Time elapsed, in milliseconds
|
||||
/// \return Time elapsed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 GetElapsedTime() const;
|
||||
Time GetElapsedTime() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Restart the clock
|
||||
///
|
||||
/// This function puts the time counter back to zero.
|
||||
/// It also returns the time elapsed since the clock was started.
|
||||
///
|
||||
/// \return Time elapsed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Reset();
|
||||
Time Restart();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint64 myStartTime; ///< Time of last reset, in microseconds
|
||||
Time myStartTime; ///< Time of last reset, in microseconds
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
@ -88,17 +92,26 @@ private :
|
|||
/// \ingroup system
|
||||
///
|
||||
/// sf::Clock is a lightweight class for measuring time.
|
||||
/// Its resolution depends on the underlying OS, but you can generally
|
||||
/// expect a 1 ms resolution.
|
||||
///
|
||||
/// Its provides the most precise time that the underlying
|
||||
/// OS can achieve (generally microseconds or nanoseconds).
|
||||
/// It also ensures monotonicity, which means that the returned
|
||||
/// time can never go backward, even if the system time is
|
||||
/// changed.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::Clock clock;
|
||||
/// ...
|
||||
/// Uint32 time1 = clock.GetElapsedTime();
|
||||
/// clock.Reset();
|
||||
/// Time time1 = clock.GetElapsedTime();
|
||||
/// ...
|
||||
/// Uint32 time2 = clock.GetElapsedTime();
|
||||
/// Time time2 = clock.Restart();
|
||||
/// \endcode
|
||||
///
|
||||
/// The sf::Time value returned by the clock can then be
|
||||
/// converted to a number of seconds, milliseconds or even
|
||||
/// microseconds.
|
||||
///
|
||||
/// \see sf::Time
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -40,10 +41,10 @@ namespace sf
|
|||
/// sf::Sleep is the best way to block a program or one of its
|
||||
/// threads, as it doesn't consume any CPU power.
|
||||
///
|
||||
/// \param duration Time to sleep, in milliseconds
|
||||
/// \param duration Time to sleep
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SFML_API Sleep(Uint32 duration);
|
||||
void SFML_API Sleep(Time duration);
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
|
452
include/SFML/System/Time.hpp
Normal file
452
include/SFML/System/Time.hpp
Normal file
|
@ -0,0 +1,452 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_TIME_HPP
|
||||
#define SFML_TIME_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Represents a time value
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Time
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Sets the time value to zero.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Time();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the time value as a number of seconds
|
||||
///
|
||||
/// \return Time in seconds
|
||||
///
|
||||
/// \see AsMilliseconds, AsMicroseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float AsSeconds() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the time value as a number of milliseconds
|
||||
///
|
||||
/// \return Time in milliseconds
|
||||
///
|
||||
/// \see AsSeconds, AsMicroseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Int32 AsMilliseconds() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the time value as a number of microseconds
|
||||
///
|
||||
/// \return Time in microseconds
|
||||
///
|
||||
/// \see AsSeconds, AsMilliseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Int64 AsMicroseconds() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const Time Zero; ///< Predefined "zero" time value
|
||||
|
||||
private :
|
||||
|
||||
friend SFML_API Time Seconds(float);
|
||||
friend SFML_API Time Milliseconds(Int32);
|
||||
friend SFML_API Time Microseconds(Int64);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a number of microseconds
|
||||
///
|
||||
/// This function is internal. To construct time values,
|
||||
/// use sf::Seconds, sf::Milliseconds or sf::Microseconds instead.
|
||||
///
|
||||
/// \param microseconds Number of microseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit Time(Int64 microseconds);
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Int64 myMicroseconds; ///< Time value stored as microseconds
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Construct a time value from a number of seconds
|
||||
///
|
||||
/// \param amount Number of seconds
|
||||
///
|
||||
/// \return Time value constructed from the amount of seconds
|
||||
///
|
||||
/// \see Milliseconds, Microseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time Seconds(float amount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Construct a time value from a number of milliseconds
|
||||
///
|
||||
/// \param amount Number of milliseconds
|
||||
///
|
||||
/// \return Time value constructed from the amount of milliseconds
|
||||
///
|
||||
/// \see Seconds, Microseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time Milliseconds(Int32 amount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Construct a time value from a number of microseconds
|
||||
///
|
||||
/// \param amount Number of microseconds
|
||||
///
|
||||
/// \return Time value constructed from the amount of microseconds
|
||||
///
|
||||
/// \see Seconds, Milliseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time Microseconds(Int64 amount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of == operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if both time values are equal
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator ==(const Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of != operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if both time values are different
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator !=(const Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of < operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if \a left is lesser than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator <(const Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of > operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if \a left is greater than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator >(const Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of <= operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if \a left is lesser or equal than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator <=(const Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of >= operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if \a left is greater or equal than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator >=(const Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of unary - operator to negate a time value
|
||||
///
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Opposite of the time value
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time operator -(const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary + operator to add two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Sum of the two times values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time operator +(const Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary += operator to add/assign two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Sum of the two times values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time& operator +=(Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary - operator to subtract two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Difference of the two times values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time operator -(const Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary -= operator to subtract/assign two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Difference of the two times values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time& operator -=(Time& left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary * operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \left multiplied by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time operator *(const Time& left, float right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary * operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \left multiplied by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time operator *(const Time& left, Int64 right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary * operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a number)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return \left multiplied by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time operator *(float left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary * operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a number)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return \left multiplied by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time operator *(Int64 left, const Time& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary *= operator to scale/assign a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \left multiplied by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time& operator *=(Time& left, float right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary *= operator to scale/assign a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \left multiplied by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time& operator *=(Time& left, Int64 right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary / operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \left divided by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time operator /(const Time& left, float right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary / operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \left divided by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time operator /(const Time& left, Int64 right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary /= operator to scale/assign a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \left divided by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time& operator /=(Time& left, float right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary /= operator to scale/assign a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \left divided by \right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API Time& operator /=(Time& left, Int64 right);
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_TIME_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Time
|
||||
/// \ingroup system
|
||||
///
|
||||
/// 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:
|
||||
/// \code
|
||||
/// 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
|
||||
/// \endcode
|
||||
///
|
||||
/// \code
|
||||
/// void Update(sf::Time elapsed)
|
||||
/// {
|
||||
/// position += speed * elapsed.AsSeconds();
|
||||
/// }
|
||||
///
|
||||
/// Update(sf::Milliseconds(100));
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Clock
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
|
@ -387,19 +387,6 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
void SetFramerateLimit(unsigned int limit);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the duration of the last frame
|
||||
///
|
||||
/// This function returns the time elapsed between the last
|
||||
/// two calls to Display().
|
||||
/// This can be useful for calculating the framerate, or for
|
||||
/// updating the application's objects.
|
||||
///
|
||||
/// \return Time elapsed in last frame, in milliseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 GetFrameTime() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the joystick threshold
|
||||
///
|
||||
|
@ -474,7 +461,6 @@ private :
|
|||
priv::WindowImpl* myImpl; ///< Platform-specific implementation of the window
|
||||
priv::GlContext* myContext; ///< Platform-specific implementation of the OpenGL context
|
||||
Clock myClock; ///< Clock for measuring the elapsed time between frames
|
||||
Uint32 myLastFrameTime; ///< Time elapsed since last frame
|
||||
unsigned int myFramerateLimit; ///< Current framerate limit
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue