html5-img
1 / 55

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 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.

Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Deep dive: Tips & tricks for porting games from other platforms to Windows 8 Randy Spong Field Engineer Unity Technologies

  2. 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

  3. 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

  4. 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 Your knowledge of the changes to the runtime APIs for WindowsStore Apps will make your porting work go more quickly

  5. 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 Your knowledge of the changes to the runtime APIs for WindowsStore Apps will make your porting work go more quickly Your understanding of performance hotspots and optimization techniques will help you extract maximum performance from Windows 8 and Windows RT devices

  6. 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 Your knowledge of the changes to the runtime APIs for WindowsStore Apps will make your porting work go more quickly Your understanding of performance hotspots and optimization techniques will help you extract maximum performance from Windows 8 and Windows RT devices

  7. Agenda Overview of Windows 8 and Windows RT Overview of Unity’s Windows Store add-on Porting Existing Code Optimizing Performance Best Practices for porting your Unity project

  8. Windows 8 and Windows RT

  9. Hardware Landscape (Slide provided courtesy of Microsoft, 2012)

  10. 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)

  11. Range of Performance

  12. 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

  13. Unity for Windows Store

  14. 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

  15. 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

  16. 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

  17. 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

  18. Porting Existing Code

  19. Overview • Disallowed Windows APIs • Sharing plugin code between the Editor and your Windows Store App

  20. Disallowed Windows APIs • HashTable • ArrayList • System.Xml.XmlDocument • System.Threading.Thread • And a few thousand Win32 functions

  21. Disallowed Windows APIs HashTable Use a Dictionary • Better performance for value types • Not necessarily thread-safe • Type-constrained

  22. Disallowed Windows APIs ArrayList Use a Dictionary or a List<T> • Possibly a small loss of performance

  23. 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

  24. Disallowed Windows APIs System.Threading.Thread Use ThreadPools http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool

  25. 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 athttp://msdn.microsoft.com/en-us/library/windows/apps/hh464945.aspx

  26. 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)

  27. Optimizing Performance

  28. Component Caching Interop in Unity for Windows Store Apps is expensive Minimize the Unity APIs you call each frame, including Component references

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

  30. Component Caching Good public class example : MonoBehaviour { private TransformmyTransform; void Awake() {myTransform= transform; } void Update() {myTransform.Translate(0, 0, 5); }}

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

  32. GameObject Pooling Instantiating and Destroying GameObjects is expensive • Reuse when possible!

  33. GameObject Pooling Instantiating and Destroying GameObjects is expensive • Reuse when possible! Instead of Destroying: gameObject.SetActive(false); MyPoolManager.AddToFreePool(gameObject); Instead of Instantiating: GameObjectgameObject = MyPoolManager.GetFreeObject(); SetupObjectDefaults(gameObject); gameObject.SetActive(true);

  34. 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

  35. 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

  36. Draw Calls - Texture Atlasing • Batching only works when objects share materials • Combine object textures into a Texture Atlas

  37. Draw Calls - Texture Atlasing

  38. Draw Calls - Texture Atlasing

  39. Unity Features on Windows RT Don’t Use • Desktop shaders • Terrains • Realtime shadows • Dense particles • Non-tessellated sprites

  40. Sprite Meshes (Images provided courtesy of Bento Studio [Uni2D], 2013)

  41. Use Our Documentation

  42. Use Our Documentation The Unity documentation is full of concise and useful optimization advice Practical Guide to Optimization for Mobiles Optimizing Graphics Performance Mobile Developer Checklist – Optimizations

  43. Best Practices

  44. Animated Loading Screen • Camouflages your loading times • Gives the user a sense of progress

  45. Target Device Testing • Regularly use different devices for development testing • Including the crappy ones

  46. 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

  47. Recap

  48. 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

  49. 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

  50. 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

More Related