Added scatter generation logic to TestPlanetGenerator
- Scatter generation is now triggered properly in TestPlanetGenerator - WorldGenerators are now required to call addChunk() themselves (again) - ChunkManager now generates loaded chunks that are not ready - Chunks scheduled for unloading no longer unload if they become requested while in queue
This commit is contained in:
parent
4332a78221
commit
7ecdfdfb4d
@ -90,7 +90,7 @@ public class ChunkManager {
|
|||||||
public LoadResult loadOrGenerateChunk(Vec3i chunkPos) {
|
public LoadResult loadOrGenerateChunk(Vec3i chunkPos) {
|
||||||
LoadResult loadResult = loadChunk(chunkPos);
|
LoadResult loadResult = loadChunk(chunkPos);
|
||||||
|
|
||||||
if (loadResult == LoadResult.NOT_LOADED) {
|
if (loadResult == LoadResult.NOT_LOADED || !getServer().getWorld().getChunk(chunkPos).isReady()) {
|
||||||
getServer().getWorld().generate(chunkPos);
|
getServer().getWorld().generate(chunkPos);
|
||||||
return LoadResult.GENERATED;
|
return LoadResult.GENERATED;
|
||||||
} else {
|
} else {
|
||||||
|
@ -140,7 +140,13 @@ public class ChunkRequestDaemon {
|
|||||||
ChunkUnloadRequest request = it.next();
|
ChunkUnloadRequest request = it.next();
|
||||||
|
|
||||||
if (request.getUnloadAt() < now) {
|
if (request.getUnloadAt() < now) {
|
||||||
|
|
||||||
it.remove();
|
it.remove();
|
||||||
|
|
||||||
|
if (requested.contains(request.getChunkPos())) {
|
||||||
|
continue; // do not unload chunks that became requested
|
||||||
|
}
|
||||||
|
|
||||||
getChunkManager().unloadChunk(request.getChunkPos());
|
getChunkManager().unloadChunk(request.getChunkPos());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,9 +106,7 @@ public class WorldLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ChunkData generate(Vec3i chunkPos) {
|
public ChunkData generate(Vec3i chunkPos) {
|
||||||
ChunkData chunk = getGenerator().generate(chunkPos, getData());
|
return getGenerator().generate(chunkPos, getData());
|
||||||
getData().addChunk(chunk);
|
|
||||||
return chunk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChunkLogic getChunk(ChunkData chunkData) {
|
public ChunkLogic getChunk(ChunkData chunkData) {
|
||||||
|
@ -78,7 +78,9 @@ public class TestWorldGenerator extends AbstractWorldGenerator<Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkData generate(Vec3i chunkPos, WorldData world) {
|
public ChunkData generate(Vec3i chunkPos, WorldData world) {
|
||||||
return generateUnpopulated(chunkPos, world);
|
ChunkData chunk = generateUnpopulated(chunkPos, world);
|
||||||
|
world.addChunk(chunk);
|
||||||
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChunkData generateUnpopulated(Vec3i chunkPos, WorldData world) {
|
private ChunkData generateUnpopulated(Vec3i chunkPos, WorldData world) {
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package ru.windcorp.progressia.test.gen.planet;
|
package ru.windcorp.progressia.test.gen.planet;
|
||||||
|
|
||||||
|
import glm.vec._3.i.Vec3i;
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
|
import ru.windcorp.progressia.common.world.block.BlockDataRegistry;
|
||||||
import ru.windcorp.progressia.test.gen.surface.SurfaceScatterGenerator;
|
import ru.windcorp.progressia.test.gen.surface.SurfaceScatterGenerator;
|
||||||
|
|
||||||
public class PlanetScatterGenerator {
|
public class PlanetScatterGenerator {
|
||||||
@ -35,6 +37,7 @@ public class PlanetScatterGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generateScatter(ChunkData chunk) {
|
public void generateScatter(ChunkData chunk) {
|
||||||
|
chunk.setBlock(new Vec3i(8, 8, 8), BlockDataRegistry.getInstance().get("Test:Log"), false);
|
||||||
surfaceGenerator.generateScatter(chunk);
|
surfaceGenerator.generateScatter(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,9 +48,11 @@ class PlanetTerrainGenerator {
|
|||||||
|
|
||||||
FloatRangeMap<TerrainLayer> layers = new ArrayFloatRangeMap<>();
|
FloatRangeMap<TerrainLayer> layers = new ArrayFloatRangeMap<>();
|
||||||
BlockData granite = BlockDataRegistry.getInstance().get("Test:GraniteMonolith");
|
BlockData granite = BlockDataRegistry.getInstance().get("Test:GraniteMonolith");
|
||||||
|
BlockData dirt = BlockDataRegistry.getInstance().get("Test:Dirt");
|
||||||
BlockData air = BlockDataRegistry.getInstance().get("Test:Air");
|
BlockData air = BlockDataRegistry.getInstance().get("Test:Air");
|
||||||
layers.put(Float.NEGATIVE_INFINITY, 0, (n, w, d, r, c) -> air);
|
layers.put(Float.NEGATIVE_INFINITY, 0, (n, w, d, r, c) -> air);
|
||||||
layers.put(0, Float.POSITIVE_INFINITY, (n, w, d, r, c) -> granite);
|
layers.put(0, 4, (n, w, d, r, c) -> dirt);
|
||||||
|
layers.put(4, Float.POSITIVE_INFINITY, (n, w, d, r, c) -> granite);
|
||||||
|
|
||||||
this.surfaceGenerator = new SurfaceTerrainGenerator((f, n, w) -> heightMap.get(f, n, w) + generator.getPlanet().getRadius(), layers);
|
this.surfaceGenerator = new SurfaceTerrainGenerator((f, n, w) -> heightMap.get(f, n, w) + generator.getPlanet().getRadius(), layers);
|
||||||
}
|
}
|
||||||
|
@ -20,16 +20,21 @@ package ru.windcorp.progressia.test.gen.planet;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
import glm.vec._3.i.Vec3i;
|
import glm.vec._3.i.Vec3i;
|
||||||
|
import ru.windcorp.progressia.common.util.VectorUtil;
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
import ru.windcorp.progressia.common.world.DecodingException;
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
|
import ru.windcorp.progressia.server.Server;
|
||||||
import ru.windcorp.progressia.server.world.WorldLogic;
|
import ru.windcorp.progressia.server.world.WorldLogic;
|
||||||
import ru.windcorp.progressia.server.world.generation.AbstractWorldGenerator;
|
import ru.windcorp.progressia.server.world.generation.AbstractWorldGenerator;
|
||||||
|
|
||||||
public class TestPlanetGenerator extends AbstractWorldGenerator<Boolean> {
|
public class TestPlanetGenerator extends AbstractWorldGenerator<Boolean> {
|
||||||
|
|
||||||
|
private final Server server;
|
||||||
|
|
||||||
private final Planet planet;
|
private final Planet planet;
|
||||||
|
|
||||||
private final PlanetTerrainGenerator terrainGenerator;
|
private final PlanetTerrainGenerator terrainGenerator;
|
||||||
@ -38,6 +43,7 @@ public class TestPlanetGenerator extends AbstractWorldGenerator<Boolean> {
|
|||||||
public TestPlanetGenerator(String id, Planet planet, WorldLogic world) {
|
public TestPlanetGenerator(String id, Planet planet, WorldLogic world) {
|
||||||
super(id, Boolean.class, "Test:PlanetGravityModel");
|
super(id, Boolean.class, "Test:PlanetGravityModel");
|
||||||
|
|
||||||
|
this.server = world.getServer();
|
||||||
this.planet = planet;
|
this.planet = planet;
|
||||||
|
|
||||||
TestPlanetGravityModel model = (TestPlanetGravityModel) this.getGravityModel();
|
TestPlanetGravityModel model = (TestPlanetGravityModel) this.getGravityModel();
|
||||||
@ -71,14 +77,33 @@ public class TestPlanetGenerator extends AbstractWorldGenerator<Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkIsChunkReady(Boolean hint) {
|
protected boolean checkIsChunkReady(Boolean hint) {
|
||||||
return hint;
|
return hint == Boolean.TRUE; // Avoid NPE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkData generate(Vec3i chunkPos, WorldData world) {
|
public ChunkData generate(Vec3i chunkPos, WorldData world) {
|
||||||
ChunkData chunk = terrainGenerator.generateTerrain(chunkPos, world);
|
VectorUtil.iterateCuboidAround(chunkPos, 3, r -> conjureTerrain(r, world));
|
||||||
scatterGenerator.generateScatter(chunk);
|
ChunkData chunk = world.getChunk(chunkPos);
|
||||||
|
|
||||||
|
if (!isChunkReady(chunk.getGenerationHint())) {
|
||||||
|
scatterGenerator.generateScatter(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void conjureTerrain(Vec3i chunkPos, WorldData world) {
|
||||||
|
ChunkData chunk = world.getChunk(chunkPos);
|
||||||
|
|
||||||
|
if (chunk == null) {
|
||||||
|
server.getLoadManager().getChunkManager().loadChunk(chunkPos);
|
||||||
|
chunk = world.getChunk(chunkPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chunk == null) {
|
||||||
|
chunk = terrainGenerator.generateTerrain(chunkPos, world);
|
||||||
|
world.addChunk(chunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user