Exemple #1
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();
    }
  }