Use Faster GlueList

Uses GlueList a faster List implementation. Drop in replacement for ArrayList.

https://github.com/ertugrulcetin/GlueList
This commit is contained in:
Bud Gidiere 2020-11-19 19:09:48 -06:00
parent bb4ecee1f8
commit d125ee3d87
No known key found for this signature in database
GPG Key ID: CD18F99E348902F7
6 changed files with 1062 additions and 7 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.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 com.dfsek.terra.util.GlueList;
import org.apache.commons.math3.util.FastMath; import org.apache.commons.math3.util.FastMath;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -48,7 +49,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
} }
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) { public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
List<Block> blocks = new ArrayList<>(); List<Block> blocks = new GlueList<>();
for(int y : check) { for(int y : check) {
if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) { if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
blocks.add(chunk.getBlock(x, y + 1, z)); blocks.add(chunk.getBlock(x, y + 1, z));

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.procgen; package com.dfsek.terra.procgen;
import com.dfsek.terra.util.GlueList;
import it.unimi.dsi.util.XoRoShiRo128PlusPlusRandom; import it.unimi.dsi.util.XoRoShiRo128PlusPlusRandom;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.polydev.gaea.math.MathUtil; import org.polydev.gaea.math.MathUtil;
@ -31,7 +32,7 @@ public class GridSpawn {
public Vector getNearestSpawn(int x, int z, long seed) { public Vector getNearestSpawn(int x, int z, long seed) {
int structureChunkX = x / (width + 2 * separation); int structureChunkX = x / (width + 2 * separation);
int structureChunkZ = z / (width + 2 * separation); int structureChunkZ = z / (width + 2 * separation);
List<Vector> zones = new ArrayList<>(); List<Vector> zones = new GlueList<>();
for(int xi = structureChunkX - 1; xi <= structureChunkX + 1; xi++) { for(int xi = structureChunkX - 1; xi <= structureChunkX + 1; xi++) {
for(int zi = structureChunkZ - 1; zi <= structureChunkZ + 1; zi++) { for(int zi = structureChunkZ - 1; zi <= structureChunkZ + 1; zi++) {
zones.add(getChunkSpawn(xi, zi, seed)); zones.add(getChunkSpawn(xi, zi, seed));

View File

@ -1,12 +1,13 @@
package com.dfsek.terra.procgen.voxel; package com.dfsek.terra.procgen.voxel;
import com.dfsek.terra.util.GlueList;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class VoxelGeometry { public abstract class VoxelGeometry {
private final List<Vector> geometry = new ArrayList<>(); private final List<Vector> geometry = new GlueList<>();
public static VoxelGeometry getBlank() { public static VoxelGeometry getBlank() {
return new VoxelGeometry() { return new VoxelGeometry() {

View File

@ -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 com.dfsek.terra.util.GlueList;
import it.unimi.dsi.util.XoRoShiRo128PlusPlusRandom; import it.unimi.dsi.util.XoRoShiRo128PlusPlusRandom;
import org.apache.commons.math3.util.FastMath; import org.apache.commons.math3.util.FastMath;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -48,7 +49,7 @@ public class EntityFeature implements Feature {
int cx = info.getCenterX(); int cx = info.getCenterX();
int cz = info.getCenterZ(); int cz = info.getCenterZ();
List<Location> locations = new ArrayList<>(); List<Location> locations = new GlueList<>();
for(int i = 0; i < number; i++) for(int i = 0; i < number; i++)
locations.add(origin.clone().add(x.get(random) - cx, y.get(random), z.get(random) - cz)); locations.add(origin.clone().add(x.get(random) - cx, y.get(random), z.get(random) - cz));
return locations; return locations;

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
import com.dfsek.terra.util.GlueList;
import org.apache.commons.math3.util.FastMath; import org.apache.commons.math3.util.FastMath;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.polydev.gaea.math.FastNoiseLite; import org.polydev.gaea.math.FastNoiseLite;
@ -13,7 +14,7 @@ class LookupGenerator {
static void main(String[] args) throws InterruptedException { static void main(String[] args) throws InterruptedException {
int dist = 4096; int dist = 4096;
List<Double> vals = new ArrayList<>(); List<Double> vals = new GlueList<>();
FastNoiseLite noise = new FastNoiseLite(); FastNoiseLite noise = new FastNoiseLite();
noise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2); noise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
noise.setFrequency(0.02f); noise.setFrequency(0.02f);
@ -26,10 +27,10 @@ class LookupGenerator {
int workerAmount = 16; int workerAmount = 16;
List<Worker> workers = new ArrayList<>(); List<Worker> workers = new GlueList<>();
for(int i = 0; i < workerAmount; i++) { for(int i = 0; i < workerAmount; i++) {
workers.add(new Worker(new ArrayList<>(), 5000000, noise)); workers.add(new Worker(new GlueList<>(), 5000000, noise));
} }
for(Worker w : workers) { for(Worker w : workers) {