Times in SFML are now Uint32 milliseconds instead of float seconds

Added the sf::Uint64 and sf::Int64 types
This commit is contained in:
Laurent Gomila 2011-05-19 08:18:40 +02:00
parent c1ce16f4d6
commit e4c6c30e0b
83 changed files with 250 additions and 262 deletions

View File

@ -86,10 +86,10 @@ CSFML_API sfBool sfMusic_GetLoop(const sfMusic* music);
/// ///
/// \param music : Music to get the duration from /// \param music : Music to get the duration from
/// ///
/// \return Music duration, in seconds /// \return Music duration, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfMusic_GetDuration(const sfMusic* music); CSFML_API sfUint32 sfMusic_GetDuration(const sfMusic* music);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Start playing a music /// Start playing a music
@ -150,10 +150,10 @@ CSFML_API sfSoundStatus sfMusic_GetStatus(const sfMusic* music);
/// ///
/// \param music : Music to get the position from /// \param music : Music to get the position from
/// ///
/// \return Current playing position, expressed in seconds /// \return Current playing position, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfMusic_GetPlayingOffset(const sfMusic* music); CSFML_API sfUint32 sfMusic_GetPlayingOffset(const sfMusic* music);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the pitch of a music /// Set the pitch of a music
@ -221,10 +221,10 @@ CSFML_API void sfMusic_SetAttenuation(sfMusic* music, float attenuation);
/// Set the current playing position of a music /// Set the current playing position of a music
/// ///
/// \param music : Music to modify /// \param music : Music to modify
/// \param timeOffset : New playing position, expressed in seconds /// \param timeOffset : New playing position, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfMusic_SetPlayingOffset(sfMusic* music, float timeOffset); CSFML_API void sfMusic_SetPlayingOffset(sfMusic* music, sfUint32 timeOffset);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the pitch of a music /// Get the pitch of a music

View File

@ -197,10 +197,10 @@ CSFML_API void sfSound_SetAttenuation(sfSound* sound, float attenuation);
/// Set the current playing position of a sound /// Set the current playing position of a sound
/// ///
/// \param sound : Sound to modify /// \param sound : Sound to modify
/// \param timeOffset : New playing position, expressed in seconds /// \param timeOffset : New playing position, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfSound_SetPlayingOffset(sfSound* sound, float timeOffset); CSFML_API void sfSound_SetPlayingOffset(sfSound* sound, sfUint32 timeOffset);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the pitch of a sound /// Get the pitch of a sound
@ -269,10 +269,10 @@ CSFML_API float sfSound_GetAttenuation(const sfSound* sound);
/// ///
/// \param sound : Sound to get the position from /// \param sound : Sound to get the position from
/// ///
/// \return Current playing position, expressed in seconds /// \return Current playing position, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfSound_GetPlayingOffset(const sfSound* sound); CSFML_API sfUint32 sfSound_GetPlayingOffset(const sfSound* sound);
#endif // SFML_SOUND_H #endif // SFML_SOUND_H

View File

@ -142,10 +142,10 @@ CSFML_API unsigned int sfSoundBuffer_GetChannelsCount(const sfSoundBuffer* sound
/// ///
/// \param soundBuffer : Sound buffer to get duration from /// \param soundBuffer : Sound buffer to get duration from
/// ///
/// \return Sound duration, in seconds /// \return Sound duration, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfSoundBuffer_GetDuration(const sfSoundBuffer* soundBuffer); CSFML_API sfUint32 sfSoundBuffer_GetDuration(const sfSoundBuffer* soundBuffer);
#endif // SFML_SOUNDBUFFER_H #endif // SFML_SOUNDBUFFER_H

View File

@ -44,7 +44,7 @@ typedef struct
} sfSoundStreamChunk; } sfSoundStreamChunk;
typedef sfBool (*sfSoundStreamGetDataCallback)(sfSoundStreamChunk*, void*); ///< Type of the callback used to get a sound stream data typedef sfBool (*sfSoundStreamGetDataCallback)(sfSoundStreamChunk*, void*); ///< Type of the callback used to get a sound stream data
typedef void (*sfSoundStreamSeekCallback)(float, void*); ///< Type of the callback used to seek in a sound stream typedef void (*sfSoundStreamSeekCallback)(sfUint32, void*); ///< Type of the callback used to seek in a sound stream
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -194,10 +194,10 @@ CSFML_API void sfSoundStream_SetAttenuation(sfSoundStream* soundStream, float at
/// Set the current playing position of a stream /// Set the current playing position of a stream
/// ///
/// \param soundStream : Sound stream to modify /// \param soundStream : Sound stream to modify
/// \param timeOffset : New playing position, expressed in seconds /// \param timeOffset : New playing position, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfSoundStream_SetPlayingOffset(sfSoundStream* soundStream, float timeOffset); CSFML_API void sfSoundStream_SetPlayingOffset(sfSoundStream* soundStream, sfUint32 timeOffset);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set a stream loop state /// Set a stream loop state
@ -285,10 +285,10 @@ CSFML_API sfBool sfSoundStream_GetLoop(const sfSoundStream* soundStream);
/// ///
/// \param soundStream : Sound stream to get the position from /// \param soundStream : Sound stream to get the position from
/// ///
/// \return Current playing position, expressed in seconds /// \return Current playing position, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfSoundStream_GetPlayingOffset(const sfSoundStream* soundStream); CSFML_API sfUint32 sfSoundStream_GetPlayingOffset(const sfSoundStream* soundStream);
#endif // SFML_SOUNDSTREAM_H #endif // SFML_SOUNDSTREAM_H

View File

@ -281,10 +281,10 @@ CSFML_API void sfRenderWindow_SetFramerateLimit(sfRenderWindow* renderWindow, un
/// ///
/// \param renderWindow : Renderwindow object /// \param renderWindow : Renderwindow object
/// ///
/// \return Time elapsed, in seconds /// \return Time elapsed, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfRenderWindow_GetFrameTime(const sfRenderWindow* renderWindow); CSFML_API sfUint32 sfRenderWindow_GetFrameTime(const sfRenderWindow* renderWindow);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Change the joystick threshold, ie. the value below which /// Change the joystick threshold, ie. the value below which

View File

@ -282,12 +282,12 @@ CSFML_API void sfFtp_Destroy(sfFtp* ftp);
/// \param ftp : Ftp instance /// \param ftp : Ftp instance
/// \param server : FTP server to connect to /// \param server : FTP server to connect to
/// \param port : Port used for connection (21 by default, standard FTP port) /// \param port : Port used for connection (21 by default, standard FTP port)
/// \param timeout : Maximum time to wait (0 to use no timeout) /// \param timeout : Maximum time to wait, in milliseconds (0 to use no timeout)
/// ///
/// \return Server response to the request /// \return Server response to the request
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, float timeout); CSFML_API sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, sfUint32 timeout);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Log in using anonymous account /// Log in using anonymous account

View File

@ -246,12 +246,12 @@ CSFML_API void sfHttp_SetHost(sfHttp* http, const char* host, unsigned short por
/// ///
/// \param http : Http object /// \param http : Http object
/// \param request : Request to send /// \param request : Request to send
/// \param timeout : Maximum time to wait (0 to use no timeout) /// \param timeout : Maximum time to wait, in milliseconds (0 to use no timeout)
/// ///
/// \return Server's response, or NULL if request is invalid /// \return Server's response, or NULL if request is invalid
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, float timeout); CSFML_API sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, sfUint32 timeout);
#endif // SFML_HTTP_H #endif // SFML_HTTP_H

View File

@ -104,12 +104,12 @@ CSFML_API sfIpAddress sfIpAddress_GetLocalAddress(void);
/// distant website ; as a consequence, this function may be /// distant website ; as a consequence, this function may be
/// very slow -- use it as few as possible ! /// very slow -- use it as few as possible !
/// ///
/// \param timeout : Maximum time to wait, in seconds (use 0 for no timeout) /// \param timeout : Maximum time to wait, in milliseconds (use 0 for no timeout)
/// ///
/// \return Public IP address /// \return Public IP address
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfIpAddress sfIpAddress_GetPublicAddress(float timeout); CSFML_API sfIpAddress sfIpAddress_GetPublicAddress(sfUint32 timeout);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the computer's loopback address /// Get the computer's loopback address

View File

@ -94,12 +94,12 @@ CSFML_API void sfSocketSelector_Clear(sfSocketSelector* selector);
/// is ready, or when the given timeout is over /// is ready, or when the given timeout is over
/// ///
/// \param selector : Selector to check /// \param selector : Selector to check
/// \param timeout : Maximum time to wait, in seconds (0 to disable timeout) /// \param timeout : Maximum time to wait, in milliseconds (0 to disable timeout)
/// ///
/// \return sfTrue if there are sockets ready, sfFalse otherwise /// \return sfTrue if there are sockets ready, sfFalse otherwise
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfBool sfSocketSelector_Wait(sfSocketSelector* selector, float timeout); CSFML_API sfBool sfSocketSelector_Wait(sfSocketSelector* selector, sfUint32 timeout);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Test a socket to know if it is ready to receive data /// Test a socket to know if it is ready to receive data

