Thursday, 22 January 2009

online javascript game, in python

Last time I spoke about pypy, which allow (among other things) to translate python code into other languages.

This week I wrote a small video game (inspired by the famous boulder dash game) in rpython and used pypy to create an online version of the game out of it.

You can play the game here.
The sources can be found here.

The game as it is now is not really fun, but I only wrote it as an example of using pypy.

What I like with this approach is that I can develop in rpython, and even run the game using python interpreter, and only before I publish it use pypy to create the javascript version.

I could also create a C version using the same code for the game engine (only the graphic functions would have to be rewritten for each backends.)

This open the door to a lot of interesting applications.

On a side note, the pypy javascript translation is really not optimised. For example, let's try to guess what this generated function does :

function (){
var v1086,v1087,self_145;
var block = 0;
for(;;){
switch(block){
case 0:
self_144 = this;
self_145 = self_144;
block = 1;
break;
case 1:
v1086 = 'H';
block = 2;
break;
case 2:
return ( v1086 );
}
}
}

I don't want to spoil the fun of figuring this out by giving the answer...

Sunday, 11 January 2009

Pypy is great

Even though I was in holidays recently, I spent some time to have a look at the update from the pypy project.

I get really excited by what the project has achieved so far.

Pypy is a python interpreter written in python.
The most interesting part of the project is the ability to use it to translate python code into other languages, like C, java, javascript, and LLVM.

So far only a subset of python language is translatable (for example generators won't work.) [edit: as the pypy people pointed out, full python language will never be translatable, that is not the goal of the project.]

But this simplified python (called RPython) is already good enough for many projects. As an example pypy interpreter itself is written in RPython and so can be compiled into machine code.

The good thing about this is that you can develop an application totally in python and then use the translators to generate fast machine code. So python could become some sort of universal language that replaces all other languages.

An other interesting things about pypy is the ability to generate stackless code, that allow many cool things, like tasklets (see the documentation about this).

Now I can't help thinking about OpenMoko paroli project, that uses python and tasklets. Could it be possible to use pypy to translate the python code into machine code and so create optimized version of paroli ?

The idea is very seducing, but many problems would need to be solved before we can get to there. The first thing is that we would have to modify our code to remove all the things that are not supported by pypy.

The second things is that even though pypy supports tasklets, it is impossible to do it using the python yield statement and the trick explained in PEP342.

An other good use of pypy would be to create web application without having to write -quite ugly- javascript code.

Paroli get a website

Happy new year everybody !
I just come back from holidays, and haven't worked for a few weeks, but now I am back to Taipei where I still work for OpenMoko, with a few news about our next software stack :

The tichy project had a lot of modifications ; it is now entirely based on etk and edje (part of raster enlightenment windows manager). It has also been renamed "paroli-core". We loose the ability to use different graphic back-ends, but the other features are still presents. Paroli-core offers :
  • Signal / slot objects (à la Qt.)
  • A service system to allow user to register and retrieve python object based on there role.
  • A tasklet library for easy creation of chained callback function.
  • A plug-in system.
  • A set of services that create a layer between the plug-ins and Mikey FSO framework.

The Paroli project based on paroli-core started.
The project includes paroli-core (ex tichy), plus a set of applets that aim at providing basic telephony functionalities.

More information (and the sources) can be found from the paroli-project web site.

Sunday, 12 October 2008

D programming on Openmoko

Today I decided to start to write a video game for OpenMoko.

I am a little bit disappointed by all the current available games for openmoko (I like action games). And the port of already existing games that I tried all have poor usability because they are not usable with a touchscreen (A touch screen is much more limited than a mouse, cause you can't move the pointer when you don't click)

So anyway, I wanted to write a very simple game where asteroids are falling from space and you have to destroy them by launching missile from the ground. The control is very simple : touch the screen to fire a missile to the pointed position.

I want the code of the game to be very small and simple, yet fast. I started to write it in vala, but after profiling got a little bit frustrated to see that a lot of time was spent getting and setting gobject properties.

I was about to consider cython + python or C++, and then I found that gdc, the gnu D programming language compiler, was available in the debian distribution for openmoko.

I immediately tried to compile my game guisterax, and it worked fine. Of course no way to play it without the keyboard, but that is great anyway.
D would be a perfect language for embedded applications.

Now the problem is that as far as I know it is not possible to compile D sources using openembedded yet, so I may have to use an other language for my game anyway.

Wednesday, 8 October 2008

OpenMoko update

I haven't post for a long time, it is time to give some update about my work at openmoko.

The last few weeks the full freesmartphone team was here in Taipei, so that we could work full time on the openmoko d-bus system interface (the so called framework).

Many changes have been done recently, I will try to update the wiki to let people that are not subscribed to the mailing list be aware of the status of the project.
To recall, the framework provides a d-bus API (the org.freesmartphone API) for applications running on the neo. The API covers usual phone functionalities (GSM, SIM, PIM, etc).

I didn't work at all on my personal project tichy, except yesterday when I stared to write a few applications that I intend to use to learn Chinese :
* A learning game application that implements the Leitner System to optimize the memorization of new words.
* An English to Chinese dictionary.
* A now working audio files player.

I think there is a interesting potential for the neo to be a learning platform.


Tuesday, 2 September 2008

Tichy running on GTK

Those days I am working on Tichy again.

Tichy is a python applet manager that allow to easily write applications for mobile phone.

From the beginning I tried to make the applets code "widget-agnostic". That means for example if an applet need to show a list of item, instead of creating the widgets for that, it will request the system for a 'design' service that will be in charge of representing the items. This way we can have totally different interfaces for the same applications.

An other advantage of this approach is that I can use any widget toolkit I want. So today I tried to make Tichy running with gtk, instead of SDL. Here is the result. The first image is using my own SDL widget toolkit, the second image is the same application using gtk toolkit.

My goal is to create a back end using etk + edje, as well as a backend using Clutter.

Monday, 21 July 2008

Tichy update

I did a video of tichy, my python applets manager, running on openmoko :



Once again the code for tichy can be retrieved from the subversion repository with this command :
svn checkout svn://svn.projects.openmoko.org/svnroot/tichy

It works fine on a desktop computer too. Parts of the program are in C, but I always provide python versions as well, so you don't need to compile anything to test it.

It is also very easy to extend tichy by adding new plugins

[Edit]: I put a copy of the video on youtube.