Deep dive: Tips & tricks for porting games from other platforms to Windows 8

55
tricks for porting games from other platforms to Windows 8 Randy Spong Field Engineer Unity Technologies

description

Deep dive: Tips & tricks for porting games from other platforms to Windows 8. Randy Spong Field Engineer Unity Technologies. The Goal. Understand the work needed to bring your existing Unity project over to Microsoft’s Windows Store for Windows 8 and Windows RT devices. The Goal. - PowerPoint PPT Presentation

Transcript of Deep dive: Tips & tricks for porting games from other platforms to Windows 8

Page 1: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Deep dive: Tips & tricks for porting games from other platforms to Windows 8Randy SpongField EngineerUnity Technologies

Page 2: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

The Goal

Understand the work needed to bring your existing Unity project over to Microsoft’s Windows Store for Windows 8 and Windows RT devices

Page 3: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

The Goal

Understand the work needed to bring your existing Unity project over to Microsoft’s Windows Store for Windows 8 and Windows RT devices

Knowing the unique features & behaviors of Windows 8/RT and Unity for Windows Store Apps, you’ll be better prepared to estimate the amount of work required to port your project

Page 4: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

The Goal

Understand the work needed to bring your existing Unity project over to Microsoft’s Windows Store for Windows 8 and Windows RT devices

Knowing the unique features & behaviors of Windows 8/RT and Unity for Windows Store Apps, you’ll be better prepared to estimate the amount of work required to port your projectYour knowledge of the changes to the runtime APIs for Windows Store Apps will make your porting work go more quickly

Page 5: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

The Goal

Understand the work needed to bring your existing Unity project over to Microsoft’s Windows Store for Windows 8 and Windows RT devices

Knowing the unique features & behaviors of Windows 8/RT and Unity for Windows Store Apps, you’ll be better prepared to estimate the amount of work required to port your projectYour knowledge of the changes to the runtime APIs for Windows Store Apps will make your porting work go more quicklyYour understanding of performance hotspots and optimization techniques will help you extract maximum performance from Windows 8 and Windows RT devices

Page 6: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

The Goal

Understand the work needed to bring your existing Unity project over to Microsoft’s Windows Store for Windows 8 and Windows RT devices

Knowing the unique features & behaviors of Windows 8/RT and Unity for Windows Store Apps, you’ll be better prepared to estimate the amount of work required to port your projectYour knowledge of the changes to the runtime APIs for Windows Store Apps will make your porting work go more quicklyYour understanding of performance hotspots and optimization techniques will help you extract maximum performance from Windows 8 and Windows RT devices

Page 7: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Agenda

Overview of Windows 8 and Windows RTOverview of Unity’s Windows Store add-onPorting Existing CodeOptimizing PerformanceBest Practices for porting your Unity project

Page 8: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Windows 8 and Windows RT

Page 9: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Hardware Landscape

(Slide provided courtesy of Microsoft, 2012)

Page 10: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

New Category of Windows PCs

New design point Always on, always connected System on a chip Battery is primary power source Focus on low power

Both x86/x64 and ARM-based systems Covers a range of form factors

(Slide provided courtesy of Microsoft, 2012)

Page 11: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Range of Performance

NVIDIA GeForce 650 NVIDIA GeForce 650M NVIDIA Tegra 3 Qualcomm Adreno 2250

100

200

300

400

500

600

700

800

900

GPU Performance Comparison

GigaFLOPS

Page 12: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Windows 8/RT Device Capabilities

Windows 8 & RT devices scale in performance from phone-equivalent all the way to high-end multi-GPU gaming desktop

Touch is a first-class citizen Minimum device resolution is 1366x768 Windows RT has a minimum DirectX feature level of

9_1 May not have 4k texture support May not have simultaneous render targets

Page 13: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Unity for Windows Store

Page 14: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Differences

Unity’s Windows Store runtime is built on .NET Unity apps for Windows Store can only consume WinRT Components (no unmanaged DLLS)