View File

@ -106,12 +106,12 @@ CSFML_API unsigned short sfTcpSocket_GetRemotePort(const sfTcpSocket* socket);
/// \param socket : Socket to connect /// \param socket : Socket to connect
/// \param host : IP Address of the host to connect to /// \param host : IP Address of the host to connect to
/// \param port : Port to use for transfers (warning : ports < 1024 are reserved) /// \param port : Port to use for transfers (warning : ports < 1024 are reserved)
/// \param timeout : Maximum time to wait (0 to use no timeout) /// \param timeout : Maximum time to wait, in milliseconds (0 to use no timeout)
/// ///
/// \return sfTrue if operation has been successful /// \return sfTrue if operation has been successful
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, float timeout); CSFML_API sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, sfUint32 timeout);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Disconnect a connect from its remote peer /// Disconnect a connect from its remote peer

View File

@ -63,8 +63,10 @@ CSFML_API void sfClock_Destroy(sfClock* clock);
/// ///
/// \param clock : Clock to get time from /// \param clock : Clock to get time from
/// ///
/// \return Elapsed time, in milliseconds
///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfClock_GetTime(const sfClock* clock); CSFML_API sfUint32 sfClock_GetTime(const sfClock* clock);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Restart a clock /// Restart a clock

View File

@ -32,12 +32,12 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Make the current thread sleep for a given time /// Make the current thread sleep for a given duration
/// ///
/// \param duration : Time to sleep, in seconds /// \param duration : Time to sleep, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfSleep(float duration); CSFML_API void sfSleep(sfUint32 duration);
#endif // SFML_SLEEP_H #endif // SFML_SLEEP_H

View File

@ -290,10 +290,10 @@ CSFML_API void sfWindow_SetFramerateLimit(sfWindow* window, unsigned int limit);
/// ///
/// \param window : Window object /// \param window : Window object
/// ///
/// \return Time elapsed, in seconds /// \return Time elapsed, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfWindow_GetFrameTime(const sfWindow* window); CSFML_API sfUint32 sfWindow_GetFrameTime(const sfWindow* window);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Change the joystick threshold, ie. the value below which /// Change the joystick threshold, ie. the value below which

View File

@ -94,9 +94,9 @@ sfBool sfMusic_GetLoop(const sfMusic* music)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get a music duration /// Get a music duration
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfMusic_GetDuration(const sfMusic* music) sfUint32 sfMusic_GetDuration(const sfMusic* music)
{ {
CSFML_CALL_RETURN(music, GetDuration(), 0.f); CSFML_CALL_RETURN(music, GetDuration(), 0);
} }
@ -159,9 +159,9 @@ sfSoundStatus sfMusic_GetStatus(const sfMusic* music)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the current playing position of a music /// Get the current playing position of a music
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfMusic_GetPlayingOffset(const sfMusic* music) sfUint32 sfMusic_GetPlayingOffset(const sfMusic* music)
{ {
CSFML_CALL_RETURN(music, GetPlayingOffset(), 0.f); CSFML_CALL_RETURN(music, GetPlayingOffset(), 0);
} }
@ -228,7 +228,7 @@ void sfMusic_SetAttenuation(sfMusic* music, float attenuation)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the current playing position of a stream /// Set the current playing position of a stream
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfMusic_SetPlayingOffset(sfMusic* music, float timeOffset) void sfMusic_SetPlayingOffset(sfMusic* music, sfUint32 timeOffset)
{ {
CSFML_CALL(music, SetPlayingOffset(timeOffset)); CSFML_CALL(music, SetPlayingOffset(timeOffset));
} }

View File

@ -202,7 +202,7 @@ void sfSound_SetAttenuation(sfSound* sound, float attenuation)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the current playing position of a sound /// Set the current playing position of a sound
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfSound_SetPlayingOffset(sfSound* sound, float timeOffset) void sfSound_SetPlayingOffset(sfSound* sound, sfUint32 timeOffset)
{ {
CSFML_CALL(sound, SetPlayingOffset(timeOffset)); CSFML_CALL(sound, SetPlayingOffset(timeOffset));
} }
@ -271,7 +271,7 @@ float sfSound_GetAttenuation(const sfSound* sound)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the current playing position of a sound /// Get the current playing position of a sound
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfSound_GetPlayingOffset(const sfSound* sound) sfUint32 sfSound_GetPlayingOffset(const sfSound* sound)
{ {
CSFML_CALL_RETURN(sound, GetPlayingOffset(), 0.f) CSFML_CALL_RETURN(sound, GetPlayingOffset(), 0)
} }

View File

@ -151,7 +151,7 @@ unsigned int sfSoundBuffer_GetChannelsCount(const sfSoundBuffer* soundBuffer)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the duration of a sound buffer /// Get the duration of a sound buffer
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfSoundBuffer_GetDuration(const sfSoundBuffer* soundBuffer) sfUint32 sfSoundBuffer_GetDuration(const sfSoundBuffer* soundBuffer)
{ {
CSFML_CALL_RETURN(soundBuffer, GetDuration(), 0.f) CSFML_CALL_RETURN(soundBuffer, GetDuration(), 0)
} }

View File

@ -172,7 +172,7 @@ void sfSoundStream_SetAttenuation(sfSoundStream* soundStream, float attenuation)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the current playing position of a stream /// Set the current playing position of a stream
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfSoundStream_SetPlayingOffset(sfSoundStream* soundStream, float timeOffset) void sfSoundStream_SetPlayingOffset(sfSoundStream* soundStream, sfUint32 timeOffset)
{ {
CSFML_CALL(soundStream, SetPlayingOffset(timeOffset)); CSFML_CALL(soundStream, SetPlayingOffset(timeOffset));
} }
@ -259,7 +259,7 @@ sfBool sfSoundStream_GetLoop(const sfSoundStream* soundStream)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the current playing position of a sound stream /// Get the current playing position of a sound stream
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfSoundStream_GetPlayingOffset(const sfSoundStream* soundStream) sfUint32 sfSoundStream_GetPlayingOffset(const sfSoundStream* soundStream)
{ {
CSFML_CALL_RETURN(soundStream, GetPlayingOffset(), 0.f); CSFML_CALL_RETURN(soundStream, GetPlayingOffset(), 0);
} }

View File

