Optimize schematic paste

This commit is contained in:
Jesse Boyd 2016-12-31 17:23:46 +11:00
parent e3eccfd476
commit 6af96f43d4
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
5 changed files with 54 additions and 69 deletions

View File

@ -23,6 +23,18 @@ public class HybridGen extends IndependentPlotGenerator {
return PS.imp().getPluginName(); return PS.imp().getPluginName();
} }
private void placeSchem(HybridPlotWorld world, ScopedLocalBlockQueue result, short relativeX, short relativeZ, int x, int z) {
char[] blocks = world.G_SCH.get(MathMan.pair(relativeX, relativeZ));
if (blocks != null) {
for (int y = 0; y < blocks.length; y++) {
PlotBlock block = PlotBlock.get(blocks[y]);
if (block != null) {
result.setBlock(x, y, z, block);
}
}
}
}
@Override @Override
public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings, PseudoRandom random) { public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings, PseudoRandom random) {
HybridPlotWorld hpw = (HybridPlotWorld) settings; HybridPlotWorld hpw = (HybridPlotWorld) settings;
@ -83,7 +95,7 @@ public class HybridGen extends IndependentPlotGenerator {
} }
} }
// generation // generation
HashMap<Integer, HashMap<Integer, PlotBlock>> sch = hpw.G_SCH; HashMap<Integer, char[]> sch = hpw.G_SCH;
for (short x = 0; x < 16; x++) { for (short x = 0; x < 16; x++) {
if (gx[x]) { if (gx[x]) {
for (short z = 0; z < 16; z++) { for (short z = 0; z < 16; z++) {
@ -92,12 +104,7 @@ public class HybridGen extends IndependentPlotGenerator {
result.setBlock(x, y, z, hpw.ROAD_BLOCK); result.setBlock(x, y, z, hpw.ROAD_BLOCK);
} }
if (hpw.ROAD_SCHEMATIC_ENABLED) { if (hpw.ROAD_SCHEMATIC_ENABLED) {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z])); placeSchem(hpw, result, rx[x], rz[z], x, z);
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
} }
} }
} else if (wx[x]) { } else if (wx[x]) {
@ -108,12 +115,7 @@ public class HybridGen extends IndependentPlotGenerator {
result.setBlock(x, y, z, hpw.ROAD_BLOCK); result.setBlock(x, y, z, hpw.ROAD_BLOCK);
} }
if (hpw.ROAD_SCHEMATIC_ENABLED) { if (hpw.ROAD_SCHEMATIC_ENABLED) {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z])); placeSchem(hpw, result, rx[x], rz[z], x, z);
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
} }
} else { } else {
// wall // wall
@ -123,12 +125,7 @@ public class HybridGen extends IndependentPlotGenerator {
if (!hpw.ROAD_SCHEMATIC_ENABLED) { if (!hpw.ROAD_SCHEMATIC_ENABLED) {
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK); result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK);
} else { } else {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z])); placeSchem(hpw, result, rx[x], rz[z], x, z);
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
} }
} }
} }
@ -140,12 +137,7 @@ public class HybridGen extends IndependentPlotGenerator {
result.setBlock(x, y, z, hpw.ROAD_BLOCK); result.setBlock(x, y, z, hpw.ROAD_BLOCK);
} }
if (hpw.ROAD_SCHEMATIC_ENABLED) { if (hpw.ROAD_SCHEMATIC_ENABLED) {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z])); placeSchem(hpw, result, rx[x], rz[z], x, z);
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
} }
} else if (wz[z]) { } else if (wz[z]) {
// wall // wall
@ -155,12 +147,7 @@ public class HybridGen extends IndependentPlotGenerator {
if (!hpw.ROAD_SCHEMATIC_ENABLED) { if (!hpw.ROAD_SCHEMATIC_ENABLED) {
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK); result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK);
} else { } else {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z])); placeSchem(hpw, result, rx[x], rz[z], x, z);
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
} }
} else { } else {
// plot // plot
@ -169,13 +156,7 @@ public class HybridGen extends IndependentPlotGenerator {
} }
result.setBlock(x, hpw.PLOT_HEIGHT, z, hpw.TOP_BLOCK[random.random(hpw.TOP_BLOCK.length)]); result.setBlock(x, hpw.PLOT_HEIGHT, z, hpw.TOP_BLOCK[random.random(hpw.TOP_BLOCK.length)]);
if (hpw.PLOT_SCHEMATIC) { if (hpw.PLOT_SCHEMATIC) {
int pair = MathMan.pair(rx[x], rz[z]); placeSchem(hpw, result, rx[x], rz[z], x, z);
HashMap<Integer, PlotBlock> map = sch.get(pair);
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
} }
} }
} }

