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

Re: [pygame] Python and Speed



Hi!

    Another thought, same as before but adding the other comment about bins.
If your object is heading in a certain direction and you know the surface
point of that object, now make a dictionary key point for it. Same for all
other objects, knowing there direction.
    key=str(x)+str(-y)+str(-z) #Keeping all as integer values in a
coordinate grid.

    The only thing you compare are the keys. Then you will say, wait a
minute, not both are going to collide at that point!

    OK, then you know the direction of both and the point where they would
in fact collide. Now that point will be approaching both at the same point
in that straight line.

    The vertex of the point may change where they intersect, but keep taking
the key value of that point because both will always have that vertex point
on that point on the surface.

    Keep updating the dictionary key and compare the value for both with the
if key in...

    That point is a key value and easy to check. It is not the surface, just
the intersection point of both straight lines of the object traveling
through free space...

    So you will be checking 2 keys for 2 objects, 3 keys for 3 objects, and
so on...

    The only addition to this is if you have an object that is not perfect
shape, like a boulder, where that outer edge will change depending on the
angle of your straight line to the vertex or intersection point.

    Not checking surfaces, just checking the intersection point of the line,
for both will have to meet and the distance to that objects surface will
also be that straight line distance for the object center, which will still
direct you to the vertex/intersection point.

    Both surface points that meet, have same key value, will also be the
collision point when they do in fact collide...

    So all points will match, just another observation and thought in this
faster and faster check of objects.

    For I do something like this with my primitive Battleship game. Instead
of an array, just keys for where an object part is located. When the missile
or shell hits that key it matches the objects location at that same key.
    No completely filled huge array, just points.

    When doing this you have up to 3 points to calculate: point of surface
of object 1, point on surface of object 2 and then the intersection point of
the vector of both objects. When all 3 points match with the same key, you
have your collision! Like I said before, the updating is the vector angle,
surface location and the intersection point of that straight line of the
vectors of both objects.

        Bruce


René Dudfield wrote:

> - SIMD instructions are the fast ones...

It's doubtful there's much in the Python core that would
benefit from SIMD, though. Most of what it does doesn't
involve doing repetitive operations on big blocks of
data.

--
Greg