@ -64,7 +64,7 @@ private :
return Continue; return Continue;
} }
virtual void OnSeek(float TimeOffset) virtual void OnSeek(sfUint32 TimeOffset)
{ {
if (mySeekCallback) if (mySeekCallback)
mySeekCallback(TimeOffset, myUserData); mySeekCallback(TimeOffset, myUserData);

View File

@ -343,9 +343,9 @@ void sfRenderWindow_SetFramerateLimit(sfRenderWindow* renderWindow, unsigned int
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get time elapsed since last frame of a window /// Get time elapsed since last frame of a window
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfRenderWindow_GetFrameTime(const sfRenderWindow* renderWindow) sfUint32 sfRenderWindow_GetFrameTime(const sfRenderWindow* renderWindow)
{ {
CSFML_CALL_RETURN(renderWindow, GetFrameTime(), 0.f); CSFML_CALL_RETURN(renderWindow, GetFrameTime(), 0);
} }

View File

@ -208,7 +208,7 @@ void sfFtp_Destroy(sfFtp* ftp)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Connect to the specified FTP server /// Connect to the specified FTP server
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, float timeout) sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, sfUint32 timeout)
{ {
CSFML_CHECK_RETURN(ftp, NULL); CSFML_CHECK_RETURN(ftp, NULL);

View File

@ -201,7 +201,7 @@ void sfHttp_SetHost(sfHttp* http, const char* host, unsigned short port)
/// not return instantly; use a thread if you don't want to block your /// not return instantly; use a thread if you don't want to block your
/// application. /// application.
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, float timeout) sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, sfUint32 timeout)
{ {
CSFML_CHECK_RETURN(http, NULL); CSFML_CHECK_RETURN(http, NULL);
CSFML_CHECK_RETURN(request, NULL); CSFML_CHECK_RETURN(request, NULL);

View File

@ -114,7 +114,7 @@ sfIpAddress sfIpAddress_GetLocalAddress(void)
/// distant website ; as a consequence, this function may be /// distant website ; as a consequence, this function may be
/// very slow -- use it as few as possible ! /// very slow -- use it as few as possible !
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfIpAddress sfIpAddress_GetPublicAddress(float timeout) sfIpAddress sfIpAddress_GetPublicAddress(sfUint32 timeout)
{ {
return FromSFMLAddress(sf::IpAddress::GetPublicAddress(timeout)); return FromSFMLAddress(sf::IpAddress::GetPublicAddress(timeout));
} }

View File

@ -116,7 +116,7 @@ void sfSocketSelector_Clear(sfSocketSelector* selector)
/// This functions will return either when at least one socket /// This functions will return either when at least one socket
/// is ready, or when the given timeout is over /// is ready, or when the given timeout is over
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfBool sfSocketSelector_Wait(sfSocketSelector* selector, float timeout) sfBool sfSocketSelector_Wait(sfSocketSelector* selector, sfUint32 timeout)
{ {
CSFML_CALL_RETURN(selector, Wait(timeout), sfFalse); CSFML_CALL_RETURN(selector, Wait(timeout), sfFalse);
} }

View File

@ -106,7 +106,7 @@ unsigned short sfTcpSocket_GetRemotePort(const sfTcpSocket* socket)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Connect a TCP socket to another computer on a specified port /// Connect a TCP socket to another computer on a specified port
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, float timeout) sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, sfUint32 timeout)
{ {
sf::IpAddress address(host.Address); sf::IpAddress address(host.Address);

View File

@ -62,9 +62,9 @@ void sfClock_Destroy(sfClock* clock)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the time elapsed for a clock /// Get the time elapsed for a clock
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfClock_GetTime(const sfClock* clock) sfUint32 sfClock_GetTime(const sfClock* clock)
{ {
CSFML_CALL_RETURN(clock, GetElapsedTime(), 0.f) CSFML_CALL_RETURN(clock, GetElapsedTime(), 0)
} }

View File

@ -31,9 +31,9 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Make the current thread sleep for a given time /// Make the current thread sleep for a given duration
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfSleep(float Duration) void sfSleep(sfUint32 Duration)
{ {
sf::Sleep(Duration); sf::Sleep(Duration);
} }

View File

@ -317,9 +317,9 @@ void sfWindow_SetFramerateLimit(sfWindow* window, unsigned int limit)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get time elapsed since last frame of a window /// Get time elapsed since last frame of a window
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfWindow_GetFrameTime(const sfWindow* window) sfUint32 sfWindow_GetFrameTime(const sfWindow* window)
{ {
CSFML_CALL_RETURN(window, GetFrameTime(), 0.f) CSFML_CALL_RETURN(window, GetFrameTime(), 0)
} }

View File

@ -87,7 +87,7 @@ namespace opengl
float y = -window.Input.GetMouseY() * 200.0F / window.Height + 100.0F; float y = -window.Input.GetMouseY() * 200.0F / window.Height + 100.0F;
// Apply some transformations // Apply some transformations
time += window.GetFrameTime(); time += window.GetFrameTime() / 1000.0F;
Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity(); Gl.glLoadIdentity();
Gl.glTranslatef(x, y, -100.0F); Gl.glTranslatef(x, y, -100.0F);

View File

@ -74,7 +74,7 @@ Module OpenGL
Dim y = -window.Input.GetMouseY() * 200.0F / window.Height + 100.0F Dim y = -window.Input.GetMouseY() * 200.0F / window.Height + 100.0F
' Apply some transformations ' Apply some transformations
time += window.GetFrameTime() time += window.GetFrameTime() / 1000.0F
Gl.glMatrixMode(Gl.GL_MODELVIEW) Gl.glMatrixMode(Gl.GL_MODELVIEW)
Gl.glLoadIdentity() Gl.glLoadIdentity()
Gl.glTranslatef(x, y, -100.0F) Gl.glTranslatef(x, y, -100.0F)

View File

@ -50,7 +50,7 @@ namespace window
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
// Apply some transformations // Apply some transformations
time += window.GetFrameTime(); time += window.GetFrameTime() / 1000.0F;
Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity(); Gl.glLoadIdentity();
Gl.glTranslatef(0.0F, 0.0F, -200.0F); Gl.glTranslatef(0.0F, 0.0F, -200.0F);

View File

@ -113,10 +113,10 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Total duration of the music, in seconds /// Total duration of the music, in milliseconds
/// </summary> /// </summary>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public float Duration public uint Duration
{ {
get {return sfMusic_GetDuration(This);} get {return sfMusic_GetDuration(This);}
} }
@ -206,10 +206,10 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Current playing position, in seconds /// Current playing position, in milliseconds
/// </summary> /// </summary>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public float PlayingOffset public uint PlayingOffset
{ {
get {return sfMusic_GetPlayingOffset(This);} get {return sfMusic_GetPlayingOffset(This);}
set {sfMusic_SetPlayingOffset(This, value);} set {sfMusic_SetPlayingOffset(This, value);}
@ -272,7 +272,7 @@ namespace SFML
static extern SoundStatus sfMusic_GetStatus(IntPtr Music); static extern SoundStatus sfMusic_GetStatus(IntPtr Music);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern float sfMusic_GetDuration(IntPtr Music); static extern uint sfMusic_GetDuration(IntPtr Music);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern uint sfMusic_GetChannelsCount(IntPtr Music); static extern uint sfMusic_GetChannelsCount(IntPtr Music);
@ -302,7 +302,7 @@ namespace SFML
static extern void sfMusic_SetAttenuation(IntPtr Music, float Attenuation); static extern void sfMusic_SetAttenuation(IntPtr Music, float Attenuation);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern void sfMusic_SetPlayingOffset(IntPtr Music, float TimeOffset); static extern void sfMusic_SetPlayingOffset(IntPtr Music, uint TimeOffset);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern bool sfMusic_GetLoop(IntPtr Music); static extern bool sfMusic_GetLoop(IntPtr Music);
@ -326,7 +326,7 @@ namespace SFML
static extern float sfMusic_GetAttenuation(IntPtr Music); static extern float sfMusic_GetAttenuation(IntPtr Music);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern float sfMusic_GetPlayingOffset(IntPtr Music); static extern uint sfMusic_GetPlayingOffset(IntPtr Music);
#endregion #endregion
} }
} }

View File

@ -151,10 +151,10 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Current playing position of the sound, in seconds /// Current playing position of the sound, in milliseconds
/// </summary> /// </summary>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public float PlayingOffset public uint PlayingOffset
{ {
get {return sfSound_GetPlayingOffset(This);} get {return sfSound_GetPlayingOffset(This);}
set {sfSound_SetPlayingOffset(This, value);} set {sfSound_SetPlayingOffset(This, value);}
@ -297,7 +297,7 @@ namespace SFML
static extern void sfSound_SetAttenuation(IntPtr Sound, float Attenuation); static extern void sfSound_SetAttenuation(IntPtr Sound, float Attenuation);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern void sfSound_SetPlayingOffset(IntPtr Sound, float TimeOffset); static extern void sfSound_SetPlayingOffset(IntPtr Sound, uint TimeOffset);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern float sfSound_GetPitch(IntPtr Sound); static extern float sfSound_GetPitch(IntPtr Sound);
@ -318,7 +318,7 @@ namespace SFML
static extern float sfSound_GetAttenuation(IntPtr Sound); static extern float sfSound_GetAttenuation(IntPtr Sound);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern float sfSound_GetPlayingOffset(IntPtr Sound); static extern uint sfSound_GetPlayingOffset(IntPtr Sound);
#endregion #endregion
} }
} }

View File

@ -122,10 +122,10 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Total duration of the buffer, in seconds /// Total duration of the buffer, in milliseconds
/// </summary> /// </summary>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public float Duration public uint Duration
{ {
get {return sfSoundBuffer_GetDuration(This);} get {return sfSoundBuffer_GetDuration(This);}
} }
@ -202,7 +202,7 @@ namespace SFML
static extern uint sfSoundBuffer_GetChannelsCount(IntPtr SoundBuffer); static extern uint sfSoundBuffer_GetChannelsCount(IntPtr SoundBuffer);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern float sfSoundBuffer_GetDuration(IntPtr SoundBuffer); static extern uint sfSoundBuffer_GetDuration(IntPtr SoundBuffer);
#endregion #endregion
} }
} }

View File

@ -171,10 +171,10 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Current playing position, in seconds /// Current playing position, in milliseconds
/// </summary> /// </summary>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public float PlayingOffset public uint PlayingOffset
{ {
get {return sfSoundStream_GetPlayingOffset(This);} get {return sfSoundStream_GetPlayingOffset(This);}
set {sfSoundStream_SetPlayingOffset(This, value);} set {sfSoundStream_SetPlayingOffset(This, value);}
@ -229,9 +229,9 @@ namespace SFML
/// <summary> /// <summary>
/// Virtual function called to seek into the stream /// Virtual function called to seek into the stream
/// </summary> /// </summary>
/// <param name="timeOffset">New position, expressed in seconds</param> /// <param name="timeOffset">New position, in milliseconds</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
protected abstract void OnSeek(float timeOffset); protected abstract void OnSeek(uint timeOffset);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
@ -289,11 +289,11 @@ namespace SFML
/// <summary> /// <summary>
/// Called to seek in the stream /// Called to seek in the stream
/// </summary> /// </summary>
/// <param name="timeOffset">New position, expressed in seconds</param> /// <param name="timeOffset">New position, in milliseconds</param>
/// <param name="userData">User data -- unused</param> /// <param name="userData">User data -- unused</param>
/// <returns>If false is returned, the playback is aborted</returns> /// <returns>If false is returned, the playback is aborted</returns>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
private void Seek(float timeOffset, IntPtr userData) private void Seek(uint timeOffset, IntPtr userData)
{ {
OnSeek(timeOffset); OnSeek(timeOffset);
} }
@ -302,7 +302,7 @@ namespace SFML
private delegate bool GetDataCallbackType(ref Chunk dataChunk, IntPtr UserData); private delegate bool GetDataCallbackType(ref Chunk dataChunk, IntPtr UserData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void SeekCallbackType(float timeOffset, IntPtr UserData); private delegate void SeekCallbackType(uint timeOffset, IntPtr UserData);
private GetDataCallbackType myGetDataCallback; private GetDataCallbackType myGetDataCallback;
private SeekCallbackType mySeekCallback; private SeekCallbackType mySeekCallback;
@ -355,7 +355,7 @@ namespace SFML
static extern void sfSoundStream_SetAttenuation(IntPtr SoundStream, float Attenuation); static extern void sfSoundStream_SetAttenuation(IntPtr SoundStream, float Attenuation);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern void sfSoundStream_SetPlayingOffset(IntPtr SoundStream, float TimeOffset); static extern void sfSoundStream_SetPlayingOffset(IntPtr SoundStream, uint TimeOffset);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern bool sfSoundStream_GetLoop(IntPtr SoundStream); static extern bool sfSoundStream_GetLoop(IntPtr SoundStream);
@ -379,7 +379,7 @@ namespace SFML
static extern float sfSoundStream_GetAttenuation(IntPtr SoundStream); static extern float sfSoundStream_GetAttenuation(IntPtr SoundStream);
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern float sfSoundStream_GetPlayingOffset(IntPtr SoundStream); static extern uint sfSoundStream_GetPlayingOffset(IntPtr SoundStream);
#endregion #endregion
} }
} }

