mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Engine support max densities
This commit is contained in:
parent
e71eb465fb
commit
9e9feb5980
@ -19,7 +19,7 @@
|
||||
package com.volmit.iris.generator;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.*;
|
||||
import com.volmit.iris.scaffold.engine.*;
|
||||
import com.volmit.iris.scaffold.hunk.Hunk;
|
||||
import com.volmit.iris.util.J;
|
||||
@ -70,6 +70,15 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
private int cacheId;
|
||||
private final int art;
|
||||
|
||||
@Getter
|
||||
private double maxBiomeObjectDensity;
|
||||
|
||||
@Getter
|
||||
private double maxBiomeLayerDensity;
|
||||
|
||||
@Getter
|
||||
private double maxBiomeDecoratorDensity;
|
||||
|
||||
public IrisEngine(EngineTarget target, EngineCompound compound, int index) {
|
||||
Iris.info("Initializing Engine: " + target.getWorld().getName() + "/" + target.getDimension().getLoadKey() + " (" + target.getHeight() + " height)");
|
||||
metrics = new EngineMetrics(32);
|
||||
@ -84,6 +93,37 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
cacheId = RNG.r.nextInt();
|
||||
effects = new IrisEngineEffects(this);
|
||||
art = J.ar(effects::tickRandomPlayer, 0);
|
||||
J.a(this::computeBiomeMaxes);
|
||||
}
|
||||
|
||||
private void computeBiomeMaxes() {
|
||||
for(IrisBiome i : getDimension().getAllBiomes(this))
|
||||
{
|
||||
double density = 0;
|
||||
|
||||
for(IrisObjectPlacement j : i.getObjects())
|
||||
{
|
||||
density += j.getDensity() * j.getChance();
|
||||
}
|
||||
|
||||
maxBiomeObjectDensity = Math.max(maxBiomeObjectDensity, density);
|
||||
density = 0;
|
||||
|
||||
for(IrisDecorator j : i.getDecorators())
|
||||
{
|
||||
density += Math.max(j.getStackMax(), 1) * j.getChance();
|
||||
}
|
||||
|
||||
maxBiomeDecoratorDensity = Math.max(maxBiomeDecoratorDensity, density);
|
||||
density = 0;
|
||||
|
||||
for(IrisBiomePaletteLayer j : i.getLayers())
|
||||
{
|
||||
density++;
|
||||
}
|
||||
|
||||
maxBiomeLayerDensity = Math.max(maxBiomeLayerDensity, density);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,10 +20,13 @@ package com.volmit.iris.object;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.generator.IrisComplex;
|
||||
import com.volmit.iris.generator.IrisEngine;
|
||||
import com.volmit.iris.generator.noise.CNG;
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.map.RenderType;
|
||||
import com.volmit.iris.scaffold.cache.AtomicCache;
|
||||
import com.volmit.iris.scaffold.data.DataProvider;
|
||||
import com.volmit.iris.scaffold.engine.Engine;
|
||||
import com.volmit.iris.scaffold.engine.IrisAccess;
|
||||
import com.volmit.iris.util.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -195,6 +198,10 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> surfaceObjectsCache = new AtomicCache<>(false);
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> carveObjectsCache = new AtomicCache<>(false);
|
||||
private final transient AtomicCache<Color> cacheColor = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColorObjectDensity = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColorDecoratorLoad = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColorLayerLoad = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColorDepositLoad = new AtomicCache<>();
|
||||
private final transient AtomicCache<CNG> childrenCell = new AtomicCache<>();
|
||||
private final transient AtomicCache<CNG> biomeGenerator = new AtomicCache<>();
|
||||
private final transient AtomicCache<Integer> maxHeight = new AtomicCache<>();
|
||||
@ -599,28 +606,61 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
return getLayers().get(0).get(rng, x, 0, z, idm);
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return this.cacheColor.aquire(() -> {
|
||||
if (this.color == null) {
|
||||
RandomColor randomColor = new RandomColor(getName().hashCode());
|
||||
if (this.getVanillaDerivative() == null) {
|
||||
Iris.warn("No vanilla biome found for " + getName());
|
||||
return new Color(randomColor.randomColor());
|
||||
}
|
||||
RandomColor.Color col = VanillaBiomeMap.getColorType(this.getVanillaDerivative());
|
||||
RandomColor.Luminosity lum = VanillaBiomeMap.getColorLuminosity(this.getVanillaDerivative());
|
||||
RandomColor.SaturationType sat = VanillaBiomeMap.getColorSaturatiom(this.getVanillaDerivative());
|
||||
int newColorI = randomColor.randomColor(col, col == RandomColor.Color.MONOCHROME ? RandomColor.SaturationType.MONOCHROME : sat, lum);
|
||||
public Color getColor(Engine engine, RenderType type) {
|
||||
switch (type) {
|
||||
case BIOME, HEIGHT, CAVE_LAND, REGION, BIOME_SEA, BIOME_LAND -> {
|
||||
return this.cacheColor.aquire(() -> {
|
||||
if (this.color == null) {
|
||||
RandomColor randomColor = new RandomColor(getName().hashCode());
|
||||
if (this.getVanillaDerivative() == null) {
|
||||
Iris.warn("No vanilla biome found for " + getName());
|
||||
return new Color(randomColor.randomColor());
|
||||
}
|
||||
RandomColor.Color col = VanillaBiomeMap.getColorType(this.getVanillaDerivative());
|
||||
RandomColor.Luminosity lum = VanillaBiomeMap.getColorLuminosity(this.getVanillaDerivative());
|
||||
RandomColor.SaturationType sat = VanillaBiomeMap.getColorSaturatiom(this.getVanillaDerivative());
|
||||
int newColorI = randomColor.randomColor(col, col == RandomColor.Color.MONOCHROME ? RandomColor.SaturationType.MONOCHROME : sat, lum);
|
||||
|
||||
return new Color(newColorI);
|
||||
}
|
||||
return new Color(newColorI);
|
||||
}
|
||||
|
||||
try {
|
||||
return Color.decode(this.color);
|
||||
} catch (NumberFormatException e) {
|
||||
Iris.warn("Could not parse color \"" + this.color + "\" for biome " + getName());
|
||||
return new Color(new RandomColor(getName().hashCode()).randomColor());
|
||||
try {
|
||||
return Color.decode(this.color);
|
||||
} catch (NumberFormatException e) {
|
||||
Iris.warn("Could not parse color \"" + this.color + "\" for biome " + getName());
|
||||
return new Color(new RandomColor(getName().hashCode()).randomColor());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
case OBJECT_LOAD -> {
|
||||
return cacheColorObjectDensity.aquire(() -> {
|
||||
double density = 0;
|
||||
|
||||
for(IrisObjectPlacement i : getObjects())
|
||||
{
|
||||
density += i.getDensity() * i.getChance();
|
||||
}
|
||||
|
||||
return Color.getHSBColor(0.225f, (float) (density / engine.getMaxBiomeObjectDensity()), 1f);
|
||||
});
|
||||
}
|
||||
case DECORATOR_LOAD -> {
|
||||
return cacheColorDecoratorLoad.aquire(() -> {
|
||||
double density = 0;
|
||||
|
||||
for(IrisDecorator i : getDecorators())
|
||||
{
|
||||
density += i.getChance() * Math.min(1, i.getStackMax()) * 256;
|
||||
}
|
||||
|
||||
return Color.getHSBColor(0.41f, (float) (density / engine.getMaxBiomeDecoratorDensity()), 1f);
|
||||
});
|
||||
}
|
||||
case LAYER_LOAD -> {
|
||||
return cacheColorLayerLoad.aquire(() -> Color.getHSBColor(0.625f, (float) (getLayers().size() / engine.getMaxBiomeLayerDensity()), 1f));
|
||||
}
|
||||
}
|
||||
|
||||
return Color.black;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import lombok.experimental.Accessors;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Deprecated()
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Desc("Represents a color")
|
||||
|
@ -21,6 +21,7 @@ package com.volmit.iris.object;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.generator.noise.CNG;
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.map.RenderType;
|
||||
import com.volmit.iris.scaffold.cache.AtomicCache;
|
||||
import com.volmit.iris.scaffold.data.DataProvider;
|
||||
import com.volmit.iris.util.*;
|
||||
@ -514,8 +515,7 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
return b.v();
|
||||
}
|
||||
|
||||
public Color getColor(DataProvider dataProvider) {
|
||||
|
||||
public Color getColor(DataProvider dataProvider, RenderType type) {
|
||||
return this.cacheColor.aquire(() -> {
|
||||
if (this.color == null) {
|
||||
Random rand = new Random(getName().hashCode() + getAllBiomeIds().hashCode());
|
||||
|
@ -21,6 +21,7 @@ package com.volmit.iris.scaffold.engine;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.manager.gui.Renderer;
|
||||
import com.volmit.iris.map.RenderType;
|
||||
import com.volmit.iris.object.*;
|
||||
import com.volmit.iris.scaffold.cache.Cache;
|
||||
import com.volmit.iris.scaffold.data.DataProvider;
|
||||
@ -45,6 +46,12 @@ import java.util.Arrays;
|
||||
public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootProvider, BlockUpdater, Renderer, Hotloadable {
|
||||
void close();
|
||||
|
||||
double getMaxBiomeObjectDensity();
|
||||
|
||||
double getMaxBiomeDecoratorDensity();
|
||||
|
||||
double getMaxBiomeLayerDensity();
|
||||
|
||||
boolean isClosed();
|
||||
|
||||
EngineWorldManager getWorldManager();
|
||||
@ -110,8 +117,8 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
|
||||
IrisBiome biome = getSurfaceBiome((int) x, (int) z);
|
||||
int height = getHeight((int) x, (int) z);
|
||||
double heightFactor = M.lerpInverse(0, getHeight(), height);
|
||||
Color irc = region.getColor(this.getFramework().getComplex());
|
||||
Color ibc = biome.getColor();
|
||||
Color irc = region.getColor(this.getFramework().getComplex(), RenderType.BIOME);
|
||||
Color ibc = biome.getColor(this, RenderType.BIOME);
|
||||
Color rc = irc != null ? irc : Color.GREEN.darker();
|
||||
Color bc = ibc != null ? ibc : biome.isAquatic() ? Color.BLUE : Color.YELLOW;
|
||||
Color f = IrisColor.blend(rc, bc, bc, Color.getHSBColor(0, 0, (float) heightFactor));
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import com.volmit.iris.generator.IrisEngineFramework;
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
import com.volmit.iris.object.*;
|
||||
import com.volmit.iris.scaffold.engine.Engine;
|
||||
import com.volmit.iris.scaffold.engine.EngineCompound;
|
||||
import com.volmit.iris.scaffold.engine.EngineEffects;
|
||||
@ -20,15 +20,59 @@ import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class FakeEngine implements Engine {
|
||||
|
||||
|
||||
@Getter
|
||||
private double maxBiomeObjectDensity;
|
||||
|
||||
@Getter
|
||||
private double maxBiomeLayerDensity;
|
||||
|
||||
@Getter
|
||||
private double maxBiomeDecoratorDensity;
|
||||
|
||||
@Getter
|
||||
private IrisDimension dimension;
|
||||
|
||||
private EngineFramework framework;
|
||||
|
||||
@Getter
|
||||
private World world;
|
||||
|
||||
public FakeEngine(IrisDimension dimension, FakeWorld world) {
|
||||
this.dimension = dimension;
|
||||
this.world = world;
|
||||
computeBiomeMaxes();
|
||||
this.framework = new IrisEngineFramework(this);
|
||||
}
|
||||
|
||||
private void computeBiomeMaxes() {
|
||||
for(IrisBiome i : getDimension().getAllBiomes(this))
|
||||
{
|
||||
double density = 0;
|
||||
|
||||
for(IrisObjectPlacement j : i.getObjects())
|
||||
{
|
||||
density += j.getDensity() * j.getChance();
|
||||
}
|
||||
|
||||
maxBiomeObjectDensity = Math.max(maxBiomeObjectDensity, density);
|
||||
density = 0;
|
||||
|
||||
for(IrisDecorator j : i.getDecorators())
|
||||
{
|
||||
density += Math.max(j.getStackMax(), 1) * j.getChance();
|
||||
}
|
||||
|
||||
maxBiomeDecoratorDensity = Math.max(maxBiomeDecoratorDensity, density);
|
||||
density = 0;
|
||||
|
||||
for(IrisBiomePaletteLayer j : i.getLayers())
|
||||
{
|
||||
density++;
|
||||
}
|
||||
|
||||
maxBiomeLayerDensity = Math.max(maxBiomeLayerDensity, density);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user