Monday, November 15, 2010

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

I have good news and bad news.

Update

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 http://bitbucket.org/johdex/fsxnalibtemplate

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# 1.9.9.9 (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.

6 comments:

. said...

Hi Joh,

Don here, posting via Laurent le Brun's google account :-)

Could you drop me an email at dsyme@microsoft.com or fsbugs@microsoft.com, and we can look into this problem? Send all the details you can about XNA versions etc. I think we will be able to determine the problem.

thanks!
don

Joh. said...

Wow, that was fast :) I have now sent the information you requested to fsbugs.

Art said...

Rich media platforms + F# = BIG F#UN!

Thanks all.

para said...

Hi, is there any way to build games with F# on the windows phone 7?

Joh. said...

Para: You can build games written in F# for the WP7 platform, but the development process (including building) has to take place on a PC. I think that's what you meant, but I wanted to clear that up anyway.

You have two separate paths to make F# applications for the F#: 1) Use Silverlight, 2) use XNA.

The first alternative has been demonstrated by Don Syme, and Dan Mohl has made project templates that are ready to use. Search on his name on the Visual Studio gallery, it shouldn't be hard to find.

The second alternative should also be possible, although I haven't tried it myself (I don't have any WP7 device to test that anyway).
Use the project templates by Dan Mohl, replace the references to silverlight by references to XNA for WP7, and that should work. I would advise you to have the top level in C# and put your F# code in a library, that's the easiest way to go.

Joh. said...

In my earlier comment,

You have two separate paths to make F# applications for the F#

should read:

You have two separate paths to make F# applications for WP7