View File

@ -288,7 +288,7 @@ namespace SFML
/// </summary> /// </summary>
/// <returns>Time elapsed, in seconds</returns> /// <returns>Time elapsed, in seconds</returns>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public override float GetFrameTime() public override uint GetFrameTime()
{ {
return sfRenderWindow_GetFrameTime(This); return sfRenderWindow_GetFrameTime(This);
} }
@ -605,7 +605,7 @@ namespace SFML
static extern void sfRenderWindow_SetFramerateLimit(IntPtr This, uint Limit); static extern void sfRenderWindow_SetFramerateLimit(IntPtr This, uint Limit);
[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern float sfRenderWindow_GetFrameTime(IntPtr This); static extern uint sfRenderWindow_GetFrameTime(IntPtr This);
[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_SetJoystickThreshold(IntPtr This, float Threshold); static extern void sfRenderWindow_SetJoystickThreshold(IntPtr This, float Threshold);

View File

@ -333,9 +333,9 @@ namespace SFML
/// <summary> /// <summary>
/// Get time elapsed since last frame /// Get time elapsed since last frame
/// </summary> /// </summary>
/// <returns>Time elapsed, in seconds</returns> /// <returns>Time elapsed, in milliseconds</returns>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public virtual float GetFrameTime() public virtual uint GetFrameTime()
{ {
return sfWindow_GetFrameTime(This); return sfWindow_GetFrameTime(This);
} }
@ -662,7 +662,7 @@ namespace SFML
static extern void sfWindow_SetFramerateLimit(IntPtr This, uint Limit); static extern void sfWindow_SetFramerateLimit(IntPtr This, uint Limit);
[DllImport("csfml-window-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-window-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern float sfWindow_GetFrameTime(IntPtr This); static extern uint sfWindow_GetFrameTime(IntPtr This);
[DllImport("csfml-window-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("csfml-window-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern void sfWindow_SetJoystickThreshold(IntPtr This, float Threshold); static extern void sfWindow_SetJoystickThreshold(IntPtr This, float Threshold);

View File

@ -97,9 +97,9 @@ int main()
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(x, y, -100.f); glTranslatef(x, y, -100.f);
glRotatef(clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f); glRotatef(clock.GetElapsedTime() * 0.05f, 1.f, 0.f, 0.f);
glRotatef(clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f); glRotatef(clock.GetElapsedTime() * 0.03f, 0.f, 1.f, 0.f);
glRotatef(clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f); glRotatef(clock.GetElapsedTime() * 0.09f, 0.f, 0.f, 1.f);
// Draw a cube // Draw a cube
float size = 20.f; float size = 20.f;

View File

@ -17,7 +17,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
int main() int main()
{ {
std::srand(std::time(NULL)); std::srand(static_cast<unsigned int>(std::time(NULL)));
// Defines PI // Defines PI
const float PI = 3.14159f; const float PI = 3.14159f;
@ -100,15 +100,15 @@ int main()
{ {
// Move the player's paddle // Move the player's paddle
if (window.GetInput().IsKeyDown(sf::Key::Up) && (leftPaddle.GetPosition().y > 5.f)) if (window.GetInput().IsKeyDown(sf::Key::Up) && (leftPaddle.GetPosition().y > 5.f))
leftPaddle.Move(0.f, -leftPaddleSpeed * window.GetFrameTime()); leftPaddle.Move(0.f, -leftPaddleSpeed * window.GetFrameTime() / 1000.f);
if (window.GetInput().IsKeyDown(sf::Key::Down) && (leftPaddle.GetPosition().y < window.GetView().GetSize().y - leftPaddle.GetSize().y - 5.f)) if (window.GetInput().IsKeyDown(sf::Key::Down) && (leftPaddle.GetPosition().y < window.GetView().GetSize().y - leftPaddle.GetSize().y - 5.f))
leftPaddle.Move(0.f, leftPaddleSpeed * window.GetFrameTime()); leftPaddle.Move(0.f, leftPaddleSpeed * window.GetFrameTime() / 1000.f);
// Move the computer's paddle // Move the computer's paddle
if (((rightPaddleSpeed < 0.f) && (rightPaddle.GetPosition().y > 5.f)) || if (((rightPaddleSpeed < 0.f) && (rightPaddle.GetPosition().y > 5.f)) ||
((rightPaddleSpeed > 0.f) && (rightPaddle.GetPosition().y < window.GetView().GetSize().y - rightPaddle.GetSize().y - 5.f))) ((rightPaddleSpeed > 0.f) && (rightPaddle.GetPosition().y < window.GetView().GetSize().y - rightPaddle.GetSize().y - 5.f)))
{ {
rightPaddle.Move(0.f, rightPaddleSpeed * window.GetFrameTime()); rightPaddle.Move(0.f, rightPaddleSpeed * window.GetFrameTime() / 1000.f);
} }
// Update the computer's paddle direction according to the ball position // Update the computer's paddle direction according to the ball position
@ -122,7 +122,7 @@ int main()
} }
// Move the ball // Move the ball
float factor = ballSpeed * window.GetFrameTime(); float factor = ballSpeed * window.GetFrameTime() / 1000.f;
ball.Move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor); ball.Move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);
// Check collisions between the ball and the screen // Check collisions between the ball and the screen

View File

@ -214,10 +214,10 @@ test.Create(800, 600);
globalShader.Update(mouseX, mouseY); globalShader.Update(mouseX, mouseY);
// Animate the entity // Animate the entity
float entityX = (cos(clock.GetElapsedTime() * 1.3f) + 1.2f) * 300; float entityX = (cos(clock.GetElapsedTime() * 0.0013f) + 1.2f) * 300;
float entityY = (cos(clock.GetElapsedTime() * 0.8f) + 1.2f) * 200; float entityY = (cos(clock.GetElapsedTime() * 0.0008f) + 1.2f) * 200;
entity.SetPosition(entityX, entityY); entity.SetPosition(entityX, entityY);
entity.Rotate(window.GetFrameTime() * 100); entity.Rotate(window.GetFrameTime() * 0.1f);
// Draw the background and the moving entity to the render image // Draw the background and the moving entity to the render image
image.Clear(); image.Clear();

View File

@ -20,9 +20,9 @@ void PlaySound()
// Display sound informations // Display sound informations
std::cout << "canary.wav :" << std::endl; std::cout << "canary.wav :" << std::endl;
std::cout << " " << buffer.GetDuration() << " sec" << std::endl; std::cout << " " << buffer.GetDuration() / 1000.f << " seconds" << std::endl;
std::cout << " " << buffer.GetSampleRate() << " samples / sec" << std::endl; std::cout << " " << buffer.GetSampleRate() << " samples / sec" << std::endl;
std::cout << " " << buffer.GetChannelsCount() << " channels" << std::endl; std::cout << " " << buffer.GetChannelsCount() << " channels" << std::endl;
// Create a sound instance and play it // Create a sound instance and play it
sf::Sound sound(buffer); sf::Sound sound(buffer);
@ -32,7 +32,7 @@ void PlaySound()
while (sound.GetStatus() == sf::Sound::Playing) while (sound.GetStatus() == sf::Sound::Playing)
{ {
// Leave some CPU time for other processes // Leave some CPU time for other processes
sf::Sleep(0.1f); sf::Sleep(100);
// Display the playing position // Display the playing position
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.GetPlayingOffset() << " sec "; std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.GetPlayingOffset() << " sec ";
@ -54,9 +54,9 @@ void PlayMusic()
// Display music informations // Display music informations
std::cout << "orchestral.ogg :" << std::endl; std::cout << "orchestral.ogg :" << std::endl;
std::cout << " " << music.GetDuration() << " sec" << std::endl; std::cout << " " << music.GetDuration() / 1000.f << " seconds" << std::endl;
std::cout << " " << music.GetSampleRate() << " samples / sec" << std::endl; std::cout << " " << music.GetSampleRate() << " samples / sec" << std::endl;
std::cout << " " << music.GetChannelsCount() << " channels" << std::endl; std::cout << " " << music.GetChannelsCount() << " channels" << std::endl;
// Play it // Play it
music.Play(); music.Play();
@ -65,7 +65,7 @@ void PlayMusic()
while (music.GetStatus() == sf::Music::Playing) while (music.GetStatus() == sf::Music::Playing)
{ {
// Leave some CPU time for other processes // Leave some CPU time for other processes
sf::Sleep(0.1f); sf::Sleep(100);
// Display the playing position // Display the playing position
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << music.GetPlayingOffset() << " sec "; std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << music.GetPlayingOffset() << " sec ";

View File

@ -46,9 +46,9 @@ int main()
// Display captured sound informations // Display captured sound informations
std::cout << "Sound information :" << std::endl; std::cout << "Sound information :" << std::endl;
std::cout << " " << buffer.GetDuration() << " seconds" << std::endl; std::cout << " " << buffer.GetDuration() / 1000.f << " seconds" << std::endl;
std::cout << " " << buffer.GetSampleRate() << " samples / seconds" << std::endl; std::cout << " " << buffer.GetSampleRate() << " samples / seconds" << std::endl;
std::cout << " " << buffer.GetChannelsCount() << " channels" << std::endl; std::cout << " " << buffer.GetChannelsCount() << " channels" << std::endl;
// Choose what to do with the recorded sound data // Choose what to do with the recorded sound data
char choice; char choice;
@ -79,7 +79,7 @@ int main()
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.GetPlayingOffset() << " sec"; std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.GetPlayingOffset() << " sec";
// Leave some CPU time for other threads // Leave some CPU time for other threads
sf::Sleep(0.1f); sf::Sleep(100);
} }
} }

View File

@ -78,7 +78,7 @@ private :
// No new data has arrived since last update : wait until we get some // No new data has arrived since last update : wait until we get some
while ((myOffset >= mySamples.size()) && !myHasFinished) while ((myOffset >= mySamples.size()) && !myHasFinished)
sf::Sleep(0.01f); sf::Sleep(10);
// Copy samples into a local buffer to avoid synchronization problems // Copy samples into a local buffer to avoid synchronization problems
// (don't forget that we run in two separate threads) // (don't forget that we run in two separate threads)
@ -101,9 +101,9 @@ private :
/// /see SoundStream::OnSeek /// /see SoundStream::OnSeek
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void OnSeek(float timeOffset) virtual void OnSeek(sf::Uint32 timeOffset)
{ {
myOffset = static_cast<std::size_t>(timeOffset * GetSampleRate() * GetChannelsCount()); myOffset = timeOffset * GetSampleRate() * GetChannelsCount() / 1000;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -179,7 +179,7 @@ void DoServer(unsigned short port)
while (audioStream.GetStatus() != sf::SoundStream::Stopped) while (audioStream.GetStatus() != sf::SoundStream::Stopped)
{ {
// Leave some CPU time for other threads // Leave some CPU time for other threads
sf::Sleep(0.1f); sf::Sleep(100);
} }
std::cin.ignore(10000, '\n'); std::cin.ignore(10000, '\n');
@ -195,6 +195,6 @@ void DoServer(unsigned short port)
while (audioStream.GetStatus() != sf::SoundStream::Stopped) while (audioStream.GetStatus() != sf::SoundStream::Stopped)
{ {
// Leave some CPU time for other threads // Leave some CPU time for other threads
sf::Sleep(0.1f); sf::Sleep(100);
} }
} }

View File

@ -105,11 +105,11 @@ INT WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT)
SFMLView2.Clear(); SFMLView2.Clear();
// Draw sprite 1 on view 1 // Draw sprite 1 on view 1
sprite1.SetRotation(clock.GetElapsedTime() * 100); sprite1.SetRotation(clock.GetElapsedTime() * 0.1f);
SFMLView1.Draw(sprite1); SFMLView1.Draw(sprite1);
// Draw sprite 2 on view 2 // Draw sprite 2 on view 2
sprite2.SetX(cos(clock.GetElapsedTime()) * 100); sprite2.SetX(cos(clock.GetElapsedTime() * 0.001f) * 100.f);
SFMLView2.Draw(sprite2); SFMLView2.Draw(sprite2);
// Display each view on screen // Display each view on screen

View File

@ -65,9 +65,9 @@ int main()
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f); glTranslatef(0.f, 0.f, -200.f);
glRotatef(clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f); glRotatef(clock.GetElapsedTime() * 0.05f, 1.f, 0.f, 0.f);
glRotatef(clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f); glRotatef(clock.GetElapsedTime() * 0.03f, 0.f, 1.f, 0.f);
glRotatef(clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f); glRotatef(clock.GetElapsedTime() * 0.09f, 0.f, 0.f, 1.f);
// Draw a cube // Draw a cube
glBegin(GL_QUADS); glBegin(GL_QUADS);

View File

@ -101,10 +101,10 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the total duration of the music /// \brief Get the total duration of the music
/// ///
/// \return Music duration, in seconds /// \return Music duration, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float GetDuration() const; Uint32 GetDuration() const;
protected : protected :
@ -124,10 +124,10 @@ protected :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the current playing position in the stream source /// \brief Change the current playing position in the stream source
/// ///
/// \param timeOffset New playing position, in seconds /// \param timeOffset New playing position, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void OnSeek(float timeOffset); virtual void OnSeek(Uint32 timeOffset);
private : private :
@ -135,7 +135,7 @@ private :
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::SoundFile* myFile; ///< Sound file priv::SoundFile* myFile; ///< Sound file
float myDuration; ///< Music duration, in seconds Uint32 myDuration; ///< Music duration, in milliseconds
std::vector<Int16> mySamples; ///< Temporary buffer of samples std::vector<Int16> mySamples; ///< Temporary buffer of samples
Mutex myMutex; ///< Mutex protecting the data Mutex myMutex; ///< Mutex protecting the data
}; };

View File

@ -149,12 +149,12 @@ public :
/// The playing position can be changed when the sound is /// The playing position can be changed when the sound is
/// either paused or playing. /// either paused or playing.
/// ///
/// \param timeOffset New playing position, in seconds /// \param timeOffset New playing position, in milliseconds
/// ///
/// \see GetPlayingOffset /// \see GetPlayingOffset
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetPlayingOffset(float timeOffset); void SetPlayingOffset(Uint32 timeOffset);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the audio buffer attached to the sound /// \brief Get the audio buffer attached to the sound
@ -177,12 +177,12 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the current playing position of the sound /// \brief Get the current playing position of the sound
/// ///
/// \return Current playing position, in seconds /// \return Current playing position, in milliseconds
/// ///
/// \see SetPlayingOffset /// \see SetPlayingOffset
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float GetPlayingOffset() const; Uint32 GetPlayingOffset() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the current status of the sound (stopped, paused, playing) /// \brief Get the current status of the sound (stopped, paused, playing)

View File

@ -191,12 +191,12 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the total duration of the sound /// \brief Get the total duration of the sound
/// ///
/// \return Sound duration, in seconds /// \return Sound duration, in milliseconds
/// ///
/// \see GetSampleRate, GetChannelsCount /// \see GetSampleRate, GetChannelsCount
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float GetDuration() const; Uint32 GetDuration() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Overload of assignment operator /// \brief Overload of assignment operator
@ -249,7 +249,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int myBuffer; ///< OpenAL buffer identifier unsigned int myBuffer; ///< OpenAL buffer identifier
std::vector<Int16> mySamples; ///< Samples buffer std::vector<Int16> mySamples; ///< Samples buffer
float myDuration; ///< Sound duration, in seconds Uint32 myDuration; ///< Sound duration, in milliseconds
mutable SoundList mySounds; ///< List of sounds that are using this buffer mutable SoundList mySounds; ///< List of sounds that are using this buffer
}; };

