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

放置代码的位置

The world logic has a number of functions that are used to code logic of the application. Initialization function of the world logic (init()) is used to create objects and initialize all other necessary resources on the world load. Shutdown function (shutdown()) is called when the world is unloaded and is used to delete resources that were created during the logic execution to avoid memory leaks. 世界逻辑具有许多用于对应用程序的逻辑进行编码的功能。世界逻辑的初始化函数(init())用于创建对象并初始化世界负载上的所有其他必要资源。 关闭函数(shutdown())在卸载世界时调用,该函数用于删除逻辑执行过程中创建的资源以避免内存泄漏。

But what about the frame-by-frame update? In the world logic, this update is performed within the main loop that has the following blocks for that:但是逐帧更新又如何呢?在世界逻辑中,此更新是在主循环中执行的,该循环具有以下块:

  • updateAsyncThread() can contain logic functions to be called every frame independently of the rendering thread: pathfinding, generation of procedural textures, custom physics, etc. updateAsyncThread()可以包含独立于渲染线程而在每一帧被调用的逻辑功能:寻路,过程纹理的生成,自定义物理等。
  • updateSyncThread() can contain any parallel logic functions to be executed before update(). updateSyncThread()可以包含要在update()之前执行的任何并行逻辑功能。
  • update() can contain any logic: control what to render on the screen and how to do it, render to textures, create nodes, call console commands, etc. update()可以包含任何逻辑:控制在屏幕上呈现的内容以及如何执行,呈现为纹理,创建节点,调用控制台命令等。
  • updatePhysics() can be used to simulate physics: perform continuous operations (pushing a car forward depending on current motor's RPM, simulating a wind blowing constantly, perform immediate collision response, etc.). updatePhysics()可用于模拟物理:执行连续操作(根据当前电动机的RPM向前推动汽车,不断模拟风吹,执行即时碰撞响应等)。
  • postUpdate() can be used to correct behavior according to the updated node states in the same frame. postUpdate()可用于根据同一帧中更新的节点状态来纠正行为。
  • swap() can be used to process the results of the updateAsyncThread() function. swap()可用于处理updateAsyncThread()函数的结果。

Code UpdateAsyncThread()
Code UpdateAsyncThread()#

In the world logic updateAsyncThread(), you can specify all logic functions you want to be called every frame independently of the rendering thread. This function can be used to perform some heavy resource-consuming calculations performed during the whole frame, such as pathfinding, generation of procedural textures, custom physics, and so on. This function does not block the main thread.在世界逻辑updateAsyncThread()中,可以独立于渲染线程指定要在每一帧调用的所有逻辑函数。此功能可用于执行在整个框架中执行的大量耗资源的计算,例如寻路,过程纹理的生成,自定义物理等。此函数不会阻塞主线程。

Code UpdateSyncThread()
Code UpdateSyncThread()#

In the world logic updateSyncThread(), you can specify any parallel logic functions you want to be executed before update(). This function blocks the Main Thread until all calls are completed.在世界逻辑updateSyncThread()中,可以指定要在update()之前执行的任何并行逻辑函数。此功能阻塞主线程,直到完成所有调用。

This function can be used to perform some heavy resource-consuming calculations such as pathfinding, generation of procedural textures, manipulations with big amounts of data, the result of which is required before the frame starts to be rendered. This function can also be used for simpler operations, that can be implemented in the update() function, to distribute between threads and improve performance.此功能可用于执行一些消耗大量资源的计算,例如寻路,过程纹理的生成,对大量数据的操作,在开始渲染帧之前需要这些结果。此函数还可以用于更简单的操作(可以在update()函数中实现),以在线程之间分配并提高性能。

Code Update()
Code Update()#

In the world logic update(), you can put all functions to be called every frame, while your application is executed. It serves for implementing any logic. In brief, you can control a lot of things (whether graphics-related or not) from within the update(). Here you can:在世界逻辑update()中,可以在执行应用程序时在每一帧调用所有函数。它用于实现任何逻辑。简而言之,您可以在update()中控制很多事情(无论是否与图形相关)。在这里您可以:

注意
Do not apply forces and torques to rigid bodies in the update(). Otherwise, you will get an unstable result that varies with each rendering frame. All continuous operations must be within updatePhysics().请勿对forces and update(). 否則,您將獲得不穩定的結果,該結果隨每個渲染幀而變化。 所有連續操作必須在 updatePhysics()之内。

World Event Handlers
世界事件处理程序#

Event handlers set in update() (for example, by using WorldTrigger or widget event handlers) are not executed immediately. They are run when the next engine function is called: that is, before updatePhysics(), if any (in the current frame), or before the next update() (in the following frame) — whatever comes first.update()中设置的事件处理程序(例如,通过使用WorldTrigger小部件事件处理程序)不会立即执行。它们在下一个引擎函数被调用时运行:也就是说,在updatePhysics()之前,如果有的话(在当前帧中),或者在下一个update()之前(在下一帧中)-无论哪个先发生。

Code UpdatePhysics()
Code UpdatePhysics()#

The updatePhysics() function of the world logic is mainly used to control physics in your application. As a rule this function is used for continuous operations such as pushing a car forward depending on current motor's RPM, simulating a wind blowing constantly, performing immediate collision response (as updatePhysics() can be executed several times during a single rendering frame, you can process multiple bounces of objects, when they collide with each other and monitor them, while the update() will only show us the final result), etc. The updatePhysics() is executed in the Main thread, so you can perform any actions here just like in the update():世界逻辑的updatePhysics()函数用于控制应用程序中的物理。此功能应用于连续操作,例如根据当前电动机的RPM推动汽车前进,不断模拟风向,执行即时碰撞响应(由于updatePhysics()可以在单个渲染帧中执行多次,因此您可以处理多次反弹对象,当它们相互碰撞并监视它们时,而update()只会向我们显示最终结果),等等。updatePhysics()在主线程中执行,因此您可以在此处执行任何操作,就像在update()中一样:

You can as well do the following (and a lot more):您还可以执行以下操作(以及更多操作):

  • Reposition and transform nodes if they are enabled.如果节点已启用,则重新定位和变换。
  • Create new nodes.创建新节点。
  • Delete nodes. 刪除節點。

Physics Event Handlers
物理回调#

By default in Async Rendering physics mode, if you set any physics-based event handlers in updatePhysics() or use a PhysicalTrigger, they cannot be executed immediately, as the rendering process is already in action and they can violate it. If there is one more physics iteration to go, these event handlers or a PhysicalTrigger are executed before the next updatePhysics(); if not, before the next world logic update().就像在使用update()的情况下一样,如果在updatePhysics()中设置任何基于物理的回调或使用PhysicalTrigger,它们将无法立即执行,因为渲染过程已经在进行中,并且可能会违反它。如果还有一个物理迭代要进行,则这些回调或PhysicalTrigger将在下一个updatePhysics()之前执行;如果不是,则在下一个世界逻辑update()之前。

You can safely reposition or transform, create or delete nodes in your physics event handler functions, as they are executed in the Main thread.如果要重新定位或变换,创建或删除物理回调返回的节点,则工作流程如下:将它们存储在数组中,然后在update()中执行所有必要的操作。

Code PostUpdate()
Code PostUpdate()#

The postUpdate() function of the world logic is an additional function used to correct behavior after the state of the node has been updated (for example, skinned animation has been played in the current frame or particle system has spawn its particles).世界逻辑的postUpdate()函数是一个附加函数,用于在更新节点状态后纠正行为(例如,在当前帧中播放了蒙皮动画或粒子系统生成了其粒子)。

Imagine a situation when we need to attach an object (let's say, a sword) to the hand of a skinned mesh character. If we get transformation of the character hand bone and set it to the sword in the update() function, the attachment will be loose rather than precise. The sword will not be tightly held in the hand, because the animation is actually played right after the world logic update() has been executed. This means, returned bone transformations in the update() will be for the previous frame. The world logic postUpdate() is executed after animation is played, which means you can get updated bone transformations for the current frame from within this function and set them to the sword.想象一下一种情况,当我们需要将一个对象(例如,一把剑)连接到蒙皮的网格角色的手上时。如果我们得到角色手骨的变形并将其设置为update()函数中的剑,则附件将变得松散而不是精确。剑不会紧紧握在手中,因为动画实际上是在执行世界逻辑update()之后立即播放的。这意味着,update()中返回的骨骼变换将用于前一帧。世界逻辑postUpdate()是在播放动画之后执行的,这意味着您可以从此函数中获取当前帧的更新骨骼转换并将其设置为剑。

注意
Use postUpdate() for correction purposes only; otherwise, this will increase the main loop time. All other functions should be placed within update() or updatePhysics() (physics).仅将postUpdate()用于更正;否则,这会增加主循环时间。所有其他功能应放在update()updatePhysics()(物理)之内。

Code Swap()
Code Swap()#

Engine calls this function after the following processes are completed: rendering (CPU portion), physics calculations and pathfinding, GUI rendering, and all Async threads. The function is designed to process the results of the updateAsyncThread() method — all other methods (threads) have already been performed and are idle. After this function, only two actions occur:引擎在完成以下过程之后调用此函数:渲染(CPU部分),物理计算和寻路,GUI渲染以及所有异步线程。该函数旨在处理updateAsyncThread()方法的结果-所有其他方法(线程)已经执行并且处于空闲状态。此功能之后,仅发生两个动作:

  • All objects that are queued for deletion are deleted.所有排队等待删除的对象都将被删除。
  • Profiler is updated. 探查器已更新。

最新更新: 2024-08-16
Build: ()