Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Cython for game development?

Tags:

python

c

cython

How practical would it be to use Cython as the primary programming language for a game?

I am a experienced Python programmer and I absolutely love it, but I'm admittedly a novice when it comes to game programming specifically. I know that typically Python is considered too slow to do any serious game programming, which is why Cython is interesting to me. With Cython I can use a Python-like language with the speed of C.

I understand that I'll probably need to learn a bit of C/C++ anyway, but it seems like Cython would speed up development time quite a bit in comparison.

So, is it practical? And would I still be able to use C/C++ libraries like OpenGL, OpenAL, and Bullet Physics?

like image 642
Liam Avatar asked Nov 15 '10 01:11

Liam


People also ask

Is Cython good for game development?

A good modern game must use threads. Cython practically forbids their use, holding to GIL (global interpreter lock) the entire time, making your code run in sequence. If you are not writing a huge game, than Python/Cython is okay. But Cython is no good as a modern language without good thread support.

Is Cython worth using?

Cython will get you good speedups on almost any raw Python code, without too much extra effort at all. The key thing to note is that the more loops you're going through, and the more data you're crunching, the more Cython can help.

Does Cython use C or C++?

Cython improves the use of C-based third-party number-crunching libraries like NumPy. Because Cython code compiles to C, it can interact with those libraries directly, and take Python's bottlenecks out of the loop.

Is Cython as fast as C?

Cython is the same speed as a carefully tuned C/C++ program; carefully tuned, Cython maps directly to C/C++. I've done many benchmarks of low level numerical code when implementing SageMath (which uses Cython for several 100K lines of code).


1 Answers

If you're working with a combination like that and your goal is to write a 3D game, you'd probably get better mileage out of a ready-made 3D engine with mature physics and audio bindings and a Python API like OGRE 3D or Panda3D. Even if you don't, this post about using Cython with Panda3D may be helpful.

I'm not sure about now, but back in 2007, the trade-off between the two was basically that:

  • Panda3D was better-documented and designed from the ground-up to be a C++ accelerated Python engine (apparently they made some API design decisions that don't occur to C++ engine projects) and, predictably, had a more mature Python API.
  • PyOgre was built on top of a much more advanced engine and had a larger and more vibrant community.

...however it's quite possible that may have changed, given that, passage of time aside, in 2007, Panda3D was still under a GPL-incompatible license and that drove off a lot of people. (Myself included)

like image 159
ssokolow Avatar answered Oct 13 '22 20:10

ssokolow