View File

@ -131,22 +131,22 @@ public :
/// The playing position can be changed when the stream is /// The playing position can be changed when the stream is
/// either paused or playing. /// either paused or playing.
/// ///
/// \param timeOffset New playing position, in seconds /// \param timeOffset New playing position, in milliseconds
/// ///
/// \see GetPlayingOffset /// \see GetPlayingOffset
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetPlayingOffset(float timeOffset); void SetPlayingOffset(Uint32 timeOffset);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the current playing position of the stream /// \brief Get the current playing position of the stream
/// ///
/// \return Current playing position, in seconds /// \return Current playing position, in milliseconds
/// ///
/// \see SetPlayingOffset /// \see SetPlayingOffset
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float GetPlayingOffset() const; Uint32 GetPlayingOffset() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set whether or not the stream should loop after reaching the end /// \brief Set whether or not the stream should loop after reaching the end
@ -232,10 +232,10 @@ private :
/// This function must be overriden by derived classes to /// This function must be overriden by derived classes to
/// allow random seeking into the stream source. /// allow random seeking into the stream source.
/// ///
/// \param timeOffset New playing position, in seconds /// \param timeOffset New playing position, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void OnSeek(float timeOffset) = 0; virtual void OnSeek(Uint32 timeOffset) = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Fill a new buffer with audio samples, and append /// \brief Fill a new buffer with audio samples, and append
@ -357,7 +357,7 @@ private :
/// return true; /// return true;
/// } /// }
/// ///
/// virtual void OnSeek(float timeOffset) /// virtual void OnSeek(Uint32 timeOffset)
/// { /// {
/// // Change the current position in the stream source /// // Change the current position in the stream source
/// ... /// ...