Many new Windows devices have a trackpad and touchscreen that can be used simultaneously

Page 15: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Other Things to Watch Out For

No 64-bit Windows Store Apps just yet Boo, JavaScript not fully implemented Network classes not supported (WWW is fully implemented, though)

Cloth not supported Microphone not implemented

Page 16: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Other Things to Watch Out For, Continued

Animation of script variables is not allowed AnimationEvent callback functions with arguments

(Supported: a function with no arguments or with AnimationEvent argument)

GameObject.SendMessage - The function argument types the message receiver must exactly match the message (we don’t have type conversion)

No fog for devices with DX feature level less than 9.3 Example workaround at http://files.unity3d.com/tomas/Metro/Examples/MyCustomFog.shader

Page 17: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Things to Get Excited About

C# debugging in Visual Studio Building the Unity project generates a tweakable Visual Studio project Simplifies native code plugin integration

Your ported code pretty much ‘just works’ on Windows Phone 8

Page 18: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Porting Existing Code

Page 19: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Overview

Disallowed Windows APIs Sharing plugin code between the Editor and your Windows Store App

Page 20: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Disallowed Windows APIs

HashTable ArrayList System.Xml.XmlDocument System.Threading.Thread And a few thousand Win32 functions

Page 21: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Disallowed Windows APIs

HashTable

Use a Dictionary Better performance for value types Not necessarily thread-safe Type-constrained

Page 22: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Disallowed Windows APIs

ArrayList

Use a Dictionary or a List<T> Possibly a small loss of performance

Page 23: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Disallowed Windows APIs

System.Xml.XmlDocument

Don’t use XML But if you have to… use System.Xml.Linq Better is to use JSON or YAML

Page 24: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Disallowed Windows APIs

System.Threading.Thread

Use ThreadPoolshttp://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool

Page 25: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Disallowed Windows APIs

Win32 APIs

Winsock2, CreateThread, HeapCreate, Sleep, etc.

(SuspendThread, GetThreadContext, SetUnhandledExceptionFilter are the ones that really threw us for a loop)

Find Windows 8/RT -compatible alternatives at http://msdn.microsoft.com/en-us/library/windows/apps/hh464945.aspx

Page 26: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Plugins in Windows Store Apps

Windows Store Apps can only consume WinRT Components Unmanaged legacy native code DLLs aren’t allowed

Check out the details at

http://msdn.microsoft.com/en-us/library/windows/apps/hh441569.aspx

The Unity Editor is still based on Mono Make sure your WinRT Component can also be built as a legacy

native code DLL (Windows Store functionality can be stubbed out)

Page 27: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Optimizing Performance

Page 28: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Component Caching

Interop in Unity for Windows Store Apps is expensive

Minimize the Unity APIs you call each frame, including Component references

Page 29: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Component Caching

Bad

public class example : MonoBehaviour { void Update() { transform.Translate(0, 0, 5); }}

Page 30: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Component Caching

Good

public class example : MonoBehaviour { private Transform myTransform;

void Awake() { myTransform = transform; } void Update() { myTransform.Translate(0, 0, 5); }}

Page 31: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Component Caching

Terrible

public class example : MonoBehaviour { void Update() { for (int i = 0; i < 1000; ++i) { transform.Translate(0, 0, transform.position.z + 0.005f); } }}

Page 32: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

GameObject Pooling

Instantiating and Destroying GameObjects is expensive Reuse when possible!

Page 33: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

GameObject Pooling

Instantiating and Destroying GameObjects is expensive Reuse when possible!

Instead of Destroying:gameObject.SetActive(false);MyPoolManager.AddToFreePool(gameObject);

Instead of Instantiating:GameObject gameObject = MyPoolManager.GetFreeObject();SetupObjectDefaults(gameObject);gameObject.SetActive(true);

Page 34: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Draw Calls - Dynamic Batching

