Misc Perf improvements

This commit is contained in:
Bud Gidiere 2020-11-20 20:49:10 -06:00
parent 28109bf999
commit ab906b47c8
No known key found for this signature in database
GPG Key ID: CD18F99E348902F7
9 changed files with 27 additions and 29 deletions

View File

@ -17,6 +17,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.time.Duration; import java.time.Duration;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -59,7 +60,7 @@ public final class ConfigUtil {
} }
public static Set<Material> toBlockData(List<String> list, String phase, String id) throws InvalidConfigurationException { public static Set<Material> toBlockData(List<String> list, String phase, String id) throws InvalidConfigurationException {
Set<Material> bl = new HashSet<>(); Set<Material> bl = EnumSet.noneOf(Material.class);
for(String s : list) { for(String s : list) {
try { try {
if(s.startsWith("#")) { if(s.startsWith("#")) {

View File

@ -42,7 +42,7 @@ public class WorldConfig {
FileConfiguration config = new YamlConfiguration(); FileConfiguration config = new YamlConfiguration();
Debug.info("Loading config " + configID + " for world " + worldID); Debug.info("Loading config " + configID + " for world " + worldID);
try { // Load/create world config file try { // Load/create world config file
if(configID == null || configID.equals("")) if(configID == null || configID.isEmpty())
throw new ConfigException("Config pack unspecified in bukkit.yml!", worldID); throw new ConfigException("Config pack unspecified in bukkit.yml!", worldID);
File configFile = new File(main.getDataFolder() + File.separator + "worlds", worldID + ".yml"); File configFile = new File(main.getDataFolder() + File.separator + "worlds", worldID + ".yml");
if(!configFile.exists()) { if(!configFile.exists()) {

View File

@ -15,13 +15,7 @@ import org.polydev.gaea.math.Range;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
public class CarverConfig extends TerraConfig { public class CarverConfig extends TerraConfig {
private final UserDefinedCarver carver; private final UserDefinedCarver carver;
@ -74,7 +68,7 @@ public class CarverConfig extends TerraConfig {
double rm = getDouble("recalculate-magnitude", 4); double rm = getDouble("recalculate-magnitude", 4);
shift = new HashMap<>(); shift = new HashMap<>();
for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("shift")).getValues(false).entrySet()) { for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("shift")).getValues(false).entrySet()) {
Set<Material> l = new HashSet<>(); Set<Material> l = EnumSet.noneOf(Material.class);
for(String s : (List<String>) e.getValue()) { for(String s : (List<String>) e.getValue()) {
l.add(Bukkit.createBlockData(s).getMaterial()); l.add(Bukkit.createBlockData(s).getMaterial());
Debug.info("Added " + s + " to shift-able blocks"); Debug.info("Added " + s + " to shift-able blocks");

View File

@ -136,7 +136,7 @@ public class BiomeConfig extends TerraConfig {
ySlantOffsetBottom = getDouble("slant.y-offset.bottom", 0.25); ySlantOffsetBottom = getDouble("slant.y-offset.bottom", 0.25);
//Make sure equation is non-null //Make sure equation is non-null
if(eq == null || eq.equals("")) if(eq == null || eq.isEmpty())
throw new ConfigException("Could not find noise equation! Biomes must include a noise equation, or extend an abstract biome with one.", getID()); throw new ConfigException("Could not find noise equation! Biomes must include a noise equation, or extend an abstract biome with one.", getID());
// Create decorator for this config. // Create decorator for this config.

View File

@ -15,6 +15,7 @@ import org.polydev.gaea.util.FastRandom;
import org.polydev.gaea.world.palette.Palette; import org.polydev.gaea.world.palette.Palette;
import org.polydev.gaea.world.palette.RandomPalette; import org.polydev.gaea.world.palette.RandomPalette;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -34,7 +35,7 @@ public class BiomeSlabConfig extends TerraConfigSection {
} }
protected Map<Material, Palette<BlockData>> getSlabPalettes(List<Map<?, ?>> paletteConfigSection) throws InvalidConfigurationException { protected Map<Material, Palette<BlockData>> getSlabPalettes(List<Map<?, ?>> paletteConfigSection) throws InvalidConfigurationException {
Map<Material, Palette<BlockData>> paletteMap = new HashMap<>(); Map<Material, Palette<BlockData>> paletteMap = new EnumMap<>(Material.class);
for(Map<?, ?> e : paletteConfigSection) { for(Map<?, ?> e : paletteConfigSection) {
for(Map.Entry<?, ?> entry : e.entrySet()) { for(Map.Entry<?, ?> entry : e.entrySet()) {

View File

@ -19,7 +19,7 @@ public class ElevationInterpolator {
for(int x = -2; x < 8; x++) { for(int x = -2; x < 8; x++) {
for(int z = -2; z < 8; z++) { for(int z = -2; z < 8; z++) {
gens[x + 2][z + 2] = (WorldGenerator) grid.getBiome(xOrigin + x * 4, zOrigin + z * 4, GenerationPhase.BASE).getGenerator(); gens[x + 2][z + 2] = (WorldGenerator) grid.getBiome(xOrigin + (x << 2), zOrigin + (z << 2), GenerationPhase.BASE).getGenerator();
} }
} }
@ -58,15 +58,15 @@ public class ElevationInterpolator {
} }
private double biomeAvg(int x, int z) { private double biomeAvg(int x, int z) {
return (elevate(getStoredGen(x + 1, z), x * 4 + 4 + xOrigin, z * 4 + zOrigin) return (elevate(getStoredGen(x + 1, z), (x << 2) + 4 + xOrigin, (z << 2) + zOrigin)
+ elevate(getStoredGen(x - 1, z), x * 4 - 4 + xOrigin, z * 4 + zOrigin) + elevate(getStoredGen(x - 1, z), (x << 2) - 4 + xOrigin, (z << 2) + zOrigin)
+ elevate(getStoredGen(x, z + 1), x * 4 + xOrigin, z * 4 + 4 + zOrigin) + elevate(getStoredGen(x, z + 1), (x << 2) + xOrigin, (z << 2) + 4 + zOrigin)
+ elevate(getStoredGen(x, z - 1), x * 4 + xOrigin, z * 4 - 4 + zOrigin) + elevate(getStoredGen(x, z - 1), (x << 2) + xOrigin, (z << 2) - 4 + zOrigin)
+ elevate(getStoredGen(x, z), x * 4 + xOrigin, z * 4 + zOrigin) + elevate(getStoredGen(x, z), (x << 2) + xOrigin, (z << 2) + zOrigin)
+ elevate(getStoredGen(x - 1, z - 1), x * 4 + xOrigin, z * 4 + zOrigin) + elevate(getStoredGen(x - 1, z - 1), (x << 2) + xOrigin, (z << 2) + zOrigin)
+ elevate(getStoredGen(x - 1, z + 1), x * 4 + xOrigin, z * 4 + zOrigin) + elevate(getStoredGen(x - 1, z + 1), (x << 2) + xOrigin, (z << 2) + zOrigin)
+ elevate(getStoredGen(x + 1, z - 1), x * 4 + xOrigin, z * 4 + zOrigin) + elevate(getStoredGen(x + 1, z - 1), (x << 2) + xOrigin, (z << 2) + zOrigin)
+ elevate(getStoredGen(x + 1, z + 1), x * 4 + xOrigin, z * 4 + zOrigin)) / 9D; + elevate(getStoredGen(x + 1, z + 1), (x << 2) + xOrigin, (z << 2) + zOrigin)) / 9D;
} }
private double elevate(WorldGenerator g, int x, int z) { private double elevate(WorldGenerator g, int x, int z) {

View File

@ -66,14 +66,15 @@ public class CavePopulator extends BlockPopulator {
updateNeeded.add(b); updateNeeded.add(b);
} }
} }
for(Location l : shiftCandidate.keySet()) { for(Map.Entry<Location, Material> entry : shiftCandidate.entrySet()) {
Location l = entry.getKey();
Location mut = l.clone(); Location mut = l.clone();
Material orig = l.getBlock().getType(); Material orig = l.getBlock().getType();
do mut.subtract(0, 1, 0); do mut.subtract(0, 1, 0);
while(mut.getBlock().getType().equals(orig)); while(mut.getBlock().getType().equals(orig));
try { try {
if(c.getShiftedBlocks().get(shiftCandidate.get(l)).contains(mut.getBlock().getType())) { if(c.getShiftedBlocks().get(entry.getValue()).contains(mut.getBlock().getType())) {
mut.getBlock().setBlockData(shiftStorage.computeIfAbsent(shiftCandidate.get(l), Material::createBlockData), false); mut.getBlock().setBlockData(shiftStorage.computeIfAbsent(entry.getValue(), Material::createBlockData), false);
} }
} catch(NullPointerException ignore) { } catch(NullPointerException ignore) {
} }

View File

@ -36,8 +36,8 @@ public class OrePopulator extends GaeaBlockPopulator {
OreConfig ore = e.getKey(); OreConfig ore = e.getKey();
int edgeOffset = ore.getChunkEdgeOffset(); int edgeOffset = ore.getChunkEdgeOffset();
for(int i = 0; i < num; i++) { for(int i = 0; i < num; i++) {
int x = random.nextInt(16 - edgeOffset * 2) + edgeOffset; int x = random.nextInt(16 - (edgeOffset << 1)) + edgeOffset;
int z = random.nextInt(16 - edgeOffset * 2) + edgeOffset; int z = random.nextInt(16 - (edgeOffset << 1)) + edgeOffset;
int y = ores.getOreHeights().get(ore).get(random); int y = ores.getOreHeights().get(ore).get(random);
Vector v = new Vector(x, y, z); Vector v = new Vector(x, y, z);

View File

@ -12,6 +12,7 @@ import org.bukkit.block.data.Rail;
import org.bukkit.block.data.Rotatable; import org.bukkit.block.data.Rotatable;
import org.bukkit.block.data.type.RedstoneWire; import org.bukkit.block.data.type.RedstoneWire;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -252,7 +253,7 @@ public final class RotationUtil {
((Directional) data).setFacing(rt); ((Directional) data).setFacing(rt);
} else if(data instanceof MultipleFacing) { } else if(data instanceof MultipleFacing) {
MultipleFacing mfData = (MultipleFacing) data; MultipleFacing mfData = (MultipleFacing) data;
Map<BlockFace, Boolean> faces = new HashMap<>(); Map<BlockFace, Boolean> faces = new EnumMap<>(BlockFace.class);
for(BlockFace f : mfData.getAllowedFaces()) { for(BlockFace f : mfData.getAllowedFaces()) {
faces.put(f, mfData.hasFace(f)); faces.put(f, mfData.hasFace(f));
} }
@ -266,7 +267,7 @@ public final class RotationUtil {
org.bukkit.Axis newAxis = getRotatedAxis(((Orientable) data).getAxis(), r); org.bukkit.Axis newAxis = getRotatedAxis(((Orientable) data).getAxis(), r);
((Orientable) data).setAxis(newAxis); ((Orientable) data).setAxis(newAxis);
} else if(data instanceof RedstoneWire) { } else if(data instanceof RedstoneWire) {
Map<BlockFace, RedstoneWire.Connection> connections = new HashMap<>(); Map<BlockFace, RedstoneWire.Connection> connections = new EnumMap<>(BlockFace.class);
RedstoneWire rData = (RedstoneWire) data; RedstoneWire rData = (RedstoneWire) data;
for(BlockFace f : rData.getAllowedFaces()) { for(BlockFace f : rData.getAllowedFaces()) {
connections.put(f, rData.getFace(f)); connections.put(f, rData.getFace(f));