I'm a new user to rabbyt and I love it. However, earlier today I ran
into a problem with using the collide() function with a small number
of sprites. After a few hours of troubleshooting I discovered that
passing a list of <= 10 sprites will cause the collide() function to
return an empty list. If the list has 11 sprites or more the collide()
function will return a list of collisions correctly.
Here's a modified script from the collisions example provided on the
website. If you change the number of generated sprites in the
range(10) for loop you can see this behavior. Using the
aabb_collisions_collide() function works properly with any number of
sprites I think. Thoughts?
Thanks,
Mike
from __future__ import division
import random
import rabbyt, rabbyt.collisions
from rabbyt import lerp, wrap
import pygame
pygame.init()
pygame.display.set_mode((120,120), pygame.OPENGL | pygame.DOUBLEBUF)
rabbyt.set_viewport((120,120))
rabbyt.set_default_attribs()
sprites = []
r = lambda: random.random()-.5
for i in range(10):
s = rabbyt.Sprite(shape=(-5,5,5,-5))
s.x = wrap([-60,60], lerp(r()*120, r()*120, dt=4,
extend="extrapolate"))
s.y = wrap([-60,60], lerp(r()*120, r()*120, dt=4,
extend="extrapolate"))
sprites.append(s)
collision_times = []
c = pygame.time.Clock()
last_fps = 0
while not pygame.event.get(pygame.QUIT):
c.tick()
if pygame.time.get_ticks() - last_fps > 1000:
print "FPS: ", c.get_fps()
last_fps = pygame.time.get_ticks()
if collision_times:
average = sum(collision_times)/len(collision_times)
print "Average ms to find collisions:", average
collision_times = []
rabbyt.clear()
rabbyt.set_time(pygame.time.get_ticks()/1000.0)
start = pygame.time.get_ticks()
collisions = rabbyt.collisions.collide(sprites)
collision_times.append(pygame.time.get_ticks()-start)
for group in collisions:
for s in group:
s.rgb = lerp((1,0,0),(1,1,1), dt=.4)
#s2.rgb = lerp((1,0,0),(1,1,1), dt=.4)
rabbyt.render_unsorted(sprites)
pygame.display.flip()
Sadly enough, it looks like it was fixed a while back. I just haven't
made a new release since then. :-( I guess I need to change that...
Looks like the problem was when the min_split argument to
rabbyt.collisions.rdc is larger than the number of items in the list.
(collisions.collide calls rdc with min_split=10.) For now use
collisions.brute_force, (or another one of the collisions functions)
if the count is under 10.
... or just use use the other functions all the time. From what I've
seen, using the RDC algorithm doesn't provide a measurable improvement
over brute_force of aabb_collide in most situations.
MWM
> --
> You received this message because you are subscribed to the Google Groups "Rabbyt" group.
> To post to this group, send email to rab...@googlegroups.com.
> To unsubscribe from this group, send email to rabbyt+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rabbyt?hl=en.
>