Exemple #1
0
  /**
   * Query an AABB for overlapping proxies, returns the user data and the count, up to the supplied
   * maximum count.
   */
  public Object[] query(AABB aabb, int maxCount) {
    if (debugPrint) {
      System.out.println("Query(2 args)");
    }

    int lowerValues[] = new int[2];
    int upperValues[] = new int[2];
    computeBounds(lowerValues, upperValues, aabb);

    int indexes[] = new int[2]; // lowerIndex, upperIndex;

    query(indexes, lowerValues[0], upperValues[0], m_bounds[0], 2 * m_proxyCount, 0);
    query(indexes, lowerValues[1], upperValues[1], m_bounds[1], 2 * m_proxyCount, 1);

    assert m_queryResultCount < Settings.maxProxies;

    Object[] results = new Object[maxCount];

    int count = 0;
    for (int i = 0; i < m_queryResultCount && count < maxCount; ++i, ++count) {
      assert m_queryResults[i] < Settings.maxProxies;
      Proxy proxy = m_proxyPool[m_queryResults[i]];
      proxy.isValid();
      results[i] = proxy.userData;
    }

    Object[] copy = new Object[count];
    System.arraycopy(results, 0, copy, 0, count);

    // Prepare for next query.
    m_queryResultCount = 0;
    incrementTimeStamp();

    return copy; // results;
  }
Exemple #2
0
  public void destroyProxy(int proxyId) {
    assert (0 < m_proxyCount && m_proxyCount <= Settings.maxProxies);
    Proxy proxy = m_proxyPool[proxyId];
    assert (proxy.isValid());

    int boundCount = 2 * m_proxyCount;

    for (int axis = 0; axis < 2; ++axis) {
      Bound[] bounds = m_bounds[axis];

      int lowerIndex = proxy.lowerBounds[axis];
      int upperIndex = proxy.upperBounds[axis];
      int lowerValue = bounds[lowerIndex].value;
      int upperValue = bounds[upperIndex].value;

      // memmove(bounds + lowerIndex, bounds + lowerIndex + 1,
      // (upperIndex - lowerIndex - 1) * sizeof(b2Bound));
      // memmove(bounds[lowerIndex + 1], bounds[lowerIndex],
      // (upperIndex - lowerIndex) * sizeof(b2Bound));
      System.arraycopy(
          m_bounds[axis], lowerIndex + 1, m_bounds[axis], lowerIndex, upperIndex - lowerIndex - 1);
      for (int i = 0; i < upperIndex - lowerIndex - 1; i++) {
        m_bounds[axis][lowerIndex + i] = new Bound(m_bounds[axis][lowerIndex + i]);
      }
      // memmove(bounds + upperIndex-1, bounds + upperIndex + 1,
      // (edgeCount - upperIndex - 1) * sizeof(b2Bound));
      System.arraycopy(
          m_bounds[axis],
          upperIndex + 1,
          m_bounds[axis],
          upperIndex - 1,
          boundCount - upperIndex - 1);
      for (int i = 0; i < boundCount - upperIndex - 1; i++) {
        m_bounds[axis][upperIndex - 1 + i] = new Bound(m_bounds[axis][upperIndex - 1 + i]);
      }

      // Fix bound indices.
      for (int index = lowerIndex; index < boundCount - 2; ++index) {
        Proxy proxyn = m_proxyPool[bounds[index].proxyId];
        if (bounds[index].isLower()) {
          proxyn.lowerBounds[axis] = index;
        } else {
          proxyn.upperBounds[axis] = index;
        }
      }

      // Fix stabbing count.
      for (int index = lowerIndex; index < upperIndex - 1; ++index) {
        --bounds[index].stabbingCount;
      }

      // Query for pairs to be removed. lowerIndex and upperIndex are not
      // needed.
      int[] ignored = new int[2];
      query(ignored, lowerValue, upperValue, bounds, boundCount - 2, axis);
    }

    assert (m_queryResultCount < Settings.maxProxies);

    for (int i = 0; i < m_queryResultCount; ++i) {
      assert (m_proxyPool[m_queryResults[i]].isValid());
      m_pairManager.removeBufferedPair(proxyId, m_queryResults[i]);
    }

    m_pairManager.commit();

    // Prepare for next query.
    m_queryResultCount = 0;
    incrementTimeStamp();

    // Return the proxy to the pool.
    proxy.userData = null;
    proxy.overlapCount = BroadPhase.INVALID;
    proxy.lowerBounds[0] = BroadPhase.INVALID;
    proxy.lowerBounds[1] = BroadPhase.INVALID;
    proxy.upperBounds[0] = BroadPhase.INVALID;
    proxy.upperBounds[1] = BroadPhase.INVALID;

    // Return the proxy to the pool.
    proxy.setNext(m_freeProxy);
    m_freeProxy = proxyId;
    --m_proxyCount;

    if (s_validate) {
      validate();
    }
  }