View File

@ -19,9 +19,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map.Entry;
public class HybridPlotManager extends ClassicPlotManager { public class HybridPlotManager extends ClassicPlotManager {
@ -84,15 +82,13 @@ public class HybridPlotManager extends ClassicPlotManager {
if (absZ < 0) { if (absZ < 0) {
absZ += size; absZ += size;
} }
HashMap<Integer, PlotBlock> blocks = hpw.G_SCH.get(MathMan.pair(absX, absZ)); char[] blocks = hpw.G_SCH.get(MathMan.pair(absX, absZ));
if (clear) {
for (short y = (short) 0; y <= hpw.SCHEMATIC_HEIGHT; y++) {
queue.setBlock(x, y, z, 0);
}
}
if (blocks != null) { if (blocks != null) {
for (Entry<Integer, PlotBlock> entry : blocks.entrySet()) { for (int y = 0; y < blocks.length; y++) {
queue.setBlock(x, entry.getKey(), z, entry.getValue()); PlotBlock block = PlotBlock.get(blocks[y]);
if (block != null) {
queue.setBlock(x, y, z, block);
}
} }
} }
} }

View File

@ -21,11 +21,10 @@ import java.util.Map;
public class HybridPlotWorld extends ClassicPlotWorld { public class HybridPlotWorld extends ClassicPlotWorld {
public boolean ROAD_SCHEMATIC_ENABLED; public boolean ROAD_SCHEMATIC_ENABLED;
public short SCHEMATIC_HEIGHT;
public boolean PLOT_SCHEMATIC = false; public boolean PLOT_SCHEMATIC = false;
public short PATH_WIDTH_LOWER; public short PATH_WIDTH_LOWER;
public short PATH_WIDTH_UPPER; public short PATH_WIDTH_UPPER;
public HashMap<Integer, HashMap<Integer, PlotBlock>> G_SCH; public HashMap<Integer, char[]> G_SCH;
public HashMap<Integer, HashMap<Integer, CompoundTag>> G_SCH_STATE; public HashMap<Integer, HashMap<Integer, CompoundTag>> G_SCH_STATE;
public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) { public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
@ -211,7 +210,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
if (id != 0) { if (id != 0) {
addOverlayBlock((short) (x + shift + oddshift + centerShiftX), (short) (y + this.PLOT_HEIGHT), addOverlayBlock((short) (x + shift + oddshift + centerShiftX), (short) (y + this.PLOT_HEIGHT),
(short) (z + shift + oddshift + centerShiftZ), id, (short) (z + shift + oddshift + centerShiftZ), id,
data, false); data, false, h3);
} }
} }
} }
@ -256,7 +255,6 @@ public class HybridPlotWorld extends ClassicPlotWorld {
short w2 = (short) d2.getX(); short w2 = (short) d2.getX();
short l2 = (short) d2.getZ(); short l2 = (short) d2.getZ();
short h2 = (short) d2.getY(); short h2 = (short) d2.getY();
this.SCHEMATIC_HEIGHT = (short) Math.max(h2, h1);
for (short x = 0; x < w1; x++) { for (short x = 0; x < w1; x++) {
for (short z = 0; z < l1; z++) { for (short z = 0; z < l1; z++) {
for (short y = 0; y < h1; y++) { for (short y = 0; y < h1; y++) {
@ -264,8 +262,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
short id = ids1[index]; short id = ids1[index];
byte data = datas1[index]; byte data = datas1[index];
if (id != 0) { if (id != 0) {
addOverlayBlock((short) (x - shift), (short) (y + this.ROAD_HEIGHT), (short) (z + shift + oddshift), id, data, false); addOverlayBlock((short) (x - shift), (short) (y + this.ROAD_HEIGHT), (short) (z + shift + oddshift), id, data, false, h1);
addOverlayBlock((short) (z + shift + oddshift), (short) (y + this.ROAD_HEIGHT), (short) (x - shift), id, data, true); addOverlayBlock((short) (z + shift + oddshift), (short) (y + this.ROAD_HEIGHT), (short) (x - shift), id, data, true, h1);
} }
} }
} }
@ -277,14 +275,14 @@ public class HybridPlotWorld extends ClassicPlotWorld {
short id = ids2[index]; short id = ids2[index];
byte data = datas2[index]; byte data = datas2[index];
if (id != 0) { if (id != 0) {
addOverlayBlock((short) (x - shift), (short) (y + this.ROAD_HEIGHT), (short) (z - shift), id, data, false); addOverlayBlock((short) (x - shift), (short) (y + this.ROAD_HEIGHT), (short) (z - shift), id, data, false, h2);
} }
} }
} }
} }
} }
public void addOverlayBlock(short x, short y, short z, short id, byte data, boolean rotate) { public void addOverlayBlock(short x, short y, short z, short id, byte data, boolean rotate, int height) {
if (z < 0) { if (z < 0) {
z += this.SIZE; z += this.SIZE;
} }
@ -298,11 +296,14 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
} }
int pair = MathMan.pair(x, z); int pair = MathMan.pair(x, z);
HashMap<Integer, PlotBlock> existing = this.G_SCH.get(pair); char[] existing = this.G_SCH.get(pair);
if (existing == null) { if (existing == null) {
existing = new HashMap<>(); existing = new char[height];
this.G_SCH.put(pair, existing); this.G_SCH.put(pair, existing);
} }
existing.put((int) y, PlotBlock.get(id, data)); if (id == 0) {
data = 1;
}
existing[(int) y] = (char) ((id << 4) + data);
} }
} }

