#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GAME_TIMING_LINUXCLOCK_H #define NUCLEX_GAME_TIMING_LINUXCLOCK_H #include "../Config.h" #include "Clock.h" #include namespace Nuclex { namespace Game { namespace Timing { // ------------------------------------------------------------------------------------------- // /// Provides accurate timing on Linux-based systems /// /// This clock uses the clock_gettime() method to obtain accurate time. This clock runs /// in nanoseconds, but the internal frequency from which this is resampled cannot be /// queried from the kernel. /// class LinuxClock : public Clock { /// Initializes a new Linux clock public: NUCLEX_GAME_API LinuxClock() {} /// Destroys the clock public: NUCLEX_GAME_API virtual ~LinuxClock() {} /// Returns the number of ticks that have passed on the clock /// The total number of ticks that have passed since a defined time /// /// The "defined time" can be anything, typically it's either when the process /// started or when the system was booted. The absolute value has no particular meaning /// and should only be used to compare against an earlier value. /// public: NUCLEX_GAME_API static std::uint64_t GetClockTime(); /// Retrieves the resolution of the clock /// The clock's resolution /// /// This can be different from the return of GetFrequency() since the Linux clock is /// always scaled to nanoseconds, regardless of the actual resolution the timer provides. /// Sadly, while this makes programming time-based code simpler, it doesn't guarantee /// infinite precision since we rely on the resampling code in the Linux kernel which /// likely picks a naive approach. /// public: NUCLEX_GAME_API static std::uint64_t GetClockResolution(); /// /// Retrieves the maximum value the time can assume before wrapping around to 0 again /// /// The highest possible value GetTime() can return public: NUCLEX_GAME_API std::uint64_t GetWraparoundTime() const; /// Retrieves the clock's current time /// The number of ticks the clock has ticked to far /// /// There's no rule for what a clock's time should be relative to, only that it /// keeps counting at a fixed pace. The clock could begin ticking when the system /// boots, when the application starts or when the class is instantiated. /// public: NUCLEX_GAME_API std::uint64_t GetTime() const; /// Retrieves the clock's tick frequency /// How often the clock will tick in one second public: NUCLEX_GAME_API std::uint64_t GetFrequency() const; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Game::Timing #endif // NUCLEX_GAME_TIMING_LINUXCLOCK_H