View File

@ -134,44 +134,31 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Define portable fixed-size types // Define portable fixed-size types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <climits>
namespace sf namespace sf
{ {
// All "common" platforms use the same size for char, short and int
// (basically there are 3 types for 3 sizes, so no other match is possible),
// we can use them without doing any kind of check
// 8 bits integer types // 8 bits integer types
#if UCHAR_MAX == 0xFF typedef signed char Int8;
typedef signed char Int8; typedef unsigned char Uint8;
typedef unsigned char Uint8;
#else
#error No 8 bits integer type for this platform
#endif
// 16 bits integer types // 16 bits integer types
#if USHRT_MAX == 0xFFFF typedef signed short Int16;
typedef signed short Int16; typedef unsigned short Uint16;
typedef unsigned short Uint16;
#elif UINT_MAX == 0xFFFF
typedef signed int Int16;
typedef unsigned int Uint16;
#elif ULONG_MAX == 0xFFFF
typedef signed long Int16;
typedef unsigned long Uint16;
#else
#error No 16 bits integer type for this platform
#endif
// 32 bits integer types // 32 bits integer types
#if USHRT_MAX == 0xFFFFFFFF typedef signed int Int32;
typedef signed short Int32; typedef unsigned int Uint32;
typedef unsigned short Uint32;
#elif UINT_MAX == 0xFFFFFFFF // 64 bits integer types
typedef signed int Int32; #if defined(_MSC_VER)
typedef unsigned int Uint32; typedef signed __int64 Int64;
#elif ULONG_MAX == 0xFFFFFFFF typedef unsigned __int64 Uint64;
typedef signed long Int32;
typedef unsigned long Uint32;
#else #else
#error No 32 bits integer type for this platform typedef signed long long Int64;
typedef unsigned long long Uint64;
#endif #endif
} // namespace sf } // namespace sf

View File

@ -269,14 +269,14 @@ public :
/// ///
/// \param server Name or address of the FTP server to connect to /// \param server Name or address of the FTP server to connect to
/// \param port Port used for the connection /// \param port Port used for the connection
/// \param timeout Maximum time to wait, in seconds /// \param timeout Maximum time to wait, in milliseconds
/// ///
/// \return Server response to the request /// \return Server response to the request
/// ///
/// \see Disconnect /// \see Disconnect
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Response Connect(const IpAddress& server, unsigned short port = 21, float timeout = 0.f); Response Connect(const IpAddress& server, unsigned short port = 21, Uint32 timeout = 0);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Close the connection with the server /// \brief Close the connection with the server

View File

@ -381,12 +381,12 @@ public :
/// (which is usually pretty long). /// (which is usually pretty long).
/// ///
/// \param request Request to send /// \param request Request to send
/// \param timeout Maximum time to wait, in seconds /// \param timeout Maximum time to wait, in milliseconds
/// ///
/// \return Server's response /// \return Server's response
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Response SendRequest(const Request& request, float timeout = 0.f); Response SendRequest(const Request& request, Uint32 timeout = 0);
private : private :

View File

@ -168,14 +168,14 @@ public :
/// to be possibly stuck waiting in case there is a problem; this /// to be possibly stuck waiting in case there is a problem; this
/// limit is deactivated by default. /// limit is deactivated by default.
/// ///
/// \param timeout Maximum time to wait, in seconds /// \param timeout Maximum time to wait, in milliseconds
/// ///
/// \return Public IP address of the computer /// \return Public IP address of the computer
/// ///
/// \see GetLocalAddress /// \see GetLocalAddress
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static IpAddress GetPublicAddress(float timeout = 0.f); static IpAddress GetPublicAddress(Uint32 timeout = 0);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Static member data // Static member data

View File

@ -111,14 +111,14 @@ public :
/// If you use a timeout and no socket is ready before the timeout /// If you use a timeout and no socket is ready before the timeout
/// is over, the function returns false. /// is over, the function returns false.
/// ///
/// \param timeout Maximum time to wait (use 0 for infinity) /// \param timeout Maximum time to wait, in milliseconds (use 0 for infinity)
/// ///
/// \return True if there are sockets ready, false otherwise /// \return True if there are sockets ready, false otherwise
/// ///
/// \see IsReady /// \see IsReady
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Wait(float timeout = 0.f); bool Wait(Uint32 timeout = 0);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Test a socket to know if it is ready to receive data /// \brief Test a socket to know if it is ready to receive data

View File

@ -99,14 +99,14 @@ public :
/// ///
/// \param remoteAddress Address of the remote peer /// \param remoteAddress Address of the remote peer
/// \param remotePort Port of the remote peer /// \param remotePort Port of the remote peer
/// \param timeout Optional maximum time to wait, in seconds /// \param timeout Optional maximum time to wait, in milliseconds
/// ///
/// \return Status code /// \return Status code
/// ///
/// \see Disconnect /// \see Disconnect
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Status Connect(const IpAddress& remoteAddress, unsigned short remotePort, float timeout = 0.f); Status Connect(const IpAddress& remoteAddress, unsigned short remotePort, Uint32 timeout = 0);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Disconnect the connect from its remote peer /// \brief Disconnect the connect from its remote peer

View File

@ -54,12 +54,12 @@ public :
/// ///
/// This function returns the time elapsed since the last call /// This function returns the time elapsed since the last call
/// to Reset() (or the construction of the instance if Reset() /// to Reset() (or the construction of the instance if Reset()
/// has not been called) in seconds. /// has not been called).
/// ///
/// \return Time elapsed, in seconds /// \return Time elapsed, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float GetElapsedTime() const; Uint32 GetElapsedTime() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Restart the timer /// \brief Restart the timer
@ -74,7 +74,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
double myStartTime; ///< Time of last reset Uint64 myStartTime; ///< Time of last reset
}; };
} // namespace sf } // namespace sf
@ -95,10 +95,10 @@ private :
/// \code /// \code
/// sf::Clock clock; /// sf::Clock clock;
/// ... /// ...
/// float time1 = clock.GetElapsedTime(); /// Uint32 time1 = clock.GetElapsedTime();
/// clock.Reset(); /// clock.Reset();
/// ... /// ...
/// float time2 = clock.GetElapsedTime(); /// Uint32 time2 = clock.GetElapsedTime();
/// \endcode /// \endcode
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -35,15 +35,15 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \ingroup system /// \ingroup system
/// \brief Make the current thread sleep for a given time /// \brief Make the current thread sleep for a given duration
/// ///
/// sf::Sleep is the best way to block a program or one of its /// sf::Sleep is the best way to block a program or one of its
/// threads, as it doesn't consume any CPU power. /// threads, as it doesn't consume any CPU power.
/// ///
/// \param duration Time to sleep, in seconds (must be positive) /// \param duration Time to sleep, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SFML_API Sleep(float duration); void SFML_API Sleep(Uint32 duration);
} // namespace sf } // namespace sf

View File

@ -188,7 +188,7 @@ private :
/// const sf::Input& input = window.GetInput(); /// const sf::Input& input = window.GetInput();
/// ///
/// // Move an entity according to the current keys state /// // Move an entity according to the current keys state
/// float offset = 5 * window.GetFrameTime(); // 5 pixels/sec /// float offset = 5.f * window.GetFrameTime(); // 5 pixels/sec
/// if (input.IsKeyDown(sf::Key::Left)) entity.Move(-offset, 0); /// if (input.IsKeyDown(sf::Key::Left)) entity.Move(-offset, 0);
/// if (input.IsKeyDown(sf::Key::Right)) entity.Move( offset, 0); /// if (input.IsKeyDown(sf::Key::Right)) entity.Move( offset, 0);
/// if (input.IsKeyDown(sf::Key::Up)) entity.Move(0, -offset); /// if (input.IsKeyDown(sf::Key::Up)) entity.Move(0, -offset);

View File

@ -415,10 +415,10 @@ public :
/// This can be useful for calculating the framerate, or for /// This can be useful for calculating the framerate, or for
/// updating the application's objects. /// updating the application's objects.
/// ///
/// \return Time elapsed in last frame, in seconds /// \return Time elapsed in last frame, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float GetFrameTime() const; Uint32 GetFrameTime() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the joystick threshold /// \brief Change the joystick threshold
@ -495,7 +495,7 @@ private :
priv::GlContext* myContext; ///< Platform-specific implementation of the OpenGL context priv::GlContext* myContext; ///< Platform-specific implementation of the OpenGL context
Input myInput; ///< Input manager connected to window Input myInput; ///< Input manager connected to window
Clock myClock; ///< Clock for measuring the elapsed time between frames Clock myClock; ///< Clock for measuring the elapsed time between frames
float myLastFrameTime; ///< Time elapsed since last frame Uint32 myLastFrameTime; ///< Time elapsed since last frame
unsigned int myFramerateLimit; ///< Current framerate limit unsigned int myFramerateLimit; ///< Current framerate limit
int mySetCursorPosX; ///< X coordinate passed to the last call to SetCursorPosition int mySetCursorPosX; ///< X coordinate passed to the last call to SetCursorPosition
int mySetCursorPosY; ///< Y coordinate passed to the last call to SetCursorPosition int mySetCursorPosY; ///< Y coordinate passed to the last call to SetCursorPosition

