#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_GAMETIME_H #define NUCLEX_GAME_GAMETIME_H #include "Config.h" #include #include namespace Nuclex { namespace Game { // ------------------------------------------------------------------------------------------- // /// Provides the timing values for the game's state update /// /// /// Most games will use multiple time sources. Typically, there is simulation time, /// which advances time in the game world (and is used for physics, movement, /// particle simulations, everything that belongs to the simulated world) and there's /// wall clock time, which keeps running even when the game is paused (used for /// UI animations, double-click detection, etc.). /// /// /// Even if a game uses more than these two channels, what each time user typically /// is interested in is the simulation time for his individual aspect of the game /// and wall clock time. This class allows to conveniently pass both time sources /// around in a single container. /// /// class GameTime { /// Initializes a new game timer set with zero values public: GameTime() : SimulationTotalUs(0), SimulationDeltaUs(0), RealWorldTotalUs(0), RealWorldDeltaUs(0) {} /// Initializes a new game timer set /// Total microseconds that have passed in-game /// Microseconds since the last update in-game /// /// Total microseconds that have passed in the real world /// /// /// Microseconds since the last update in the real world /// public: GameTime( std::chrono::microseconds simulationTotalUs, std::chrono::microseconds simulationDeltaUs, std::chrono::microseconds realWorldTotalUs, std::chrono::microseconds realWorldDeltaUs ) : SimulationTotalUs(simulationTotalUs), SimulationDeltaUs(simulationDeltaUs), RealWorldTotalUs(realWorldTotalUs), RealWorldDeltaUs(realWorldDeltaUs) {} /// Total number of microseconds that have passed in-game /// /// /// This clock will only continue to count when the game is running and not paused. /// Use it for things dependent on the passing of time within the game, such as /// movement, physics, rain and water animation. Do not use it for animations that /// should keep playing even when the game is paused like animated menus or /// loading screens. /// /// public: std::chrono::microseconds SimulationTotalUs; /// Microseconds that have passed since that last update in-game /// /// /// This clock will only run when the game is running and not paused. Use it for /// things that depend on the passing of time within the game, such as movement, /// physics, rain and water animation. Do not use it for animations that should /// keep playing even when the game is paused like animated menus or loading screens. /// /// public: std::chrono::microseconds SimulationDeltaUs; /// Total number of real world microseconds the game has been running /// /// This clock will continue to run even when the game is paused. It should be used /// for the timing of elements outside your game's world such as your menu system, /// fps timing and so on. Do not use it for in-game events and game object movement. /// public: std::chrono::microseconds RealWorldTotalUs; /// Real world microseconds that have elapsed since the last update /// /// This clock will continue to run even when the game is paused. It should be used /// for the timing of animated menus or loading animations where the in-game time might /// not be advancing. Do not use it for in-game events and game object movement. /// public: std::chrono::microseconds RealWorldDeltaUs; }; // ------------------------------------------------------------------------------------------- // }} // namespace Nuclex::Game #endif // NUCLEX_GAME_GAMETIME_H