From 0000fa3e5ec7a47bc35f7e11c1ab08742fcca5f3 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sun, 2 Apr 2017 03:27:05 +0200 Subject: [PATCH] Replaced Clock, Time and Sleep implementations with std::chrono based ones. --- include/SFML/System/Time.hpp | 48 ++++++++++++++---- src/SFML/System/CMakeLists.txt | 31 +++-------- src/SFML/System/Clock.cpp | 22 +++++--- src/SFML/System/Sleep.cpp | 10 ++-- src/SFML/System/Time.cpp | 30 ++++++++--- src/SFML/System/Unix/ClockImpl.cpp | 64 ----------------------- src/SFML/System/Unix/ClockImpl.hpp | 61 ---------------------- src/SFML/System/Unix/SleepImpl.cpp | 59 --------------------- src/SFML/System/Unix/SleepImpl.hpp | 52 ------------------- src/SFML/System/Win32/ClockImpl.cpp | 79 ----------------------------- src/SFML/System/Win32/ClockImpl.hpp | 61 ---------------------- src/SFML/System/Win32/SleepImpl.cpp | 55 -------------------- src/SFML/System/Win32/SleepImpl.hpp | 52 ------------------- 13 files changed, 83 insertions(+), 541 deletions(-) delete mode 100644 src/SFML/System/Unix/ClockImpl.cpp delete mode 100644 src/SFML/System/Unix/ClockImpl.hpp delete mode 100644 src/SFML/System/Unix/SleepImpl.cpp delete mode 100644 src/SFML/System/Unix/SleepImpl.hpp delete mode 100644 src/SFML/System/Win32/ClockImpl.cpp delete mode 100644 src/SFML/System/Win32/ClockImpl.hpp delete mode 100644 src/SFML/System/Win32/SleepImpl.cpp delete mode 100644 src/SFML/System/Win32/SleepImpl.hpp diff --git a/include/SFML/System/Time.hpp b/include/SFML/System/Time.hpp index 4dff9283..b33ba998 100644 --- a/include/SFML/System/Time.hpp +++ b/include/SFML/System/Time.hpp @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include namespace sf @@ -54,7 +55,7 @@ public: /// /// \return Time in seconds /// - /// \see asMilliseconds, asMicroseconds + /// \see asMilliseconds, asMicroseconds, asNanoseconds /// //////////////////////////////////////////////////////////// float asSeconds() const; @@ -64,7 +65,7 @@ public: /// /// \return Time in milliseconds /// - /// \see asSeconds, asMicroseconds + /// \see asSeconds, asMicroseconds, asNanoseconds /// //////////////////////////////////////////////////////////// Int32 asMilliseconds() const; @@ -74,11 +75,21 @@ public: /// /// \return Time in microseconds /// - /// \see asSeconds, asMilliseconds + /// \see asSeconds, asMilliseconds, asNanoseconds /// //////////////////////////////////////////////////////////// Int64 asMicroseconds() const; + //////////////////////////////////////////////////////////// + /// \brief Return the time value as a number of nanoseconds + /// + /// \return Time in nanoseconds + /// + /// \see asSeconds, asMilliseconds, asMicroseconds + /// + //////////////////////////////////////////////////////////// + Int64 asNanoseconds() const; + //////////////////////////////////////////////////////////// // Static member data //////////////////////////////////////////////////////////// @@ -89,24 +100,26 @@ private: friend SFML_SYSTEM_API Time seconds(float); friend SFML_SYSTEM_API Time milliseconds(Int32); friend SFML_SYSTEM_API Time microseconds(Int64); + friend SFML_SYSTEM_API Time nanoseconds(Int64); //////////////////////////////////////////////////////////// - /// \brief Construct from a number of microseconds + /// \brief Construct from a number of nanoseconds /// /// This function is internal. To construct time values, - /// use sf::seconds, sf::milliseconds or sf::microseconds instead. + /// use sf::seconds, sf::milliseconds, sf::microseconds + /// or sf::nanoseconds instead. /// - /// \param microseconds Number of microseconds + /// \param nanoseconds Number of nanoseconds /// //////////////////////////////////////////////////////////// - explicit Time(Int64 microseconds); + explicit Time(Int64 nanoseconds); private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Int64 m_microseconds; ///< Time value stored as microseconds + std::chrono::nanoseconds m_nanoseconds; ///< Time value stored as nanoseconds }; //////////////////////////////////////////////////////////// @@ -117,7 +130,7 @@ private: /// /// \return Time value constructed from the amount of seconds /// -/// \see milliseconds, microseconds +/// \see milliseconds, microseconds, nanoseconds /// //////////////////////////////////////////////////////////// SFML_SYSTEM_API Time seconds(float amount); @@ -130,7 +143,7 @@ SFML_SYSTEM_API Time seconds(float amount); /// /// \return Time value constructed from the amount of milliseconds /// -/// \see seconds, microseconds +/// \see seconds, microseconds, nanoseconds /// //////////////////////////////////////////////////////////// SFML_SYSTEM_API Time milliseconds(Int32 amount); @@ -143,11 +156,24 @@ SFML_SYSTEM_API Time milliseconds(Int32 amount); /// /// \return Time value constructed from the amount of microseconds /// -/// \see seconds, milliseconds +/// \see seconds, milliseconds, nanoseconds /// //////////////////////////////////////////////////////////// SFML_SYSTEM_API Time microseconds(Int64 amount); +//////////////////////////////////////////////////////////// +/// \relates Time +/// \brief Construct a time value from a number of nanoseconds +/// +/// \param amount Number of nanoseconds +/// +/// \return Time value constructed from the amount of nanoseconds +/// +/// \see seconds, milliseconds, microseconds +/// +//////////////////////////////////////////////////////////// +SFML_SYSTEM_API Time nanoseconds(Int64 amount); + //////////////////////////////////////////////////////////// /// \relates Time /// \brief Overload of == operator to compare two time values diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index dbac1081..683f23f8 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -33,31 +33,14 @@ set(SRC source_group("" FILES ${SRC}) # add platform specific sources -if(SFML_OS_WINDOWS) - set(PLATFORM_SRC - ${SRCROOT}/Win32/ClockImpl.cpp - ${SRCROOT}/Win32/ClockImpl.hpp - ${SRCROOT}/Win32/SleepImpl.cpp - ${SRCROOT}/Win32/SleepImpl.hpp +if(SFML_OS_ANDROID) + set(PLATFORM_SRC ${PLATFORM_SRC} + ${SRCROOT}/Android/Activity.hpp + ${SRCROOT}/Android/Activity.cpp + ${SRCROOT}/Android/NativeActivity.cpp + ${SRCROOT}/Android/ResourceStream.cpp + ${SRCROOT}/Android/ResourceStream.cpp ) - source_group("windows" FILES ${PLATFORM_SRC}) -else() - set(PLATFORM_SRC - ${SRCROOT}/Unix/ClockImpl.cpp - ${SRCROOT}/Unix/ClockImpl.hpp - ${SRCROOT}/Unix/SleepImpl.cpp - ${SRCROOT}/Unix/SleepImpl.hpp - ) - - if(SFML_OS_ANDROID) - set(PLATFORM_SRC ${PLATFORM_SRC} - ${SRCROOT}/Android/Activity.hpp - ${SRCROOT}/Android/Activity.cpp - ${SRCROOT}/Android/NativeActivity.cpp - ${SRCROOT}/Android/ResourceStream.cpp - ${SRCROOT}/Android/ResourceStream.cpp - ) - endif() source_group("unix" FILES ${PLATFORM_SRC}) endif() diff --git a/src/SFML/System/Clock.cpp b/src/SFML/System/Clock.cpp index e4f347e3..80efa681 100644 --- a/src/SFML/System/Clock.cpp +++ b/src/SFML/System/Clock.cpp @@ -26,19 +26,25 @@ // Headers //////////////////////////////////////////////////////////// #include +#include -#if defined(SFML_SYSTEM_WINDOWS) - #include -#else - #include -#endif + +namespace +{ + sf::Time getCurrentTime() + { + auto timeSinceEpoch = std::chrono::high_resolution_clock::now().time_since_epoch(); + + return sf::nanoseconds(std::chrono::duration_cast(timeSinceEpoch).count()); + } +} namespace sf { //////////////////////////////////////////////////////////// Clock::Clock() : -m_startTime(priv::ClockImpl::getCurrentTime()) +m_startTime(getCurrentTime()) { } @@ -46,14 +52,14 @@ m_startTime(priv::ClockImpl::getCurrentTime()) //////////////////////////////////////////////////////////// Time Clock::getElapsedTime() const { - return priv::ClockImpl::getCurrentTime() - m_startTime; + return getCurrentTime() - m_startTime; } //////////////////////////////////////////////////////////// Time Clock::restart() { - Time now = priv::ClockImpl::getCurrentTime(); + Time now = getCurrentTime(); Time elapsed = now - m_startTime; m_startTime = now; diff --git a/src/SFML/System/Sleep.cpp b/src/SFML/System/Sleep.cpp index 4f2a50e4..282ad259 100644 --- a/src/SFML/System/Sleep.cpp +++ b/src/SFML/System/Sleep.cpp @@ -26,12 +26,8 @@ // Headers //////////////////////////////////////////////////////////// #include - -#if defined(SFML_SYSTEM_WINDOWS) - #include -#else - #include -#endif +#include +#include namespace sf @@ -40,7 +36,7 @@ namespace sf void sleep(Time duration) { if (duration >= Time::Zero) - priv::sleepImpl(duration); + std::this_thread::sleep_for(std::chrono::microseconds(duration.asMicroseconds())); } } // namespace sf diff --git a/src/SFML/System/Time.cpp b/src/SFML/System/Time.cpp index 63de359a..760ef2b7 100644 --- a/src/SFML/System/Time.cpp +++ b/src/SFML/System/Time.cpp @@ -36,7 +36,7 @@ const Time Time::Zero; //////////////////////////////////////////////////////////// Time::Time() : -m_microseconds(0) +m_nanoseconds(0) { } @@ -44,27 +44,34 @@ m_microseconds(0) //////////////////////////////////////////////////////////// float Time::asSeconds() const { - return m_microseconds / 1000000.f; + return std::chrono::duration_cast>>(m_nanoseconds).count(); } //////////////////////////////////////////////////////////// Int32 Time::asMilliseconds() const { - return static_cast(m_microseconds / 1000); + return std::chrono::duration_cast>(m_nanoseconds).count(); } //////////////////////////////////////////////////////////// Int64 Time::asMicroseconds() const { - return m_microseconds; + return std::chrono::duration_cast>(m_nanoseconds).count(); } //////////////////////////////////////////////////////////// -Time::Time(Int64 microseconds) : -m_microseconds(microseconds) +Int64 Time::asNanoseconds() const +{ + return std::chrono::duration_cast>(m_nanoseconds).count(); +} + + +//////////////////////////////////////////////////////////// +Time::Time(Int64 nanoseconds) : +m_nanoseconds(std::chrono::nanoseconds(nanoseconds)) { } @@ -72,19 +79,26 @@ m_microseconds(microseconds) //////////////////////////////////////////////////////////// Time seconds(float amount) { - return Time(static_cast(amount * 1000000)); + return Time(static_cast(amount * 1000000000)); } //////////////////////////////////////////////////////////// Time milliseconds(Int32 amount) { - return Time(static_cast(amount) * 1000); + return Time(static_cast(amount) * 1000000); } //////////////////////////////////////////////////////////// Time microseconds(Int64 amount) +{ + return Time(static_cast(amount) * 1000); +} + + +//////////////////////////////////////////////////////////// +Time nanoseconds(Int64 amount) { return Time(amount); } diff --git a/src/SFML/System/Unix/ClockImpl.cpp b/src/SFML/System/Unix/ClockImpl.cpp deleted file mode 100644 index 2cd89cfc..00000000 --- a/src/SFML/System/Unix/ClockImpl.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// 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 -#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) - #include -#else - #include -#endif - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -Time ClockImpl::getCurrentTime() -{ -#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) - - // 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 sf::microseconds(nanoseconds / 1000); - -#else - - // POSIX implementation - timespec time; - clock_gettime(CLOCK_MONOTONIC, &time); - return sf::microseconds(static_cast(time.tv_sec) * 1000000 + time.tv_nsec / 1000); - -#endif -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Unix/ClockImpl.hpp b/src/SFML/System/Unix/ClockImpl.hpp deleted file mode 100644 index 26c6433a..00000000 --- a/src/SFML/System/Unix/ClockImpl.hpp +++ /dev/null @@ -1,61 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// 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 -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Unix implementation of sf::Clock -/// -//////////////////////////////////////////////////////////// -class ClockImpl -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Get the current time - /// - /// \return Current time - /// - //////////////////////////////////////////////////////////// - static Time getCurrentTime(); -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_CLOCKIMPLUNIX_HPP diff --git a/src/SFML/System/Unix/SleepImpl.cpp b/src/SFML/System/Unix/SleepImpl.cpp deleted file mode 100644 index 22b6f358..00000000 --- a/src/SFML/System/Unix/SleepImpl.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// 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 - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -void sleepImpl(Time time) -{ - Uint64 usecs = time.asMicroseconds(); - - // Construct the time to wait - timespec ti; - ti.tv_nsec = (usecs % 1000000) * 1000; - ti.tv_sec = usecs / 1000000; - - // Wait... - // If nanosleep returns -1, we check errno. If it is EINTR - // nanosleep was interrupted and has set ti to the remaining - // duration. We continue sleeping until the complete duration - // has passed. We stop sleeping if it was due to an error. - while ((nanosleep(&ti, &ti) == -1) && (errno == EINTR)) - { - } -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Unix/SleepImpl.hpp b/src/SFML/System/Unix/SleepImpl.hpp deleted file mode 100644 index a4039b6b..00000000 --- a/src/SFML/System/Unix/SleepImpl.hpp +++ /dev/null @@ -1,52 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// 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 -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Unix implementation of sf::Sleep -/// -/// \param time Time to sleep -/// -//////////////////////////////////////////////////////////// -void sleepImpl(Time 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 deleted file mode 100644 index b41f4e76..00000000 --- a/src/SFML/System/Win32/ClockImpl.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// 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 - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -Time ClockImpl::getCurrentTime() -{ - // Get the frequency of the performance counter - // (it is constant across the program lifetime) - static const auto frequency = [] - { - LARGE_INTEGER frequency; - QueryPerformanceFrequency(&frequency); - return frequency; - }(); - - // Detect if we are on Windows XP or older - static const auto oldWindows = [] - { - // Windows XP was the last 5.x version of Windows - return static_cast(LOBYTE(LOWORD(GetVersion()))) < 6; - }(); - - LARGE_INTEGER time; - - if (oldWindows) - { - static std::mutex oldWindowsMutex; - - // Acquire a lock to prevent travelling back in time - std::lock_guard lock(oldWindowsMutex); - - // Get the current time - QueryPerformanceCounter(&time); - } - else - { - // Get the current time - QueryPerformanceCounter(&time); - } - - // Return the current time as microseconds - return sf::microseconds(1000000 * time.QuadPart / frequency.QuadPart); -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Win32/ClockImpl.hpp b/src/SFML/System/Win32/ClockImpl.hpp deleted file mode 100644 index 45e08e87..00000000 --- a/src/SFML/System/Win32/ClockImpl.hpp +++ /dev/null @@ -1,61 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// 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 -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Windows implementation of sf::Clock -/// -//////////////////////////////////////////////////////////// -class ClockImpl -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Get the current time - /// - /// \return Current time - /// - //////////////////////////////////////////////////////////// - static Time getCurrentTime(); -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_CLOCKIMPLWIN32_HPP diff --git a/src/SFML/System/Win32/SleepImpl.cpp b/src/SFML/System/Win32/SleepImpl.cpp deleted file mode 100644 index 8a8eee1c..00000000 --- a/src/SFML/System/Win32/SleepImpl.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// 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(Time time) -{ - // Get the supported timer resolutions on this system - TIMECAPS tc; - timeGetDevCaps(&tc, sizeof(TIMECAPS)); - - // Set the timer resolution to the minimum for the Sleep call - timeBeginPeriod(tc.wPeriodMin); - - // Wait... - ::Sleep(time.asMilliseconds()); - - // Reset the timer resolution back to the system default - timeEndPeriod(tc.wPeriodMin); -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Win32/SleepImpl.hpp b/src/SFML/System/Win32/SleepImpl.hpp deleted file mode 100644 index 2cde5b3d..00000000 --- a/src/SFML/System/Win32/SleepImpl.hpp +++ /dev/null @@ -1,52 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// 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 -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Windows implementation of sf::Sleep -/// -/// \param time Time to sleep -/// -//////////////////////////////////////////////////////////// -void sleepImpl(Time time); - -} // namespace priv - -} // namespace sf - - -#endif // SFML_SLEEPIMPLWIN32_HPP