This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

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.

Last update: 2024-11-06
Build: ()