Almost resolved feature generation issue, removed dead code
- SurfaceFeatures that change neighboring chunks no longer suffer from tearing if world saving is enabled - World saving is still disabled by default - wontfix until we get a new, more optimized world IO system - See GitHub issue #13 for details - Removed WorldAccessor getter from Server. This is an implementation detail. - Removed SurfaceWorld, SurfaceFeature.Request (see previous commit)
This commit is contained in:
parent
a3760d7425
commit
539a61e854
@ -82,7 +82,8 @@ public class Server {
|
|||||||
this.world = new DefaultWorldLogic(
|
this.world = new DefaultWorldLogic(
|
||||||
world,
|
world,
|
||||||
this,
|
this,
|
||||||
new TestPlanetGenerator("Test:PlanetGenerator", this, new Planet(4, 9.8f, 16f, 16f))
|
new TestPlanetGenerator("Test:PlanetGenerator", this, new Planet(4, 9.8f, 16f, 16f)),
|
||||||
|
worldAccessor
|
||||||
);
|
);
|
||||||
this.serverThread = new ServerThread(this);
|
this.serverThread = new ServerThread(this);
|
||||||
|
|
||||||
@ -308,10 +309,6 @@ public class Server {
|
|||||||
public long getUptimeTicks() {
|
public long getUptimeTicks() {
|
||||||
return this.serverThread.getTicker().getUptimeTicks();
|
return this.serverThread.getTicker().getUptimeTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldAccessor getWorldAccessor___really_bad_dont_use() {
|
|
||||||
return worldAccessor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ticking settings for this server.
|
* Returns the ticking settings for this server.
|
||||||
|
@ -33,6 +33,7 @@ import ru.windcorp.progressia.common.world.entity.EntityData;
|
|||||||
import ru.windcorp.progressia.server.Server;
|
import ru.windcorp.progressia.server.Server;
|
||||||
import ru.windcorp.progressia.server.world.generation.WorldGenerator;
|
import ru.windcorp.progressia.server.world.generation.WorldGenerator;
|
||||||
import ru.windcorp.progressia.server.world.tasks.TickEntitiesTask;
|
import ru.windcorp.progressia.server.world.tasks.TickEntitiesTask;
|
||||||
|
import ru.windcorp.progressia.server.world.tasks.WorldAccessor;
|
||||||
import ru.windcorp.progressia.server.world.ticking.Evaluation;
|
import ru.windcorp.progressia.server.world.ticking.Evaluation;
|
||||||
|
|
||||||
public class DefaultWorldLogic implements WorldLogic {
|
public class DefaultWorldLogic implements WorldLogic {
|
||||||
@ -46,7 +47,7 @@ public class DefaultWorldLogic implements WorldLogic {
|
|||||||
|
|
||||||
private final Evaluation tickEntitiesTask = new TickEntitiesTask();
|
private final Evaluation tickEntitiesTask = new TickEntitiesTask();
|
||||||
|
|
||||||
public DefaultWorldLogic(DefaultWorldData data, Server server, WorldGenerator generator) {
|
public DefaultWorldLogic(DefaultWorldData data, Server server, WorldGenerator generator, WorldAccessor accessor) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ public class DefaultWorldLogic implements WorldLogic {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
data.addListener(ChunkDataListeners.createAdder(new UpdateTriggerer(server.getWorldAccessor___really_bad_dont_use())));
|
data.addListener(ChunkDataListeners.createAdder(new UpdateTriggerer(accessor)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,11 +88,8 @@ public class TestPlanetGenerator extends AbstractWorldGenerator<Boolean> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void conjureTerrain(Vec3i chunkPos) {
|
private void conjureTerrain(Vec3i chunkPos) {
|
||||||
|
getServer().getLoadManager().getChunkManager().loadChunk(chunkPos);
|
||||||
DefaultChunkData chunk = getWorldData().getChunk(chunkPos);
|
DefaultChunkData chunk = getWorldData().getChunk(chunkPos);
|
||||||
|
|
||||||
if (chunk == null) {
|
|
||||||
chunk = getWorldData().getChunk(chunkPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
chunk = terrainGenerator.generateTerrain(chunkPos);
|
chunk = terrainGenerator.generateTerrain(chunkPos);
|
||||||
|
@ -17,90 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package ru.windcorp.progressia.test.gen.surface;
|
package ru.windcorp.progressia.test.gen.surface;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import glm.Glm;
|
|
||||||
import glm.vec._3.i.Vec3i;
|
|
||||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||||
import ru.windcorp.progressia.common.world.DefaultChunkData;
|
|
||||||
import ru.windcorp.progressia.common.world.generic.GenericChunks;
|
|
||||||
import ru.windcorp.progressia.test.gen.surface.context.SurfaceWorldContext;
|
import ru.windcorp.progressia.test.gen.surface.context.SurfaceWorldContext;
|
||||||
|
|
||||||
public abstract class SurfaceFeature extends Namespaced {
|
public abstract class SurfaceFeature extends Namespaced {
|
||||||
|
|
||||||
public static class Request {
|
|
||||||
|
|
||||||
private final SurfaceWorld world;
|
|
||||||
private final DefaultChunkData chunk;
|
|
||||||
private final Vec3i minSfc = new Vec3i();
|
|
||||||
private final Vec3i maxSfc = new Vec3i();
|
|
||||||
|
|
||||||
private final Random random;
|
|
||||||
|
|
||||||
public Request(SurfaceWorld world, DefaultChunkData chunk, Random random) {
|
|
||||||
this.world = world;
|
|
||||||
this.chunk = chunk;
|
|
||||||
this.random = random;
|
|
||||||
|
|
||||||
Vec3i tmpMin = chunk.getMinBIW(null);
|
|
||||||
Vec3i tmpMax = chunk.getMaxBIW(null);
|
|
||||||
|
|
||||||
GenericChunks.relativize(tmpMin, chunk.getUp(), tmpMin);
|
|
||||||
GenericChunks.relativize(tmpMax, chunk.getUp(), tmpMax);
|
|
||||||
|
|
||||||
Glm.min(tmpMin, tmpMax, minSfc);
|
|
||||||
Glm.max(tmpMin, tmpMax, maxSfc);
|
|
||||||
|
|
||||||
minSfc.z -= world.getSurface().getSeaLevel();
|
|
||||||
maxSfc.z -= world.getSurface().getSeaLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultChunkData getChunk() {
|
|
||||||
return chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SurfaceWorld getWorld() {
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Random getRandom() {
|
|
||||||
return random;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMinX() {
|
|
||||||
return minSfc.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxX() {
|
|
||||||
return maxSfc.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMinY() {
|
|
||||||
return minSfc.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxY() {
|
|
||||||
return maxSfc.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMinZ() {
|
|
||||||
return minSfc.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxZ() {
|
|
||||||
return maxSfc.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vec3i getMin() {
|
|
||||||
return minSfc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vec3i getMax() {
|
|
||||||
return maxSfc;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public SurfaceFeature(String id) {
|
public SurfaceFeature(String id) {
|
||||||
super(id);
|
super(id);
|
||||||
}
|
}
|
||||||
|
@ -1,205 +0,0 @@
|
|||||||
/*
|
|
||||||
* Progressia
|
|
||||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package ru.windcorp.progressia.test.gen.surface;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
|
||||||
import ru.windcorp.progressia.common.state.StateChange;
|
|
||||||
import ru.windcorp.progressia.common.state.StatefulObject;
|
|
||||||
import ru.windcorp.progressia.common.util.Vectors;
|
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
|
||||||
import ru.windcorp.progressia.common.world.GravityModel;
|
|
||||||
import ru.windcorp.progressia.common.world.block.BlockData;
|
|
||||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
|
||||||
import ru.windcorp.progressia.common.world.generic.EntityGeneric;
|
|
||||||
import ru.windcorp.progressia.common.world.generic.GenericChunks;
|
|
||||||
import ru.windcorp.progressia.common.world.rels.BlockFace;
|
|
||||||
import ru.windcorp.progressia.common.world.tile.TileData;
|
|
||||||
import ru.windcorp.progressia.common.world.TileDataStack;
|
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
|
||||||
|
|
||||||
public class SurfaceWorld
|
|
||||||
implements WorldData {
|
|
||||||
|
|
||||||
private final Surface surface;
|
|
||||||
private final WorldData parent;
|
|
||||||
|
|
||||||
public SurfaceWorld(
|
|
||||||
Surface surface,
|
|
||||||
WorldData parent
|
|
||||||
) {
|
|
||||||
this.surface = surface;
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the surface
|
|
||||||
*/
|
|
||||||
public Surface getSurface() {
|
|
||||||
return surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the parent
|
|
||||||
*/
|
|
||||||
public WorldData getParent() {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Delegate methods
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<? extends ChunkData> getChunks() {
|
|
||||||
return parent.getChunks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChunkData getChunk(Vec3i pos) {
|
|
||||||
return parent.getChunk(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<EntityData> getEntities() {
|
|
||||||
return parent.getEntities();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityData getEntity(long entityId) {
|
|
||||||
return parent.getEntity(entityId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBlock(Vec3i blockInWorld, BlockData block, boolean notify) {
|
|
||||||
parent.setBlock(blockInWorld, block, notify);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addEntity(EntityData entity) {
|
|
||||||
parent.addEntity(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeEntity(long entityId) {
|
|
||||||
parent.removeEntity(entityId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vec3i resolve(Vec3i surfacePosition, Vec3i output) {
|
|
||||||
if (output == null) {
|
|
||||||
output = new Vec3i();
|
|
||||||
}
|
|
||||||
|
|
||||||
output.set(surfacePosition.x, surfacePosition.y, surfacePosition.z);
|
|
||||||
output.z += getSurface().getSeaLevel();
|
|
||||||
|
|
||||||
GenericChunks.resolve(output, getSurface().getUp(), output);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vec3i relativize(Vec3i absolutePosition, Vec3i output) {
|
|
||||||
if (output == null) {
|
|
||||||
output = new Vec3i();
|
|
||||||
}
|
|
||||||
|
|
||||||
output.set(absolutePosition.x, absolutePosition.y, absolutePosition.z);
|
|
||||||
|
|
||||||
GenericChunks.relativize(output, getSurface().getUp(), output);
|
|
||||||
output.z -= getSurface().getSeaLevel();
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockData getBlockSfc(Vec3i surfaceBlockInWorld) {
|
|
||||||
Vec3i blockInWorld = Vectors.grab3i();
|
|
||||||
resolve(surfaceBlockInWorld, blockInWorld);
|
|
||||||
BlockData result = parent.getBlock(blockInWorld);
|
|
||||||
Vectors.release(blockInWorld);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBlockSfc(Vec3i surfaceBlockInWorld, BlockData block, boolean notify) {
|
|
||||||
Vec3i blockInWorld = Vectors.grab3i();
|
|
||||||
resolve(surfaceBlockInWorld, blockInWorld);
|
|
||||||
parent.setBlock(blockInWorld, block, notify);
|
|
||||||
Vectors.release(blockInWorld);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileDataStack getTilesSfc(Vec3i surfaceBlockInWorld, BlockFace face) {
|
|
||||||
Vec3i blockInWorld = Vectors.grab3i();
|
|
||||||
resolve(surfaceBlockInWorld, blockInWorld);
|
|
||||||
TileDataStack result = parent.getTiles(blockInWorld, face);
|
|
||||||
Vectors.release(blockInWorld);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileDataStack getTilesOrNullSfc(Vec3i surfaceBlockInWorld, BlockFace face) {
|
|
||||||
Vec3i blockInWorld = Vectors.grab3i();
|
|
||||||
resolve(surfaceBlockInWorld, blockInWorld);
|
|
||||||
TileDataStack result = parent.getTilesOrNull(blockInWorld, face);
|
|
||||||
Vectors.release(blockInWorld);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasTilesSfc(Vec3i surfaceBlockInWorld, BlockFace face) {
|
|
||||||
Vec3i blockInWorld = Vectors.grab3i();
|
|
||||||
resolve(surfaceBlockInWorld, blockInWorld);
|
|
||||||
boolean result = parent.hasTiles(blockInWorld, face);
|
|
||||||
Vectors.release(blockInWorld);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileData getTileSfc(Vec3i surfaceBlockInWorld, BlockFace face, int layer) {
|
|
||||||
Vec3i blockInWorld = Vectors.grab3i();
|
|
||||||
resolve(surfaceBlockInWorld, blockInWorld);
|
|
||||||
TileData result = parent.getTile(blockInWorld, face, layer);
|
|
||||||
Vectors.release(blockInWorld);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBlockLoadedSfc(Vec3i surfaceBlockInWorld) {
|
|
||||||
Vec3i blockInWorld = Vectors.grab3i();
|
|
||||||
resolve(surfaceBlockInWorld, blockInWorld);
|
|
||||||
boolean result = parent.isLocationLoaded(blockInWorld);
|
|
||||||
Vectors.release(blockInWorld);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getTime() {
|
|
||||||
return parent.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GravityModel getGravityModel() {
|
|
||||||
return parent.getGravityModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <SE extends StatefulObject & EntityGeneric> void changeEntity(SE entity, StateChange<SE> change) {
|
|
||||||
parent.changeEntity(entity, change);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void advanceTime(float change) {
|
|
||||||
parent.advanceTime(change);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user