Saturday, November 27, 2010

XNA GS 4.0 + F# 2.0 + Xbox 360 = love !

Those of you who read the previous entry could notice in the comments that it did not take long for Don Syme, the designer of F#, to offer to help resolve the issue.

Less than a week later I had a new version of the FSharp core library tailored for the Xbox 360 in my mailbox. To the F# OSS team (Don Syme, Laurent Le Brun and Tomas Petricek): big thanks to all of you!

What took a bit more time was to build a Visual Studio 2010 template for projects using the new F# core library. Thanks a lot to Dan Mohl for his help. He is the author of templates for F# + Silverlight + WP7 projects, which are available on the Visual Studio gallery.

It's the first time I make a Visual Studio extension package, I hope I got it right. It's available on the Visual Studio gallery. If you try it out, please let me know if it worked for you (or if it did not).

A small but important note: In the project properties, the build tab has "generate tail calls" unchecked, both in Release and Debug builds. That's the way it is meant to be. If checked, your game will crash with an InvalidProgramException.


Monday, November 15, 2010

XNA GS 4.0 + F# 2.0 + Xbox 360 = no love (yet...)

I have good news and bad news.


Actually, it's all good news, see the next post.
I considered erasing this article, but finally decided against it, as it shows how fast and helpful the people behind F# are.

So, just to clarify things: It is possible to write games for the Xbox 360 in F# using Visual Studio 2010 and XNA Games Studio 4.0

A word of caution: I don't want to give the impression that F# is officially supported by the XNA team at Microsoft. It isn't. As far as technical matters go, it works, and that's all I need as far as I'm concerned.

End of update

Good news first

1. I have posted Visual Studio templates, both for PC and the Xbox. I have only tested the Xbox one so far. Located on bitbucket, see

2. I have posted an example on how to use XNAUtils, it's included in the repository under "Samples". Hosted on bitbucket too.

Bad news

1. The templates are a bit rough around the edges still. Not so easy to install, in particular. I should probably upload them to the template repository so that they are accessible from with Visual Studio. However, I have other cats to whip at the moment, see below (I could have said bigger fish to fry ;)

2. When you attempt to run the example, you will get an "InvalidProgramException", which I suppose means the IL code generated by the F# compiler cannot be handled by the new XNA framework. I had been using XNA GS 3.1 and F# (dating from may 2010, I believe). I don't know where the problem lies, XNA GS 4.0 or F# 2.0.

There is hope!

The source code for the F# compiler and the core library are now available on Codeplex. If the problem is indeed some hard-to-digest IL instruction, it should be fixable.

(Small note: The source code for the F# compiler has been available for some time now, but building was not a walk in the park. Now there are instructions, and the result can be legally used and distributed).

The next steps for me is to confirm my guesses, produce minimal reproduction cases, hope Microsoft will do something about it. That's quite a long shot though. As far as I know, there is no official support from Microsoft for languages other than C# in XNA.

Anyway, I'll see if I can get to grips with the source code of compiler and the core library and solve these issues.

By the way, I guess similar issues may exist on the Windows Phone 7 platform.

In the mean time...

XNA and F# can be used together for the PC platform. Don't let this post scare you from trying F# + XNA.

Saturday, November 13, 2010

XNAUtils released under the Apache 2.0 license

I have just created a public repository on bitbucket containing various reusable F# modules that I developed for Asteroid Hunter.

It's all there:

I had a quick look over the code, it's all pretty clean and short, but it lacks documentation and examples on how to use it.

I ported the code and project files to XNA 4.0 and F# 2.0, but I have not tested the binaries. Chances are, they do not work yet.

Nevertheless, I hope it will be useful to others out here, and help more Xbox games to be written in F#.

UPDATE (Nov 25):
Asteroid Hunter was written for XNA Game Studio 3.1 using F# (from may 2010). As I describe it in further details in the next post, the latest versions of XNA Game Studio and F# are not compatible.

Friday, November 12, 2010

Asteroid Hunter box art

I'm working on Asteroid Hunter at a very steady pace: Every week, I do half of all the work that's left to do.

At this point, I had just enough motivation left to do the virtual box art which will appear on the Xbox marketplace when/if the game passes peer review.

Realized with Wings 3D, POVRAY and GIMP 2.

By the way, I have now submitted the game to peer review. If you are a member of the XNA Creator's Club, please consider reviewing the game. You are more than welcome to fail it if you find something wrong :)