Esempio n. 1
0
        # r[1].vx += 1
        # if event.key == pygame.K_RIGHT:
        # r[1].vx += -1

    for i in r:
        i.Move()

    screen.fill((MyColor.black))

    for i in r:
        pygame.draw.rect(screen, (255, 255, 255), i.GetBounds(), 0)

    arrayStop.start()
    arrayResult = arrayDetection.CheckCollisions(r)
    arrayStop.stop()
    arrayTimeNum = arrayStop.time_elapsed()
    arrayTime = myfont.render(str(arrayTimeNum) + ' ms', False, MyColor.white)
    arrayStop.reset()
    screen.blit(arrayLabel, (MyScreen.width * 1.05, 0))
    screen.blit(arrayTime, (MyScreen.width * 1.05, 30))

    hashStop.start()
    hashResult = hashDetection.CheckCollisions(r)
    hashStop.stop()
    hashTimeNum = hashStop.time_elapsed()
    hashTime = myfont.render(
        str(hashTimeNum) + ' ms  ~' +
        str(math.ceil(arrayTimeNum / max(hashTimeNum, 1))) + " Times Faster",
        False, MyColor.white)
    hashStop.reset()
    screen.blit(hashLabel, (MyScreen.width * 1.05, 60))
Esempio n. 2
0
def CheckTimesForN(n):

    times = []
    arrayDetection = Collision_detection_Array()
    arrayStop = Stopwatch()

    hashDetection = Collision_Detection_Spatial_hashing()
    hashStop = Stopwatch()

    skipDetection = Collision_Detection_SkipList()
    skipStop = Stopwatch()

    quadDetection = Collision_Detection_Quad_Tree()
    quadStop = Stopwatch()

    aabbDetection = Collision_detection_AABB()
    aabbStop = Stopwatch()

    binDetection = Collision_Detection_Binary_Tree()
    binStop = Stopwatch()

    r = GetRandomRects(n)
    arrayStop.start()
    arrayResult = arrayDetection.CheckCollisions(r)
    arrayStop.stop()
    arrayTimeNum = arrayStop.time_elapsed()
    times.append(arrayTimeNum)
    arrayStop.reset()

    hashStop.start()
    hashResult = hashDetection.CheckCollisions(r)
    hashStop.stop()
    hashTimeNum = hashStop.time_elapsed()
    times.append(hashTimeNum)
    hashStop.reset()

    skipStop.start()
    skipResult = skipDetection.CheckCollisions(r)
    skipStop.stop()
    skipTimeNum = skipStop.time_elapsed()
    times.append(skipTimeNum)
    skipStop.reset()

    quadStop.start()
    quadResult = quadDetection.CheckCollisions(r)
    quadStop.stop()
    quadTimeNum = quadStop.time_elapsed()
    times.append(quadTimeNum)
    quadStop.reset()

    binStop.start()
    binResult = binDetection.CheckCollisions(r)
    binStop.stop()
    binTimeNum = binStop.time_elapsed()
    times.append(binTimeNum)
    binStop.reset()

    # aabbStop.start()
    # aabbResult = aabbDetection.CheckCollisions(r)
    # aabbStop.stop()
    # aabbTimeNum = aabbStop.time_elapsed()
    # times.append(aabbTimeNum)
    # aabbStop.reset()

    return times