Times in SFML are now Uint32 milliseconds instead of float seconds
Added the sf::Uint64 and sf::Int64 types
This commit is contained in:
parent
c1ce16f4d6
commit
e4c6c30e0b
83 changed files with 250 additions and 262 deletions
|
@ -38,7 +38,7 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
Music::Music() :
|
||||
myFile (new priv::SoundFile),
|
||||
myDuration(0.f)
|
||||
myDuration(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ bool Music::OpenFromFile(const std::string& filename)
|
|||
}
|
||||
|
||||
// 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
|
||||
mySamples.resize(myFile->GetSampleRate() * myFile->GetChannelsCount());
|
||||
|
@ -94,7 +94,7 @@ bool Music::OpenFromMemory(const void* data, std::size_t sizeInBytes)
|
|||
}
|
||||
|
||||
// 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
|
||||
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;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ bool Music::OnGetData(SoundStream::Chunk& data)
|
|||
////////////////////////////////////////////////////////////
|
||||
/// /see SoundStream::OnSeek
|
||||
////////////////////////////////////////////////////////////
|
||||
void Music::OnSeek(float timeOffset)
|
||||
void Music::OnSeek(Uint32 timeOffset)
|
||||
{
|
||||
Lock lock(myMutex);
|
||||
|
||||
|
|
|
@ -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;
|
||||
ALCheck(alGetSourcef(mySource, AL_SEC_OFFSET, &seconds));
|
||||
|
||||
return seconds;
|
||||
return static_cast<Uint32>(seconds * 1000);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace sf
|
|||
////////////////////////////////////////////////////////////
|
||||
SoundBuffer::SoundBuffer() :
|
||||
myBuffer (0),
|
||||
myDuration(0.f)
|
||||
myDuration(0)
|
||||
{
|
||||
priv::EnsureALInit();
|
||||
|
||||
|
@ -219,7 +219,7 @@ unsigned int SoundBuffer::GetChannelsCount() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float SoundBuffer::GetDuration() const
|
||||
Uint32 SoundBuffer::GetDuration() const
|
||||
{
|
||||
return myDuration;
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ bool SoundBuffer::Update(unsigned int channelsCount, unsigned int sampleRate)
|
|||
ALCheck(alBufferData(myBuffer, format, &mySamples[0], size, sampleRate));
|
||||
|
||||
// Compute the duration
|
||||
myDuration = static_cast<float>(mySamples.size()) / sampleRate / channelsCount;
|
||||
myDuration = static_cast<Uint32>(1000 * mySamples.size() / sampleRate / channelsCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
sf_count_t frameOffset = static_cast<sf_count_t>(timeOffset * mySampleRate);
|
||||
sf_count_t frameOffset = timeOffset * mySampleRate / 1000;
|
||||
sf_seek(myFile, frameOffset, SEEK_SET);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,10 +137,10 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// \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 :
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ void SoundRecorder::Record()
|
|||
ProcessCapturedSamples();
|
||||
|
||||
// Don't bother the CPU while waiting for more captured data
|
||||
Sleep(0.1f);
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
// Capture is finished : clean up everything
|
||||
|
|
|
@ -150,7 +150,7 @@ SoundStream::Status SoundStream::GetStatus() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::SetPlayingOffset(float timeOffset)
|
||||
void SoundStream::SetPlayingOffset(Uint32 timeOffset)
|
||||
{
|
||||
// Stop the stream
|
||||
Stop();
|
||||
|
@ -159,19 +159,19 @@ void SoundStream::SetPlayingOffset(float timeOffset)
|
|||
OnSeek(timeOffset);
|
||||
|
||||
// Restart streaming
|
||||
mySamplesProcessed = static_cast<unsigned int>(timeOffset * mySampleRate * myChannelsCount);
|
||||
mySamplesProcessed = timeOffset * mySampleRate * myChannelsCount / 1000;
|
||||
myIsStreaming = true;
|
||||
myThread.Launch();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float SoundStream::GetPlayingOffset() const
|
||||
Uint32 SoundStream::GetPlayingOffset() const
|
||||
{
|
||||
ALfloat seconds = 0.f;
|
||||
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
|
||||
if (SoundSource::GetStatus() != Stopped)
|
||||
Sleep(0.01f);
|
||||
Sleep(10);
|
||||
}
|
||||
|
||||
// Stop the playback
|
||||
|
|
|
@ -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
|
||||
if (myCommandSocket.Connect(server, port, timeout) != Socket::Done)
|
||||
|
|
|
@ -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
|
||||
Request toSend(request);
|
||||
|
|
|
@ -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
|
||||
// to get our public IP address is to get it from a distant computer.
|
||||
|
|
|
@ -100,18 +100,18 @@ void SocketSelector::Clear()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SocketSelector::Wait(float timeout)
|
||||
bool SocketSelector::Wait(Uint32 timeout)
|
||||
{
|
||||
// Setup the timeout
|
||||
timeval time;
|
||||
time.tv_sec = static_cast<long>(timeout);
|
||||
time.tv_usec = (static_cast<long>(timeout * 1000) % 1000) * 1000;
|
||||
time.tv_sec = timeout / 1000;
|
||||
time.tv_usec = (timeout - time.tv_sec * 1000) * 1000;
|
||||
|
||||
// Initialize the set that will contain the sockets that are ready
|
||||
myImpl->SocketsReady = myImpl->AllSockets;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
@ -114,7 +114,7 @@ Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short
|
|||
// Create the remote address
|
||||
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 -----
|
||||
|
||||
|
@ -160,8 +160,8 @@ Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short
|
|||
|
||||
// Setup the timeout
|
||||
timeval time;
|
||||
time.tv_sec = static_cast<long>(timeout);
|
||||
time.tv_usec = (static_cast<long>(timeout * 1000) % 1000) * 1000;
|
||||
time.tv_sec = timeout / 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)
|
||||
if (select(static_cast<int>(GetHandle() + 1), NULL, &selector, NULL, &time) > 0)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,10 +32,9 @@
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sleep(float duration)
|
||||
void Sleep(Uint32 duration)
|
||||
{
|
||||
if (duration >= 0)
|
||||
priv::Platform::Sleep(duration);
|
||||
priv::Platform::Sleep(duration);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -35,19 +35,19 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
double Platform::GetSystemTime()
|
||||
Uint64 Platform::GetSystemTime()
|
||||
{
|
||||
timeval time = {0, 0};
|
||||
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
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -38,6 +37,7 @@ namespace priv
|
|||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Give access to some system-specific low-level functions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class Platform
|
||||
{
|
||||
|
@ -46,18 +46,18 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// \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
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
double Platform::GetSystemTime()
|
||||
Uint64 Platform::GetSystemTime()
|
||||
{
|
||||
static LARGE_INTEGER frequency;
|
||||
static BOOL useHighPerformanceTimer = QueryPerformanceFrequency(&frequency);
|
||||
|
@ -45,20 +45,20 @@ double Platform::GetSystemTime()
|
|||
LARGE_INTEGER currentTime;
|
||||
QueryPerformanceCounter(¤tTime);
|
||||
|
||||
return static_cast<double>(currentTime.QuadPart) / frequency.QuadPart;
|
||||
return currentTime.QuadPart * 1000 / frequency.QuadPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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
|
||||
|
|
|
@ -47,18 +47,18 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// \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
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace sf
|
|||
Window::Window() :
|
||||
myWindow (NULL),
|
||||
myContext (NULL),
|
||||
myLastFrameTime (0.f),
|
||||
myLastFrameTime (0),
|
||||
myFramerateLimit(0),
|
||||
mySetCursorPosX (0xFFFF),
|
||||
mySetCursorPosY (0xFFFF)
|
||||
|
@ -60,7 +60,7 @@ mySetCursorPosY (0xFFFF)
|
|||
Window::Window(VideoMode mode, const std::string& title, unsigned long style, const ContextSettings& settings) :
|
||||
myWindow (NULL),
|
||||
myContext (NULL),
|
||||
myLastFrameTime (0.f),
|
||||
myLastFrameTime (0),
|
||||
myFramerateLimit(0),
|
||||
mySetCursorPosX (0xFFFF),
|
||||
mySetCursorPosY (0xFFFF)
|
||||
|
@ -73,7 +73,7 @@ mySetCursorPosY (0xFFFF)
|
|||
Window::Window(WindowHandle handle, const ContextSettings& settings) :
|
||||
myWindow (NULL),
|
||||
myContext (NULL),
|
||||
myLastFrameTime (0.f),
|
||||
myLastFrameTime (0),
|
||||
myFramerateLimit(0),
|
||||
mySetCursorPosX (0xFFFF),
|
||||
mySetCursorPosY (0xFFFF)
|
||||
|
@ -337,7 +337,7 @@ void Window::Display()
|
|||
// Limit the framerate if needed
|
||||
if (myFramerateLimit > 0)
|
||||
{
|
||||
float remainingTime = 1.f / myFramerateLimit - myClock.GetElapsedTime();
|
||||
Int32 remainingTime = 1000 / myFramerateLimit - myClock.GetElapsedTime();
|
||||
if (remainingTime > 0)
|
||||
Sleep(remainingTime);
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ void Window::SetFramerateLimit(unsigned int limit)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Window::GetFrameTime() const
|
||||
Uint32 Window::GetFrameTime() const
|
||||
{
|
||||
return myLastFrameTime;
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ void Window::Initialize()
|
|||
|
||||
// Reset frame time
|
||||
myClock.Reset();
|
||||
myLastFrameTime = 0.f;
|
||||
myLastFrameTime = 0;
|
||||
|
||||
// Activate the window
|
||||
SetActive();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue