#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_MANUALCLOCK_H #define NUCLEX_GAME_TIMING_MANUALCLOCK_H #include "../Config.h" #include "Clock.h" #include namespace Nuclex { namespace Game { namespace Timing { // ------------------------------------------------------------------------------------------- // /// A clock that is advanced by hand /// /// /// A manually advanced clock can be used to conditionally lock the game into fixed time /// increments. This is useful in several situations: /// /// /// video footage - when producing a gameplay movie, after each rendered /// frame, time should be advanced by a set amount depending on the target frame rate of /// the video, regardless of how long the frame took to render. /// /// /// unit testing - if you need a mock clock for unit testing that says /// whatever you want it to say in the test, this class deals with just that situation /// and lets you unit test your timing code with any arbitrary clock frequence and /// elapsed times. /// /// class ManualClock : public Clock { /// Initializes a new manually advanced clock /// Frequency at which the clock ticks public: ManualClock(std::uint64_t frequency = 1000) : elapsedTicks(0), frequency(frequency) {} /// Destroys the clock public: virtual ~ManualClock() {} /// Advances the clock's time by the specified number of ticks /// Number of ticks the clock will be advanced by /// /// The duration of one tick depends on the frequency you passed to the constructor. /// public: NUCLEX_GAME_API void AddTime(std::uint64_t ticks); /// /// 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; /// Number of ticks that have elapsed on the clock private: std::uint64_t elapsedTicks; /// Frequency at which the clock ticks private: std::uint64_t frequency; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Game::Timing #endif // NUCLEX_GAME_TIMING_MANUALCLOCK_H