From 3e89dd652feb1445a927f9b7c3ea1a36e82c54d9 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Tue, 20 Dec 2011 18:47:33 +0100 Subject: [PATCH] Rewrote the implementation of sf::Clock, it now ensures microseconds resolution and monotonicity --- include/SFML/System/Clock.hpp | 4 +- src/SFML/System/CMakeLists.txt | 13 +- src/SFML/System/Clock.cpp | 12 +- src/SFML/System/Sleep.cpp | 9 +- src/SFML/System/Unix/ClockImpl.cpp | 64 +++++++ .../Platform.hpp => Unix/ClockImpl.hpp} | 129 +++++++------- .../Unix/{Platform.cpp => SleepImpl.cpp} | 159 +++++++++--------- .../Platform.cpp => Unix/SleepImpl.hpp} | 117 ++++++------- src/SFML/System/Win32/ClockImpl.cpp | 74 ++++++++ .../Platform.hpp => Win32/ClockImpl.hpp} | 128 +++++++------- .../{Platform.hpp => Win32/SleepImpl.cpp} | 89 +++++----- src/SFML/System/Win32/SleepImpl.hpp | 51 ++++++ 12 files changed, 505 insertions(+), 344 deletions(-) create mode 100644 src/SFML/System/Unix/ClockImpl.cpp rename src/SFML/System/{Win32/Platform.hpp => Unix/ClockImpl.hpp} (69%) rename src/SFML/System/Unix/{Platform.cpp => SleepImpl.cpp} (82%) rename src/SFML/System/{Win32/Platform.cpp => Unix/SleepImpl.hpp} (66%) create mode 100644 src/SFML/System/Win32/ClockImpl.cpp rename src/SFML/System/{Unix/Platform.hpp => Win32/ClockImpl.hpp} (67%) rename src/SFML/System/{Platform.hpp => Win32/SleepImpl.cpp} (80%) create mode 100644 src/SFML/System/Win32/SleepImpl.hpp diff --git a/include/SFML/System/Clock.hpp b/include/SFML/System/Clock.hpp index 19784ac39..668e800ca 100644 --- a/include/SFML/System/Clock.hpp +++ b/include/SFML/System/Clock.hpp @@ -62,7 +62,7 @@ public : Uint32 GetElapsedTime() const; //////////////////////////////////////////////////////////// - /// \brief Restart the timer + /// \brief Restart the clock /// /// This function puts the time counter back to zero. /// @@ -74,7 +74,7 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Uint64 myStartTime; ///< Time of last reset + Uint64 myStartTime; ///< Time of last reset, in nanoseconds }; } // namespace sf diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index 8cc3a26f8..3083ab30b 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -13,7 +13,6 @@ set(SRC ${SRCROOT}/Mutex.cpp ${INCROOT}/Mutex.hpp ${INCROOT}/NonCopyable.hpp - ${SRCROOT}/Platform.hpp ${SRCROOT}/Sleep.cpp ${INCROOT}/Sleep.hpp ${SRCROOT}/String.cpp @@ -37,10 +36,12 @@ set(SRC if(WINDOWS) set(SRC ${SRC} + ${SRCROOT}/Win32/ClockImpl.cpp + ${SRCROOT}/Win32/ClockImpl.hpp ${SRCROOT}/Win32/MutexImpl.cpp ${SRCROOT}/Win32/MutexImpl.hpp - ${SRCROOT}/Win32/Platform.cpp - ${SRCROOT}/Win32/Platform.hpp + ${SRCROOT}/Win32/SleepImpl.cpp + ${SRCROOT}/Win32/SleepImpl.hpp ${SRCROOT}/Win32/ThreadImpl.cpp ${SRCROOT}/Win32/ThreadImpl.hpp ${SRCROOT}/Win32/ThreadLocalImpl.cpp @@ -49,10 +50,12 @@ if(WINDOWS) else() set(SRC ${SRC} + ${SRCROOT}/Unix/ClockImpl.cpp + ${SRCROOT}/Unix/ClockImpl.hpp ${SRCROOT}/Unix/MutexImpl.cpp ${SRCROOT}/Unix/MutexImpl.hpp - ${SRCROOT}/Unix/Platform.cpp - ${SRCROOT}/Unix/Platform.hpp + ${SRCROOT}/Unix/SleepImpl.cpp + ${SRCROOT}/Unix/SleepImpl.hpp ${SRCROOT}/Unix/ThreadImpl.cpp ${SRCROOT}/Unix/ThreadImpl.hpp ${SRCROOT}/Unix/ThreadLocalImpl.cpp diff --git a/src/SFML/System/Clock.cpp b/src/SFML/System/Clock.cpp index 5a5bf8ca5..5039195bc 100644 --- a/src/SFML/System/Clock.cpp +++ b/src/SFML/System/Clock.cpp @@ -26,7 +26,12 @@ // Headers //////////////////////////////////////////////////////////// #include -#include + +#if defined(SFML_SYSTEM_WINDOWS) + #include +#else + #include +#endif namespace sf @@ -41,14 +46,15 @@ Clock::Clock() //////////////////////////////////////////////////////////// Uint32 Clock::GetElapsedTime() const { - return static_cast(priv::Platform::GetSystemTime() - myStartTime); + Uint64 microseconds = priv::ClockImpl::GetMicroSeconds() - myStartTime; + return static_cast(microseconds / 1000); } //////////////////////////////////////////////////////////// void Clock::Reset() { - myStartTime = priv::Platform::GetSystemTime(); + myStartTime = priv::ClockImpl::GetMicroSeconds(); } } // namespace sf diff --git a/src/SFML/System/Sleep.cpp b/src/SFML/System/Sleep.cpp index 588d629d3..d13780f2e 100644 --- a/src/SFML/System/Sleep.cpp +++ b/src/SFML/System/Sleep.cpp @@ -26,7 +26,12 @@ // Headers //////////////////////////////////////////////////////////// #include -#include + +#if defined(SFML_SYSTEM_WINDOWS) + #include +#else + #include +#endif namespace sf @@ -34,7 +39,7 @@ namespace sf //////////////////////////////////////////////////////////// void Sleep(Uint32 duration) { - priv::Platform::Sleep(duration); + priv::SleepImpl(duration); } } // namespace sf diff --git a/src/SFML/System/Unix/ClockImpl.cpp b/src/SFML/System/Unix/ClockImpl.cpp new file mode 100644 index 000000000..4e1b683b4 --- /dev/null +++ b/src/SFML/System/Unix/ClockImpl.cpp @@ -0,0 +1,64 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#ifdef SFML_SYSTEM_MACOS + #include +#else + #include +#endif + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +Uint64 ClockImpl::GetMicroSeconds() +{ +#ifdef SFML_SYSTEM_MACOS + + // Mac OS X specific implementation (it doesn't support clock_gettime) + static mach_timebase_info_data_t frequency = {0, 0}; + if (frequency.denom == 0) + mach_timebase_info(&frequency); + Uint64 nanoseconds = mach_absolute_time() * frequency.numer / frequency.denom; + return nanoseconds / 1000; + +#else + + // POSIX implementation + timespec time; + clock_gettime(CLOCK_MONOTONIC, &time); + return time.tv_sec * 1000000 + time.tv_nsec / 1000; + +#endif +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Win32/Platform.hpp b/src/SFML/System/Unix/ClockImpl.hpp similarity index 69% rename from src/SFML/System/Win32/Platform.hpp rename to src/SFML/System/Unix/ClockImpl.hpp index 84162b685..5ee3ea91e 100644 --- a/src/SFML/System/Win32/Platform.hpp +++ b/src/SFML/System/Unix/ClockImpl.hpp @@ -1,69 +1,60 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_PLATFORMWIN32_HPP -#define SFML_PLATFORMWIN32_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Gives access to some system-specific low-level functions -/// -//////////////////////////////////////////////////////////// -class Platform -{ -public : - - //////////////////////////////////////////////////////////// - /// \brief Get the current system time - /// - /// \return System time, in milliseconds - /// - //////////////////////////////////////////////////////////// - static Uint64 GetSystemTime(); - - //////////////////////////////////////////////////////////// - /// \brief Suspend the execution of the current thread for a specified duration - /// - /// \param time Time to sleep, in milliseconds - /// - //////////////////////////////////////////////////////////// - static void Sleep(Uint32 time); -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_PLATFORMWIN32_HPP +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_CLOCKIMPLUNIX_HPP +#define SFML_CLOCKIMPLUNIX_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Unix implementaton of sf::Clock +/// +//////////////////////////////////////////////////////////// +class ClockImpl +{ +public : + + //////////////////////////////////////////////////////////// + /// \brief Get the current time + /// + /// \return Current time, in microseconds + /// + //////////////////////////////////////////////////////////// + static Uint64 GetMicroSeconds(); +}; + +} // namespace priv + +} // namespace sf + + +#endif // SFML_CLOCKIMPLUNIX_HPP diff --git a/src/SFML/System/Unix/Platform.cpp b/src/SFML/System/Unix/SleepImpl.cpp similarity index 82% rename from src/SFML/System/Unix/Platform.cpp rename to src/SFML/System/Unix/SleepImpl.cpp index 275c0fde3..f5cbc29ed 100644 --- a/src/SFML/System/Unix/Platform.cpp +++ b/src/SFML/System/Unix/SleepImpl.cpp @@ -1,84 +1,75 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -Uint64 Platform::GetSystemTime() -{ - timeval time = {0, 0}; - gettimeofday(&time, NULL); - - return time.tv_sec * 1000 + time.tv_usec / 1000; -} - - -//////////////////////////////////////////////////////////// -void Platform::Sleep(Uint32 time) -{ - // usleep is not reliable enough (it might block the - // whole process instead of just the current thread) - // so we must use pthread_cond_timedwait instead - // this implementation is inspired from Qt - - // first get the current time - timeval tv; - gettimeofday(&tv, NULL); - - // construct the time limit (current time + time to wait) - timespec ti; - ti.tv_nsec = (tv.tv_usec + (time % 1000) * 1000) * 1000; - ti.tv_sec = tv.tv_sec + (time / 1000) + (ti.tv_nsec / 1000000000); - ti.tv_nsec %= 1000000000; - - // create a mutex and thread condition - pthread_mutex_t mutex; - pthread_mutex_init(&mutex, 0); - pthread_cond_t condition; - pthread_cond_init(&condition, 0); - - // wait... - pthread_mutex_lock(&mutex); - pthread_cond_timedwait(&condition, &mutex, &ti); - pthread_mutex_unlock(&mutex); - - // destroy the mutex and condition - pthread_cond_destroy(&condition); - pthread_mutex_destroy(&mutex); -} - -} // namespace priv - -} // namespace sf +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +void SleepImpl(Uint32 time) +{ + // usleep is not reliable enough (it might block the + // whole process instead of just the current thread) + // so we must use pthread_cond_timedwait instead + + // this implementation is inspired from Qt + + // first get the current time + timeval tv; + gettimeofday(&tv, NULL); + + // construct the time limit (current time + time to wait) + timespec ti; + ti.tv_nsec = (tv.tv_usec + (time % 1000) * 1000) * 1000; + ti.tv_sec = tv.tv_sec + (time / 1000) + (ti.tv_nsec / 1000000000); + ti.tv_nsec %= 1000000000; + + // create a mutex and thread condition + pthread_mutex_t mutex; + pthread_mutex_init(&mutex, 0); + pthread_cond_t condition; + pthread_cond_init(&condition, 0); + + // wait... + pthread_mutex_lock(&mutex); + pthread_cond_timedwait(&condition, &mutex, &ti); + pthread_mutex_unlock(&mutex); + + // destroy the mutex and condition + pthread_cond_destroy(&condition); + pthread_mutex_destroy(&mutex); +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Win32/Platform.cpp b/src/SFML/System/Unix/SleepImpl.hpp similarity index 66% rename from src/SFML/System/Win32/Platform.cpp rename to src/SFML/System/Unix/SleepImpl.hpp index f99671167..e3a5cf781 100644 --- a/src/SFML/System/Win32/Platform.cpp +++ b/src/SFML/System/Unix/SleepImpl.hpp @@ -1,66 +1,51 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -Uint64 Platform::GetSystemTime() -{ - static LARGE_INTEGER frequency; - static BOOL useHighPerformanceTimer = QueryPerformanceFrequency(&frequency); - - if (useHighPerformanceTimer) - { - // High performance counter available : use it - LARGE_INTEGER currentTime; - QueryPerformanceCounter(¤tTime); - - return currentTime.QuadPart * 1000 / frequency.QuadPart; - } - else - { - // High performance counter not available: use GetTickCount (less accurate) - return GetTickCount(); - } -} - - -//////////////////////////////////////////////////////////// -void Platform::Sleep(Uint32 time) -{ - ::Sleep(time); -} - -} // namespace priv - -} // namespace sf +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_SLEEPIMPLUNIX_HPP +#define SFML_SLEEPIMPLUNIX_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Unix implementation of sf::Sleep +/// +/// \param time Time to sleep, in milliseconds +/// +//////////////////////////////////////////////////////////// +void SleepImpl(Uint32 time); + +} // namespace priv + +} // namespace sf + + +#endif // SFML_SLEEPIMPLUNIX_HPP diff --git a/src/SFML/System/Win32/ClockImpl.cpp b/src/SFML/System/Win32/ClockImpl.cpp new file mode 100644 index 000000000..f69d1aa42 --- /dev/null +++ b/src/SFML/System/Win32/ClockImpl.cpp @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +//////////////////////////////////////////////////////////// +// Private data +//////////////////////////////////////////////////////////// +namespace +{ + LARGE_INTEGER GetFrequency() + { + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + return frequency; + } +} + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +Uint64 ClockImpl::GetMicroSeconds() +{ + // Force the following code to run on first core + // (see http://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx) + HANDLE currentThread = GetCurrentThread(); + DWORD_PTR previousMask = SetThreadAffinityMask(currentThread, 1); + + // Get the frequency of the performance counter + // (it is constant across the program lifetime) + static LARGE_INTEGER frequency = GetFrequency(); + + // Get the current time + LARGE_INTEGER time; + QueryPerformanceCounter(&time); + + // Restore the thread affinity + SetThreadAffinityMask(currentThread, previousMask); + + // Return the current time as microseconds + return 1000000 * time.QuadPart / frequency.QuadPart; +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Unix/Platform.hpp b/src/SFML/System/Win32/ClockImpl.hpp similarity index 67% rename from src/SFML/System/Unix/Platform.hpp rename to src/SFML/System/Win32/ClockImpl.hpp index abd4e1957..1052779c8 100644 --- a/src/SFML/System/Unix/Platform.hpp +++ b/src/SFML/System/Win32/ClockImpl.hpp @@ -1,68 +1,60 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_PLATFORMUNIX_HPP -#define SFML_PLATFORMUNIX_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Give access to some system-specific low-level functions -/// -//////////////////////////////////////////////////////////// -class Platform -{ -public : - - //////////////////////////////////////////////////////////// - /// \brief Get the current system time - /// - /// \return System time, in milliseconds - /// - //////////////////////////////////////////////////////////// - static Uint64 GetSystemTime(); - - //////////////////////////////////////////////////////////// - /// \brief Suspend the execution of the current thread for a specified duration - /// - /// \param time Time to sleep, in milliseconds - /// - //////////////////////////////////////////////////////////// - static void Sleep(Uint32 time); -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_PLATFORMUNIX_HPP +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_CLOCKIMPLWIN32_HPP +#define SFML_CLOCKIMPLWIN32_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Windows implementaton of sf::Clock +/// +//////////////////////////////////////////////////////////// +class ClockImpl +{ +public : + + //////////////////////////////////////////////////////////// + /// \brief Get the current time + /// + /// \return Current time, in microseconds + /// + //////////////////////////////////////////////////////////// + static Uint64 GetMicroSeconds(); +}; + +} // namespace priv + +} // namespace sf + + +#endif // SFML_CLOCKIMPLWIN32_HPP diff --git a/src/SFML/System/Platform.hpp b/src/SFML/System/Win32/SleepImpl.cpp similarity index 80% rename from src/SFML/System/Platform.hpp rename to src/SFML/System/Win32/SleepImpl.cpp index acf62c0f8..bbc67c6b4 100644 --- a/src/SFML/System/Platform.hpp +++ b/src/SFML/System/Win32/SleepImpl.cpp @@ -1,45 +1,44 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_PLATFORM_HPP -#define SFML_PLATFORM_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -#if defined(SFML_SYSTEM_WINDOWS) - - #include - -#else - - #include - -#endif - - -#endif // SFML_PLATFORM_HPP +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +void SleepImpl(Uint32 time) +{ + ::Sleep(time); +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Win32/SleepImpl.hpp b/src/SFML/System/Win32/SleepImpl.hpp new file mode 100644 index 000000000..b4f40f7fa --- /dev/null +++ b/src/SFML/System/Win32/SleepImpl.hpp @@ -0,0 +1,51 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_SLEEPIMPLWIN32_HPP +#define SFML_SLEEPIMPLWIN32_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Windows implementation of sf::Sleep +/// +/// \param time Time to sleep, in milliseconds +/// +//////////////////////////////////////////////////////////// +void SleepImpl(Uint32 time); + +} // namespace priv + +} // namespace sf + + +#endif // SFML_SLEEPIMPLWIN32_HPP