mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
A proper structure mgr
This commit is contained in:
parent
23188c3898
commit
f4056a3fca
@ -3,12 +3,16 @@ package com.volmit.iris.v2.generator;
|
||||
import com.volmit.iris.v2.scaffold.engine.Engine;
|
||||
import com.volmit.iris.v2.scaffold.engine.EngineFramework;
|
||||
import com.volmit.iris.v2.scaffold.engine.EngineParallax;
|
||||
import com.volmit.iris.v2.scaffold.engine.EngineStructure;
|
||||
import lombok.Getter;
|
||||
|
||||
public class IrisEngineParallax implements EngineParallax {
|
||||
@Getter
|
||||
private final Engine engine;
|
||||
|
||||
@Getter
|
||||
private final EngineStructure structureManager;
|
||||
|
||||
@Getter
|
||||
private final int parallaxSize;
|
||||
|
||||
@ -16,5 +20,6 @@ public class IrisEngineParallax implements EngineParallax {
|
||||
{
|
||||
this.engine = engine;
|
||||
parallaxSize = computeParallaxSize();
|
||||
structureManager = new IrisEngineStructure(getEngine());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package com.volmit.iris.v2.generator;
|
||||
|
||||
import com.volmit.iris.v2.scaffold.engine.Engine;
|
||||
import com.volmit.iris.v2.scaffold.engine.EngineAssignedStructure;
|
||||
|
||||
public class IrisEngineStructure extends EngineAssignedStructure {
|
||||
public IrisEngineStructure(Engine engine) {
|
||||
super(engine);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.volmit.iris.v2.scaffold.engine;
|
||||
|
||||
public abstract class EngineAssignedStructure extends EngineAssignedComponent implements EngineStructure {
|
||||
public EngineAssignedStructure(Engine engine) {
|
||||
super(engine, "Structure");
|
||||
}
|
||||
}
|
@ -31,6 +31,8 @@ public interface EngineParallax extends DataProvider, IObjectPlacer
|
||||
|
||||
public int getParallaxSize();
|
||||
|
||||
public EngineStructure getStructureManager();
|
||||
|
||||
default EngineFramework getFramework()
|
||||
{
|
||||
return getEngine().getFramework();
|
||||
@ -148,7 +150,7 @@ public interface EngineParallax extends DataProvider, IObjectPlacer
|
||||
continue;
|
||||
}
|
||||
|
||||
placeStructure(k, rng.nextParallelRNG(2228 * 2 * g++), x, z);
|
||||
getStructureManager().placeStructure(k, rng.nextParallelRNG(2228 * 2 * g++), x, z);
|
||||
}
|
||||
|
||||
for(IrisStructurePlacement k : biome.getStructures())
|
||||
@ -158,111 +160,10 @@ public interface EngineParallax extends DataProvider, IObjectPlacer
|
||||
continue;
|
||||
}
|
||||
|
||||
placeStructure(k, rng.nextParallelRNG(-22228 * 4 * g++), x, z);
|
||||
getStructureManager().placeStructure(k, rng.nextParallelRNG(-22228 * 4 * g++), x, z);
|
||||
}
|
||||
}
|
||||
|
||||
default void placeStructure(IrisStructurePlacement structure, RNG rngno, int cx, int cz)
|
||||
{
|
||||
RNG rng = new RNG(getEngine().getWorld().getSeed()).nextParallelRNG(-88738456 + rngno.nextInt());
|
||||
RNG rnp = rng.nextParallelRNG(cx - (cz * cz << 3) + rngno.nextInt());
|
||||
int s = structure.gridSize(getEngine()) - (structure.getStructure(getEngine()).isMergeEdges() ? 1 : 0);
|
||||
int sh = structure.gridHeight(getEngine()) - (structure.getStructure(getEngine()).isMergeEdges() ? 1 : 0);
|
||||
KSet<ChunkPosition> m = new KSet<>();
|
||||
|
||||
for(int i = cx << 4; i <= (cx << 4) + 15; i += 1)
|
||||
{
|
||||
if(Math.floorDiv(i, s) * s >> 4 < cx)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for(int j = cz << 4; j <= (cz << 4) + 15; j += 1)
|
||||
{
|
||||
if(Math.floorDiv(j, s) * s >> 4 < cz)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ChunkPosition p = new ChunkPosition(Math.floorDiv(i, s) * s, Math.floorDiv(j, s) * s);
|
||||
|
||||
if(m.contains(p))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
m.add(p);
|
||||
|
||||
if(structure.getStructure(getEngine()).getMaxLayers() <= 1)
|
||||
{
|
||||
placeLayer(structure, rng, rnp, i, 0, j, s, sh);
|
||||
continue;
|
||||
}
|
||||
|
||||
for(int k = 0; k < s * structure.getStructure(getEngine()).getMaxLayers(); k += Math.max(sh, 1))
|
||||
{
|
||||
placeLayer(structure, rng, rnp, i, k, j, s, sh);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default void placeLayer(IrisStructurePlacement structure, RNG rng, RNG rnp, int i, int k, int j, int s, int sh)
|
||||
{
|
||||
if(!hasStructure(structure, rng, i, k, j))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int h = (structure.getHeight() == -1 ? 0 : structure.getHeight()) + (Math.floorDiv(k, sh) * sh);
|
||||
TileResult t = structure.getStructure(getEngine()).getTile(rng, Math.floorDiv(i, s) * s, h, Math.floorDiv(j, s) * s);
|
||||
|
||||
if(t != null)
|
||||
{
|
||||
IrisObject o = null;
|
||||
|
||||
for(IrisRareObject l : t.getTile().getRareObjects())
|
||||
{
|
||||
if(rnp.i(1, l.getRarity()) == 1)
|
||||
{
|
||||
o = structure.load(getEngine(), l.getObject());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
o = o != null ? o : structure.load(getEngine(), t.getTile().getObjects().get(rnp.nextInt(t.getTile().getObjects().size())));
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
IrisObject oo = o;
|
||||
o.place(
|
||||
Math.floorDiv(i, s) * s,
|
||||
structure.getHeight() == -1 ? -1 : h,
|
||||
Math.floorDiv(j, s) * s,
|
||||
this,
|
||||
t.getPlacement(),
|
||||
rng,
|
||||
(b) -> {
|
||||
getParallaxAccess().setObject(b.getX(), b.getY(), b.getZ(), oo.getLoadKey() + "@" + id);
|
||||
ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(b.getX() >> 4, b.getZ() >> 4);
|
||||
meta.setObjects(true);
|
||||
meta.setMaxObject(Math.max(b.getY(), meta.getMaxObject()));
|
||||
meta.setMinObject(Math.min(b.getY(), Math.max(meta.getMinObject(), 0)));
|
||||
},
|
||||
null,
|
||||
getData()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
default boolean hasStructure(IrisStructurePlacement structure, RNG random, double x, double y, double z)
|
||||
{
|
||||
if(structure.getChanceGenerator(new RNG(getEngine().getWorld().getSeed())).getIndex(x / structure.getZoom(), y / structure.getZoom(), z / structure.getZoom(), structure.getRarity()) == structure.getRarity() / 2)
|
||||
{
|
||||
return structure.getRatio() > 0 ? structure.getChanceGenerator(new RNG(getEngine().getWorld().getSeed())).getDistance(x / structure.getZoom(), z / structure.getZoom()) > structure.getRatio() : structure.getChanceGenerator(new RNG(getEngine().getWorld().getSeed())).getDistance(x / structure.getZoom(), z / structure.getZoom()) < Math.abs(structure.getRatio());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
default void generateParallaxSurface(RNG rng, int x, int z, IrisBiome biome) {
|
||||
for (IrisObjectPlacement i : biome.getSurfaceObjects())
|
||||
{
|
||||
|
@ -0,0 +1,114 @@
|
||||
package com.volmit.iris.v2.scaffold.engine;
|
||||
|
||||
import com.volmit.iris.object.IrisObject;
|
||||
import com.volmit.iris.object.IrisRareObject;
|
||||
import com.volmit.iris.object.IrisStructurePlacement;
|
||||
import com.volmit.iris.object.TileResult;
|
||||
import com.volmit.iris.util.ChunkPosition;
|
||||
import com.volmit.iris.util.KSet;
|
||||
import com.volmit.iris.util.RNG;
|
||||
import com.volmit.iris.v2.scaffold.parallax.ParallaxChunkMeta;
|
||||
|
||||
public interface EngineStructure extends EngineComponent
|
||||
{
|
||||
default void placeStructure(IrisStructurePlacement structure, RNG rngno, int cx, int cz)
|
||||
{
|
||||
RNG rng = new RNG(getEngine().getWorld().getSeed()).nextParallelRNG(-88738456 + rngno.nextInt());
|
||||
RNG rnp = rng.nextParallelRNG(cx - (cz * cz << 3) + rngno.nextInt());
|
||||
int s = structure.gridSize(getEngine()) - (structure.getStructure(getEngine()).isMergeEdges() ? 1 : 0);
|
||||
int sh = structure.gridHeight(getEngine()) - (structure.getStructure(getEngine()).isMergeEdges() ? 1 : 0);
|
||||
KSet<ChunkPosition> m = new KSet<>();
|
||||
|
||||
for(int i = cx << 4; i <= (cx << 4) + 15; i += 1)
|
||||
{
|
||||
if(Math.floorDiv(i, s) * s >> 4 < cx)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for(int j = cz << 4; j <= (cz << 4) + 15; j += 1)
|
||||
{
|
||||
if(Math.floorDiv(j, s) * s >> 4 < cz)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ChunkPosition p = new ChunkPosition(Math.floorDiv(i, s) * s, Math.floorDiv(j, s) * s);
|
||||
|
||||
if(m.contains(p))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
m.add(p);
|
||||
|
||||
if(structure.getStructure(getEngine()).getMaxLayers() <= 1)
|
||||
{
|
||||
placeLayer(structure, rng, rnp, i, 0, j, s, sh);
|
||||
continue;
|
||||
}
|
||||
|
||||
for(int k = 0; k < s * structure.getStructure(getEngine()).getMaxLayers(); k += Math.max(sh, 1))
|
||||
{
|
||||
placeLayer(structure, rng, rnp, i, k, j, s, sh);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default void placeLayer(IrisStructurePlacement structure, RNG rng, RNG rnp, int i, int k, int j, int s, int sh)
|
||||
{
|
||||
if(!hasStructure(structure, rng, i, k, j))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int h = (structure.getHeight() == -1 ? 0 : structure.getHeight()) + (Math.floorDiv(k, sh) * sh);
|
||||
TileResult t = structure.getStructure(getEngine()).getTile(rng, Math.floorDiv(i, s) * s, h, Math.floorDiv(j, s) * s);
|
||||
|
||||
if(t != null)
|
||||
{
|
||||
IrisObject o = null;
|
||||
|
||||
for(IrisRareObject l : t.getTile().getRareObjects())
|
||||
{
|
||||
if(rnp.i(1, l.getRarity()) == 1)
|
||||
{
|
||||
o = structure.load(getEngine(), l.getObject());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
o = o != null ? o : structure.load(getEngine(), t.getTile().getObjects().get(rnp.nextInt(t.getTile().getObjects().size())));
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
IrisObject oo = o;
|
||||
o.place(
|
||||
Math.floorDiv(i, s) * s,
|
||||
structure.getHeight() == -1 ? -1 : h,
|
||||
Math.floorDiv(j, s) * s,
|
||||
getEngine().getFramework().getEngineParallax(),
|
||||
t.getPlacement(),
|
||||
rng,
|
||||
(b) -> {
|
||||
getEngine().getParallax().setObject(b.getX(), b.getY(), b.getZ(), oo.getLoadKey() + "@" + id);
|
||||
ParallaxChunkMeta meta = getEngine().getParallax().getMetaRW(b.getX() >> 4, b.getZ() >> 4);
|
||||
meta.setObjects(true);
|
||||
meta.setMaxObject(Math.max(b.getY(), meta.getMaxObject()));
|
||||
meta.setMinObject(Math.min(b.getY(), Math.max(meta.getMinObject(), 0)));
|
||||
},
|
||||
null,
|
||||
getData()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
default boolean hasStructure(IrisStructurePlacement structure, RNG random, double x, double y, double z)
|
||||
{
|
||||
if(structure.getChanceGenerator(new RNG(getEngine().getWorld().getSeed())).getIndex(x / structure.getZoom(), y / structure.getZoom(), z / structure.getZoom(), structure.getRarity()) == structure.getRarity() / 2)
|
||||
{
|
||||
return structure.getRatio() > 0 ? structure.getChanceGenerator(new RNG(getEngine().getWorld().getSeed())).getDistance(x / structure.getZoom(), z / structure.getZoom()) > structure.getRatio() : structure.getChanceGenerator(new RNG(getEngine().getWorld().getSeed())).getDistance(x / structure.getZoom(), z / structure.getZoom()) < Math.abs(structure.getRatio());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user