diff --git a/include/SFML/Audio/Music.h b/include/SFML/Audio/Music.h index f981c28..772e21e 100644 --- a/include/SFML/Audio/Music.h +++ b/include/SFML/Audio/Music.h @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -121,10 +122,10 @@ CSFML_API sfBool sfMusic_GetLoop(const sfMusic* music); /// /// \param music Music object /// -/// \return Music duration, in milliseconds +/// \return Music duration /// //////////////////////////////////////////////////////////// -CSFML_API sfUint32 sfMusic_GetDuration(const sfMusic* music); +CSFML_API sfTime sfMusic_GetDuration(const sfMusic* music); //////////////////////////////////////////////////////////// /// \brief Start or resume playing a music @@ -203,10 +204,10 @@ CSFML_API sfSoundStatus sfMusic_GetStatus(const sfMusic* music); /// /// \param music Music object /// -/// \return Current playing position, in milliseconds +/// \return Current playing position /// //////////////////////////////////////////////////////////// -CSFML_API sfUint32 sfMusic_GetPlayingOffset(const sfMusic* music); +CSFML_API sfTime sfMusic_GetPlayingOffset(const sfMusic* music); //////////////////////////////////////////////////////////// /// \brief Set the pitch of a music diff --git a/include/SFML/Audio/Sound.h b/include/SFML/Audio/Sound.h index 17fce00..8393124 100644 --- a/include/SFML/Audio/Sound.h +++ b/include/SFML/Audio/Sound.h @@ -31,6 +31,7 @@ #include #include #include +#include //////////////////////////////////////////////////////////// @@ -251,10 +252,10 @@ CSFML_API void sfSound_SetAttenuation(sfSound* sound, float attenuation); /// either paused or playing. /// /// \param sound Sound object -/// \param timeOffset New playing position, in milliseconds +/// \param timeOffset New playing position /// //////////////////////////////////////////////////////////// -CSFML_API void sfSound_SetPlayingOffset(sfSound* sound, sfUint32 timeOffset); +CSFML_API void sfSound_SetPlayingOffset(sfSound* sound, sfTime timeOffset); //////////////////////////////////////////////////////////// /// \brief Get the pitch of a sound @@ -323,10 +324,10 @@ CSFML_API float sfSound_GetAttenuation(const sfSound* sound); /// /// \param sound Sound object /// -/// \return Current playing position, in milliseconds +/// \return Current playing position /// //////////////////////////////////////////////////////////// -CSFML_API sfUint32 sfSound_GetPlayingOffset(const sfSound* sound); +CSFML_API sfTime sfSound_GetPlayingOffset(const sfSound* sound); #endif // SFML_SOUND_H diff --git a/include/SFML/Audio/SoundBuffer.h b/include/SFML/Audio/SoundBuffer.h index c948794..a49e411 100644 --- a/include/SFML/Audio/SoundBuffer.h +++ b/include/SFML/Audio/SoundBuffer.h @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -185,10 +186,10 @@ CSFML_API unsigned int sfSoundBuffer_GetChannelCount(const sfSoundBuffer* soundB /// /// \param soundBuffer Sound buffer object /// -/// \return Sound duration, in milliseconds +/// \return Sound duration /// //////////////////////////////////////////////////////////// -CSFML_API sfUint32 sfSoundBuffer_GetDuration(const sfSoundBuffer* soundBuffer); +CSFML_API sfTime sfSoundBuffer_GetDuration(const sfSoundBuffer* soundBuffer); #endif // SFML_SOUNDBUFFER_H diff --git a/include/SFML/Audio/SoundStream.h b/include/SFML/Audio/SoundStream.h index a998a20..8ae30ca 100644 --- a/include/SFML/Audio/SoundStream.h +++ b/include/SFML/Audio/SoundStream.h @@ -31,6 +31,7 @@ #include #include #include +#include //////////////////////////////////////////////////////////// @@ -44,7 +45,7 @@ typedef struct } sfSoundStreamChunk; typedef sfBool (*sfSoundStreamGetDataCallback)(sfSoundStreamChunk*, void*); ///< Type of the callback used to get a sound stream data -typedef void (*sfSoundStreamSeekCallback)(sfUint32, void*); ///< Type of the callback used to seek in a sound stream +typedef void (*sfSoundStreamSeekCallback)(sfTime, void*); ///< Type of the callback used to seek in a sound stream //////////////////////////////////////////////////////////// @@ -243,10 +244,10 @@ CSFML_API void sfSoundStream_SetAttenuation(sfSoundStream* soundStream, float at /// either paused or playing. /// /// \param soundStream Sound stream object -/// \param timeOffset New playing position, in milliseconds +/// \param timeOffset New playing position /// //////////////////////////////////////////////////////////// -CSFML_API void sfSoundStream_SetPlayingOffset(sfSoundStream* soundStream, sfUint32 timeOffset); +CSFML_API void sfSoundStream_SetPlayingOffset(sfSoundStream* soundStream, sfTime timeOffset); //////////////////////////////////////////////////////////// /// \brief Set whether or not a sound stream should loop after reaching the end @@ -339,10 +340,10 @@ CSFML_API sfBool sfSoundStream_GetLoop(const sfSoundStream* soundStream); /// /// \param soundStream Sound stream object /// -/// \return Current playing position, in milliseconds +/// \return Current playing position /// //////////////////////////////////////////////////////////// -CSFML_API sfUint32 sfSoundStream_GetPlayingOffset(const sfSoundStream* soundStream); +CSFML_API sfTime sfSoundStream_GetPlayingOffset(const sfSoundStream* soundStream); #endif // SFML_SOUNDSTREAM_H diff --git a/include/SFML/Graphics/Texture.h b/include/SFML/Graphics/Texture.h index b30e43b..03a9ba6 100644 --- a/include/SFML/Graphics/Texture.h +++ b/include/SFML/Graphics/Texture.h @@ -246,17 +246,6 @@ CSFML_API void sfTexture_SetRepeated(sfTexture* texture, sfBool repeated); //////////////////////////////////////////////////////////// CSFML_API sfBool sfTexture_IsRepeated(const sfTexture* texture); -//////////////////////////////////////////////////////////// -/// \brief Convert a rectangle of pixels into texture coordinates -/// -/// \param texture Texture to use for conversion -/// \param rectangle Rectangle to convert -/// -/// \return Texture coordinates corresponding to \a rectangle -/// -//////////////////////////////////////////////////////////// -CSFML_API sfFloatRect sfTexture_GetTexCoords(const sfTexture* texture, sfIntRect rectangle); - //////////////////////////////////////////////////////////// /// \brief Get the maximum texture size allowed /// diff --git a/include/SFML/Network/Http.h b/include/SFML/Network/Http.h index e75f1e5..b5fbbe0 100644 --- a/include/SFML/Network/Http.h +++ b/include/SFML/Network/Http.h @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include //////////////////////////////////////////////////////////// @@ -285,12 +286,12 @@ CSFML_API void sfHttp_SetHost(sfHttp* http, const char* host, unsigned short por /// /// \param http Http object /// \param request Request to send -/// \param timeout Maximum time to wait, in milliseconds +/// \param timeout Maximum time to wait /// /// \return Server's response /// //////////////////////////////////////////////////////////// -CSFML_API sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, sfUint32 timeout); +CSFML_API sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, sfTime timeout); #endif // SFML_HTTP_H diff --git a/include/SFML/Network/IpAddress.h b/include/SFML/Network/IpAddress.h index 38d5c31..b1dd8d3 100644 --- a/include/SFML/Network/IpAddress.h +++ b/include/SFML/Network/IpAddress.h @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include //////////////////////////////////////////////////////////// @@ -146,12 +147,12 @@ CSFML_API sfIpAddress sfIpAddress_GetLocalAddress(void); /// to be possibly stuck waiting in case there is a problem; use /// 0 to deactivate this limit. /// -/// \param timeout Maximum time to wait, in milliseconds +/// \param timeout Maximum time to wait /// /// \return Public IP address of the computer /// //////////////////////////////////////////////////////////// -CSFML_API sfIpAddress sfIpAddress_GetPublicAddress(sfUint32 timeout); +CSFML_API sfIpAddress sfIpAddress_GetPublicAddress(sfTime timeout); //////////////////////////////////////////////////////////// /// \brief Get the empty/invalid address diff --git a/include/SFML/Network/SocketSelector.h b/include/SFML/Network/SocketSelector.h index c941185..55b9804 100644 --- a/include/SFML/Network/SocketSelector.h +++ b/include/SFML/Network/SocketSelector.h @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include //////////////////////////////////////////////////////////// @@ -109,12 +110,12 @@ CSFML_API void sfSocketSelector_Clear(sfSocketSelector* selector); /// is over, the function returns sfFalse. /// /// \param selector Socket selector object -/// \param timeout Maximum time to wait, in milliseconds (use 0 for infinity) +/// \param timeout Maximum time to wait (use sfTimeZero for infinity) /// /// \return sfTrue if there are sockets ready, sfFalse otherwise /// //////////////////////////////////////////////////////////// -CSFML_API sfBool sfSocketSelector_Wait(sfSocketSelector* selector, sfUint32 timeout); +CSFML_API sfBool sfSocketSelector_Wait(sfSocketSelector* selector, sfTime timeout); //////////////////////////////////////////////////////////// /// \brief Test a socket to know if it is ready to receive data diff --git a/include/SFML/Network/TcpSocket.h b/include/SFML/Network/TcpSocket.h index af606c8..b3599df 100644 --- a/include/SFML/Network/TcpSocket.h +++ b/include/SFML/Network/TcpSocket.h @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -128,12 +129,12 @@ CSFML_API unsigned short sfTcpSocket_GetRemotePort(const sfTcpSocket* socket); /// \param socket TCP socket object /// \param remoteAddress Address of the remote peer /// \param remotePort Port of the remote peer -/// \param timeout Maximum time to wait, in milliseconds +/// \param timeout Maximum time to wait /// /// \return Status code /// //////////////////////////////////////////////////////////// -CSFML_API sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, sfUint32 timeout); +CSFML_API sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, sfTime timeout); //////////////////////////////////////////////////////////// /// \brief Disconnect a TCP socket from its remote peer diff --git a/include/SFML/System/Clock.h b/include/SFML/System/Clock.h index eae171c..92cdf65 100644 --- a/include/SFML/System/Clock.h +++ b/include/SFML/System/Clock.h @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include @@ -62,25 +63,28 @@ CSFML_API void sfClock_Destroy(sfClock* clock); /// \brief Get the time elapsed in a clock /// /// This function returns the time elapsed since the last call -/// to sfClock_Reset (or the construction of the object if -/// sfClock_Reset has not been called). +/// to sfClock_Restart (or the construction of the object if +/// sfClock_Restart has not been called). /// /// \param clock Clock object /// -/// \return Time elapsed, in milliseconds +/// \return Time elapsed /// //////////////////////////////////////////////////////////// -CSFML_API sfUint32 sfClock_GetTime(const sfClock* clock); +CSFML_API sfTime sfClock_GetElapsedTime(const sfClock* clock); //////////////////////////////////////////////////////////// /// \brief Restart a clock /// /// This function puts the time counter back to zero. +/// It also returns the time elapsed since the clock was started. /// /// \param clock Clock object /// +/// \return Time elapsed +/// //////////////////////////////////////////////////////////// -CSFML_API void sfClock_Reset(sfClock* clock); +CSFML_API sfTime sfClock_Restart(sfClock* clock); #endif // SFML_CLOCK_H diff --git a/include/SFML/System/Sleep.h b/include/SFML/System/Sleep.h index 1c5d8ab..ea4ccb2 100644 --- a/include/SFML/System/Sleep.h +++ b/include/SFML/System/Sleep.h @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include //////////////////////////////////////////////////////////// @@ -37,10 +38,10 @@ /// sfSleep 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 /// //////////////////////////////////////////////////////////// -CSFML_API void sfSleep(sfUint32 duration); +CSFML_API void sfSleep(sfTime duration); #endif // SFML_SLEEP_H diff --git a/include/SFML/System/Time.h b/include/SFML/System/Time.h new file mode 100644 index 0000000..ea309fe --- /dev/null +++ b/include/SFML/System/Time.h @@ -0,0 +1,110 @@ +//////////////////////////////////////////////////////////// +// +// 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_H +#define SFML_TIME_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +//////////////////////////////////////////////////////////// +/// \brief Represents a time value +/// +//////////////////////////////////////////////////////////// +typedef struct +{ + sfInt64 Microseconds; +} sfTime; + +//////////////////////////////////////////////////////////// +/// \brief Predefined "zero" time value +/// +//////////////////////////////////////////////////////////// +CSFML_API sfTime sfTimeZero; + +//////////////////////////////////////////////////////////// +/// \brief Return a time value as a number of seconds +/// +/// \param time Time value +/// +/// \return Time in seconds +/// +//////////////////////////////////////////////////////////// +CSFML_API float sfTime_AsSeconds(sfTime time); + +//////////////////////////////////////////////////////////// +/// \brief Return a time value as a number of milliseconds +/// +/// \param time Time value +/// +/// \return Time in milliseconds +/// +//////////////////////////////////////////////////////////// +CSFML_API sfInt32 sfTime_AsMilliseconds(sfTime time); + +//////////////////////////////////////////////////////////// +/// \brief Return a time value as a number of microseconds +/// +/// \param time Time value +/// +/// \return Time in microseconds +/// +//////////////////////////////////////////////////////////// +CSFML_API sfInt64 sfTime_AsMicroseconds(sfTime 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 +/// +//////////////////////////////////////////////////////////// +CSFML_API sfTime sfSeconds(float amount); + +//////////////////////////////////////////////////////////// +/// \brief Construct a time value from a number of milliseconds +/// +/// \param amount Number of milliseconds +/// +/// \return Time value constructed from the amount of milliseconds +/// +//////////////////////////////////////////////////////////// +CSFML_API sfTime sfMilliseconds(sfInt32 amount); + +//////////////////////////////////////////////////////////// +/// \brief Construct a time value from a number of microseconds +/// +/// \param amount Number of microseconds +/// +/// \return Time value constructed from the amount of microseconds +/// +//////////////////////////////////////////////////////////// +CSFML_API sfTime sfMicroseconds(sfInt64 amount); + + +#endif // SFML_TIME_H diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index e71ea08..e55fdfe 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -97,9 +97,12 @@ sfBool sfMusic_GetLoop(const sfMusic* music) //////////////////////////////////////////////////////////// -sfUint32 sfMusic_GetDuration(const sfMusic* music) +sfTime sfMusic_GetDuration(const sfMusic* music) { - CSFML_CALL_RETURN(music, GetDuration(), 0); + CSFML_CHECK_RETURN(music, sfTimeZero); + + sf::Time time = music->This.GetDuration(); + return sfMicroseconds(time.AsMicroseconds()); } @@ -148,9 +151,12 @@ sfSoundStatus sfMusic_GetStatus(const sfMusic* music) //////////////////////////////////////////////////////////// -sfUint32 sfMusic_GetPlayingOffset(const sfMusic* music) +sfTime sfMusic_GetPlayingOffset(const sfMusic* music) { - CSFML_CALL_RETURN(music, GetPlayingOffset(), 0); + CSFML_CHECK_RETURN(music, sfTimeZero); + + sf::Time time = music->This.GetPlayingOffset(); + return sfMicroseconds(time.AsMicroseconds()); } @@ -197,9 +203,9 @@ void sfMusic_SetAttenuation(sfMusic* music, float attenuation) //////////////////////////////////////////////////////////// -void sfMusic_SetPlayingOffset(sfMusic* music, sfUint32 timeOffset) +void sfMusic_SetPlayingOffset(sfMusic* music, sfTime timeOffset) { - CSFML_CALL(music, SetPlayingOffset(timeOffset)); + CSFML_CALL(music, SetPlayingOffset(sf::Microseconds(timeOffset.Microseconds))); } diff --git a/src/SFML/Audio/Sound.cpp b/src/SFML/Audio/Sound.cpp index a951f36..891a8c1 100644 --- a/src/SFML/Audio/Sound.cpp +++ b/src/SFML/Audio/Sound.cpp @@ -160,9 +160,9 @@ void sfSound_SetAttenuation(sfSound* sound, float attenuation) //////////////////////////////////////////////////////////// -void sfSound_SetPlayingOffset(sfSound* sound, sfUint32 timeOffset) +void sfSound_SetPlayingOffset(sfSound* sound, sfTime timeOffset) { - CSFML_CALL(sound, SetPlayingOffset(timeOffset)); + CSFML_CALL(sound, SetPlayingOffset(sf::Microseconds(timeOffset.Microseconds))); } @@ -214,7 +214,10 @@ float sfSound_GetAttenuation(const sfSound* sound) //////////////////////////////////////////////////////////// -sfUint32 sfSound_GetPlayingOffset(const sfSound* sound) +sfTime sfSound_GetPlayingOffset(const sfSound* sound) { - CSFML_CALL_RETURN(sound, GetPlayingOffset(), 0) + CSFML_CHECK_RETURN(sound, sfTimeZero) + + sf::Time time = sound->This.GetPlayingOffset(); + return sfMicroseconds(time.AsMicroseconds()); } diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index 528ed93..12b84de 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -146,7 +146,10 @@ unsigned int sfSoundBuffer_GetChannelCount(const sfSoundBuffer* soundBuffer) //////////////////////////////////////////////////////////// -sfUint32 sfSoundBuffer_GetDuration(const sfSoundBuffer* soundBuffer) +sfTime sfSoundBuffer_GetDuration(const sfSoundBuffer* soundBuffer) { - CSFML_CALL_RETURN(soundBuffer, GetDuration(), 0) + CSFML_CHECK_RETURN(soundBuffer, sfTimeZero) + + sf::Time duration = soundBuffer->This.GetDuration(); + return sfMicroseconds(duration.AsMicroseconds()); } diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index c0f6b1f..3cbeeff 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -135,9 +135,9 @@ void sfSoundStream_SetAttenuation(sfSoundStream* soundStream, float attenuation) //////////////////////////////////////////////////////////// -void sfSoundStream_SetPlayingOffset(sfSoundStream* soundStream, sfUint32 timeOffset) +void sfSoundStream_SetPlayingOffset(sfSoundStream* soundStream, sfTime timeOffset) { - CSFML_CALL(soundStream, SetPlayingOffset(timeOffset)); + CSFML_CALL(soundStream, SetPlayingOffset(sf::Microseconds(timeOffset.Microseconds))); } @@ -203,7 +203,10 @@ sfBool sfSoundStream_GetLoop(const sfSoundStream* soundStream) //////////////////////////////////////////////////////////// -sfUint32 sfSoundStream_GetPlayingOffset(const sfSoundStream* soundStream) +sfTime sfSoundStream_GetPlayingOffset(const sfSoundStream* soundStream) { - CSFML_CALL_RETURN(soundStream, GetPlayingOffset(), 0); + CSFML_CHECK_RETURN(soundStream, sfTimeZero); + + sf::Time offset = soundStream->This.GetPlayingOffset(); + return sfMicroseconds(offset.AsMicroseconds()); } diff --git a/src/SFML/Audio/SoundStreamStruct.h b/src/SFML/Audio/SoundStreamStruct.h index cbafcac..c3e9f3d 100644 --- a/src/SFML/Audio/SoundStreamStruct.h +++ b/src/SFML/Audio/SoundStreamStruct.h @@ -64,10 +64,10 @@ private : return ok; } - virtual void OnSeek(sfUint32 timeOffset) + virtual void OnSeek(sf::Time timeOffset) { if (mySeekCallback) - mySeekCallback(timeOffset, myUserData); + mySeekCallback(sfMicroseconds(timeOffset.AsMicroseconds()), myUserData); } sfSoundStreamGetDataCallback myGetDataCallback; diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 8589e2b..1df323f 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -248,25 +248,6 @@ sfBool sfTexture_IsRepeated(const sfTexture* texture) } -//////////////////////////////////////////////////////////// -sfFloatRect sfTexture_GetTexCoords(const sfTexture* texture, sfIntRect rectangle) -{ - sfFloatRect result = {0, 0, 0, 0}; - CSFML_CHECK_RETURN(texture, result); - CSFML_CHECK_RETURN(texture->This, result); - - sf::IntRect rect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height); - sf::FloatRect sfmlResult = texture->This->GetTexCoords(rect); - - result.Left = sfmlResult.Left; - result.Top = sfmlResult.Top; - result.Width = sfmlResult.Width; - result.Height = sfmlResult.Height; - - return result; -} - - //////////////////////////////////////////////////////////// unsigned int sfTexture_GetMaximumSize() { diff --git a/src/SFML/Graphics/VertexArray.cpp b/src/SFML/Graphics/VertexArray.cpp index ef447e0..de15e46 100644 --- a/src/SFML/Graphics/VertexArray.cpp +++ b/src/SFML/Graphics/VertexArray.cpp @@ -38,7 +38,7 @@ sfVertexArray* sfVertexArray_Create(void) //////////////////////////////////////////////////////////// -sfVertexArray* sfTransform_Copy(sfVertexArray* vertexArray) +sfVertexArray* sfVertexArray_Copy(sfVertexArray* vertexArray) { CSFML_CHECK_RETURN(vertexArray, NULL); @@ -118,4 +118,6 @@ sfFloatRect sfVertexArray_GetBounds(sfVertexArray* vertexArray) rect.Top = sfmlRect.Top; rect.Width = sfmlRect.Width; rect.Height = sfmlRect.Height; + + return rect; } diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index f9eaab6..71580b6 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -169,13 +169,13 @@ void sfFtp_Destroy(sfFtp* ftp) //////////////////////////////////////////////////////////// -sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, sfUint32 timeout) +sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, sfTime timeout) { CSFML_CHECK_RETURN(ftp, NULL); sf::IpAddress SFMLServer(server.Address); - return new sfFtpResponse(ftp->This.Connect(SFMLServer, port, timeout)); + return new sfFtpResponse(ftp->This.Connect(SFMLServer, port, sf::Microseconds(timeout.Microseconds))); } diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index 31751b0..1d5046b 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -153,13 +153,13 @@ void sfHttp_SetHost(sfHttp* http, const char* host, unsigned short port) //////////////////////////////////////////////////////////// -sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, sfUint32 timeout) +sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, sfTime timeout) { CSFML_CHECK_RETURN(http, NULL); CSFML_CHECK_RETURN(request, NULL); sfHttpResponse* response = new sfHttpResponse; - response->This = http->This.SendRequest(request->This, timeout); + response->This = http->This.SendRequest(request->This, sf::Microseconds(timeout.Microseconds)); return response; } diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 58d14e6..1d55b23 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -93,9 +93,9 @@ sfIpAddress sfIpAddress_GetLocalAddress(void) //////////////////////////////////////////////////////////// -sfIpAddress sfIpAddress_GetPublicAddress(sfUint32 timeout) +sfIpAddress sfIpAddress_GetPublicAddress(sfTime timeout) { - return FromSFMLAddress(sf::IpAddress::GetPublicAddress(timeout)); + return FromSFMLAddress(sf::IpAddress::GetPublicAddress(sf::Microseconds(timeout.Microseconds))); } diff --git a/src/SFML/Network/SocketSelector.cpp b/src/SFML/Network/SocketSelector.cpp index 2f8137b..23d8ccc 100644 --- a/src/SFML/Network/SocketSelector.cpp +++ b/src/SFML/Network/SocketSelector.cpp @@ -100,9 +100,9 @@ void sfSocketSelector_Clear(sfSocketSelector* selector) //////////////////////////////////////////////////////////// -sfBool sfSocketSelector_Wait(sfSocketSelector* selector, sfUint32 timeout) +sfBool sfSocketSelector_Wait(sfSocketSelector* selector, sfTime timeout) { - CSFML_CALL_RETURN(selector, Wait(timeout), sfFalse); + CSFML_CALL_RETURN(selector, Wait(sf::Microseconds(timeout.Microseconds)), sfFalse); } diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index 3fcb7fc..ac69ec2 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -89,13 +89,13 @@ unsigned short sfTcpSocket_GetRemotePort(const sfTcpSocket* socket) //////////////////////////////////////////////////////////// -sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, sfUint32 timeout) +sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, sfTime timeout) { sf::IpAddress address(host.Address); CSFML_CHECK_RETURN(socket, sfSocketError); - return static_cast(socket->This.Connect(address, port, timeout)); + return static_cast(socket->This.Connect(address, port, sf::Microseconds(timeout.Microseconds))); } diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index b1d0baf..834c34a 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -16,6 +16,8 @@ set(SRC ${SRCROOT}/Thread.cpp ${SRCROOT}/ThreadStruct.h ${INCROOT}/Thread.h + ${SRCROOT}/Time.cpp + ${INCROOT}/Time.h ${INCROOT}/Types.h ) diff --git a/src/SFML/System/Clock.cpp b/src/SFML/System/Clock.cpp index ce56ef6..327ffb2 100644 --- a/src/SFML/System/Clock.cpp +++ b/src/SFML/System/Clock.cpp @@ -54,14 +54,20 @@ void sfClock_Destroy(sfClock* clock) //////////////////////////////////////////////////////////// -sfUint32 sfClock_GetTime(const sfClock* clock) +sfTime sfClock_GetElapsedTime(const sfClock* clock) { - CSFML_CALL_RETURN(clock, GetElapsedTime(), 0) + CSFML_CHECK_RETURN(clock, sfTimeZero); + + sf::Time time = clock->This.GetElapsedTime(); + return sfMicroseconds(time.AsMicroseconds()); } //////////////////////////////////////////////////////////// -void sfClock_Reset(sfClock* clock) +sfTime sfClock_Restart(sfClock* clock) { - CSFML_CALL(clock, Reset()) + CSFML_CHECK_RETURN(clock, sfTimeZero); + + sf::Time time = clock->This.Restart(); + return sfMicroseconds(time.AsMicroseconds()); } diff --git a/src/SFML/System/Sleep.cpp b/src/SFML/System/Sleep.cpp index 24dd4f7..ec42d87 100644 --- a/src/SFML/System/Sleep.cpp +++ b/src/SFML/System/Sleep.cpp @@ -31,7 +31,7 @@ //////////////////////////////////////////////////////////// -void sfSleep(sfUint32 Duration) +void sfSleep(sfTime duration) { - sf::Sleep(Duration); + sf::Sleep(sf::Microseconds(duration.Microseconds)); } diff --git a/src/SFML/System/Time.cpp b/src/SFML/System/Time.cpp new file mode 100644 index 0000000..059c4aa --- /dev/null +++ b/src/SFML/System/Time.cpp @@ -0,0 +1,80 @@ +//////////////////////////////////////////////////////////// +// +// 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. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +//////////////////////////////////////////////////////////// +sfTime sfTimeZero = {0}; + + +//////////////////////////////////////////////////////////// +float sfTime_AsSeconds(sfTime time) +{ + return time.Microseconds / 1000000.f; +} + + +//////////////////////////////////////////////////////////// +sfInt32 sfTime_AsMilliseconds(sfTime time) +{ + return static_cast(time.Microseconds / 1000); +} + + +//////////////////////////////////////////////////////////// +sfInt64 sfTime_AsMicroseconds(sfTime time) +{ + return time.Microseconds; +} + + +//////////////////////////////////////////////////////////// +sfTime sfSeconds(float amount) +{ + sfTime time; + time.Microseconds = static_cast(amount * 1000000); + return time; +} + + +//////////////////////////////////////////////////////////// +sfTime sfMilliseconds(sfInt32 amount) +{ + sfTime time; + time.Microseconds = static_cast(amount) * 1000; + return time; +} + + +//////////////////////////////////////////////////////////// +sfTime sfMicroseconds(sfInt64 amount) +{ + sfTime time; + time.Microseconds = amount; + return time; +}