Python and Game Development

Started by
4 comments, last by Atzeng 12 years, 11 months ago
Python is an interpreted, inherently object oriented dynamic language which has been gaining popularity for the past several years. It’s widely used by organizations such as NASA, Google and Industrial Light and Magic, among others. It has easy to understand syntax which allows programmers to develop programs faster and be more efficient. But at a Cost, programs written in Python have the disadvantage of slow speeds when compared to compiled languages, predominately C/C++. This is a particularly perplexing problem when programming for such CPU intensive applications such as Video Games. However, there are ways of mitigating that cost via JIT's and Bytecode Interpreters, PyPy and CPython respectively. For those more competent on the subject I am looking for this thread to be an exploration of the use of these implementations of Python in order to produce code that performs at nearly the same speed as C/C++. If you are currently using any of these implementations to produce fast game code please describe any problems you have had with the implementation, what libraries you are using, and what Game Engine you are using. Thanks in Advance!
---------------------
If past history was all there was to the game, the richest people would be librarians. - Warren Buffet
Advertisement
... Sorry, what's your question exactly?
I haven't used python in a game, but I've used other interpreted languages that have JIT-implementations.

In games, the codebase is generally seperated into two parts - the "game" and the "engine". The engine is usually written in C or C++ and does all the heavy lifting.
The game itself though can be written in a nicer "scripting" language though. The engine exposes bindings to this language so that the "game" code can interact with the "engine" code. The tasks being performed by the "game" code are usually NOT computationally intensive, so it really doesn't matter if the chosen language is "slow". On the odd occasion that the game code does implement some computationally expensive operation, and profiling shows that it is consuming a significant percentage of the available resources, then that code can be ported over to the engine code-base and implemented efficiently in a more performant language.

Also, as a side note - JIT compiled code is not permitted on game consoles. Even though JIT versions of our chosen languages exist, we can't and don't make use of them.
So how do you bind the Engine to the Game? Is this a massive task? As of right now I have been programming all my games completely in Python, with pygame. I am curious if a large project could be written completely in Python, with the assumption that it would never be ported off a Windows/Linux desktop. A JIT could bring the Engine code to levels that are close to compiled language, that is if my understanding of a JIT is correct. I am looking into this even though I'm beginner because when I start projects I usually take them serious enough that I need to look far ahead. I want to be able to pick up a language that I wont have to deviate from for a while, understandably thats probably C but I don't like the idea of the slow RAD iterations that comes with a compiled language.
---------------------
If past history was all there was to the game, the richest people would be librarians. - Warren Buffet

So how do you bind the Engine to the Game? Is this a massive task?
Coincidentally, there's a journal entry on binding C++/Python on the front page today.
You can use tools like SWIG to completely automate the process, you can use libraries like boost to help out, or you can do it yourself.
We use a manual solution that involves writing one line of code for each C or C++ function that we want the game-scripts to be able to access.
As of right now I have been programming all my games completely in Python, with pygame. I am curious if a large project could be written completely in Python, with the assumption that it would never be ported off a Windows/Linux desktop.[/quote]You should note that you're already using the "C engine, interpreted game" approach with pygame.
There's a lot of big commercial games which are mostly written in python (google/wikipedia will give you entire lists), most notably Eve Online, and any of the BigWorld games.
understandably thats probably C but I don't like the idea of the slow RAD iterations that comes with a compiled language.[/quote]IMO if you need a "lower level" language, you'd be better off with C++ over C, especially if you prefer OOP style.
However, as I alluded to before, most games get around the "slow iteration" problem by only using a C++ engine, and writing the game itself in an interpreted langauge like Python... just like you're doing right now by using Pygame...
Danke for clearing that all up for me. I was under the impression pygame was written in Python, guess I should have looked that up first. Out of pure curiosity how long have you been in the business?
---------------------
If past history was all there was to the game, the richest people would be librarians. - Warren Buffet

This topic is closed to new replies.

Advertisement