[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Mixing Python and C in games



On Fri, 17 Feb 2006 11:15:00 +0200, "Sami Hangaslammi"
<sami.hangaslammi@xxxxxxxxx> said:
> I've coded some simple extensions using Pyrex in the past, but I've
> mostly been putting off the effort of learning to mix Python and C
> properly. So I was wondering what experiences do people here have, and
> what would you recommend. My goal is mostly to rewrite the inner loops
> in my Pygext framework for event handling, rendering and collisions.
> So I'm wonder how to best e.g. access Pygame surfaces and OpenGL
> functions directly to lose some overhead, and how easy it is to take
> advantage of, for example, the fast dict and set implementations in
> Python (my event manager uses a lot of set objects internally, and I'd
> rather not write my own set implementation in C).
> 
> Pyrex is my main candidate, as I'm the most familiar with it, and
> creating extension classes for my purposes seems pretty easy. I just
> have to figure out how to convert all usages of set and dict object
> from my Python code to Pyrex. I've been reading Boost::Python
> documentation lately, but the wrapper files feel a bit cumbersome and
> verbose. The third option is using ctypes, but I know hardly anything
> about it. If I understood correctly, its main purpose is to interface
> with existing C-libraries, and it wouldn't be so well suited for
> rewriting small bits of exisiting Python code in C.
> 
> So, if any of you have used Pyrex for example to optimize inner loops
> in your games, I would appreciate some example code and pointers.

I'm not completely clear on what your trying to do - are you wanting to
wrap C code in Python?  If so, have you looked at SWIG?   I used SWIG to
wrap C++ code in Perl a few years back and it was fairly easy.

http://www.swig.org/