| 1 | //////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // SFML - Simple and Fast Multimedia Library |
| 4 | // Copyright (C) 2007-2020 Laurent Gomila (laurent@sfml-dev.org) |
| 5 | // |
| 6 | // This software is provided 'as-is', without any express or implied warranty. |
| 7 | // In no event will the authors be held liable for any damages arising from the use of this software. |
| 8 | // |
| 9 | // Permission is granted to anyone to use this software for any purpose, |
| 10 | // including commercial applications, and to alter it and redistribute it freely, |
| 11 | // subject to the following restrictions: |
| 12 | // |
| 13 | // 1. The origin of this software must not be misrepresented; |
| 14 | // you must not claim that you wrote the original software. |
| 15 | // If you use this software in a product, an acknowledgment |
| 16 | // in the product documentation would be appreciated but is not required. |
| 17 | // |
| 18 | // 2. Altered source versions must be plainly marked as such, |
| 19 | // and must not be misrepresented as being the original software. |
| 20 | // |
| 21 | // 3. This notice may not be removed or altered from any source distribution. |
| 22 | // |
| 23 | //////////////////////////////////////////////////////////// |
| 24 | |
| 25 | #ifndef SFML_CLOCK_HPP |
| 26 | #define SFML_CLOCK_HPP |
| 27 | |
| 28 | //////////////////////////////////////////////////////////// |
| 29 | // Headers |
| 30 | //////////////////////////////////////////////////////////// |
| 31 | #include <SFML/System/Export.hpp> |
| 32 | #include <SFML/System/Time.hpp> |
| 33 | |
| 34 | |
| 35 | namespace sf |
| 36 | { |
| 37 | //////////////////////////////////////////////////////////// |
| 38 | /// \brief Utility class that measures the elapsed time |
| 39 | /// |
| 40 | //////////////////////////////////////////////////////////// |
| 41 | class SFML_SYSTEM_API Clock |
| 42 | { |
| 43 | public: |
| 44 | |
| 45 | //////////////////////////////////////////////////////////// |
| 46 | /// \brief Default constructor |
| 47 | /// |
| 48 | /// The clock starts automatically after being constructed. |
| 49 | /// |
| 50 | //////////////////////////////////////////////////////////// |
| 51 | Clock(); |
| 52 | |
| 53 | //////////////////////////////////////////////////////////// |
| 54 | /// \brief Get the elapsed time |
| 55 | /// |
| 56 | /// This function returns the time elapsed since the last call |
| 57 | /// to restart() (or the construction of the instance if restart() |
| 58 | /// has not been called). |
| 59 | /// |
| 60 | /// \return Time elapsed |
| 61 | /// |
| 62 | //////////////////////////////////////////////////////////// |
| 63 | Time getElapsedTime() const; |
| 64 | |
| 65 | //////////////////////////////////////////////////////////// |
| 66 | /// \brief Restart the clock |
| 67 | /// |
| 68 | /// This function puts the time counter back to zero. |
| 69 | /// It also returns the time elapsed since the clock was started. |
| 70 | /// |
| 71 | /// \return Time elapsed |
| 72 | /// |
| 73 | //////////////////////////////////////////////////////////// |
| 74 | Time restart(); |
| 75 | |
| 76 | private: |
| 77 | |
| 78 | //////////////////////////////////////////////////////////// |
| 79 | // Member data |
| 80 | //////////////////////////////////////////////////////////// |
| 81 | Time m_startTime; //!< Time of last reset, in microseconds |
| 82 | }; |
| 83 | |
| 84 | } // namespace sf |
| 85 | |
| 86 | |
| 87 | #endif // SFML_CLOCK_HPP |
| 88 | |
| 89 | |
| 90 | //////////////////////////////////////////////////////////// |
| 91 | /// \class sf::Clock |
| 92 | /// \ingroup system |
| 93 | /// |
| 94 | /// sf::Clock is a lightweight class for measuring time. |
| 95 | /// |
| 96 | /// Its provides the most precise time that the underlying |
| 97 | /// OS can achieve (generally microseconds or nanoseconds). |
| 98 | /// It also ensures monotonicity, which means that the returned |
| 99 | /// time can never go backward, even if the system time is |
| 100 | /// changed. |
| 101 | /// |
| 102 | /// Usage example: |
| 103 | /// \code |
| 104 | /// sf::Clock clock; |
| 105 | /// ... |
| 106 | /// Time time1 = clock.getElapsedTime(); |
| 107 | /// ... |
| 108 | /// Time time2 = clock.restart(); |
| 109 | /// \endcode |
| 110 | /// |
| 111 | /// The sf::Time value returned by the clock can then be |
| 112 | /// converted to a number of seconds, milliseconds or even |
| 113 | /// microseconds. |
| 114 | /// |
| 115 | /// \see sf::Time |
| 116 | /// |
| 117 | //////////////////////////////////////////////////////////// |
| 118 | |