Ive got a tiny Acer Aspire netbook I use while commuting to work. Its a very low specd machine but it has a very functional keyboard and I love programming on it!
I think I enjoy programming on it because it doesnt have Visual Studios installed. I have the Windows SDK so I can build .NET projects with MsBuild, but I mainly use it for developing Python code. With some free tools and notepad++ plug-ins its a great light weight environment for coding simple Django and Google App Engine web applications and dynamic language .NET applications.
Im not really into computer gaming, but I do like 2d physics games. I remember losing days work when I first found Magic Pen. I decided to try using the cool Farseer Physics Engine, which is described on the Codeplex page as;
The Farseer Physics Engine is an easy to use 2D physics engine designed for Microsofts XNA and Silverlight platforms. The Farseer Physics Engine focuses on simplicity, useful features, and enabling the creation of fun, dynamic games.
The Farseer engine is written in C# and I found once Id installed the Silverlight SDK I could use MSBuild to build the Farseer engine that targets the Silverlight runtime. The Farseer engine doesnt itself reference anything Silverlight specific, but it does need to be built against the limited .NET framework available in Silverlight.
Ive previously blogged about writing dynamic language Silverlight applications; the Silverlight Dynamic Languages SDK contains the Silverlight IronPython assemblies and a command line application called Chiron. Chiron is a web server that runs from the command line and dynamically packages up XAPs as they are requested.
XAPs are packaged Silverlight applications that are downloaded and run on the clients Silverlight runtime. It turns out the XAP is just zip files containing the assemblies, resources and in the case of dynamic language applications, some plain text source code!
Additionally there is an AppManifest.xaml included in the XAP which tells Silverlight about what is included in the XAP and where to find an entry point. Below is an example of an AppManifest.xaml automatically generated by Chiron.
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RuntimeVersion="2.0.31005.0" EntryPointAssembly="Microsoft.Scripting.Silverlight" EntryPointType="Microsoft.Scripting.Silverlight.DynamicApplication"> <Deployment.Parts> <AssemblyPart Source="Microsoft.Scripting.Silverlight.dll" /> <AssemblyPart Source="Microsoft.Scripting.ExtensionAttribute.dll" /> <AssemblyPart Source="Microsoft.Scripting.Core.dll" /> <AssemblyPart Source="Microsoft.Scripting.dll" /> <AssemblyPart Source="IronPython.dll" /> <AssemblyPart Source="IronPython.Modules.dll" /> <AssemblyPart x:Name="FarseerPhysics" Source="bin/FarseerPhysics.dll"/> </Deployment.Parts> </Deployment>
This would probably be more interesting compared to a non dynamic language manifest file, but here are a few things I found interesting about it;
There is a whole lot of additional referenced assemblies required to compile Pyhton code in the Silverlight client, and yes, they are included in the XAP sent to the client.
The FarseerPhysics assembly is also included the XAP and is referenced in the manifest.
The EntryPointType is really the only difference between XAP manifest files generated for statically typed languages. For dynamic languages there are additional assemblies that compile the dynamic code, there doesnt seem any reason you couldnt feasibly write EntryPoint assemblies that interpreted lol- cat or brainfuck code.
And, Im still targeting Silverlight 2! (Just havent got round to upgrading..)
I started by having a play with the Farseer engine by writing some IronPython scripts and running them from the console. As its just a physics engine, it can be coupled with any user interface, even a console.
When I tried to get the same script working in Silverlight I did encounter some difficulties referencing the Farseer assembly. I had to use the assemblies strong name, which I found using Reflector, but seems unnecessary given it was sent in the same XAP as the code referencing it!
Instead of just hacking this demo together in one giant script I decided to structure my code a little, including separating the view and the simulation model over different namespaces. Generally Im learning heaps about what is pythonic, what I carry over from C/C++/C# and what is good software design.
Im not entirely happy with my view classes, which are just wrappers around Silverlight controls. Even though the Silverlight control can be accessed through a property, I feel this isnt the elegant solution I should be able to build in a dynamic language. It seemed more right for the physics wrappers, but still overly verbose.
I limited the example for this post to a very simple, but interactive 2d physics demo. Clicking any of the objects in the simulation creates a spring between the object and the mouse cursor until the mouse click is released or leaves the simulation view area.
The Farseer physics engine is a lot of fun to use, its easy to get into and you can do some really cool stuff with it.
The source code is sent as plain text and compiled (or interpreted) on client. As the XAP is just a normal zip file, it can unzipped by almost any zip tool. Inside is all the plain text source code, compiled assemblies and manifest file.
Its awesome to be able to develop Silverlight applications with physics libraries using a high level language and light weight development environment. Happy hacking..