Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Social Gaming with Windows Phone and Azure

Social Gaming with Windows Phone and Azure

Presented at TechEd South Africa 2011

Daron Yondem

October 19, 2011
Tweet

More Decks by Daron Yondem

Other Decks in Programming

Transcript

  1. 17-20 OCTOBER 2011
    DURBAN ICC

    View Slide

  2. Submit your session
    evaluation for a
    chance to win!
    Sponsored by MVA
    http://microsoftvirtualacademy.com

    View Slide

  3. Social Gaming with
    Windows Phone and Azure
    Daron Yondem
    Chief Architect | DEVELOAD Software
    Microsof Regional Director
    Silverlight MVP
    INETA MEA President

    View Slide

  4. Daron Yöndem is
    • Silverlight MVP
    • Microsoft Regional Director for MEA
    • INETA MEA President
    • Book Author about HTML5, ASP.NET AJAX,
    Silverlight
    • Architect at DEVELOAD Software
    • Blog at http://daron.yondem.com

    View Slide

  5. DEVELOAD is
    • Consulting
    – Software architecture and design
    – Custom software development of Windows, Web
    Windows Phone, Azure and Silverlight applications
    – Mentoring services to get you started and keep you
    going
    • Web site: www.deveload.com

    View Slide

  6. You Are...
    • Interested in building WP7 Games
    • Wondering what Cloud computing can offer to
    help your serve millions of gamers?

    View Slide

  7. Let’s start with...
    • What Cloud computing can offer?
    • What we have in hand with Windows Azure?
    • What kind of integration scenarios can happen
    between WP7 and Azure.
    • How can Azure help me fascilitade building
    Social Games reacing millions of people?

    View Slide

  8. Why Phone + Cloud?
    • The cloud levels the playing
    field
    • The cloud provides a larger
    pool of resources from which
    to pull
    • The cloud provides a way to
    reach across device platforms

    View Slide

  9. Why WP7 and Windows Azure?
    • PaaS: you build it, Windows Azure runs it
    • Automatic O/S patching
    • Scalable
    • Utility billing
    • Additional services (e.g. ACS, Traffic
    Manager, Caching, CDN, etc.)
    • Common development tools
    – Visual Studio
    – Languages
    – Emulators for development

    View Slide

  10. Identity

    View Slide

  11. Identity Options
    • Create your own (e.g. username + password,
    token)
    – Custom model
    – ASP.NET Membership Providers
    • Use a single existing identity system (e.g. Live Id,
    Facebook, etc.)
    • Outsource identity management (e.g. Access
    Control Service)

    View Slide

  12. To learn more …
    Authenticating Users in a Windows Phone 7
    App via Access Control Service, OData
    Services and Windows Azure
    http://bit.ly/wp7acs

    View Slide

  13. Storage

    View Slide

  14. Storage
    • SQL Azure
    – Relational database
    – Highly available
    – Managed for you as a service
    • Windows Azure Tables
    – Non-relational structured storage
    – Massive scale-out
    – OData
    • Windows Azure Blobs
    – Big files
    – REST

    View Slide

  15. SQL Azure: OData Service
    • Client sends data to
    web role
    • Web role stores data
    in SQL Azure
    Web
    Role
    (1)
    (2)

    View Slide

  16. Windows Azure Blobs: Public Blobs
    • Client sends data to
    web role
    • Web role stores data
    in blobs
    • Client fetches public
    blobs directly
    Web
    Role
    (1)
    (2)
    (3)

    View Slide

  17. Windows Azure Blobs: SAS
    • Client gets Shared Access
    Signature from web role
    • Client stores data in
    blobs
    • Client fetches public
    blobs directly
    Web
    Role

    View Slide

  18. Windows Azure Tables: Proxy Calls
    • Client sends data to
    web role
    • Web role stores data
    in blobs
    Web
    Role

    View Slide

  19. Do not store your secrets on the phone

    View Slide

  20. Services

    View Slide

  21. Web Role versus Worker Role
    • Web Role has IIS
    • Worker Role does
    not
    – DLL with Main()
    • Both implement
    the
    RoleEntryPoint

    View Slide

  22. Scaling Work in Windows Azure
    1. Web role receives
    message
    2. Web role enqueues
    work
    3. Worker role polls
    queue
    4. Worker role sends
    notifications
    MPNS
    Worker
    Role
    Web
    Role
    (1)
    (2)
    (3)
    (4)

    View Slide

  23. Multitenancy
    • You can have more than one application
    running in your role instance

    View Slide

  24. Content Delivery Network
    CD
    N
    CD
    N
    CD
    N
    CD
    N
    CD
    N
    CD
    N

    View Slide

  25. Communications

    View Slide

  26. Communications
    • Two communication models
    – Phone-initiated
    – Cloud-initiated

    View Slide

  27. Phone-Initiated Communication
    Options
    • HTTP-based, request/response
    • Framework choices (WCF, OData, WebRequest,
    etc.)
    • Wire format choices (SOAP, JSON, POX, etc.)

    View Slide

  28. Cloud-Initiated Communication
    • Push Notifications
    – Single connection between phone and Microsoft Push
    Notification Service
    – Bandwidth- and battery-friendly
    – No guarantee of delivery
    • Three kinds of push notifications
    – Raw – send a message to an application
    – Toast – send a message to the user
    – Tile – update an image, title, or count

    View Slide

  29. Subscribing to Push Notifications
    • Phone opens a channel
    • Phone sends URL to
    cloud
    • Cloud pushes
    notifications via URL
    • Microsoft Push
    Notification service
    notifies phone
    MPNS
    Web
    Role

    View Slide

  30. Let’s go on with...
    • How can we build social games with
    Silverlight?
    • Performance Tips and Tricks

    View Slide

  31. First : Performance!

    View Slide

  32. Threading
    • UIThread
    – PerFrame Callbacks, Touch, Networking, User
    Code, Layout
    • RenderThread (Composition Thread)
    – Opacity, DoubleAnimations, Perspective
    Transforms, Rectangular Clips, RenderTransforms
    • Worker Threads

    View Slide

  33. • Application.Current.Host.Settings.
    • EnableFrameRateCounter = true;
    Fillrate

    View Slide

  34. Application.Current.Host.Settings.EnableRedrawRegions = true;

    View Slide

  35. Application.Current.Host.Settings.EnableCacheVisualization= true;

    View Slide

  36. Performance Strategy
    Minimize UI Thread Work
    Leverage Off-Thread
    Use the GPU
    Less is more!

    View Slide

  37. CacheMode = BitmapCache

    View Slide

  38. Visibility OR Opacity?

    View Slide

  39. JPEG or PNG?
    Faster Decoding
    Opacity

    View Slide

  40. XAML or Pictures?

    View Slide

  41. App Start-Up
    Delay Loading the Unneeded!
    Include applicationsplashscreen.jpg
    Use a splash screen

    View Slide

  42. DON’T!
    Non-rectangular clips Large textures
    ( > 2K pixels either way)
    Complex animations
    (e.g. ColorAnimation)
    Opacity mask

    View Slide

  43. Second: How To?

    View Slide

  44. Step 1 : Timer
    • CompositionTarget.Rendering
    – Frame Animations
    • DispatchTimer
    – It’s inside the UIThread
    • StoryBoard
    • System.Thread.Timer
    public partial class Page : UserControl
    {
    System.Threading.Timer Sayac;
    public Page()
    {
    InitializeComponent();
    Sayac = new System.Threading.Timer(Tick, TOP, 500, 500);
    }
    public void Tick(object sender)
    {
    ((Ellipse)sender).Dispatcher.BeginInvoke(delegate() { ((Ellipse)sender).Height +=
    1; });
    }
    }

    View Slide

  45. Step 2 : Graphics
    • 2D games easy to build inside Silverlight
    • What about 3D?
    – Kit3D - http://www.markdawson.org/kit3d/
    – Balder - http://www.codeplex.com/Balder
    – XNA!
    • You can create a whole new 3D world!

    View Slide

  46. Step 3 : Audio
    • Windows Media Audio and MP3 support.
    • XNA Libraries to play effects and wma files.
    • MediaElement can help you for background
    music.
    • You can even have live streams in your game!

    View Slide

  47. Final Step: Pyhsics
    • Farseer Pyhsics Engine
    – It’s for both Silverlight and XNA!
    – Includes helpers and behaviors easy to use inside
    Expression Blend!

    View Slide

  48. In Conclusion
    • Azure and Cloud
    – Helps us serve millions of gamers with web/worker
    roles, CDN, SQL Azure, Notification Services
    – Azure Toolkit for Windows Phone helps us there.
    • Performanca and tactics for WP7 game
    development
    – Composition Thread, DoubleAnimations, Performance
    Counter and so on.
    – Using Dispatcher and StoryBoards together.

    View Slide

  49. THANKS!!!
    [email protected]
    http://daron.yondem.com

    View Slide

  50. Submit your session
    evaluation for a
    chance to win!
    Sponsored by MVA
    http://microsoftvirtualacademy.com

    View Slide