View File

@ -38,7 +38,7 @@ namespace sf
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Music::Music() : Music::Music() :
myFile (new priv::SoundFile), myFile (new priv::SoundFile),
myDuration(0.f) myDuration(0)
{ {
} }
@ -68,7 +68,7 @@ bool Music::OpenFromFile(const std::string& filename)
} }
// Compute the duration // Compute the duration
myDuration = static_cast<float>(myFile->GetSamplesCount()) / myFile->GetSampleRate() / myFile->GetChannelsCount(); myDuration = static_cast<Uint32>(1000 * myFile->GetSamplesCount() / myFile->GetSampleRate() / myFile->GetChannelsCount());
// Resize the internal buffer so that it can contain 1 second of audio samples // Resize the internal buffer so that it can contain 1 second of audio samples
mySamples.resize(myFile->GetSampleRate() * myFile->GetChannelsCount()); mySamples.resize(myFile->GetSampleRate() * myFile->GetChannelsCount());
@ -94,7 +94,7 @@ bool Music::OpenFromMemory(const void* data, std::size_t sizeInBytes)
} }
// Compute the duration // Compute the duration
myDuration = static_cast<float>(myFile->GetSamplesCount()) / myFile->GetSampleRate() / myFile->GetChannelsCount(); myDuration = static_cast<Uint32>(1000 * myFile->GetSamplesCount() / myFile->GetSampleRate() / myFile->GetChannelsCount());
// Resize the internal buffer so that it can contain 1 second of audio samples // Resize the internal buffer so that it can contain 1 second of audio samples
mySamples.resize(myFile->GetSampleRate() * myFile->GetChannelsCount()); mySamples.resize(myFile->GetSampleRate() * myFile->GetChannelsCount());
@ -107,7 +107,7 @@ bool Music::OpenFromMemory(const void* data, std::size_t sizeInBytes)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float Music::GetDuration() const Uint32 Music::GetDuration() const
{ {
return myDuration; return myDuration;
} }
@ -130,7 +130,7 @@ bool Music::OnGetData(SoundStream::Chunk& data)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// /see SoundStream::OnSeek /// /see SoundStream::OnSeek
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Music::OnSeek(float timeOffset) void Music::OnSeek(Uint32 timeOffset)
{ {
Lock lock(myMutex); Lock lock(myMutex);

View File

@ -116,9 +116,9 @@ void Sound::SetLoop(bool Loop)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sound::SetPlayingOffset(float timeOffset) void Sound::SetPlayingOffset(Uint32 timeOffset)
{ {
ALCheck(alSourcef(mySource, AL_SEC_OFFSET, timeOffset)); ALCheck(alSourcef(mySource, AL_SEC_OFFSET, timeOffset / 1000.f));
} }
@ -140,12 +140,12 @@ bool Sound::GetLoop() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float Sound::GetPlayingOffset() const Uint32 Sound::GetPlayingOffset() const
{ {
ALfloat seconds = 0.f; ALfloat seconds = 0.f;
ALCheck(alGetSourcef(mySource, AL_SEC_OFFSET, &seconds)); ALCheck(alGetSourcef(mySource, AL_SEC_OFFSET, &seconds));
return seconds; return static_cast<Uint32>(seconds * 1000);
} }

View File

@ -39,7 +39,7 @@ namespace sf
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundBuffer::SoundBuffer() : SoundBuffer::SoundBuffer() :
myBuffer (0), myBuffer (0),
myDuration(0.f) myDuration(0)
{ {
priv::EnsureALInit(); priv::EnsureALInit();
@ -219,7 +219,7 @@ unsigned int SoundBuffer::GetChannelsCount() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float SoundBuffer::GetDuration() const Uint32 SoundBuffer::GetDuration() const
{ {
return myDuration; return myDuration;
} }
@ -261,7 +261,7 @@ bool SoundBuffer::Update(unsigned int channelsCount, unsigned int sampleRate)
ALCheck(alBufferData(myBuffer, format, &mySamples[0], size, sampleRate)); ALCheck(alBufferData(myBuffer, format, &mySamples[0], size, sampleRate));
// Compute the duration // Compute the duration
myDuration = static_cast<float>(mySamples.size()) / sampleRate / channelsCount; myDuration = static_cast<Uint32>(1000 * mySamples.size() / sampleRate / channelsCount);
return true; return true;
} }

View File

@ -195,11 +195,11 @@ void SoundFile::Write(const Int16* data, std::size_t nbSamples)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundFile::Seek(float timeOffset) void SoundFile::Seek(Uint32 timeOffset)
{ {
if (myFile) if (myFile)
{ {
sf_count_t frameOffset = static_cast<sf_count_t>(timeOffset * mySampleRate); sf_count_t frameOffset = timeOffset * mySampleRate / 1000;
sf_seek(myFile, frameOffset, SEEK_SET); sf_seek(myFile, frameOffset, SEEK_SET);
} }
} }

View File

@ -137,10 +137,10 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the current read position in the file /// \brief Change the current read position in the file
/// ///
/// \param timeOffset New read position, in seconds /// \param timeOffset New read position, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Seek(float timeOffset); void Seek(Uint32 timeOffset);
private : private :

View File

@ -155,7 +155,7 @@ void SoundRecorder::Record()
ProcessCapturedSamples(); ProcessCapturedSamples();
// Don't bother the CPU while waiting for more captured data // Don't bother the CPU while waiting for more captured data
Sleep(0.1f); Sleep(100);
} }
// Capture is finished : clean up everything // Capture is finished : clean up everything

View File

@ -150,7 +150,7 @@ SoundStream::Status SoundStream::GetStatus() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundStream::SetPlayingOffset(float timeOffset) void SoundStream::SetPlayingOffset(Uint32 timeOffset)
{ {
// Stop the stream // Stop the stream
Stop(); Stop();
@ -159,19 +159,19 @@ void SoundStream::SetPlayingOffset(float timeOffset)
OnSeek(timeOffset); OnSeek(timeOffset);
// Restart streaming // Restart streaming
mySamplesProcessed = static_cast<unsigned int>(timeOffset * mySampleRate * myChannelsCount); mySamplesProcessed = timeOffset * mySampleRate * myChannelsCount / 1000;
myIsStreaming = true; myIsStreaming = true;
myThread.Launch(); myThread.Launch();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float SoundStream::GetPlayingOffset() const Uint32 SoundStream::GetPlayingOffset() const
{ {
ALfloat seconds = 0.f; ALfloat seconds = 0.f;
ALCheck(alGetSourcef(mySource, AL_SEC_OFFSET, &seconds)); ALCheck(alGetSourcef(mySource, AL_SEC_OFFSET, &seconds));
return seconds + static_cast<float>(mySamplesProcessed) / mySampleRate / myChannelsCount; return static_cast<Uint32>(1000 * seconds) + 1000 * mySamplesProcessed / mySampleRate / myChannelsCount;
} }
@ -264,7 +264,7 @@ void SoundStream::Stream()
// Leave some time for the other threads if the stream is still playing // Leave some time for the other threads if the stream is still playing
if (SoundSource::GetStatus() != Stopped) if (SoundSource::GetStatus() != Stopped)
Sleep(0.01f); Sleep(10);
} }
// Stop the playback // Stop the playback

View File

