Saturday, March 14, 2009

F# game running on the console

I have just succeeded to write and run my first game on my XBox360. Here is proof of it:



The game is composed of an F# library and a top-level C# application. The game, a 3d clone of Asteroids, is still very far from being complete. For instance controls require a keyboard, and the code is still riddled with bugs. Never the less, the first attempt to deploy on the XBox was successful, which is quite encouraging. See Grammerjack's old blog for details on each step of the deployment process.

The F# code is written in a pure functional way, which I fear is not going to work out in the end. Such code relies heavily on the garbage collector, and the current version of the XBox360 .NET environment is known to be weak on this point.

I wonder if it's possible to modify the .NET code emitted by the F# compiler to replace instantiations of new objects by references to items in pre-allocated arrays. This would make it possible to keep purity in the F# source code while maintaining decent performance.
Right now, I feel that if I was to write code relying heavily on in-place modifications, I would rather do that in C# than in F#.

4 comments:

Art said...

Thanks Joh.
It is the Visual Age.
Jon Harrop is into GC.
I'm not sure if what he is doing could be used in this situation ...?

Looking forward to your posts.

Art

Bunt said...

Hi Joh, been reading your posts w/ interest, sad to see after all that F# optimization you think it might not work out! Can you reconcile the poor performance you're seeing with the earlier results you showed? Do you think the XBox360 GC specifically is the problem, and you'd be alright up on the PC? Or did your earlier timings not capture some-real world aspect of the 3D asteriods game do you think? Cheers, Bunt - El Gouna, Egypt.

snk_kid said...

You might find this useful: http://blogs.msdn.com/shawnhar/archive/2007/07/02/twin-paths-to-garbage-collector-nirvana.aspx

Joh. said...

Art: I am not aware of Jon Harrop's work on GC. Is there information available on the net? I doubt this would help me though, unless Jon is working on the XBox360.

Bunt: The performance is actually good, so far. My fears are based on what I have read on various blogs and forums.

snk_kid: Very good link, thanks! The game runs quite smoothly at the moment, which I guess can be explained by the fact that the code mostly uses records containing exclusively primitive types or structs. I suspect this kind of use may fall under the low-latency scenario.