Using Entity Command Buffers – Unite Copenhagen 2019

https://www.youtube.com/watch?v=SecJibpoTYw

https://www.slideshare.net/unity3d/using-entity-command-buffers-unite-copenhagen-2019

https://docs.unity3d.com/Packages/com.unity.entities@0.0/api/Unity.Entities.EntityCommandBuffer.html

https://docs.unity3d.com/Packages/com.unity.entities@0.1/manual/entity_command_buffer.html

Using Entity Command Buffers – Unite Copenhagen 2019

并非所有游戏玩法都需要立即发生。 实际上,在许多情况下,延迟命令可能会提供更好的结果–改善用户体验,性能等。这些幻灯片探讨了在何处需要延迟命令的思考,并提供了有关如何充分利用实体命令缓冲区的示例。

Overview

— What are Entity Command Buffers?什么是实体命令缓冲区?

– Recording Commands记录命令

– Playback Order播放顺序

— Command Playback命令播放

– EntityCommandBufferSystems

– Immediate vs Deferred立即与延迟

— Traps to Avoid避免陷阱

— Possible Future Improvements未来可能的改进

Problem They Solve他们解决的问题

-Structural changes happen on the Main Thread主线程上发生结构更改

-Solution for recording changes in parallel through Jobs通过Jobs并行记录更改的解决方案

这些是什么?

–Chains of data transformations that are recorded记录的数据转换链

–Either from the Main Thread or within Jobs (Concurrent)从主线程中或在Jobs中(并发)

–Played back at a specific point in the future在将来的特定时间回放

–从EntityCommandBufferSystem

命令

–一些可用命令

–实例化,创建或销毁实体  Instantiate, Create, or Destroy an Entity

–添加,设置或删除组件数据Add, Set, or Remove Component Data

–向实体添加或设置IBufferElementData    Add or Set IBufferElementData to an Entity

–添加或设置SharedComponent数据     Add or Set SharedComponent Data

–向EntityQuery中的每个实体添加或删除组件   Add or Remove Components to each Entity in an EntityQuery

– 主线程与并发命令        Main Thread vs Concurrent Commands

–主线程:托管数据正常         Main Thread: Managed Data OK

–并发:子集,不允许使用托管数据            Concurrent: Subset with No Managed Data Allowed

Main Thread Chain

— Single chain单链

— Played back in order of recording 按录制的顺序播放

Concurrent Chains并发链

— Multiple chains多个链

— Playback in order by JobIndex按JobIndex顺序播放

– JobIndex unique per batch of work  每批工作唯一的JobIndex

— Deterministic确定性

– JobIndex becomes a way to sort commandsJobIndex成为对命令进行排序的一种方式

– Large continuous chunks of monotonically increasing numbers连续大块单调递增的数字

Concurrent Chains Recording并发链记录

— Multiple threads recording from Concurrent EntityCommandBuffer to their own chain从并发EntityCommandBuffer记录到自己的链的多个线程

Concurrent Chains Playback (Today)并发链播放(今天)

— Find the batch with the lowest job index 查找job index最低的批次

— Start executing commands linearly until the end of the batch开始线性执行命令,直到批处理结束

— Repeat looking for the next smallest until done重复寻找下一个最小值,直到完成

Command Playback命令播放

Deferred vs Immediate Playback延迟与即时播放

— Deferred

– Scheduling Playback later in another EntityCommandBufferSystem稍后在另一个EntityCommandBufferSystem中安排播放

– Systems already there已经存在的系统

– Example: BeginInitializationEntityCommandBufferSystem示例

— Immediate

– Calling myCommandBuffer.Playback(…) right after recording录制后立即调用myCommandBuffer.Playback(…)

– PostUpdateCommands: Right after System’s Update()    ||PostUpdateCommands:在系统的Update()之后

// Taken from SpawnFromEntity example BeginInitializationEntityCommandBufferSystem m_EntityCommandBufferSystem;protected override void OnCreate(){// 1: Set your command buffer systemm_EntityCommandBufferSystem = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();}protected override JobHandle OnUpdate(JobHandle inputDeps) {// 2: Pass a Concurrent Command Buffer into the jobvar job = new SpawnJob { CommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent() }.Schedule(this, inputDeps);// 3: Add the JobHandle to the Command Buffer System m_EntityCommandBufferSystem.AddJobHandleForProducer(job); return job;}

示例 RPG 游戏,释放技能施毒,掉血伤害, DPS