@ -146,7 +146,7 @@ Ftp::~Ftp()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Ftp::Response Ftp::Connect(const IpAddress& server, unsigned short port, float timeout) Ftp::Response Ftp::Connect(const IpAddress& server, unsigned short port, Uint32 timeout)
{ {
// Connect to the server // Connect to the server
if (myCommandSocket.Connect(server, port, timeout) != Socket::Done) if (myCommandSocket.Connect(server, port, timeout) != Socket::Done)

View File

@ -310,7 +310,7 @@ void Http::SetHost(const std::string& host, unsigned short port)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Http::Response Http::SendRequest(const Http::Request& request, float timeout) Http::Response Http::SendRequest(const Http::Request& request, Uint32 timeout)
{ {
// First make sure that the request is valid -- add missing mandatory fields // First make sure that the request is valid -- add missing mandatory fields
Request toSend(request); Request toSend(request);

View File

@ -165,7 +165,7 @@ IpAddress IpAddress::GetLocalAddress()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
IpAddress IpAddress::GetPublicAddress(float timeout) IpAddress IpAddress::GetPublicAddress(Uint32 timeout)
{ {
// The trick here is more complicated, because the only way // The trick here is more complicated, because the only way
// to get our public IP address is to get it from a distant computer. // to get our public IP address is to get it from a distant computer.

View File

@ -100,18 +100,18 @@ void SocketSelector::Clear()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool SocketSelector::Wait(float timeout) bool SocketSelector::Wait(Uint32 timeout)
{ {
// Setup the timeout // Setup the timeout
timeval time; timeval time;
time.tv_sec = static_cast<long>(timeout); time.tv_sec = timeout / 1000;
time.tv_usec = (static_cast<long>(timeout * 1000) % 1000) * 1000; time.tv_usec = (timeout - time.tv_sec * 1000) * 1000;
// Initialize the set that will contain the sockets that are ready // Initialize the set that will contain the sockets that are ready
myImpl->SocketsReady = myImpl->AllSockets; myImpl->SocketsReady = myImpl->AllSockets;
// Wait until one of the sockets is ready for reading, or timeout is reached // Wait until one of the sockets is ready for reading, or timeout is reached
int count = select(myImpl->MaxSocket + 1, &myImpl->SocketsReady, NULL, NULL, timeout > 0 ? &time : NULL); int count = select(myImpl->MaxSocket + 1, &myImpl->SocketsReady, NULL, NULL, timeout != 0 ? &time : NULL);
return count > 0; return count > 0;
} }

View File

@ -106,7 +106,7 @@ unsigned short TcpSocket::GetRemotePort() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short remotePort, float timeout) Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short remotePort, Uint32 timeout)
{ {
// Create the internal socket if it doesn't exist // Create the internal socket if it doesn't exist
Create(); Create();
@ -114,7 +114,7 @@ Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short
// Create the remote address // Create the remote address
sockaddr_in address = priv::SocketImpl::CreateAddress(remoteAddress.ToInteger(), remotePort); sockaddr_in address = priv::SocketImpl::CreateAddress(remoteAddress.ToInteger(), remotePort);
if (timeout <= 0) if (timeout == 0)
{ {
// ----- We're not using a timeout: just try to connect ----- // ----- We're not using a timeout: just try to connect -----
@ -160,8 +160,8 @@ Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short
// Setup the timeout // Setup the timeout
timeval time; timeval time;
time.tv_sec = static_cast<long>(timeout); time.tv_sec = timeout / 1000;
time.tv_usec = (static_cast<long>(timeout * 1000) % 1000) * 1000; time.tv_usec = (timeout - time.tv_sec * 1000) * 1000;
// Wait for something to write on our socket (which means that the connection request has returned) // Wait for something to write on our socket (which means that the connection request has returned)
if (select(static_cast<int>(GetHandle() + 1), NULL, &selector, NULL, &time) > 0) if (select(static_cast<int>(GetHandle() + 1), NULL, &selector, NULL, &time) > 0)

View File

@ -39,9 +39,9 @@ Clock::Clock()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float Clock::GetElapsedTime() const Uint32 Clock::GetElapsedTime() const
{ {
return static_cast<float>(priv::Platform::GetSystemTime() - myStartTime); return static_cast<Uint32>(priv::Platform::GetSystemTime() - myStartTime);
} }

View File

@ -32,10 +32,9 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Sleep(float duration) void Sleep(Uint32 duration)
{ {
if (duration >= 0) priv::Platform::Sleep(duration);
priv::Platform::Sleep(duration);
} }
} // namespace sf } // namespace sf

View File

@ -35,19 +35,19 @@ namespace sf
namespace priv namespace priv
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
double Platform::GetSystemTime() Uint64 Platform::GetSystemTime()
{ {
timeval time = {0, 0}; timeval time = {0, 0};
gettimeofday(&time, NULL); gettimeofday(&time, NULL);
return time.tv_sec + time.tv_usec / 1000000.; return time.tv_sec * 1000 + time.tv_usec / 1000;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Platform::Sleep(float time) void Platform::Sleep(Uint32 time)
{ {
usleep(static_cast<unsigned long>(time * 1000000)); usleep(time * 1000);
} }
} // namespace priv } // namespace priv

View File

@ -29,7 +29,6 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Config.hpp> #include <SFML/Config.hpp>
#include <vector>
namespace sf namespace sf
@ -38,6 +37,7 @@ namespace priv
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Give access to some system-specific low-level functions /// \brief Give access to some system-specific low-level functions
///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class Platform class Platform
{ {
@ -46,18 +46,18 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the current system time /// \brief Get the current system time
/// ///
/// \return System time, in seconds /// \return System time, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static double GetSystemTime(); static Uint64 GetSystemTime();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Suspend the execution of the current thread for a specified time /// \brief Suspend the execution of the current thread for a specified duration
/// ///
/// \param time Time to sleep, in seconds /// \param time Time to sleep, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static void Sleep(float time); static void Sleep(Uint32 time);
}; };
} // namespace priv } // namespace priv

View File

@ -34,7 +34,7 @@ namespace sf
namespace priv namespace priv
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
double Platform::GetSystemTime() Uint64 Platform::GetSystemTime()
{ {
static LARGE_INTEGER frequency; static LARGE_INTEGER frequency;
static BOOL useHighPerformanceTimer = QueryPerformanceFrequency(&frequency); static BOOL useHighPerformanceTimer = QueryPerformanceFrequency(&frequency);
@ -45,20 +45,20 @@ double Platform::GetSystemTime()
LARGE_INTEGER currentTime; LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime); QueryPerformanceCounter(&currentTime);
return static_cast<double>(currentTime.QuadPart) / frequency.QuadPart; return currentTime.QuadPart * 1000 / frequency.QuadPart;
} }
else else
{ {
// High performance counter not available: use GetTickCount (less accurate) // High performance counter not available: use GetTickCount (less accurate)
return GetTickCount() * 0.001; return GetTickCount();
} }
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Platform::Sleep(float time) void Platform::Sleep(Uint32 time)
{ {
::Sleep(static_cast<DWORD>(time * 1000)); ::Sleep(time);
} }
} // namespace priv } // namespace priv

View File

@ -47,18 +47,18 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the current system time /// \brief Get the current system time
/// ///
/// \return System time, in seconds /// \return System time, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static double GetSystemTime(); static Uint64 GetSystemTime();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Suspend the execution of the current thread for a specified time /// \brief Suspend the execution of the current thread for a specified duration
/// ///
/// \param time Time to sleep, in seconds /// \param time Time to sleep, in milliseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static void Sleep(float time); static void Sleep(Uint32 time);
}; };
} // namespace priv } // namespace priv

View File

@ -47,7 +47,7 @@ namespace sf
Window::Window() : Window::Window() :
myWindow (NULL), myWindow (NULL),
myContext (NULL), myContext (NULL),
myLastFrameTime (0.f), myLastFrameTime (0),
myFramerateLimit(0), myFramerateLimit(0),
mySetCursorPosX (0xFFFF), mySetCursorPosX (0xFFFF),
mySetCursorPosY (0xFFFF) mySetCursorPosY (0xFFFF)
@ -60,7 +60,7 @@ mySetCursorPosY (0xFFFF)
Window::Window(VideoMode mode, const std::string& title, unsigned long style, const ContextSettings& settings) : Window::Window(VideoMode mode, const std::string& title, unsigned long style, const ContextSettings& settings) :
myWindow (NULL), myWindow (NULL),
myContext (NULL), myContext (NULL),
myLastFrameTime (0.f), myLastFrameTime (0),
myFramerateLimit(0), myFramerateLimit(0),
mySetCursorPosX (0xFFFF), mySetCursorPosX (0xFFFF),
mySetCursorPosY (0xFFFF) mySetCursorPosY (0xFFFF)
@ -73,7 +73,7 @@ mySetCursorPosY (0xFFFF)
Window::Window(WindowHandle handle, const ContextSettings& settings) : Window::Window(WindowHandle handle, const ContextSettings& settings) :
myWindow (NULL), myWindow (NULL),
myContext (NULL), myContext (NULL),
myLastFrameTime (0.f), myLastFrameTime (0),
myFramerateLimit(0), myFramerateLimit(0),
mySetCursorPosX (0xFFFF), mySetCursorPosX (0xFFFF),
mySetCursorPosY (0xFFFF) mySetCursorPosY (0xFFFF)
@ -337,7 +337,7 @@ void Window::Display()
// Limit the framerate if needed // Limit the framerate if needed
if (myFramerateLimit > 0) if (myFramerateLimit > 0)
{ {
float remainingTime = 1.f / myFramerateLimit - myClock.GetElapsedTime(); Int32 remainingTime = 1000 / myFramerateLimit - myClock.GetElapsedTime();
if (remainingTime > 0) if (remainingTime > 0)
Sleep(remainingTime); Sleep(remainingTime);
} }
@ -367,7 +367,7 @@ void Window::SetFramerateLimit(unsigned int limit)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float Window::GetFrameTime() const Uint32 Window::GetFrameTime() const
{ {
return myLastFrameTime; return myLastFrameTime;
} }
@ -437,7 +437,7 @@ void Window::Initialize()
// Reset frame time // Reset frame time
myClock.Reset(); myClock.Reset();
myLastFrameTime = 0.f; myLastFrameTime = 0;
// Activate the window // Activate the window
SetActive(); SetActive();