Replace Math with FastMath for improved performance.

FastMath is a drop in replacement for the native Java math class with improved performance and fall backs to the native Java math class if necessary.

https://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/util/FastMath.html

This requires further testing and might cause chunk borders due the FastMath giving slightly different results than the native Java math class.

I also added .idea/Terra.iml to the .gitignore
This commit is contained in:
Bud Gidiere
2020-11-18 17:23:09 -06:00
parent 19162a1924
commit 0a77487399
21 changed files with 73 additions and 52 deletions

View File

@@ -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.BiomeFloraConfig;
import com.dfsek.terra.event.TreeGenerateEvent;
import org.apache.commons.math3.util.FastMath;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
@@ -57,7 +58,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
}
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")

View File

@@ -13,6 +13,7 @@ import com.dfsek.terra.structure.Structure;
import com.dfsek.terra.structure.StructureContainedInventory;
import com.dfsek.terra.structure.features.Feature;
import com.dfsek.terra.util.structure.RotationUtil;
import org.apache.commons.math3.util.FastMath;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
@@ -48,15 +49,15 @@ public class StructurePopulator extends BlockPopulator {
spawn.setY(y);
if(!struc.checkSpawns(spawn, rotation)) continue;
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);
for(StructureContainedInventory i : struc.getInventories()) {
try {
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());
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());
if(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(FastMath.floorDiv(inv.getBlockX(), 16) != chunk.getX() || FastMath.floorDiv(inv.getBlockZ(), 16) != chunk.getZ())
continue;
Debug.info("Target is in chunk.");
Debug.info(spawn.toString() + " became: " + inv.toString() + " (" + rotation + ", " + inv.getBlock().getType() + ")");