Frame0的时候, 玩家对命中的Enemy

伤害, 技能, CD 三个系统

进入 Frame1 了

System Begin 的时候

Damage系统进行处理

Traps to Avoid 避免陷阱

Knowing When Data Is Available知道何时有数据

— Important to know when you will need that data to exist重要的是要知道何时需要该数据存在

— Tradeoff: Narrow window for playback vs longer deferment权衡:播放的窗口较窄,延迟时间更长

– Systems running between recording and playback will see the “old” data在录制和播放之间运行的系统将看到“旧”数据

Deferred Entities

— Instantiate(…) returns an Entity that’s deferred   实例化(...)返回一个延迟的实体

– It does not exist yet它尚不存在

– Has a negative Entity ID实体ID为负

— During Playback播放期间

– Entity gets a positive ID once it’s created实体创建后会获得一个肯定的ID

– Future references to that Entity in the chain are fixed up修复了链中对该实体的将来引用

Storing a Reference to a Deferred Entity ID存储对延迟实体ID的引用

— When your ComponentData stores a reference to some entity that will be created later当您的ComponentData存储对稍后将创建的某些实体的引用时

— That Entity will be invalid!该实体将无效!

Too Many Sync Points同步点太多

— Sync points can prevent a lot of work to be done in parallel同步点可能会阻止大量并行工作

— Playing back commands when you need that data在需要该数据时播放命令

— Consolidate those points to specific times in the frame将这些点合并到框架中的特定时间

– Use the pre-existing ECB Systems or create your own使用现有的ECB系统或创建自己的ECB系统

ECB Invalid After Playback播放后ECB无效

— Once it’s played back, can’t record to it again播放后,无法再次录制

— Error regarding a Native Container有关本机容器的错误

— Create a new ECB创建一个新的ECB

Possible Future Improvements 未来可能的改进

Bursted ECB

— Bursted Recording and Bursted Playback突发记录和突发播放

— Recording Available Soon! 即将提供录制!

Bursted ECB Code Example 突发ECB代码示例

// Taken from SpawnFromEntity example[BurstCompile(CompileSynchronously = true)]struct SpawnJob : IJobForEachWithEntity<Spawner_FromEntity, LocalToWorld>{public EntityCommandBuffer.Concurrent CommandBuffer;public void Execute(Entity entity, int index, [ReadOnly] ref Spawner_FromEntity spawnerFromEntity, [ReadOnly] ref LocalToWorld location){for (var x = 0; x < spawnerFromEntity.CountX; x++)// CountX = 100 { for (var y = 0; y < spawnerFromEntity.CountY; y++)// CountY = 100 { var instance = CommandBuffer.Instantiate(index, spawnerFromEntity.Prefab);// Place the instantiated in a grid with some noisevar position = math.transform(location.Value, new float3(x * 1.3F, noise.cnoise(new float2(x, y) * 0.21F) * 2, y * 1.3F));CommandBuffer.SetComponent(index, instance, new Translation {Value = position}); } } CommandBuffer.DestroyEntity(index, entity); } } 

Without Burst (in ms) 0.64 With Burst (in ms)* *Average = 10x speedup 10kEntities

Batched Playback批量播放

— Processing certain commands in bulk for better performance批量处理某些命令以获得更好的性能

– Such as Instantiate or AddComponent如实例化或AddComponent

— All playback is still happening on the Main Thread所有回放仍在主线程上进行

Entity Manager Feature Parity实体管理器功能奇偶校验

— EntityManager has more options for each functionEntityManager为每个功能提供更多选项

– Such as AddComponent ( NativeArray <Entity>, Component )如

— Would like them to be unified希望它们被统一

Review评论

What To Remember要记住什么

— Chains of data transformations数据转换链

— Played back at a specific point in the future在将来的特定时间播放

— Think about the point when you need that data考虑一下何时需要该数据

— No managed data within jobs, therefore no commands with managed data within jobs作业中没有托管数据,因此作业中没有包含托管数据的命令

Thank you!

