9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-30 20:39:21 +00:00

Performance

This commit is contained in:
Daniel Mills
2020-09-01 20:41:26 -04:00
parent 683becabda
commit e8addbc954
12 changed files with 235 additions and 81 deletions

View File

@@ -23,7 +23,8 @@ import lombok.Data;
@Desc("An iris effect")
@Data
public class IrisEffect {
public class IrisEffect
{
@DontObfuscate
@Desc("The potion effect to apply in this area")
private String potionEffect = "";
@@ -32,45 +33,45 @@ public class IrisEffect {
@Desc("The particle effect to apply in the area")
private Particle particleEffect = null;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@MinNumber(-32)
@MaxNumber(32)
@DontObfuscate
@Desc("Randomly offset from the surface to this surface+value")
private int particleOffset = 0;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@MinNumber(-8)
@MaxNumber(8)
@DontObfuscate
@Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.")
private double particleAltX = 0;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@MinNumber(-8)
@MaxNumber(8)
@DontObfuscate
@Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.")
private double particleAltY = 0;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@MinNumber(-8)
@MaxNumber(8)
@DontObfuscate
@Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.")
private double particleAltZ = 0;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@DontObfuscate
@Desc("Randomize the altX by -altX to altX")
private boolean randomAltX = true;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@DontObfuscate
@Desc("Randomize the altY by -altY to altY")
private boolean randomAltY = false;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@DontObfuscate
@Desc("Randomize the altZ by -altZ to altZ")
private boolean randomAltZ = true;
@@ -79,74 +80,74 @@ public class IrisEffect {
@Desc("The sound to play")
private Sound sound = null;
@DependsOn({ "sound" })
@DependsOn({"sound"})
@MinNumber(0)
@MaxNumber(512)
@DontObfuscate
@Desc("The max distance from the player the sound will play")
private int soundDistance = 12;
@DependsOn({ "sound", "maxPitch" })
@DependsOn({"sound", "maxPitch"})
@MinNumber(0.01)
@MaxNumber(1.99)
@DontObfuscate
@Desc("The minimum sound pitch")
private double minPitch = 0.5D;
@DependsOn({ "sound", "minVolume" })
@DependsOn({"sound", "minVolume"})
@MinNumber(0.01)
@MaxNumber(1.99)
@DontObfuscate
@Desc("The max sound pitch")
private double maxPitch = 1.5D;
@DependsOn({ "sound" })
@DependsOn({"sound"})
@MinNumber(0.001)
@MaxNumber(512)
@DontObfuscate
@Desc("The sound volume.")
private double volume = 1.5D;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@MinNumber(0)
@MaxNumber(512)
@DontObfuscate
@Desc("The particle count. Try setting to zero for using the alt xyz to a motion value instead of an offset")
private int particleCount = 0;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@MinNumber(0)
@MaxNumber(64)
@DontObfuscate
@Desc("How far away from the player particles can play")
private int particleDistance = 20;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@MinNumber(0)
@MaxNumber(128)
@DontObfuscate
@Desc("How wide the particles can play (player's view left and right) RADIUS")
private int particleDistanceWidth = 24;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@DontObfuscate
@Desc("An extra value for some particles... Which bukkit doesn't even document.")
private double extra = 0;
@DependsOn({ "potionEffect" })
@DependsOn({"potionEffect"})
@MinNumber(-1)
@MaxNumber(1024)
@DontObfuscate
@Desc("The Potion Strength or -1 to disable")
private int potionStrength = -1;
@DependsOn({ "potionEffect", "potionTicksMin" })
@DependsOn({"potionEffect", "potionTicksMin"})
@MinNumber(1)
@DontObfuscate
@Desc("The max time the potion will last for")
private int potionTicksMax = 155;
@DependsOn({ "potionEffect", "potionTicksMax" })
@DependsOn({"potionEffect", "potionTicksMax"})
@MinNumber(1)
@DontObfuscate
@Desc("The min time the potion will last for")
@@ -158,7 +159,7 @@ public class IrisEffect {
@Desc("The effect interval in milliseconds")
private int interval = 150;
@DependsOn({ "particleEffect" })
@DependsOn({"particleEffect"})
@MinNumber(0)
@MaxNumber(16)
@DontObfuscate
@@ -174,25 +175,33 @@ public class IrisEffect {
private transient AtomicCache<PotionEffectType> pt = new AtomicCache<>();
private transient AtomicCache<ChronoLatch> latch = new AtomicCache<>();
public IrisEffect() {
public IrisEffect()
{
}
public boolean canTick() {
public boolean canTick()
{
return latch.aquire(() -> new ChronoLatch(interval)).flip();
}
public PotionEffectType getRealType() {
return pt.aquire(() -> {
public PotionEffectType getRealType()
{
return pt.aquire(() ->
{
PotionEffectType t = PotionEffectType.LUCK;
if (getPotionEffect().isEmpty()) {
if(getPotionEffect().isEmpty())
{
return t;
}
try {
for (PotionEffectType i : PotionEffectType.values()) {
if (i.getName().toUpperCase().replaceAll("\\Q \\E", "_").equals(getPotionEffect())) {
try
{
for(PotionEffectType i : PotionEffectType.values())
{
if(i.getName().toUpperCase().replaceAll("\\Q \\E", "_").equals(getPotionEffect()))
{
t = i;
return t;
@@ -200,7 +209,8 @@ public class IrisEffect {
}
}
catch (Throwable e) {
catch(Throwable e)
{
}
@@ -210,57 +220,55 @@ public class IrisEffect {
});
}
public void apply(Player p, IrisChunkGenerator g) {
if (!canTick()) {
public void apply(Player p, IrisChunkGenerator g)
{
if(!canTick())
{
return;
}
if (RNG.r.nextInt(chance) != 0) {
if(RNG.r.nextInt(chance) != 0)
{
return;
}
if (sound != null) {
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance),
RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
if(sound != null)
{
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
p.playSound(part, getSound(), (float) volume, (float) RNG.r.d(minPitch, maxPitch));
}
if (particleEffect != null) {
Location part = p.getLocation().clone()
.add(p.getLocation().getDirection().clone().multiply(RNG.r.i(particleDistance) + particleAway))
.clone().add(p.getLocation().getDirection().clone().rotateAroundY(Math.toRadians(90))
.multiply(RNG.r.d(-particleDistanceWidth, particleDistanceWidth)));
if(particleEffect != null)
{
Location part = p.getLocation().clone().add(p.getLocation().getDirection().clone().multiply(RNG.r.i(particleDistance) + particleAway)).clone().add(p.getLocation().getDirection().clone().rotateAroundY(Math.toRadians(90)).multiply(RNG.r.d(-particleDistanceWidth, particleDistanceWidth)));
part.setY(Math.round(g.getTerrainHeight(part.getBlockX(), part.getBlockZ())) + 1);
part.add(RNG.r.d(), 0, RNG.r.d());
if (extra != 0) {
p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(),
particleCount, randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX,
randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY,
randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ, extra);
if(extra != 0)
{
p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(), particleCount, randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ, extra);
}
else {
p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(),
particleCount, randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX,
randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY,
randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ);
else
{
p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(), particleCount, randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ);
}
}
if (potionStrength > -1) {
if (p.hasPotionEffect(getRealType())) {
if(potionStrength > -1)
{
if(p.hasPotionEffect(getRealType()))
{
PotionEffect e = p.getPotionEffect(getRealType());
if (e.getAmplifier() > getPotionStrength()) {
if(e.getAmplifier() > getPotionStrength())
{
return;
}
p.removePotionEffect(getRealType());
}
p.addPotionEffect(new PotionEffect(getRealType(),
RNG.r.i(Math.min(potionTicksMax, potionTicksMin), Math.max(potionTicksMax, potionTicksMin)),
getPotionStrength(), true, false, false));
p.addPotionEffect(new PotionEffect(getRealType(), RNG.r.i(Math.min(potionTicksMax, potionTicksMin), Math.max(potionTicksMax, potionTicksMin)), getPotionStrength(), true, false, false));
}
}
}

View File

@@ -13,7 +13,8 @@ import lombok.Data;
@Desc("A gen style")
@Data
public class IrisGeneratorStyle {
public class IrisGeneratorStyle
{
@Required
@DontObfuscate
@@ -42,23 +43,33 @@ public class IrisGeneratorStyle {
private final transient AtomicCache<CNG> cng = new AtomicCache<CNG>();
public IrisGeneratorStyle() {
public IrisGeneratorStyle()
{
}
public IrisGeneratorStyle(NoiseStyle s) {
public IrisGeneratorStyle(NoiseStyle s)
{
this.style = s;
}
public CNG create(RNG rng) {
return cng.aquire(() -> {
public CNG create(RNG rng)
{
return cng.aquire(() ->
{
CNG cng = style.create(rng).bake().scale(1D / zoom).pow(exponent).bake();
if (fracture != null) {
if(fracture != null)
{
cng.fractureWith(fracture.create(rng.nextParallelRNG(2934)), fracture.getMultiplier());
}
return cng;
});
}
public boolean isFlat()
{
return style.equals(NoiseStyle.FLAT);
}
}

View File

@@ -191,6 +191,7 @@ public class IrisObject extends IrisRegistrant
public int place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, Consumer<BlockPosition> listener)
{
boolean warped = !config.getWarp().isFlat();
boolean stilting = (config.getMode().equals(ObjectPlaceMode.STILT) || config.getMode().equals(ObjectPlaceMode.FAST_STILT));
KMap<ChunkPosition, Integer> lowmap = stilting ? new KMap<>() : null;
KMap<ChunkPosition, BlockData> lowmapData = stilting ? new KMap<>() : null;
@@ -366,6 +367,12 @@ public class IrisObject extends IrisRegistrant
int yy = y + (int) Math.round(i.getY());
int zz = z + (int) Math.round(i.getZ());
if(warped)
{
xx += config.warp(rng, i.getX() + x, i.getY() + y, i.getZ() + z);
zz += config.warp(rng, i.getZ() + z, i.getY() + y, i.getX() + x);
}
if(yv < 0 && config.getMode().equals(ObjectPlaceMode.PAINT))
{
yy = (int) Math.round(i.getY()) + Math.floorDiv(h, 2) + placer.getHighest(xx, zz, config.isUnderwater());

View File

@@ -2,6 +2,8 @@ package com.volmit.iris.object;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.ContextualChunkGenerator;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.noise.CNG;
import com.volmit.iris.util.ArrayType;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
@@ -110,11 +112,30 @@ public class IrisObjectPlacement
@Desc("If set to true, air will be placed before the schematic places.")
private boolean bore = false;
@DontObfuscate
@Desc("Use a generator to warp the field of coordinates. Using simplex for example would make a square placement warp like a flag")
private IrisGeneratorStyle warp = new IrisGeneratorStyle(NoiseStyle.FLAT);
private transient AtomicCache<CNG> surfaceWarp = new AtomicCache<>();
public IrisObjectPlacement()
{
}
public CNG getSurfaceWarp(RNG rng)
{
return surfaceWarp.aquire(() ->
{
return getWarp().create(rng);
});
}
public double warp(RNG rng, double x, double y, double z)
{
return getSurfaceWarp(rng).fitDouble(-(getWarp().getMultiplier() / 2D), (getWarp().getMultiplier() / 2D), x, y, z);
}
public IrisObject getSchematic(ContextualChunkGenerator g, RNG random)
{
if(place.isEmpty())

View File

@@ -49,10 +49,6 @@ public class IrisTextRenderer
@Desc("The palette of blocks to use when drawing text")
private IrisMaterialPalette blockPalette = new IrisMaterialPalette();
@DontObfuscate
@Desc("Use a generator to shuffle the surface field of coordinates. Using simplex for example would make the text rendered wavy. Use the multiplier to stretch further.")
private IrisGeneratorStyle surfaceField = new IrisGeneratorStyle(NoiseStyle.FLAT);
private transient AtomicCache<KList<IrisObject>> objects = new AtomicCache<>();
private transient AtomicCache<Font> fontData = new AtomicCache<>();
private transient AtomicCache<FontMetrics> fontMetrics = new AtomicCache<>();