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

Re: [pygame] raycasting engine performances (numpy array)



On Thu, Apr 26, 2012 at 1:49 PM, Nathan Biagini <nathan.open@xxxxxxxxx> wrote:
> i dunno if i can do more "optimized" as a drawing line function...

I see a moderate speed-up when replacing:

    asf[x][y] = 255

with:

    asf[x,y] = 255

Which avoids doing two layers of Python indexing for each pixel.
Still, it doesn't make it fast enough to be smooth. I see a much
bigger speed-up if I replace that loop with:

    asf[x,start:end] = 255

This shifts the whole loop into C code with no Python interpreter to
slow it down. The only problem is figuring out how to express the
texturing as something numpy can do do efficiently. I think it may
well be possible, but I'm not enough of a numpy expert to know off the
top of my head.

I totally agree with Greg: only do this if it's for your own education
and amusement. Raycasting on the CPU is always going to be way slower
than a GPU can do, even if you can get the Python interpreter out of
all the slow bits (whether that's by way of numpy, PyPy or just plain
writing some C).