Beispiel #1
0
 public void updateChunk(RegionManager regionManager, MwChunk chunk) {
   for (int i = 0; i < this.regionArray.length; i++) {
     Region region = this.regionArray[i];
     if ((region != null) && (region.isChunkWithin(chunk))) {
       this.updateTextureFromRegion(
           region, chunk.x << 4, chunk.z << 4, MwChunk.SIZE, MwChunk.SIZE);
       this.setRegionModified(i);
     }
   }
 }
Beispiel #2
0
  public void updateTextureFromRegion(Region region, int x, int z, int w, int h) {
    int tx = (x >> region.zoomLevel) & (this.w - 1);
    int ty = (z >> region.zoomLevel) & (this.h - 1);
    int tw = (w >> region.zoomLevel);
    int th = (h >> region.zoomLevel);

    // make sure we don't write outside texture
    tw = Math.min(tw, this.w - tx);
    th = Math.min(th, this.h - th);

    // MwUtil.log("updateTextureFromRegion: region %s, %d %d %d %d -> %d %d %d %d", region, x, z, w,
    // h, tx, ty, tw, th);

    int[] pixels = region.getPixels();
    if (pixels != null) {
      this.setRGBOpaque(tx, ty, tw, th, pixels, region.getPixelOffset(x, z), Region.SIZE);
    } else {
      this.fillRect(tx, ty, tw, th, 0xff000000);
    }
  }
Beispiel #3
0
 public boolean loadRegion(
     RegionManager regionManager, int x, int z, int zoomLevel, int dimension) {
   // MwUtil.log("mapTexture.loadRegion %d %d %d %d", x, z, zoomLevel, dimension);
   boolean alreadyLoaded = true;
   int index = this.getRegionIndex(x, z, zoomLevel);
   Region currentRegion = this.regionArray[index];
   if ((currentRegion == null) || (!currentRegion.equals(x, z, zoomLevel, dimension))) {
     if (currentRegion != null) {
       currentRegion.refCount--;
     }
     Region newRegion = regionManager.getRegion(x, z, zoomLevel, dimension);
     this.regionArray[index] = newRegion;
     newRegion.refCount++;
     this.updateTextureFromRegion(
         newRegion, newRegion.x, newRegion.z, newRegion.size, newRegion.size);
     // oops! this needs to be after updateTextureFromRegion otherwise the GL texture will be
     // updated
     // and the regionModified flag cleared before the region is actually loaded.
     this.setRegionModified(index);
     // MwUtil.log("regionArray[%d] = %s", newRegion.index, newRegion);
     alreadyLoaded = false;
   }
   return alreadyLoaded;
 }