Python in game development?

Martijn Faassen m.faassen at vet.uu.nl
Thu Jul 20 11:04:11 EDT 2000


In comp.lang.python Moritz Voss <nospam at buzzoff.com> wrote:

> "Martijn Faassen" <m.faassen at vet.uu.nl> schrieb im Newsbeitrag
> news:8l6pgt$fmc$1 at newshost.accu.uu.nl...
>> In comp.lang.python Moritz Voss <nospam at buzzoff.com> wrote:
>> > HOW FAST ARE THESE? <drool>
>>
>> Python's not amazingly fast by itself.
>>
>> Note that the speed of the compiler doesn't matter much; it's near
>> instantaneous, but since it outputs bytecodes and you can use those,
>> the speed of the interpreter is what really matters, and the interpreter
>> isn't too fast.

> Of course! That'S the problem.

I was pointing out that it is often *not* a problem. Premature optimization,
even in game programming, is not a good idea. While Python is slow 
compared to C code, if the same algorithm is used, you can:

  * use smarter algorithms much more easily in Python. Especially since
    Python allows rapid prototyping.

  * offload the time critical bits to C.

> So there is not a JIT compiler style thingy
> for Pyhon?

There's no JIT for Python.

>> From a game programming perspective, you can probably consider Python to
>> be dirt-slow, though. The trade-off is a lot of power for speed, but
>> that power can help you gain back speed because you can be a lot smarter.

> Well...my python use would be for animation scriipts, micro AI scripts, and
> map event scripts...maybe a little more, even.

It should be fine for map event scripts and for AI scripts, though
this of course depends on your exact implementation. Animation scripts
could be more tricky. Animation overal control can be done in
Python, though individual frame updates I'd do with C.
(that said, I made a simple animation system once in Python built on
top of SDL with PySDL and it seemed fast enough. no intensive testing,
though)

> Thanks :) So designing my own scripting language is easier.

That's of course not true; designing your own scripting language will
most likely result in an ad-hoc broken design. Look at all the various
application specific scripting languages for examples. It's even possible
your own design will be slower in many cases than the equivalent code
in Python, as you don't have as much time to polish it.

Of course you can do it right too, but it'll cost lots of time and is
definitely not easier.

> Or: Isn't it feasibble to pull of a stunt like ID software did with their VM
> files? These contain compiled C code that is loaded dynamically - and of
> course is fast as hell. We currently do a lot like this with DLLs for the
> Engine and Contoller modules, but maybe this is even an idea at unit level?

If you want to script your game in C there isn't any problem. :)

The idea of using a higher level language however is that you can use
higher level constructs. Which, believe me, is often a lot easier than
using C or C++.

> I'll open a thread on this... Compiled Scripts.

> Thanks for the hints, though, I was jus getting started in Python :) It's
> neat, but if it's slow, then it's worthless.

I think this focus on speed is even for a game programmer the wrong
approach. It's only too slow when you find it's too slow. You haven't
found out Python's too slow for your purposes yet.

That said, there are various other scripting languages which can be
faster and which are embeddable as well. I suggest you look at Lua:

http://www.tecgraf.puc-rio.br/lua/

Pike:

http://pike.idonex.com/

And I'm sure there are more.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list