Fixed crashes when using multiple chunks. FPS is still terrible though

This commit is contained in:
OLEGSHA 2020-12-16 11:36:21 +03:00
parent 4fa3592c98
commit 0a8db1cd02
6 changed files with 26 additions and 10 deletions

View File

@ -107,7 +107,7 @@ public class LayerWorld extends Layer {
tmp_testControls.applyPlayerControls(); tmp_testControls.applyPlayerControls();
for (EntityData data : this.client.getWorld().getData().getEntities()) { for (EntityData data : this.client.getWorld().getData().getEntities()) {
tmp_applyFriction(data); tmp_applyFriction(data, tickLength);
tmp_applyGravity(data, tickLength); tmp_applyGravity(data, tickLength);
tmp_renderCollisionModel(data); tmp_renderCollisionModel(data);
} }
@ -177,9 +177,9 @@ public class LayerWorld extends Layer {
return new StaticModel(b); return new StaticModel(b);
} }
private void tmp_applyFriction(EntityData entity) { private void tmp_applyFriction(EntityData entity, float tickLength) {
final float frictionCoeff = 1 - 1e-5f; final float frictionCoeff = Units.get(1e-5f, "kg/s");
entity.getVelocity().mul(frictionCoeff); entity.getVelocity().mul((float) Math.exp(-frictionCoeff / entity.getCollisionMass() * tickLength));
} }
private static final float MC_g = Units.get("32 m/s^2"); private static final float MC_g = Units.get("32 m/s^2");

View File

@ -55,7 +55,7 @@ public class WorldData {
} }
public void tmp_generate() { public void tmp_generate() {
final int size = 1; final int size = 3;
Vec3i cursor = new Vec3i(0, 0, 0); Vec3i cursor = new Vec3i(0, 0, 0);
for (cursor.x = -(size / 2); cursor.x <= (size / 2); ++cursor.x) { for (cursor.x = -(size / 2); cursor.x <= (size / 2); ++cursor.x) {

View File

@ -133,6 +133,11 @@ public abstract class TickContextMutable implements BlockTickContext, TSTickCont
protected Role role = Role.NONE; protected Role role = Role.NONE;
protected boolean isBeingBuilt = false; protected boolean isBeingBuilt = false;
/**
* Updated lazily
*/
protected final Vec3i blockInChunk = new Vec3i();
/* /*
* TickContextMutable * TickContextMutable
*/ */
@ -275,6 +280,11 @@ public abstract class TickContextMutable implements BlockTickContext, TSTickCont
* Optimization * Optimization
*/ */
@Override
public Vec3i getBlockInChunk() {
return Coordinates.convertInWorldToInChunk(getBlockInWorld(), this.blockInChunk);
}
@Override @Override
public void forEachBlock(Consumer<BlockTickContext> action) { public void forEachBlock(Consumer<BlockTickContext> action) {
checkContextState(Role.CHUNK); checkContextState(Role.CHUNK);

View File

@ -5,6 +5,7 @@ import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import glm.vec._3.i.Vec3i; import glm.vec._3.i.Vec3i;
import ru.windcorp.progressia.common.world.Coordinates;
import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.block.BlockData;
import ru.windcorp.progressia.common.world.block.BlockFace; import ru.windcorp.progressia.common.world.block.BlockFace;
import ru.windcorp.progressia.common.world.block.BlockRelation; import ru.windcorp.progressia.common.world.block.BlockRelation;
@ -20,6 +21,10 @@ public interface BlockTickContext extends ChunkTickContext {
*/ */
Vec3i getBlockInWorld(); Vec3i getBlockInWorld();
default Vec3i getBlockInChunk() {
return Coordinates.convertInWorldToInChunk(getBlockInWorld(), null);
}
default BlockLogic getBlock() { default BlockLogic getBlock() {
return getWorld().getBlock(getBlockInWorld()); return getWorld().getBlock(getBlockInWorld());
} }

View File

@ -27,22 +27,22 @@ public interface TSTickContext extends BlockTickContext {
ChunkLogic chunkLogic = getChunkLogic(); ChunkLogic chunkLogic = getChunkLogic();
if (chunkLogic == null) return null; if (chunkLogic == null) return null;
return chunkLogic.getTilesOrNull(getBlockInWorld(), getFace()); return chunkLogic.getTilesOrNull(getBlockInChunk(), getFace());
} }
default TileLogicStack getTLS() { default TileLogicStack getTLS() {
return getChunkLogic().getTiles(getBlockInWorld(), getFace()); return getChunkLogic().getTiles(getBlockInChunk(), getFace());
} }
default TileDataStack getTDSOrNull() { default TileDataStack getTDSOrNull() {
ChunkData chunkData = getChunkData(); ChunkData chunkData = getChunkData();
if (chunkData == null) return null; if (chunkData == null) return null;
return chunkData.getTilesOrNull(getBlockInWorld(), getFace()); return chunkData.getTilesOrNull(getBlockInChunk(), getFace());
} }
default TileDataStack getTDS() { default TileDataStack getTDS() {
return getChunkData().getTiles(getBlockInWorld(), getFace()); return getChunkData().getTiles(getBlockInChunk(), getFace());
} }
/* /*

View File

@ -252,7 +252,7 @@ public class TestContent {
TileData flowers = TileDataRegistry.getInstance().get("Test:YellowFlowers"); TileData flowers = TileDataRegistry.getInstance().get("Test:YellowFlowers");
TileData sand = TileDataRegistry.getInstance().get("Test:Sand"); TileData sand = TileDataRegistry.getInstance().get("Test:Sand");
Vec3i aPoint = new Vec3i(5, 0, bpc + bpc/2).sub(chunk.getPosition()); Vec3i aPoint = new Vec3i(5, 0, bpc + bpc/4).sub(chunk.getPosition().mul_(ChunkData.BLOCKS_PER_CHUNK));
Vec3i pos = new Vec3i(); Vec3i pos = new Vec3i();
for (int x = 0; x < bpc; ++x) { for (int x = 0; x < bpc; ++x) {
@ -280,6 +280,7 @@ public class TestContent {
pos.set(x, y, 0); pos.set(x, y, 0);
for (pos.z = bpc - 1; pos.z >= 0 && chunk.getBlock(pos) == air; --pos.z); for (pos.z = bpc - 1; pos.z >= 0 && chunk.getBlock(pos) == air; --pos.z);
if (pos.z < 0) continue;
chunk.getTiles(pos, BlockFace.TOP).add(grass); chunk.getTiles(pos, BlockFace.TOP).add(grass);
for (BlockFace face : BlockFace.getFaces()) { for (BlockFace face : BlockFace.getFaces()) {