Working With Time via API
There is a set of "times" that you can get via API using different classes, so you might get confused - which one to use and when. The goal of this small article is to get rid of the ambiguity.
Time#
Game::getTime() - time of the game. This method is the least accurate, based on internal Engine::time it ignores spikes and freezes. It is suitable for creating games. Moreover, you can change the speed of this timer using Game::setScale() and Game::setEnabled(). That is, after a game pause, the game state will remain where it was before the pause, without shifting far away - animations, particles, etc. will resume from the same position.
Time::getSeconds() method is the most accurate and closest to wall-clock time. It returns seconds as a double value, allowing operation with microseconds/nanoseconds. It does not take any spikes and freezes into account (uses QueryPerformanceCounter for Windows; gettimeofday for Linux/Unix inside). Can be used for any application independent time calculations.
Unigine::Plugins::Syncker::Syncker::getTime() method returns seconds as a double value. Based on Time, it also ignores spikes but may be shifted forward or backward in case of synchronization disruption between the Master and Slaves. Should be used for critical animations and logic synchronized through Syncker mechanisms.
Unigine::Plugins::IG::Manager::getInterpolationTime() method can also be shifted forward or backward in case of disruption of IG-Host synchronization. Between host-frames, it uses Unigine::Plugins::Syncker::Syncker::getTime(), so it can also be shifted in case of disruption of Master-Slave synchronization. This is used only for interpolating motion of entities obtained with timestamps from the host.
Delta Time (a.k.a. IFps)#
With regards to game engines, Delta Time means the amount of time that has elapsed since the previous frame. In UNIGINE this thing is called Inverse FPS or shorter IFps. Similar to the times described above, there are several 'delta times' you can meet as well.
Engine::getIFps() - time spent to complete the last frame (time between the last frame and the current one). It returns seconds as a float value, so precision after the decimal point is not guaranteed. It is normal to deliberately ignore any spikes and freezes of the application. You can call Engine::startFps() / Engine::stopFps() to ignore (exclude from being taken into account) a certain spike that you're going to make (e.g., process some heavy non-rendering tasks) or in case the application window is hidden.
Game::getIFps() - similar to Engine::getIFps(), it's the time between the last frame of the game and the current one (the time in seconds it took to complete the last frame). It is suitable for creating games. Usually this time is the same as the Engine's IFps, but you can change the scale of this timer using Game::setScale() and even stop it for a while via Game::setEnabled(). After a game pause, the game state will remain where it was before the pause - animations/expression will continue from the same position and state, etc. Moreover, you can use Game::setIFps() to set your own IFps value when necessary.
Unigine::Plugins::Syncker::Syncker::getIFps() and Unigine::Plugins::IG::Manager::getIFps() methods will both give you the actual time difference between the last subsequent frames (previous and current), without an option to tweak or ignore anything. Should be used for critical animations and logic synchronization through Syncker mechanisms on different computers, without being afraid of sync disruption.