mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Merge pull request #16 from budgidiere/master
Replace Math with FastMath for improved performance.
This commit is contained in:
commit
3d092df9d5
1
.gitignore
vendored
1
.gitignore
vendored
@ -136,3 +136,4 @@ build
|
|||||||
.idea/modules/**.iml
|
.idea/modules/**.iml
|
||||||
|
|
||||||
!lib/*.jar
|
!lib/*.jar
|
||||||
|
.idea/Terra.iml
|
||||||
|
@ -39,16 +39,23 @@ dependencies {
|
|||||||
compileOnly(name = "Gaea-${gaeaVersion}", group = "")
|
compileOnly(name = "Gaea-${gaeaVersion}", group = "")
|
||||||
testImplementation(name = "Gaea-${gaeaVersion}", group = "")
|
testImplementation(name = "Gaea-${gaeaVersion}", group = "")
|
||||||
|
|
||||||
compileOnly("org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT")
|
|
||||||
compileOnly("org.jetbrains:annotations:20.1.0")
|
compileOnly("org.jetbrains:annotations:20.1.0")
|
||||||
|
|
||||||
implementation("commons-io:commons-io:2.4")
|
implementation("commons-io:commons-io:2.4")
|
||||||
implementation("org.apache.commons:commons-imaging:1.0-alpha2")
|
implementation("org.apache.commons:commons-imaging:1.0-alpha2")
|
||||||
|
implementation("org.apache.commons:commons-math3:3.6.1")
|
||||||
|
|
||||||
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT")
|
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT")
|
||||||
implementation("org.bstats:bstats-bukkit:1.7")
|
implementation("org.bstats:bstats-bukkit:1.7")
|
||||||
|
|
||||||
compileOnly("com.googlecode.json-simple:json-simple:1.1")
|
compileOnly("com.googlecode.json-simple:json-simple:1.1")
|
||||||
implementation(name = "parsii-1.2", group = "")
|
|
||||||
|
implementation(name = "parsii-1.2.1", group = "")
|
||||||
|
|
||||||
|
compileOnly("org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT")
|
||||||
implementation("io.papermc:paperlib:1.0.5")
|
implementation("io.papermc:paperlib:1.0.5")
|
||||||
|
|
||||||
|
|
||||||
// JUnit.
|
// JUnit.
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
|
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
|
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,5 +1,6 @@
|
|||||||
package com.dfsek.terra.biome.postprocessing;
|
package com.dfsek.terra.biome.postprocessing;
|
||||||
|
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.polydev.gaea.math.FastNoiseLite;
|
import org.polydev.gaea.math.FastNoiseLite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +28,7 @@ public class ErosionNoise {
|
|||||||
* @return Whether location is eroded
|
* @return Whether location is eroded
|
||||||
*/
|
*/
|
||||||
public boolean isEroded(int x, int z) {
|
public boolean isEroded(int x, int z) {
|
||||||
double abs = Math.pow(noise.getNoise(x, z), 2);
|
double abs = FastMath.pow(noise.getNoise(x, z), 2);
|
||||||
return abs < thresh;
|
return abs < thresh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.dfsek.terra.carving;
|
package com.dfsek.terra.carving;
|
||||||
|
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.polydev.gaea.math.FastNoiseLite;
|
import org.polydev.gaea.math.FastNoiseLite;
|
||||||
@ -15,7 +16,7 @@ public class SimplexCarver extends Carver {
|
|||||||
private final FastNoiseLite height;
|
private final FastNoiseLite height;
|
||||||
private final FastNoiseLite column;
|
private final FastNoiseLite column;
|
||||||
private final FastNoiseLite hasCaves;
|
private final FastNoiseLite hasCaves;
|
||||||
private final double root2inverse = 1D / Math.sqrt(2);
|
private final double root2inverse = 1D / FastMath.sqrt(2);
|
||||||
|
|
||||||
public SimplexCarver(int minY, int maxY) {
|
public SimplexCarver(int minY, int maxY) {
|
||||||
super(minY, maxY);
|
super(minY, maxY);
|
||||||
@ -41,7 +42,7 @@ public class SimplexCarver extends Carver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static double acot(double x) {
|
private static double acot(double x) {
|
||||||
return Math.PI / 2 - Math.atan(x);
|
return FastMath.PI / 2 - FastMath.atan(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,15 +54,15 @@ public class SimplexCarver extends Carver {
|
|||||||
for(int z = oz; z < oz + 16; z++) {
|
for(int z = oz; z < oz + 16; z++) {
|
||||||
double heightNoise = height.getNoise(x, z);
|
double heightNoise = height.getNoise(x, z);
|
||||||
double mainNoise = noise.getNoise(x, z) * 2;
|
double mainNoise = noise.getNoise(x, z) * 2;
|
||||||
double columnNoise = Math.pow(Math.max(column.getNoise(x, z), 0) * 2, 3);
|
double columnNoise = FastMath.pow(FastMath.max(column.getNoise(x, z), 0) * 2, 3);
|
||||||
double hc = (acot(16 * (hasCaves.getNoise(x, z) - 0.2)) / Math.PI) - 0.1;
|
double hc = (acot(16 * (hasCaves.getNoise(x, z) - 0.2)) / FastMath.PI) - 0.1;
|
||||||
CarvingData.CarvingType type = CarvingData.CarvingType.BOTTOM;
|
CarvingData.CarvingType type = CarvingData.CarvingType.BOTTOM;
|
||||||
double simplex = (Math.pow(mainNoise + root2inverse, 3) / 2 + columnNoise) * hc;
|
double simplex = (FastMath.pow(mainNoise + root2inverse, 3) / 2 + columnNoise) * hc;
|
||||||
for(int y = 0; y < 64; y++) {
|
for(int y = 0; y < 64; y++) {
|
||||||
double finalNoise = (-0.05 * Math.abs(y - (heightNoise * 16 + 24)) + 1 - simplex) * hc;
|
double finalNoise = (-0.05 * FastMath.abs(y - (heightNoise * 16 + 24)) + 1 - simplex) * hc;
|
||||||
if(finalNoise > 0.5) {
|
if(finalNoise > 0.5) {
|
||||||
c.carve(x - ox, y, z - oz, type);
|
c.carve(x - ox, y, z - oz, type);
|
||||||
double finalNoiseUp = (-0.05 * Math.abs((y + 1) - (heightNoise * 16 + 24)) + 1 - simplex) * hc;
|
double finalNoiseUp = (-0.05 * FastMath.abs((y + 1) - (heightNoise * 16 + 24)) + 1 - simplex) * hc;
|
||||||
if(finalNoiseUp > 0.5) {
|
if(finalNoiseUp > 0.5) {
|
||||||
type = CarvingData.CarvingType.CENTER;
|
type = CarvingData.CarvingType.CENTER;
|
||||||
} else type = CarvingData.CarvingType.TOP;
|
} else type = CarvingData.CarvingType.TOP;
|
||||||
|
@ -3,6 +3,7 @@ package com.dfsek.terra.carving;
|
|||||||
import com.dfsek.terra.TerraWorld;
|
import com.dfsek.terra.TerraWorld;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.polydev.gaea.generation.GenerationPhase;
|
import org.polydev.gaea.generation.GenerationPhase;
|
||||||
@ -81,9 +82,9 @@ public class UserDefinedCarver extends Carver {
|
|||||||
@Override
|
@Override
|
||||||
public void step() {
|
public void step() {
|
||||||
if(steps == nextDirection) {
|
if(steps == nextDirection) {
|
||||||
direction.rotateAroundX(Math.toRadians((getRandom().nextGaussian()) * mutate[0] * recalcMagnitude));
|
direction.rotateAroundX(FastMath.toRadians((getRandom().nextGaussian()) * mutate[0] * recalcMagnitude));
|
||||||
direction.rotateAroundY(Math.toRadians((getRandom().nextGaussian()) * mutate[1] * recalcMagnitude));
|
direction.rotateAroundY(FastMath.toRadians((getRandom().nextGaussian()) * mutate[1] * recalcMagnitude));
|
||||||
direction.rotateAroundZ(Math.toRadians((getRandom().nextGaussian()) * mutate[2] * recalcMagnitude));
|
direction.rotateAroundZ(FastMath.toRadians((getRandom().nextGaussian()) * mutate[2] * recalcMagnitude));
|
||||||
currentRotation = new double[] {(getRandom().nextGaussian()) * mutate[0],
|
currentRotation = new double[] {(getRandom().nextGaussian()) * mutate[0],
|
||||||
(getRandom().nextGaussian()) * mutate[1],
|
(getRandom().nextGaussian()) * mutate[1],
|
||||||
(getRandom().nextGaussian()) * mutate[2]};
|
(getRandom().nextGaussian()) * mutate[2]};
|
||||||
@ -92,10 +93,10 @@ public class UserDefinedCarver extends Carver {
|
|||||||
steps++;
|
steps++;
|
||||||
setRadius(new int[] {(int) (runningRadius * radiusMultiplier[0]), (int) (runningRadius * radiusMultiplier[1]), (int) (runningRadius * radiusMultiplier[2])});
|
setRadius(new int[] {(int) (runningRadius * radiusMultiplier[0]), (int) (runningRadius * radiusMultiplier[1]), (int) (runningRadius * radiusMultiplier[2])});
|
||||||
runningRadius += (getRandom().nextDouble() - 0.5) * mutate[3];
|
runningRadius += (getRandom().nextDouble() - 0.5) * mutate[3];
|
||||||
runningRadius = Math.max(Math.min(runningRadius, maxRad), 1);
|
runningRadius = FastMath.max(FastMath.min(runningRadius, maxRad), 1);
|
||||||
direction.rotateAroundX(Math.toRadians(currentRotation[0] * mutate[0]));
|
direction.rotateAroundX(FastMath.toRadians(currentRotation[0] * mutate[0]));
|
||||||
direction.rotateAroundY(Math.toRadians(currentRotation[1] * mutate[1]));
|
direction.rotateAroundY(FastMath.toRadians(currentRotation[1] * mutate[1]));
|
||||||
direction.rotateAroundZ(Math.toRadians(currentRotation[2] * mutate[2]));
|
direction.rotateAroundZ(FastMath.toRadians(currentRotation[2] * mutate[2]));
|
||||||
getRunning().add(direction);
|
getRunning().add(direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.dfsek.terra.command;
|
|||||||
import com.dfsek.terra.TerraWorld;
|
import com.dfsek.terra.TerraWorld;
|
||||||
import com.dfsek.terra.config.genconfig.OreConfig;
|
import com.dfsek.terra.config.genconfig.OreConfig;
|
||||||
import com.dfsek.terra.config.lang.LangUtil;
|
import com.dfsek.terra.config.lang.LangUtil;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -34,7 +35,7 @@ public class OreCommand extends WorldCommand {
|
|||||||
LangUtil.send("command.ore.out-of-range", sender);
|
LangUtil.send("command.ore.out-of-range", sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Vector source = new Vector(Math.floorMod(bl.getX(), 16), bl.getY(), Math.floorMod(bl.getZ(), 16));
|
Vector source = new Vector(FastMath.floorMod(bl.getX(), 16), bl.getY(), FastMath.floorMod(bl.getZ(), 16));
|
||||||
ore.doVein(source, bl.getChunk(), new Random());
|
ore.doVein(source, bl.getChunk(), new Random());
|
||||||
} else {
|
} else {
|
||||||
LangUtil.send("command.ore.main-menu", sender);
|
LangUtil.send("command.ore.main-menu", sender);
|
||||||
|
@ -4,6 +4,7 @@ import com.dfsek.terra.config.TerraConfig;
|
|||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
import com.dfsek.terra.config.base.ConfigUtil;
|
import com.dfsek.terra.config.base.ConfigUtil;
|
||||||
import com.dfsek.terra.config.exception.ConfigException;
|
import com.dfsek.terra.config.exception.ConfigException;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -95,12 +96,12 @@ public class FloraConfig extends TerraConfig implements Flora {
|
|||||||
public boolean plant(Location location) {
|
public boolean plant(Location location) {
|
||||||
int size = floraPalette.getSize();
|
int size = floraPalette.getSize();
|
||||||
int c = ceiling ? -1 : 1;
|
int c = ceiling ? -1 : 1;
|
||||||
for(int i = 0; Math.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||||
if(i + 1 > 255) return false;
|
if(i + 1 > 255) return false;
|
||||||
if(!replaceable.contains(location.clone().add(0, i + c, 0).getBlock().getType())) return false;
|
if(!replaceable.contains(location.clone().add(0, i + c, 0).getBlock().getType())) return false;
|
||||||
}
|
}
|
||||||
for(int i = 0; Math.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||||
int lvl = (Math.abs(i));
|
int lvl = (FastMath.abs(i));
|
||||||
location.clone().add(0, i + c, 0).getBlock().setBlockData(floraPalette.get((ceiling ? lvl : size - lvl - 1), location.getBlockX(), location.getBlockZ()), physics);
|
location.clone().add(0, i + c, 0).getBlock().setBlockData(floraPalette.get((ceiling ? lvl : size - lvl - 1), location.getBlockX(), location.getBlockZ()), physics);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -4,6 +4,7 @@ import com.dfsek.terra.config.TerraConfig;
|
|||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
import com.dfsek.terra.config.base.ConfigUtil;
|
import com.dfsek.terra.config.base.ConfigUtil;
|
||||||
import com.dfsek.terra.config.exception.ConfigException;
|
import com.dfsek.terra.config.exception.ConfigException;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -80,9 +81,9 @@ public class OreConfig extends TerraConfig {
|
|||||||
Vector source = l.clone().add(new Vector(x, y, z));
|
Vector source = l.clone().add(new Vector(x, y, z));
|
||||||
if(oreLoc.getBlockY() > 255 || oreLoc.getBlockY() < 0) continue;
|
if(oreLoc.getBlockY() > 255 || oreLoc.getBlockY() < 0) continue;
|
||||||
if(source.distance(l) < (rad + 0.5) * ((ore.getNoise(x, y, z) + 1) * deform)) {
|
if(source.distance(l) < (rad + 0.5) * ((ore.getNoise(x, y, z) + 1) * deform)) {
|
||||||
ChunkCoordinate coord = new ChunkCoordinate(Math.floorDiv(oreLoc.getBlockX(), 16), Math.floorDiv(oreLoc.getBlockZ(), 16), chunk.getWorld().getUID());
|
ChunkCoordinate coord = new ChunkCoordinate(FastMath.floorDiv(oreLoc.getBlockX(), 16), FastMath.floorDiv(oreLoc.getBlockZ(), 16), chunk.getWorld().getUID());
|
||||||
Block b = chunks.computeIfAbsent(coord, k -> chunk.getWorld().getChunkAt(oreLoc.toLocation(chunk.getWorld())))
|
Block b = chunks.computeIfAbsent(coord, k -> chunk.getWorld().getChunkAt(oreLoc.toLocation(chunk.getWorld())))
|
||||||
.getBlock(Math.floorMod(source.getBlockX(), 16), source.getBlockY(), Math.floorMod(source.getBlockZ(), 16)); // Chunk caching conditional computation
|
.getBlock(FastMath.floorMod(source.getBlockX(), 16), source.getBlockY(), FastMath.floorMod(source.getBlockZ(), 16)); // Chunk caching conditional computation
|
||||||
if(replaceable.contains(b.getType()) && b.getLocation().getY() >= 0)
|
if(replaceable.contains(b.getType()) && b.getLocation().getY() >= 0)
|
||||||
b.setBlockData(oreData, update);
|
b.setBlockData(oreData, update);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.dfsek.terra.TerraWorld;
|
|||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||||
import com.dfsek.terra.image.ImageLoader;
|
import com.dfsek.terra.image.ImageLoader;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.polydev.gaea.generation.GenerationPhase;
|
import org.polydev.gaea.generation.GenerationPhase;
|
||||||
@ -33,12 +34,12 @@ public class DebugFrame extends JFrame implements ActionListener {
|
|||||||
super.paintComponents(g);
|
super.paintComponents(g);
|
||||||
for(Player p : Bukkit.getOnlinePlayers()) {
|
for(Player p : Bukkit.getOnlinePlayers()) {
|
||||||
if(!(p.getWorld().getGenerator() instanceof TerraChunkGenerator)) break;
|
if(!(p.getWorld().getGenerator() instanceof TerraChunkGenerator)) break;
|
||||||
int xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX() - (img.getWidth() / 2), x) / x) * getWidth());
|
int xp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockX() - (img.getWidth() / 2), x) / x) * getWidth());
|
||||||
int zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ() - (img.getHeight() / 2), z) / z) * getHeight());
|
int zp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockZ() - (img.getHeight() / 2), z) / z) * getHeight());
|
||||||
ImageLoader loader = TerraWorld.getWorld(p.getWorld()).getWorldConfig().imageLoader;
|
ImageLoader loader = TerraWorld.getWorld(p.getWorld()).getWorldConfig().imageLoader;
|
||||||
if(loader != null && loader.getAlign().equals(ImageLoader.Align.NONE)) {
|
if(loader != null && loader.getAlign().equals(ImageLoader.Align.NONE)) {
|
||||||
xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
|
xp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
|
||||||
zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
|
zp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
|
||||||
}
|
}
|
||||||
String str = TerraWorld.getWorld(p.getWorld()).getConfig().getBiome((UserDefinedBiome) TerraWorld.getWorld(p.getWorld()).getGrid().getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
|
String str = TerraWorld.getWorld(p.getWorld()).getConfig().getBiome((UserDefinedBiome) TerraWorld.getWorld(p.getWorld()).getGrid().getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
|
||||||
g.setColor(new Color(255, 255, 255, 128));
|
g.setColor(new Color(255, 255, 255, 128));
|
||||||
|
@ -5,6 +5,7 @@ import com.dfsek.terra.biome.BiomeZone;
|
|||||||
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
||||||
import com.dfsek.terra.config.base.ConfigUtil;
|
import com.dfsek.terra.config.base.ConfigUtil;
|
||||||
import com.dfsek.terra.debug.gui.DebugGUI;
|
import com.dfsek.terra.debug.gui.DebugGUI;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.polydev.gaea.biome.NormalizationUtil;
|
import org.polydev.gaea.biome.NormalizationUtil;
|
||||||
|
|
||||||
@ -108,12 +109,12 @@ public class ImageLoader {
|
|||||||
NONE {
|
NONE {
|
||||||
@Override
|
@Override
|
||||||
public int getRGB(BufferedImage image, int x, int y) {
|
public int getRGB(BufferedImage image, int x, int y) {
|
||||||
return image.getRGB(Math.floorMod(x, image.getWidth()), Math.floorMod(y, image.getHeight()));
|
return image.getRGB(FastMath.floorMod(x, image.getWidth()), FastMath.floorMod(y, image.getHeight()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static int getRGBNoAlign(BufferedImage image, int x, int y) {
|
private static int getRGBNoAlign(BufferedImage image, int x, int y) {
|
||||||
return image.getRGB(Math.floorMod(x, image.getWidth()), Math.floorMod(y, image.getHeight()));
|
return image.getRGB(FastMath.floorMod(x, image.getWidth()), FastMath.floorMod(y, image.getHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract int getRGB(BufferedImage image, int x, int y);
|
public abstract int getRGB(BufferedImage image, int x, int y);
|
||||||
|
@ -9,6 +9,7 @@ import com.dfsek.terra.config.base.ConfigPack;
|
|||||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||||
import com.dfsek.terra.config.genconfig.biome.BiomeFloraConfig;
|
import com.dfsek.terra.config.genconfig.biome.BiomeFloraConfig;
|
||||||
import com.dfsek.terra.event.TreeGenerateEvent;
|
import com.dfsek.terra.event.TreeGenerateEvent;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -57,7 +58,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int offset(Random r, int i) {
|
private static int offset(Random r, int i) {
|
||||||
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
|
return FastMath.min(FastMath.max(i + r.nextInt(3) - 1, 0), 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
|
@ -13,6 +13,7 @@ import com.dfsek.terra.structure.Structure;
|
|||||||
import com.dfsek.terra.structure.StructureContainedInventory;
|
import com.dfsek.terra.structure.StructureContainedInventory;
|
||||||
import com.dfsek.terra.structure.features.Feature;
|
import com.dfsek.terra.structure.features.Feature;
|
||||||
import com.dfsek.terra.util.structure.RotationUtil;
|
import com.dfsek.terra.util.structure.RotationUtil;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -48,15 +49,15 @@ public class StructurePopulator extends BlockPopulator {
|
|||||||
spawn.setY(y);
|
spawn.setY(y);
|
||||||
if(!struc.checkSpawns(spawn, rotation)) continue;
|
if(!struc.checkSpawns(spawn, rotation)) continue;
|
||||||
double horizontal = struc.getStructureInfo().getMaxHorizontal();
|
double horizontal = struc.getStructureInfo().getMaxHorizontal();
|
||||||
if(Math.abs((cx + 8) - spawn.getBlockX()) <= horizontal && Math.abs((cz + 8) - spawn.getBlockZ()) <= horizontal) {
|
if(FastMath.abs((cx + 8) - spawn.getBlockX()) <= horizontal && FastMath.abs((cz + 8) - spawn.getBlockZ()) <= horizontal) {
|
||||||
struc.paste(spawn, chunk, rotation);
|
struc.paste(spawn, chunk, rotation);
|
||||||
for(StructureContainedInventory i : struc.getInventories()) {
|
for(StructureContainedInventory i : struc.getInventories()) {
|
||||||
try {
|
try {
|
||||||
Debug.info("Attempting to populate loot: " + i.getUid());
|
Debug.info("Attempting to populate loot: " + i.getUid());
|
||||||
Vector2 lootCoords = RotationUtil.getRotatedCoords(new Vector2(i.getX() - struc.getStructureInfo().getCenterX(), i.getZ() - struc.getStructureInfo().getCenterZ()), rotation.inverse());
|
Vector2 lootCoords = RotationUtil.getRotatedCoords(new Vector2(i.getX() - struc.getStructureInfo().getCenterX(), i.getZ() - struc.getStructureInfo().getCenterZ()), rotation.inverse());
|
||||||
Location inv = spawn.clone().add(lootCoords.getX(), i.getY(), lootCoords.getZ());
|
Location inv = spawn.clone().add(lootCoords.getX(), i.getY(), lootCoords.getZ());
|
||||||
Debug.info(Math.floorDiv(inv.getBlockX(), 16) + ":" + chunk.getX() + ", " + Math.floorDiv(inv.getBlockZ(), 16) + ":" + chunk.getZ());
|
Debug.info(FastMath.floorDiv(inv.getBlockX(), 16) + ":" + chunk.getX() + ", " + FastMath.floorDiv(inv.getBlockZ(), 16) + ":" + chunk.getZ());
|
||||||
if(Math.floorDiv(inv.getBlockX(), 16) != chunk.getX() || Math.floorDiv(inv.getBlockZ(), 16) != chunk.getZ())
|
if(FastMath.floorDiv(inv.getBlockX(), 16) != chunk.getX() || FastMath.floorDiv(inv.getBlockZ(), 16) != chunk.getZ())
|
||||||
continue;
|
continue;
|
||||||
Debug.info("Target is in chunk.");
|
Debug.info("Target is in chunk.");
|
||||||
Debug.info(spawn.toString() + " became: " + inv.toString() + " (" + rotation + ", " + inv.getBlock().getType() + ")");
|
Debug.info(spawn.toString() + " became: " + inv.toString() + " (" + rotation + ", " + inv.getBlock().getType() + ")");
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.dfsek.terra.procgen.math;
|
package com.dfsek.terra.procgen.math;
|
||||||
|
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* oh yeah
|
* oh yeah
|
||||||
*/
|
*/
|
||||||
@ -111,7 +113,7 @@ public class Vector2 implements Cloneable {
|
|||||||
* @return length
|
* @return length
|
||||||
*/
|
*/
|
||||||
public double length() {
|
public double length() {
|
||||||
return Math.sqrt(lengthSquared());
|
return FastMath.sqrt(lengthSquared());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,7 +132,7 @@ public class Vector2 implements Cloneable {
|
|||||||
* @return Distance between vectors
|
* @return Distance between vectors
|
||||||
*/
|
*/
|
||||||
public double distance(Vector2 other) {
|
public double distance(Vector2 other) {
|
||||||
return Math.sqrt(distanceSquared(other));
|
return FastMath.sqrt(distanceSquared(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.dfsek.terra.procgen.pixel;
|
package com.dfsek.terra.procgen.pixel;
|
||||||
|
|
||||||
import com.dfsek.terra.procgen.math.Vector2;
|
import com.dfsek.terra.procgen.math.Vector2;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -11,8 +12,8 @@ public class Rectangle extends Polygon {
|
|||||||
private final Vector2 max;
|
private final Vector2 max;
|
||||||
|
|
||||||
public Rectangle(Vector2 min, Vector2 max) {
|
public Rectangle(Vector2 min, Vector2 max) {
|
||||||
this.max = new Vector2(Math.min(min.getX(), max.getX()), Math.min(min.getZ(), max.getZ()));
|
this.max = new Vector2(FastMath.min(min.getX(), max.getX()), FastMath.min(min.getZ(), max.getZ()));
|
||||||
this.min = new Vector2(Math.max(min.getX(), max.getX()), Math.max(min.getZ(), max.getZ()));
|
this.min = new Vector2(FastMath.max(min.getX(), max.getX()), FastMath.max(min.getZ(), max.getZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle(Vector2 center, double xRadius, double zRadius) {
|
public Rectangle(Vector2 center, double xRadius, double zRadius) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.dfsek.terra.structure;
|
package com.dfsek.terra.structure;
|
||||||
|
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
|
|
||||||
public enum Rotation {
|
public enum Rotation {
|
||||||
CW_90(90), CW_180(180), CCW_90(270), NONE(0);
|
CW_90(90), CW_180(180), CCW_90(270), NONE(0);
|
||||||
private final int degrees;
|
private final int degrees;
|
||||||
@ -9,7 +11,7 @@ public enum Rotation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Rotation fromDegrees(int deg) {
|
public static Rotation fromDegrees(int deg) {
|
||||||
switch(Math.floorMod(deg, 360)) {
|
switch(FastMath.floorMod(deg, 360)) {
|
||||||
case 0:
|
case 0:
|
||||||
return Rotation.NONE;
|
return Rotation.NONE;
|
||||||
case 90:
|
case 90:
|
||||||
|
@ -3,6 +3,7 @@ package com.dfsek.terra.structure;
|
|||||||
import com.dfsek.terra.Debug;
|
import com.dfsek.terra.Debug;
|
||||||
import com.dfsek.terra.procgen.math.Vector2;
|
import com.dfsek.terra.procgen.math.Vector2;
|
||||||
import com.dfsek.terra.util.structure.RotationUtil;
|
import com.dfsek.terra.util.structure.RotationUtil;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -198,7 +199,7 @@ public class Structure implements Serializable {
|
|||||||
}
|
}
|
||||||
int offset = block.getPullOffset();
|
int offset = block.getPullOffset();
|
||||||
if(offset != 0)
|
if(offset != 0)
|
||||||
worldBlock = worldBlock.getRelative((offset > 0) ? BlockFace.UP : BlockFace.DOWN, Math.abs(offset));
|
worldBlock = worldBlock.getRelative((offset > 0) ? BlockFace.UP : BlockFace.DOWN, FastMath.abs(offset));
|
||||||
|
|
||||||
RotationUtil.rotateBlockData(data, r);
|
RotationUtil.rotateBlockData(data, r);
|
||||||
|
|
||||||
@ -265,9 +266,9 @@ public class Structure implements Serializable {
|
|||||||
Vector2 max = getRotatedCoords(new Vector2(x.getMax(), z.getMax()).subtract(center), r.inverse()).add(center);
|
Vector2 max = getRotatedCoords(new Vector2(x.getMax(), z.getMax()).subtract(center), r.inverse()).add(center);
|
||||||
|
|
||||||
if(a.equals(Rotation.Axis.X))
|
if(a.equals(Rotation.Axis.X))
|
||||||
return new Range((int) Math.floor(Math.min(min.getX(), max.getX())), (int) Math.ceil(Math.max(min.getX(), max.getX())) + 1);
|
return new Range((int) FastMath.floor(FastMath.min(min.getX(), max.getX())), (int) FastMath.ceil(FastMath.max(min.getX(), max.getX())) + 1);
|
||||||
else
|
else
|
||||||
return new Range((int) Math.floor(Math.min(min.getZ(), max.getZ())), (int) Math.ceil(Math.max(min.getZ(), max.getZ())) + 1);
|
return new Range((int) FastMath.floor(FastMath.min(min.getZ(), max.getZ())), (int) FastMath.ceil(FastMath.max(min.getZ(), max.getZ())) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.dfsek.terra.structure;
|
package com.dfsek.terra.structure;
|
||||||
|
|
||||||
import com.dfsek.terra.procgen.math.Vector2;
|
import com.dfsek.terra.procgen.math.Vector2;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@ -41,6 +42,6 @@ public class StructureInfo implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getMaxHorizontal() {
|
public double getMaxHorizontal() {
|
||||||
return Math.sqrt(Math.pow(sizeX, 2) + Math.pow(sizeZ, 2));
|
return FastMath.sqrt(FastMath.pow(sizeX, 2) + FastMath.pow(sizeZ, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.dfsek.terra.Debug;
|
|||||||
import com.dfsek.terra.structure.Rotation;
|
import com.dfsek.terra.structure.Rotation;
|
||||||
import com.dfsek.terra.structure.Structure;
|
import com.dfsek.terra.structure.Structure;
|
||||||
import com.dfsek.terra.structure.StructureInfo;
|
import com.dfsek.terra.structure.StructureInfo;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -35,7 +36,7 @@ public class EntityFeature implements Feature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInChunk(Chunk c, Location l) {
|
private static boolean isInChunk(Chunk c, Location l) {
|
||||||
return Math.floorDiv(l.getBlockX(), 16) == c.getX() && Math.floorDiv(l.getBlockZ(), 16) == c.getZ();
|
return FastMath.floorDiv(l.getBlockX(), 16) == c.getX() && FastMath.floorDiv(l.getBlockZ(), 16) == c.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Location> getLocations(Structure structure, Rotation r, Location origin, Random random, int number) {
|
private static List<Location> getLocations(Structure structure, Rotation r, Location origin, Random random, int number) {
|
||||||
|
@ -2,6 +2,7 @@ package com.dfsek.terra.util.structure;
|
|||||||
|
|
||||||
import com.dfsek.terra.procgen.math.Vector2;
|
import com.dfsek.terra.procgen.math.Vector2;
|
||||||
import com.dfsek.terra.structure.Rotation;
|
import com.dfsek.terra.structure.Rotation;
|
||||||
|
import org.apache.commons.math3.util.FastMath;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.Directional;
|
import org.bukkit.block.data.Directional;
|
||||||
@ -107,7 +108,7 @@ public final class RotationUtil {
|
|||||||
* @return BlockFace represented by integer.
|
* @return BlockFace represented by integer.
|
||||||
*/
|
*/
|
||||||
public static BlockFace fromRotation(int r) {
|
public static BlockFace fromRotation(int r) {
|
||||||
switch(Math.floorMod(r, 16)) {
|
switch(FastMath.floorMod(r, 16)) {
|
||||||
case 0:
|
case 0:
|
||||||
return BlockFace.NORTH;
|
return BlockFace.NORTH;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -26,8 +26,8 @@ class DistributionTest {
|
|||||||
long l = System.nanoTime();
|
long l = System.nanoTime();
|
||||||
for(int i = 0; i < 1000000; i++) {
|
for(int i = 0; i < 1000000; i++) {
|
||||||
double n = noise.getNoise(0, i);
|
double n = noise.getNoise(0, i);
|
||||||
max = Math.max(max, n);
|
max = FastMath.max(max, n);
|
||||||
min = Math.min(min, n);
|
min = FastMath.min(min, n);
|
||||||
numbers[normalize(n, attempts)]++;
|
numbers[normalize(n, attempts)]++;
|
||||||
}
|
}
|
||||||
long l2 = System.nanoTime() - l;
|
long l2 = System.nanoTime() - l;
|
||||||
@ -36,8 +36,8 @@ class DistributionTest {
|
|||||||
l = System.nanoTime();
|
l = System.nanoTime();
|
||||||
for(int i = 0; i < 1000000; i++) {
|
for(int i = 0; i < 1000000; i++) {
|
||||||
double n = noise.getNoise(0, i);
|
double n = noise.getNoise(0, i);
|
||||||
max = Math.max(max, n);
|
max = FastMath.max(max, n);
|
||||||
min = Math.min(min, n);
|
min = FastMath.min(min, n);
|
||||||
}
|
}
|
||||||
l2 = System.nanoTime() - l;
|
l2 = System.nanoTime() - l;
|
||||||
System.out.println("Took " + (double) l2 / 1000000 + "ms (" + ((double) l2 / 1000000) + "ns per.");
|
System.out.println("Took " + (double) l2 / 1000000 + "ms (" + ((double) l2 / 1000000) + "ns per.");
|
||||||
@ -67,8 +67,8 @@ class DistributionTest {
|
|||||||
end = mid;
|
end = mid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double left = Math.abs(normalMap[start] - d);
|
double left = FastMath.abs(normalMap[start] - d);
|
||||||
double right = Math.abs(normalMap[end] - d);
|
double right = FastMath.abs(normalMap[end] - d);
|
||||||
if (left <= right) {
|
if (left <= right) {
|
||||||
return start * (num) / (normalMap.length);
|
return start * (num) / (normalMap.length);
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ class DistributionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int normal(double d, int max) {
|
public static int normal(double d, int max) {
|
||||||
double ranged = Math.max(0, Math.min((d + 1) / 2D, 1));
|
double ranged = FastMath.max(0, FastMath.min((d + 1) / 2D, 1));
|
||||||
return (int) (ranged * max);
|
return (int) (ranged * max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,8 @@ class LookupGenerator {
|
|||||||
|
|
||||||
public static int normalize(double i, int n) {
|
public static int normalize(double i, int n) {
|
||||||
i *= 1.42; // Magic simplex value (sqrt(2) plus a little)
|
i *= 1.42; // Magic simplex value (sqrt(2) plus a little)
|
||||||
i = Math.min(Math.max(i, -1), 1);
|
i = FastMath.min(FastMath.max(i, -1), 1);
|
||||||
return Math.min((int) Math.floor((i + 1) * ((double) n / 2)), n - 1);
|
return FastMath.min((int) FastMath.floor((i + 1) * ((double) n / 2)), n - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Worker extends Thread {
|
private static class Worker extends Thread {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user