Closed BertrandBordage closed 11 years ago
I think we should use Cython, but only to the most important functions. We should also keep pure Python equivalents. The game is sometimes very slow, so every performance update is needed. We can also add some command line argument to switch between Cython and Python code.
There is a nice feature of Cython called Pure Python Mode to achieve such a compatibility.
Using "magic attributes" seem painful and requires to have Cython installed, even if you don't use the compiled binaries.
But the solution of having .py files of pure Python and .pxd files where C types are defined looks like a perfect solution! I start working on this.
See #36 and #39 for the first successful implementation of Cython optimized modules for this game. There is a detailled description of the performance boost.
After doing some experiments using numpy (see #30), I managed to save some execution time. Now I made some experiments using Cython. And some sensible functions are executed more than 10 times faster. I therefore wonder whether we should use Cython (that mixes beautifully with numpy).
If we make an advanced terrain generator like in the original game, I bet that we will quickly see the limits of Python. And unfortunately, pyglet is not thread-safe, so it may be impossible to do parallel computations.
And of course, the main problem with Cython is that we have to compile (beautiful) code.