Works automatically Maximum of 900 vertex attributes per mesh Differently scaled objects won’t batch together Dynamic Batching incurs some CPU overhead at runtime

Page 35: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Draw Calls - Static Batching

Supports arbitrarily complex geometry Can significantly reduce CPU usage at runtime for setting up draw

calls

Objects cannot move, rotate, or scale Objects must be marked as static in Unity Uses lots of device memory

Page 36: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Draw Calls - Texture Atlasing

Batching only works when objects share materials

Combine object textures into a Texture Atlas

Page 37: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Draw Calls - Texture Atlasing

Page 38: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Draw Calls - Texture Atlasing

Page 39: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Unity Features on Windows RT

Don’t Use Desktop shaders Terrains Realtime shadows Dense particles Non-tessellated sprites

Page 40: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Sprite Meshes

(Images provided courtesy of Bento Studio [Uni2D], 2013)

Page 41: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Use Our Documentation

Page 43: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Best Practices

Page 44: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Animated Loading Screen

Camouflages your loading times Gives the user a sense of progress

Page 45: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Target Device Testing

Regularly use different devices for development testing Including the crappy ones

Page 46: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Stay Compliant

Run the WACK tool regularly Aim for daily runs when you’re refactoring for Windows 8 support or

laying down new .NET code

Page 47: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Recap

Page 48: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Recap - Windows 8 and Windows RT Windows 8 and RT are mobile operating systems

Touch is a first-class citizen Broad range of form factors Broad range of performance capabilities

Page 49: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Recap – Unity for Windows Store

Need to handle both trackpad and mouse input in the same app

Native code plugins have to be rewritten as WinRT Components

The Editor can’t consume WinRT Components (need to use a version of the com

Page 50: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Recap – Porting Existing Code

Convert usage of HashTable and ArrayList to Dictionary

Rewrite native code plugins as WinRT Components Keep a native code version (which stubs Windows Store

functionality) for using in the Editor’s Play Mode

Page 51: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Recap – Optimizing Performance

Cache Component references Pool GameObjects Batch draw calls Use texture atlases to increase batch sizes Avoid expensive “do it all” features like terrain Use Unity’s extensive optimization resources

http://docs.unity3d.com/Documentation/Manual/ MobileOptimisation.html http://docs.unity3d.com/Documentation/Manual/iphone- PracticalGuide.html http://docs.unity3d.com/Documentation/Manual/ OptimizingGraphicsPerformance.html

Page 52: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Recap – Best Practices

Test on low-end devices more than high-end devices

Run the WACK toolkit regularly Finds coding errors and use of disallowed APIs Informs you about potential certification failures

Page 53: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Resources for Windows 8 & RT

Disallowed .NET APIshttp://msdn.microsoft.com/en-us/library/windows/apps/xaml/br230302.aspx

Allowed win32 APIshttp://msdn.microsoft.com/en-us/library/windows/apps/br205757.aspx

Replacing disallowed win32 APIshttp://msdn.microsoft.com/en-us/library/windows/apps/hh464945.aspx

Windows 8 & RT Hardware Compatibility FAQhttp://www.microsoft.com/en-us/windows/compatibility/win8/compatcenter/faq

Page 54: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8

Resources for Unity

Windows 8 and Windows RT Open Beta Sign-Uphttp://unity3d.com/beta/windowsstoreapps

Windows 8/RT Help In the Editor: “Help -> Unity Manual (Metro)”

Mobile Optimization Tipshttp://docs.unity3d.com/Documentation/Manual/MobileOptimisation.html

Optimizing Graphics Performancehttp://docs.unity3d.com/Documentation/Manual/OptimizingGraphicsPerformance.html

Practical Guide to Optimization for Mobileshttp://docs.unity3d.com/Documentation/Manual/iphone-PracticalGuide.html

Page 55: Deep  dive: Tips & tricks for porting games from other platforms to Windows 8