The hand-drawn, 2D indie darling Cuphead just released to Nintendo Switch. We talked with Studio MDHR engineer Adam Winkels to learn about the team’s approach to optimizing for the platform and he shares his advice for developers in today’s blog.
手绘的2D独立宠儿Cuphead 刚刚发布给Nintendo Switch。 我们与Studio MDHR工程师Adam Winkels进行了交谈,以了解团队针对平台进行优化的方法,他在今天的博客中分享了对开发人员的建议。
“Bringing Cuphead to Nintendo Switch was a very smooth endeavor. Much of the game worked right out of the box, allowing us to focus on making sure the experience and performance was up to our standards,” – Adam Winkels, Engineer at Studio MDHR.
“将 Cuphead 带到Nintendo Switch是一项非常顺利的努力。 游戏的大部分内容都是开箱即用的,使我们能够专注于确保体验和性能达到我们的标准。” – Studio MDHR的工程师Adam Winkels。
Nintendo Switch的预先计划 (Pre-plan for Nintendo Switch)
While it may be obvious to some, Studio MDHR encourages teams to have the foresight to target the Nintendo Switch hardware from the onset.
尽管对某些人来说显而易见,但Studio MDHR鼓励团队具有远见卓识,从一开始就瞄准Nintendo Switch硬件。
“When working on a new game that you’d like to publish (or eventually bring) to Nintendo Switch, always design and performance test it with the platform’s minimum spec target in mind. This avoids a situation where you only test your game on a high powered development PC only to realize that the game performs unexpectedly on the target hardware.”
“在开发要发布(或最终引入)Nintendo Switch的新游戏时,请始终在设计和性能测试时考虑平台的最低规格目标。 这样可以避免只在高功率开发PC上测试游戏,却意识到该游戏在目标硬件上的性能异常的情况。”
尽早并经常进行简介 (Profile early and often)
The team advocates the use of profilers to optimize for the Nintendo Switch hardware, helping create the smooth and responsive gameplay that Cuphead is known for.
该团队提倡使用分析器针对Nintendo Switch硬件进行优化,以帮助创建 Cuphead 闻名 的流畅响应式游戏 。
“Be very cognizant of performance bottlenecks in your game. We used Unity’s built-in profiler and Nintendo’s own CPU profiler to analyze our code, clean up any performance spikes, and do our best to make our baseline processor usage as low as possible. Don’t be afraid to use these tools early and often to address problem areas before the technical debt of re-architecting inefficient systems becomes too large.”
“非常清楚游戏中的性能瓶颈。 我们使用Unity的内置探查器和Nintendo自己的CPU探查器来分析我们的代码,清理所有性能峰值,并尽最大努力使基线处理器使用率尽可能低。 不要害怕在重新架构效率低下的系统的技术负担变得太大之前,尽早使用这些工具,并且经常使用它们来解决问题区域。”
使用SpriteAtlas释放RAM (Free up RAM with SpriteAtlas)
In its initial release, Cuphead’s 45,000+ hand-drawn animation frames were individually packaged, but that approach isn’t super efficient. The answer: Sprite Atlases.
在其初始版本中, Cuphead的45,000 多个手绘动画帧是单独包装的,但是这种方法并不是非常有效。 答案: 精灵地图集 。
“We were running low on RAM for some of our larger levels (looking at you, Djimmi the Great!), so we chose to use Unity’s Sprite Atlas feature. After trimming transparencies and allowing for in-memory compression using ASTC, Sprite Atlases significantly reduced RAM usage.”
“在我们的某些较大级别上,我们的RAM不足(看着您,Djimmi大帝!),因此我们选择使用Unity的Sprite Atlas功能。 在调整了透明度并允许使用ASTC进行内存内压缩之后,Sprite Atlases 大大 减少了RAM的使用。”
AssetBundles的好处 (The benefits of AssetBundles)
Unity’s AssetBundles helped Studio MDHR shrink not only the total size of the game but also set them up for success for when they release future updates.
Unity的 AssetBundles不仅 帮助Studio MDHR缩小了游戏的整体尺寸,而且还为发行未来的更新做好了准备。
“Use AssetBundles for as much of your game as you can. For Cuphead, we took the SpriteAtlases and split them into compressed AssetBundles. This significantly helped reduce the size of the game (given hard drive space is a premium) and made it much easier to adhere to Nintendo’s patch size requirements. AssetBundles are also an effective way to ensure that your game’s data layout does not change too much between builds.”
“尽可能多地使用AssetBundles游戏。 对于 Cuphead ,我们获取了SpriteAtlases并将其拆分为压缩的AssetBundles。 这极大地帮助减小了游戏的大小(给硬盘空间带来了额外的收益),并使满足Nintendo补丁尺寸要求变得更加容易。 AssetBundles也是确保游戏数据布局在两次构建之间不会发生太大变化的有效方法。”
调整着色器加载行为 (Adjust shader loading behavior)
The team saw benefit from preloading shaders to avoid performance hiccups when new or rarely used sprites loaded into a level for the first time.
该团队看到了从预加载着色器中受益的好处,可以避免在新的或很少使用的精灵第一次加载到关卡中时出现性能故障。
“We ran into a slight performance hitch when first instantiating certain enemies in our Run ‘n Gun levels. After some digging, we discovered that the shader loading was the culprit. Thankfully, Unity provides the ability to preload shaders using Shader Variant Collections, so although the problem was tricky to identify, it was easy to fix!”
“当我们首先在Run'n Gun关卡中实例化某些敌人时,我们遇到了轻微的性能问题。 经过一番挖掘后,我们发现着色器加载是罪魁祸首。 幸运的是,Unity提供了使用“ Shader Variant Collections” 预加载着色器的功能 ,因此,尽管很难识别问题,但很容易解决!”
考虑垃圾收集调整 (Consider garbage collection tweaks)
Unity does a great job of automatic garbage collection, but the team opted to create manual calls to realize additional performance gains.
Unity在 自动垃圾收集方面 做得很出色 ,但是团队选择创建手动调用来实现额外的性能提升。
“Although there isn’t a direct way to control the size of the heap in Unity, you can force it to expand by manually allocating memory when you launch your game. Luckily, we had the RAM budget to increase the heap so that it collected once every 15-20 minutes. Given we also trigger garbage collection on every pause, load, or restart (when invisible to the player) and because, well, Cuphead is a very difficult game, it is extraordinarily unlikely that players will be in a level long enough to experience garbage collection during gameplay.”
“尽管在Unity中没有直接控制堆大小的方法,但是您可以在启动游戏时通过手动分配内存来强制其扩展。 幸运的是,我们有RAM预算来增加堆,以便每15-20分钟收集一次。 考虑到我们还会在每次暂停,加载或重启时触发垃圾收集(当玩家不可见时),并且由于 Cuphead 是一款非常困难的游戏,因此玩家不可能处于足够长时间来体验垃圾收集的级别在玩游戏期间。”
那是所有人! (That’s all folks!)
If you’d like to learn more about Studio MDHR and Cuphead (now available on Nintendo Switch!), check out the official Made with Unity page. To learn more about creating games for the Nintendo Switch platform, visit the Nintendo Developer Portal.
如果您想了解更多关于工作室MDHR和 Cuphead( 现已 任天堂开关!),请参阅官方 制造使用Unity页 。 要了解有关为Nintendo Switch平台创建游戏的更多信息,请访问 Nintendo Developer Portal 。
翻译自: https://blogs.unity3d.com/2019/04/18/cuphead-developers-tips-to-optimize-for-nintendo-switch/