deep dive: tips & tricks for porting games from other platforms to windows 8

Post on 02-Jan-2016

50 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

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

Deep dive: Tips & tricks for porting games from other platforms to Windows 8Randy SpongField EngineerUnity 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

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

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

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

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

Agenda

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

Windows 8 and Windows RT

Hardware Landscape

(Slide provided courtesy of Microsoft, 2012)

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)

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

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

Unity for Windows Store

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

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

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

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

Porting Existing Code

Overview

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

Disallowed Windows APIs

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

Disallowed Windows APIs

HashTable

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

Disallowed Windows APIs

ArrayList

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

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

Disallowed Windows APIs

System.Threading.Thread

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

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

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)

Optimizing Performance

Component Caching

Interop in Unity for Windows Store Apps is expensive

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

Component Caching

Bad

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

Component Caching

Good

public class example : MonoBehaviour { private Transform myTransform;

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

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); } }}

GameObject Pooling

Instantiating and Destroying GameObjects is expensive Reuse when possible!

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);

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

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

Draw Calls - Texture Atlasing

Batching only works when objects share materials

Combine object textures into a Texture Atlas

Draw Calls - Texture Atlasing

Draw Calls - Texture Atlasing

Unity Features on Windows RT

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

Sprite Meshes

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

Use Our Documentation

Best Practices

Animated Loading Screen

Camouflages your loading times Gives the user a sense of progress

Target Device Testing

Regularly use different devices for development testing Including the crappy ones

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

Recap

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

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

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

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

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

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

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

top related