in

XNA: Gaming across many platforms and the cloud

I’ve been working with UK XNA MVP Charles Humphrey on project ZuneRay. ZuneRay is a raycasting engine built by Charles’ for the Zune HD using XNA 3.1. With Windows Phone 7 Series in the pipeline we used the Zune HD as a target test platform with the intention of porting it to WP7S once the tools became available. ZuneRay uses a classic approach to delivering a 3D experience without requiring 3D support – at the time we didn’t know if 3D support would be in the Windows Phone 7 Series XNA version – so it was a pleasant surprise to find 3D support in there, and very satisfying to see ZuneRay port to XNA 4.0 and the WP7S really easily.

Well the tools CTP is now available, so Charles and I have been working away on ZuneRay with excellent results. ZuneRay is an XNA 3.1 with Zune HD extensions project. You get a Windows version ‘for free’, and an Xbox version just required the additional of Gamepad support. Moving ZuneRay to WP7S required upgrading the project to XNA 4.0. There is no ‘wizard’ to do this, the best approach is to create a new XNA 4.0 game and then pull in all your existing code and content. There are some platform specific bits in the generated Game1.CS file that you want to ensure are retained – but coming from the Zune platform originally these already existed.

There are breaking changes between Xna 3.1 and Xna 4.0 – the main ones for ZuneRay being around storage API, change of screen resolution and the changes in SpriteBatch parameters – but none of these took long to sort out. Shawn Hargreaves pointed out that WP7S running at 800x480 has 25% more pixels to draw than the original Xbox – but less CPU/GPU power to do it. The WP7S has a dedicated hardware scaler which means you can render your game at lower resolutions – like 600x360 56% of pixel data - and have the device scale it to fill the screen. While developing in the emulator this scaling functionality isn’t available, but then as the emulator is just that – not a simulator – your game takes advantage of the underlying PC hardware performance.

ZuneRay1

Project ZuneRay

Now I have the game running across Windows, Xbox, Windows Phone 7 Series and Zune HD – I wanted to integrate the cloud. My idea for demonstration purposes was really simple. Capture a camera image, publish it to the cloud and then have ZuneRay games acquire the image and use it in game as a wall texture.

Storing my image in the cloud is very simple – the image copy to Windows Azure Blob storage just uses the code I posted a while back. To capture the web cam I used a WPF application by Geert van Horrik – all I had to add was the resizing of the image to fit with the game requirements before sending it to Azure blob storage.

To retrieve the image from the blob store proved to be the tricky part. Although XNA is hugely consistent across the platforms the networking support varies enormously. The Zune has no programmatic network support. The Xbox only has networking to the Xbox  Live services. Windows Phone 7 Series has a good sprinkling of support in various areas and Windows of course has the lot.

Looking at Windows Phone I was able to use the following code to simple make a webrequest using a known URL to the current image file.

  1. private void GetTextureFromAzure()
  2. {
  3.  
  4.     HttpWebRequest request;
  5.  
  6.     HttpWebResponse response = null;
  7.  
  8.     try
  9.     {
  10.  
  11.         request = (HttpWebRequest)WebRequest.Create(new Uri(@"https://xxxx.blob.core.windows.net/publicfiles/dynamic.png"));
  12.  
  13.         response = (HttpWebResponse)request.BeginGetResponse(new AsyncCallback(RespCallback), request);
  14.  
  15.     }
  16.     catch { }
  17. }

The callback function then uses Texture2D.FromStream to create a new texture from the response stream.

  1. private void RespCallback(IAsyncResult asynchronousResult)
  2. {
  3.  
  4.     try
  5.     {
  6.         HttpWebRequest myRequestState = (HttpWebRequest)asynchronousResult.AsyncState;
  7.  
  8.         HttpWebResponse response = (HttpWebResponse)myRequestState.EndGetResponse(asynchronousResult);
  9.  
  10.         Stream s = response.GetResponseStream();
  11.  
  12.         map.Textures[5] = Texture2D.FromStream(GraphicsDevice, s);
  13.  
  14.         s.Close();
  15.  
  16.         response.Close();
  17.  
  18.     }
  19.  
  20.     catch (System.Net.WebException)
  21.     {
  22.  
  23.         //if (response != null)
  24.  
  25.         //    response.Close();
  26.  
  27.     }
  28.  
  29.  
  30. }

The maps.texture array contains the textures presented as walls and objects in the game. By directly replacing the texture[5] only certain walls in the game levels present the web cam image, as can be seen below.

ZuneRay2

I use a count down timer to poll for a new image every minute for the purposes of this demo. I want to upgrade this poll mechanism with a push notification using the new Push Notification service for WP7S. In this way, the web cam application will be able to publish an image and then notify WP7S phones running the game of a new game texture. The games can then go and retrieve the image based on user preference for data service usage.

Charles and I intend to share more of Project ZuneRay’s code shortly.

Digg This

» Trackbacks & Pingbacks

  1. Pingback from Twitter Trackbacks for XNA: Gaming across many platforms and the cloud - wotudo [wotudo.net] on Topsy.com
  2. This post was mentioned on Twitter by Paulfo: New blog post: http://tinyurl.com/yemoxxu - XNA: Gaming across many platforms and the cloud. #WP7DEV

    uberVU - social comments — March 26, 2010 2:24 AM
  3. ... הדברת פשפשים - מכל זה אנו חייבים לעשות משהו בעצמכם יכול להיות הרבה יותר אך מדבירים מוסמכים. לפני הפעולות היו ערימות לשלשת בעובי מס' סנטימטר גגות , מתקני חשמל ומרפסות. מיותר לחשוב כיצד היו... XNA: Gaming across many platforms and the cloud - wotudo

    מדבירים מוסמכים — November 8, 2013 1:26 PM
  4. ... הסרת משקפיים השוואת מחירים - מרבית הדוגמאות הן לכיוון הנשי, משמע, מרבית הטיפולים מקושרים למין הנשי. מכשיר הלייזר ניתן לפגוע בפיגמנט השערה הנקרא מלנין, להגיע לשורש השערה ולהסיר אותה סרטון הסרת משקפיים.

    ... XNA: Gaming across many platforms and the

    סרטון הסרת משקפיים — November 18, 2013 7:50 PM
  5. ... - Take into deliberation on how to get specific share prices of the better your chances of losses. They can be applied and employed for almost any market condition. Intraday marke... XNA: Gaming across many platforms and the cloud - wotudo ...

    Best Forex Trading System For Beginners — July 16, 2014 1:28 AM
  6. XNA: Gaming across many platforms and the cloud - wotudo

    Pre Workout Formula — October 27, 2014 7:39 PM
Trackback url for this post:
http://wotudo.net/blogs/wotudo/trackback.ashx?PostID=955

» Comments

  1. hello, hope ur well. i had just stubled across this and am awestruck! this is exactly the set-up im looking to do to publish my gaming content across these Windows Platforms. thanks so much for sharing your ideas, i hope to learn more.
    Jabari Dumisani — May 5, 2010 4:10 PM

» Leave a Comment

(required) 
(optional)
(required) 

Submit