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.
Sunday, 12 October 2008
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.
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.
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.
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.
Friday, 4 July 2008
Introducing tichy
The last few weeks I have been working on a python applets manager for OpenMoko cell phone.
The idea is to be able to very easily develop applications in python. Each application can define a set of services and request for a given services. So if for example I write a text editor, other applications that need a text text editor will be able to use it, even if they don't know about this particular text editor.
The code can be downloaded from the subversion server :
svn checkout svn://svn.projects.openmoko.org/svnroot/tichy
It can work directly on a desktop computer, or on the open moko (See the README file for more informations)
It uses Mickey freesmartphone Framework
Here are some screen shots :
The idea is to be able to very easily develop applications in python. Each application can define a set of services and request for a given services. So if for example I write a text editor, other applications that need a text text editor will be able to use it, even if they don't know about this particular text editor.
The code can be downloaded from the subversion server :
svn checkout svn://svn.projects.openmoko.org/svnroot/tichy
It can work directly on a desktop computer, or on the open moko (See the README file for more informations)
It uses Mickey freesmartphone Framework
Here are some screen shots :
Sunday, 18 May 2008
Calling Vala code from Python
Today I gave a try at using vala and python together in my OpenMoko mobile phone.
Python is a powerful object oriented script language, and vala is a C gobject compiler that makes it easy to generate object oriented code in C. It is quite easy to mix python and vala in a same programme, allowing us to write very quickly modular and fast applications.
So here is how it works :
Let say I have a vala module, that defines one class, with one public method. Here is the file (test.vala) :
I can generate the C/gobject code for this module, using vala :
this command will create test.c and test.h. These files are conform C and can be compiled with gcc (in fact these are the files people using gobject in C would write. If we have a look at it, we understand the pain that it is to write gobject code in C !).
But to be able to call the functions from python, we need to create wrapper to the python C interface. This can be easily done using some tools (included in the debian pygtk-dev package). For more information, see this page.
Here are the commands that generate our C python interface :
Where 'test.override' is a compulsory file that looks like this :
Alright we now have a file called test_wrap.c, that contains all the wrapper functions from the python C interface to gobject C.
The next step is to actually create the C library callable from python. this library must contains a function 'inittest' (this is the function that will be called when we import the module from python.) The file looks like this (test_module.c) :
And then we are almost done... finally we compile and link everything :
And now we finally have our library : test.so, that can be directly used from python. Here is our python script (test.py):
Conclusion :
This combination (python + vala) is ideal to write applications for OpenMoko : there is no need to compile the python part, and since the vala code generate C code, it can be easily compiled for different targets.
So no excuses not to write great apps for OpenMoko :)
Python is a powerful object oriented script language, and vala is a C gobject compiler that makes it easy to generate object oriented code in C. It is quite easy to mix python and vala in a same programme, allowing us to write very quickly modular and fast applications.
So here is how it works :
Let say I have a vala module, that defines one class, with one public method. Here is the file (test.vala) :
using GLib;
namespace Test {
public class Test : Object {
public int sum(int x, int y) {
return x + y;
}
}
}
I can generate the C/gobject code for this module, using vala :
valac -C test.vala
this command will create test.c and test.h. These files are conform C and can be compiled with gcc (in fact these are the files people using gobject in C would write. If we have a look at it, we understand the pain that it is to write gobject code in C !).
But to be able to call the functions from python, we need to create wrapper to the python C interface. This can be easily done using some tools (included in the debian pygtk-dev package). For more information, see this page.
Here are the commands that generate our C python interface :
python /usr/share/pygtk/2.0/codegen/h2def.py test.h > test.defs
pygtk-codegen-2.0 -o test.override -p test test.defs > test_wrap.c
Where 'test.override' is a compulsory file that looks like this :
%%
headers
#include
#include "pygobject.h"
#include "test.h"
%%
modulename test
%%
import gobject.GObject as PyGObject_Type
%%
ignore-glob
*_get_type
%%
Alright we now have a file called test_wrap.c, that contains all the wrapper functions from the python C interface to gobject C.
The next step is to actually create the C library callable from python. this library must contains a function 'inittest' (this is the function that will be called when we import the module from python.) The file looks like this (test_module.c) :
#include
void test_register_classes (PyObject *d);
extern PyMethodDef test_functions[];
DL_EXPORT(void)
inittest(void)
{
PyObject *m, *d;
init_pygobject();
m = Py_InitModule("test", test_functions);
d = PyModule_GetDict(m);
test_register_classes(d);
if (PyErr_Occurred ()) {
Py_FatalError ("can't initialise module test");
}
}
And then we are almost done... finally we compile and link everything :
CFLAGS="`pkg-config --cflags gtk+-2.0 pygtk-2.0` -I/usr/include/python2.5/ -I."
LDFLAGS=`pkg-config --libs gtk+-2.0 pygtk-2.0`
gcc -c -o test.o test.c
gcc $CFLAGS -c test_wrap.c -o test_wrap.o
gcc $CFLAGS -c test_module.c -o test_module.o
gcc $LDFLAGS -shared test.o test_wrap.o test_module.o -o test.so
And now we finally have our library : test.so, that can be directly used from python. Here is our python script (test.py):
import test
t = test.Test()
print t.sum(2,3)
Conclusion :
This combination (python + vala) is ideal to write applications for OpenMoko : there is no need to compile the python part, and since the vala code generate C code, it can be easily compiled for different targets.
So no excuses not to write great apps for OpenMoko :)
Monday, 12 May 2008
First day at OpenMoko
Today is my first working day at OpenMoko.
After I met my new coworkers - I will need some time to get used to all the new faces - I started to play with the Neo FreeRunner. So I followed the wiki instructions to flash my cell phone with the last kernel and file system image. It worked fine :-)
Of course, since I am a fan of python and gtk, the second thing I tried was to run a python / gtk / glade application. And the proof that it works with no problem :
Here is a screenshot of glade designer running on my laptop :
And here is the same interface running on the Neo FreeRunner, from a python script :
This is pretty cool. The only problem is that the menu bar looks a little bit too small for a screen touch interface.
After I met my new coworkers - I will need some time to get used to all the new faces - I started to play with the Neo FreeRunner. So I followed the wiki instructions to flash my cell phone with the last kernel and file system image. It worked fine :-)
Of course, since I am a fan of python and gtk, the second thing I tried was to run a python / gtk / glade application. And the proof that it works with no problem :
Here is a screenshot of glade designer running on my laptop :
And here is the same interface running on the Neo FreeRunner, from a python script :
This is pretty cool. The only problem is that the menu bar looks a little bit too small for a screen touch interface.
Wednesday, 30 April 2008
Enough of C++ !
I used to like C++ a lot but the more I use this language the less I like it.
I think I really definitively made up my opinion about this language when I started to look at the boost libraries.
First I though all those crazy meta programing stuffs were genius (and indeed the boost libraries are an impressive piece of work), but then I realize that if C++ didn't have so much drawback, the boost code would be quite simple.
All the boost libraries do is find tricky ways to do things that C++ hasn't been made for in the first place.
For me it is a clear sign that C++ is going nowhere. And the new C++0x doesn't look so good to me. They make the language very complicated, I wonder if people are actually going to learn all the new things they add to the language. Yet one of the most important feature (garbage collector) is still not planed.
I am getting very interested by the D language, I even made a small video game in D.
At first sight D looks similar to C++, cause it has the same syntax (I would have preferred a python like syntax though), but it corrects all the things that made me not want to write C++ again :
So far the language is still new, and unfortunately not so many libraries have been created for it, but for me D may well be the future of compiled language.
I think I really definitively made up my opinion about this language when I started to look at the boost libraries.
First I though all those crazy meta programing stuffs were genius (and indeed the boost libraries are an impressive piece of work), but then I realize that if C++ didn't have so much drawback, the boost code would be quite simple.
All the boost libraries do is find tricky ways to do things that C++ hasn't been made for in the first place.
For me it is a clear sign that C++ is going nowhere. And the new C++0x doesn't look so good to me. They make the language very complicated, I wonder if people are actually going to learn all the new things they add to the language. Yet one of the most important feature (garbage collector) is still not planed.
I am getting very interested by the D language, I even made a small video game in D.
At first sight D looks similar to C++, cause it has the same syntax (I would have preferred a python like syntax though), but it corrects all the things that made me not want to write C++ again :
- a garbage collector (you can disable it if you want more control on memory)
- a foreach loop
- dynamic arrays part of the core language
- automatic type deduction (like "auto x = 10")
- simpler and more powerful template system.
So far the language is still new, and unfortunately not so many libraries have been created for it, but for me D may well be the future of compiled language.
How to compute "y = a * x + y"
I recently tried to write a numerical computation software that needed to perform a lot of vector operations. My first idea was to use python, and the numpy library.
But then I found that this simple operation :
Where x and y are large numpy arrays, and a is a scalar,
was much slower than the same thing coded in C, like this :
The reason is that numpy has to create a temporary object to store the result of the multiplication, and then also create a new object to store the result of the addition. When the size of the arrays becomes large - I was dealing with several Megabytes data arrays - it can make a lot of difference.
But I don't like the C code either, because of the very ugly loop.
So what can I do ? Well, first I could use the C blas library, then the operation is replaced by a function call, like this :
But it still looks over complicated.
OK maybe some other languages can be more suitable for this task. What about C++ ? With the boost::ublas library, it looks already much better :
Well, almost what I wanted, I could even use template parameters to make the function accepts any kind of input data.
But since at the end I want to be able to call this function from python, C++ is not the easiest choice (beside, I don't like C++ that much). Finally I used a language I really don't like, but that appeared to be the best for this particular task : Fortran90
Fortran90 is already much better than the horrible Fortran77 (That nobody should ever use). and most important, it has vector operations included in the language.
So now my simple operation looks like this :
(Note : in Fortran90, you DON'T need to start every lines at the 7th character !)
I can call this fortran function from python quite easily, thanks to F2PY, and voilà. Then I can extend my function to perform all sort of numerical operations.
Conclusion : Fortran90 is not as bad as I though it was, combined with python it can even be quite useful. But I still don't like this language, I am looking forward for the D language to have good numerical operations library, as well as python wrapping (it already exists, but there are still a few issues.)
But then I found that this simple operation :
y = a * x + y
Where x and y are large numpy arrays, and a is a scalar,
was much slower than the same thing coded in C, like this :
void func(float x[N], float y[N], float a) {
for(size_t i = 0; i < N; ++i) {
y[i] += a * x[i];
}
}
The reason is that numpy has to create a temporary object to store the result of the multiplication, and then also create a new object to store the result of the addition. When the size of the arrays becomes large - I was dealing with several Megabytes data arrays - it can make a lot of difference.
But I don't like the C code either, because of the very ugly loop.
So what can I do ? Well, first I could use the C blas library, then the operation is replaced by a function call, like this :
cblas_daxpy(N, a, (double*)x, 1, (double*)y, 1);
But it still looks over complicated.
OK maybe some other languages can be more suitable for this task. What about C++ ? With the boost::ublas library, it looks already much better :
using namespace boost::numeric::ublas;
void func(const vector& x, vector & y, double a) {
y += a * x;
}
Well, almost what I wanted, I could even use template parameters to make the function accepts any kind of input data.
But since at the end I want to be able to call this function from python, C++ is not the easiest choice (beside, I don't like C++ that much). Finally I used a language I really don't like, but that appeared to be the best for this particular task : Fortran90
Fortran90 is already much better than the horrible Fortran77 (That nobody should ever use). and most important, it has vector operations included in the language.
So now my simple operation looks like this :
subroutine func(x, y, a)
implicit none
REAL, dimension(:), intent(in) :: x
REAL, dimension(:), intent(inout) :: y
REAL, intent(in) :: a
y = a * x + y
end subroutine func
(Note : in Fortran90, you DON'T need to start every lines at the 7th character !)
I can call this fortran function from python quite easily, thanks to F2PY, and voilà. Then I can extend my function to perform all sort of numerical operations.
Conclusion : Fortran90 is not as bad as I though it was, combined with python it can even be quite useful. But I still don't like this language, I am looking forward for the D language to have good numerical operations library, as well as python wrapping (it already exists, but there are still a few issues.)
Wednesday, 23 April 2008
New job at openmoko
In a few weeks I will start to work with the great people of the OpenMoko project.
The goal of this project is to produce a totally open source mobile phone that everyone can modify at will.
You can learn more from the web site, download the sources, and even the CAO files !
My job will start in a few weeks, for the moment I am still working for Taiwan university, but I start to have a look at the huge mailing list archives of OpenMoko to get a better idea of the project and the people involved.
I'll post more on the subject when I will actually start working. I guess this will be a great experience for me, and I will do my best to contribute to the project.
Welcome to my new blog
Welcome to Charlie137 (aka Guillaume Chereau) new blog.
I start this new blog in addition to my other blog.
This blog will be more tech oriented. I will talk about the things I like in computer science, and also about my new job for OpenMoko.
So get ready to hear a lot about linux, OpenMoko, Python, D, Vala, Stellarium (among other things.)
I'll keep updating my old blog with drawings and video games stuffs when I'll get the time. I have been pretty busy (and sick) recently so I didn't take time to post anything.
Enjoy,
-gui
I start this new blog in addition to my other blog.
This blog will be more tech oriented. I will talk about the things I like in computer science, and also about my new job for OpenMoko.
So get ready to hear a lot about linux, OpenMoko, Python, D, Vala, Stellarium (among other things.)
I'll keep updating my old blog with drawings and video games stuffs when I'll get the time. I have been pretty busy (and sick) recently so I didn't take time to post anything.
Enjoy,
-gui
Subscribe to:
Posts (Atom)