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

Re: [pygame] fast sqrt? and profiling



First:
Thanks everyone for all the replies.
Lots of useful information.

On Wed, Jan 21, 2009 at 11:11 AM, Casey Duncan <casey@xxxxxxxxxxx> wrote:
Others have made good suggestions about reducing the amount of work you do detecting collision (i.e., partitioning) and using complex numbers instead of euclid for 2d vectors. The latter made a big performance difference for me in a vector-heavy game I was working on.

1) How do you use complex(imaginary) numbers in place of euclid vectors? I tried searching for a tut/article, but, not having luck.

@casey:
I thought my function was bad -- but your solution will be easy to use. I'm using a factory, ie "spawn('type', 'loc | rand', *args)" to spawn units. So I can append to the subgroups here. ( I am not subclassing Sprite, but I do have a .dead member, that auto-deletes when iterated. )

2) Iterating on copy-of-list speed? Is there a reason to not do this?

Right now, if I'm iterating on a list which might be modified ( deleted, not sure if additions break it too. ), I'm in the habit of iterating on a copy of the list. ( because, at least in some cases, it breaks if not a copy )

ie:
def update(self):
    for a in self.actor_list[:]: # iterate on copy, incase I delete any later
        a.update()
        if a.dead or offscreen( a.loc ):
            self.actor_list.remove( a )

--
Jake