What does Python offer?

Ken Seehof kseehof at neuralintegrator.com
Thu May 30 07:38:10 EDT 2002


> Hello
>
> I have beome curious about Python after playing a game called 'Severance -
> Blade of Darkness', which uses python scripts. I know very little
> about the
> language. I am a C++ programmer, and would like to ask the Python
> community
> :
>
> What is unique or special about Python?

Excellent for rapid development, and blends nicely with C++.

> Why would it be useful to a games programmer?

Python programs are highly scaleable, robust, and resilient to
change (as compared to C++).  Resilience is very important to
games programmers because the design specification is usually
in a state of constant flux.

> Could it be used for allowing users to customize games, eg
> reprogramming AI
> bots etc?

Yes!

> Thanks for all answers
>
> Dáire

I highly recommend PyGame if you want to get a game up and running
quickly.  I've been writing a remake of the old arcade game "QIX".
It's got about three days work in it and probably will take about
two more days to finish it (when I have some free time).  And that
includes most of the learning curve for the PyGame API (which I had
only dabbled in briefly).  I think it would be very unusual to
complete such a game in C++ in less than a month.

http://www.neuralintegrator.com/pyx - My QIX remake
http://www.pygame.org - The PyGame tool kit

Now I suppose I should point out that it runs quite a bit slower
than it would if written in C++, but I'm getting frame rates up to
200 on a 600Mhz Pentium.  My target frame rate is a maximum of 45,
(so I can safely require no more than a 200Mhz system)  I don't
really see a need to optimize it in my case, since I'm just writing
the game for fun anyway and it's more than fast enough.  If I had
the inclination, I could easily rewrite some of the underlying
structures in C++ and get close to the same speed as pure C++, but
that would require compiling the C++ portion on each platform that
I desire to run on.  As it is, the pure python+pygame implementation
means that the game runs on everything from Mac to Linux.

On the other hand, if I were working on a more ambitious project
such as a massively multiplayer real-time simulation game, I'd
write all the CPU intensive code in C++.  I'd definitely still write
the main program in python whether I was allowing user scripting
or not.

If you are still concerned about speed, install PyGame and look
at the "Liquid" example.  It is very cool.  :-)

Since you are thinking about python scripting capabilities in
your game, I feel the need to steer you in the right direction
regarding architecture:

There are two basic ways to combine C++ and python: "Extending" and
"Embedding".  Extending refers to writing code in C++ such that the
functions and classes are accessible from python.  Embedding refers
to executing python code from c++.  Although embedding is one way
to add python scripting to an existing c/c++ program, I much prefer
to use extending exclusively whenever possible.  That is, I write
low level layer in c++, but always write the outer layers and the
main application in python (after all, the high level portion of
the program generally will not usually be CPU intensive).  With the
correct architecture, it should never be necessary to call python
from C++.  Embedding just feels like inside-out programming to me.

C++ and python work very nicely together.  Use them both.
Good luck on your project, and let me know how it's going.

- Ken Seehof







More information about the Python-list mailing list