[Unity ECS]使用 Entity Command Buffers – Unite Copenhagen 2019相关推荐

  1. 倒计时 4 天!年度开发者盛会 Unite Shanghai 2019 全日程揭晓(附表)

    技术沉淀,华丽蜕变.跨越十四个春秋,Unity 在不断迭代的过程中已成为全球知名的游戏开发引擎,于此,其不仅可以为游戏开发者.发行商们带来底层工具的支持,更能够帮助各类的创作者.艺术家们实现各行各业高 ...

  2. 倒计时 5 天!年度开发者盛会 Unite Shanghai 2019 全日程揭晓(附表)

    技术沉淀,华丽蜕变.跨越十四个春秋,Unity 在不断迭代的过程中已成为全球知名的游戏开发引擎,于此,其不仅可以为游戏开发者.发行商们带来底层工具的支持,更能够帮助各类的创作者.艺术家们实现各行各业高 ...

  3. unity ECS简介

    什么是Unity ECS Unity ECS是Unity引擎中的一种高性能游戏开发架构,它采用了基于数据的设计思路,与传统的面向对象编程不同.它的目标是提高游戏的性能和可伸缩性. Unity ECS通 ...

  4. [Unity ECS] 游戏对象转换和子场景 [1]

      游戏只是关于玩家输入改变数据,然后看到不同呈现的事物,因此玩得开心.这些数据是使用 Unity 的 WYSIWYG 工具在scene设计的.但是那些基于 GameObject 的数据与 ECS 不 ...

  5. Unity ECS小知识1 - PhysicsTrigger Event

    Unity ECS 小知识1 - PhysicsTrigger Event ECS套件学习过程中会遇到各种问题,专门开辟一个专题"ECS小知识"来记录这些点滴.每个小知识文章是没有 ...

  6. Unity Ecs源码分析

    C# Job System 什么是Job System? Job System通过创建Job而不是线程来管理多线程代码. Job System跨多个核心管理一组工作线程.它通常每个逻辑CPU核心有一个 ...

  7. Unity ECS 视频笔记

    视频摘要 本文视频资料:使用Entity Component System开发<快乐的Minecraft>游戏 使用Unity2018及以上版本才有ECS功能. 本文是看视频的一些摘要. ...

  8. Unity ECS实例:制作俯视角射击游戏!

    目录 创建主角 3:主角移动和摄像机跟随 4:实现敌人角色 5:子弹,死亡,机器人 6:粒子与音效 这次我们来使用Unity ECS系统制作一个俯视角度的射击游戏.虽然现在网上有不少ECS的资料和项目 ...

  9. unity android 在后台运行_Unity问答 | 盘点2019年社区优秀问答

    Unity社区创建以来便成为广大Unity开发者与创作者的经验分享以及技术交流的平台,社区成员互帮互助,分享个人开发心得的同时,也积极踊跃地在社区提出自己遇到的开发难题. 2019年,Unity Co ...

最新文章

  1. 推荐一些算法方面的好书
  2. ES5-Array-join
  3. Shiro中进行角色与权限认证流程
  4. 代码是写给人看的,请C/C++过来的程序员们多学习软件工程
  5. HDU3183(RMQ问题,ST算法)
  6. linux中操作数据库的使用命令记录
  7. Science:“熬夜会变傻”终于有科学依据了
  8. c语言 正号运算符 作用,C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,...
  9. 如何将JavaScript转化成Swift?(二)
  10. (转)移动互联加速金融科技的渗透 中国将成为全球最大智能投顾市场
  11. Win10 系统字体美化
  12. CQU python题库
  13. Scrapy爬取当当网畅销图书保存csv格式!最详细的教程!
  14. 5个常用的大数据可视化分析工具,你知道吗?
  15. Dell安装Ubuntu教程
  16. 计算机考研和软件的区别吗,考研考计算机与考软件有什么区别
  17. 《论文阅读》THE CURIOUS CASE OF NEURAL TEXT DeGENERATION
  18. 微信Windows客户端版本无法打开小程序问题的解决
  19. VSCode用Run code插件配置python环境(win10)
  20. C基础学习之C 存储类

热门文章

  1. spring boot 实现自定义排序功能
  2. php 判断联通移动电信,JavaScript_JavaScript判断手机号运营商是移动、联通、电信还是其他(代码简单),正则表达式判断所填入号码的 - phpStudy...
  3. imac android studio,MAC系统下Android Studio 实用小技巧 – 站长微资讯
  4. node 定时任务管理ctask-simple的使用
  5. 【渝粤题库】陕西师范大学163106旅游心理学 作业【专升本】
  6. java计算机毕业设计中小学家校通系统源码+mysql数据库+系统+部署+lw文档
  7. self-attention代码
  8. 安装 Jenkins 保姆级别教程 jdk17 安装插件htmlpublisher
  9. 【ROS入门21讲】发布者Publisher的编程使用
  10. 汇编语言实现冒泡法排序