public void updateChunks() {
    ArrayList<Chunk> chunks = CoreRegistry.get(WorldRenderer.class).getChunksInProximity();
    HashSet<RigidBody> newBodies = new HashSet<RigidBody>();

    for (int i = 0; i < 32 && i < chunks.size(); i++) {
      final Chunk chunk = chunks.get(i);

      if (chunk != null) {
        chunk.updateRigidBody();

        RigidBody c = chunk.getRigidBody();

        if (c != null) {
          newBodies.add(c);

          if (!_chunks.contains(c)) {
            _discreteDynamicsWorld.addRigidBody(c);
          }
        }
      }
    }

    for (RigidBody body : _chunks) {
      if (!newBodies.contains(body)) {
        _discreteDynamicsWorld.removeRigidBody(body);
      }
    }

    _chunks = newBodies;
  }
  private synchronized void addQueuedBodies() {
    while (!_insertionQueue.isEmpty()) {
      RigidBody body = _insertionQueue.poll();

      if (body instanceof BlockRigidBody) _blocks.add((BlockRigidBody) body);

      _discreteDynamicsWorld.addRigidBody(body);
    }
  }
Exemple #3
0
 void addStaticServerElement(ServerElement elem) {
   RigidBody rb =
       createBody(
           0f, elem.getPosition(), getCollisionShape(elem.getSize()), 0f, elem.getOriantation());
   staticBodies.add(rb);
   // staticServerElements.add(elem);
   elementToRigidBody.put(elem, rb);
   rigidBodyToServerElement.put(rb, elem);
   dynamicsWorld.addRigidBody(rb);
 }
Exemple #4
0
  public void addDynamicServerElement(ServerElement elem, Float initialVelocity) {
    RigidBody rb =
        createBody(
            elem.getMass(),
            elem.getPosition(),
            getCollisionShape(elem.getSize()),
            initialVelocity,
            elem.getOriantation());
    dynamicsWorld.addRigidBody(rb);

    rigidBodyToServerElement.put(rb, elem);
    elementToRigidBody.put(elem, rb);
    rigidBodies.add(rb);
    // dynamicServerElements.put(elem.getId(),elem);
    if (elem instanceof ServerPlayer) {
      ServerPlayer p = (ServerPlayer) elem;
      players.add(p);
      rb.setAngularFactor(0.3f);
    }

    if (elem instanceof ServerBullet) {
      rb.setGravity(new Vector3f(0, -0.2f, 0));
    }
  }