KillThePeas-WindowsPhone7Series

It’s been a while since my last post as the new projects I’m working on are still not publicly released.  However, last night I spent some time updating the Popfly Game Engine project on codeplex to get Popfly games running on Windows Phone 7 Series:

http://popflygameengine.codeplex.com/SourceControl/list/changesets

It took about two hours from downloading the tools released at MIX to having Kill the Peas! up and running on the included emulator (see above).  That includes some time spent reading documentation, digging up the game code for Kill the Peas and figuring out conditional compilation in C# (I’m a C++ guy - #if?? #ifdef all the way). 

So, what did it take?  The answer is: not much.  They really did include essentially the full Silverlight runtime minus the browser / scripting integration classes.  So strictly speaking, the only real change I had to make was to create a new project, include the files and replace some includes of the System.Windows.Browser namespace with System.Net to get HttpUtility.UrlDecode (used in reading some of the xml files) and remove the attributes used to interact with an HTML page.  However, I wanted things a bit cleaner than that.

I wanted to keep using the same code as much as possible for both the standard Silverlight web app version of the project as well as the WP7S version.  To do this, I created a second project “WindowsPhoneGameEngine” at the same level as the original “GameEngine” solution.  I then added an additional conditional compilation symbol “Phone” to the WindowsPhoneGameEngine and use #if statements to deal with any required differences.  This allowed the same files to compile in either project.  I did run into a few snafus.

If you’re familiar with how the XAML/CS files interplay with each other, there are some intermediate “.g.cs” files generated to init your objects from the XAML.  Unfortunately, when you create two projects in the same solution in the same directory, the both end up using the same intermediate and output directores “obj\debug|release” and “bin\debug|release” which can end up confusing compilation.  In order to deal with this, it’s fairly easy to specify in the project properties via the IDE to use a different bin directory – just right click the project, select properties, choose the build tab and change the Output path. 

However, there’s not a nice way in the IDE to change the intermediate “obj” directory.  Thankfully, this post from Jason Olson, along with this helpful comment from Pradeep Prabhakar, explained how to edit the .csproj file to set the intermediate directory.  With those changes, the project built an ran just fine.

Well, not quite.  I did make one additional change, but I’m not sure it was strictly necessary.  It’s bugged me since we released this project that it required a couple binary only dependencies.  Rather than try to figure out whether the 0.4 DLR works on Windows Phone 7 Series and dig up the two binary dependencies we weren’t able to release as MsPL, I decided to remove support for “Custom Code” behaviors.  At first this might seem somewhat onerous, but I believe any remaining developers working on this project are probably comfortable enough with C# and XML that they’d be able to rewrite any old custom behaviors in C# and add them to the project as built-in behaviors.  Then, all you need to do is replace your old custom code behaviors in your default.game file with your new built in behavior and your game should be working just as before, only faster and with a smaller binary since we no longer need to include any scripting components. 

Just to make things clear, I don’t have any connection to the Windows Phone team, and I only learned about the development story with the rest of you watching the talks at http://live.visitmix.com on Monday.  I downloaded the tools with the rest of you from http://developer.windowsphone.com and had Kill the Peas up and running with about an hour’s worth of effort after installing the tools.  I don’t have hardware to try this out, but it was running great in debug mode in the emulator on my single-core 1.3Ghz Core 2 Solo almost-netbook.  Congrats to the Windows Phone team.  This stuff is awesome!

 

Links below

Download the tools: http://go.microsoft.com/?linkid=9713250 this is all you need if you just want to load the phone csproj. 

Download the VS 2010 RC if you want to load the full solution and build both the Silverlight Web App and Phone App (until RTM is available.  I updated the project to VS 2010): http://www.microsoft.com/visualstudio/en-us/download.  Install VS 2010, then the tools from above to get phone support.

Download TFS from the above link if you want to connect via source control to Codeplex (or use their support for Subversion, the Codeplex Client or Teamprise Explorer)

Download the code: http://popflygameengine.codeplex.com/SourceControl/list/changesets

Let me know in the comments if you have any questions!