Esempio n. 1
0
 private void updateObserver() {
   // Player view distance is handled in the network synchronizer
   if (controllerLive.get() instanceof PlayerController) {
     return;
   }
   int viewDistance = (getViewDistance() + 15) / Chunk.CHUNK_SIZE; // round up
   World w = transform.getPosition().getWorld();
   int cx = chunkLive.get().getX();
   int cy = chunkLive.get().getY();
   int cz = chunkLive.get().getZ();
   HashSet<SpoutChunk> observing =
       new HashSet<SpoutChunk>(viewDistance * viewDistance * viewDistance);
   for (int dx = -viewDistance; dx < viewDistance; dx++) {
     for (int dy = -viewDistance; dy < viewDistance; dy++) {
       for (int dz = -viewDistance; dz < viewDistance; dz++) {
         Chunk chunk = w.getChunk(cx + dx, cy + dy, cz + dz, true);
         chunk.refreshObserver(this);
         observing.add((SpoutChunk) chunk);
       }
     }
   }
   observingChunks.removeAll(observing);
   for (SpoutChunk chunk : observingChunks) {
     if (chunk.isLoaded()) {
       chunk.removeObserver(this);
     }
   }
   observingChunks.clear();
   observingChunks.addAll(observing);
 }
Esempio n. 2
0
 private void removeObserver() {
   // Player view distance is handled in the network synchronizer
   if (controllerLive.get() instanceof PlayerController) {
     return;
   }
   for (SpoutChunk chunk : observingChunks) {
     if (chunk.isLoaded()) {
       chunk.removeObserver(this);
     }
   }
   observingChunks.clear();
 }
Esempio n. 3
0
 public PhysicsQueue(SpoutChunk chunk) {
   this.region = chunk.getRegion();
   this.chunk = chunk;
   this.mainThread = ((SpoutScheduler) Spout.getScheduler()).getMainThread();
 }
Esempio n. 4
0
  @Override
  public void finalizeRun() {
    // Moving from one region to another
    if (entityManager != null) {
      if (entityManager != entityManagerLive.get()) {
        // Deallocate entity
        if (entityManager.getRegion() != null) {
          entityManager.getRegion().removeEntity(this);
        } else {
          entityManager.deallocate(this);
        }
      }
    }
    if (entityManagerLive.get() != null) {
      if (entityManager != entityManagerLive.get()) {
        // Allocate entity
        entityManagerLive.get().allocate(this);
      }
    }

    // Could be 1 of 3 scenarios:
    //    1.) Entity is dead (ControllerLive == null)
    //    2.) Entity is swapping controllers (ControllerLive != Controller, niether is null)
    //    3.) Entity has just spawned and has never executed copy snapshot, Controller == null,
    // ControllerLive != null
    if (controller != controllerLive.get()) {
      // 1.) Entity is dead
      if (controller != null && controllerLive.get() == null) {
        // Sanity check
        if (!isDead())
          throw new IllegalStateException("ControllerLive is null, but entity is not dead!");

        // Kill old controller
        controller.onDeath();
        if (controller instanceof PlayerController) {
          Player p = ((PlayerController) controller).getPlayer();
          if (p != null) {
            p.getNetworkSynchronizer().onDeath();
          }
        }
      }
      // 2.) Entity is changing controllers
      else if (controller != null && controllerLive.get() != null) {
        // Kill old controller
        controller.onDeath();
        if (controller instanceof PlayerController) {
          Player p = ((PlayerController) controller).getPlayer();
          if (p != null) {
            p.getNetworkSynchronizer().onDeath();
          }
        }

        // Allocate new controller
        if (entityManagerLive.get() != null) {
          entityManagerLive.get().allocate(this);
        }
      }
      // 3.) Entity was just spawned, has not copied snapshots yet
      else if (controller == null && controllerLive.get() != null) {
        // Sanity check
        if (!this.justSpawned())
          throw new IllegalStateException(
              "Controller is null, ControllerLive is not-null, and the entity did not just spawn.");
      }
    }

    if (chunkLive.get() != chunk) {
      if (observer) {
        if (!isDead()) {
          updateObserver();
        } else {
          removeObserver();
        }
      }
      if (chunkLive.get() != null) {
        ((SpoutChunk) chunkLive.get()).addEntity(this);
      }
      if (chunk != null && chunk.isLoaded()) {
        ((SpoutChunk) chunk).removeEntity(this);
      }
      if (chunkLive.get() == null) {
        if (chunk != null && chunk.isLoaded()) {
          ((SpoutChunk) chunk).removeEntity(this);
        }
        if (entityManagerLive.get() != null) {
          entityManagerLive.get().deallocate(this);
        }
      }
    }

    if (observerLive.get() != observer) {
      observer = !observer;
      if (observer) {
        updateObserver();
      } else {
        removeObserver();
      }
    }
  }
Esempio n. 5
0
 public void registerActive() {
   chunk.setPhysicsActive(true);
   chunk.setPhysicsActive(false);
 }