View File

@ -21,16 +21,13 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue; import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
import com.intellectualcrafters.plot.util.block.LocalBlockQueue; import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
import com.intellectualcrafters.plot.util.expiry.PlotAnalysis; import com.intellectualcrafters.plot.util.expiry.PlotAnalysis;
import java.io.File; import java.io.File;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -378,7 +375,6 @@ public abstract class HybridUtils {
int ex = x + 15; int ex = x + 15;
int ez = z + 15; int ez = z + 15;
HybridPlotWorld plotWorld = (HybridPlotWorld) area; HybridPlotWorld plotWorld = (HybridPlotWorld) area;
extend = Math.min(extend, 255 - plotWorld.ROAD_HEIGHT - plotWorld.SCHEMATIC_HEIGHT);
if (!plotWorld.ROAD_SCHEMATIC_ENABLED) { if (!plotWorld.ROAD_SCHEMATIC_ENABLED) {
return false; return false;
} }
@ -436,13 +432,13 @@ public abstract class HybridUtils {
condition = !gx || !gz || !lx || !lz; condition = !gx || !gz || !lx || !lz;
} }
if (condition) { if (condition) {
HashMap<Integer, PlotBlock> blocks = plotWorld.G_SCH.get(MathMan.pair(absX, absZ)); char[] blocks = plotWorld.G_SCH.get(MathMan.pair(absX, absZ));
for (short y = (short) plotWorld.ROAD_HEIGHT; y <= plotWorld.ROAD_HEIGHT + plotWorld.SCHEMATIC_HEIGHT + extend; y++) {
queue.setBlock(x + X + plotWorld.ROAD_OFFSET_X, y, z + Z + plotWorld.ROAD_OFFSET_Z, 0);
}
if (blocks != null) { if (blocks != null) {
for (Entry<Integer, PlotBlock> entry : blocks.entrySet()) { for (int y = 0; y < blocks.length; y++) {
queue.setBlock(x + X + plotWorld.ROAD_OFFSET_X, entry.getKey(), z + Z + plotWorld.ROAD_OFFSET_Z, entry.getValue()); PlotBlock block = PlotBlock.get(blocks[y]);
if (block != null) {
queue.setBlock(x + X + plotWorld.ROAD_OFFSET_X, y, z + Z + plotWorld.ROAD_OFFSET_Z, block);
}
} }
} }
} }

View File

@ -21,6 +21,17 @@ public class PlotBlock {
this.data = data; this.data = data;
} }
public static PlotBlock get(char combinedId) {
switch (combinedId) {
case 0:
return null;
case 1:
return get(0, 0);
default:
return get(combinedId >> 4, combinedId & 15);
}
}
public static PlotBlock get(int id, int data) { public static PlotBlock get(int id, int data) {
return Settings.Enabled_Components.BLOCK_CACHE && data > 0 ? CACHE[(id << 4) + data] : new PlotBlock((short) id, (byte) data); return Settings.Enabled_Components.BLOCK_CACHE && data > 0 ? CACHE[(id << 4) + data] : new PlotBlock((short) id, (byte) data);
} }