Skip to content

Commit

Permalink
Started work on mmaped subchunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilligans committed Jan 27, 2024
1 parent bb60ad9 commit e0b0e6c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.hilligans.ourcraft.world.newworldsystem;

import dev.hilligans.ourcraft.block.blockstate.IBlockState;

import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.util.ArrayList;

public class BufferedSubChunk implements ISubChunk {

public MemorySegment memorySegment;
public ArrayList<IBlockState> blockStatePalette;

public BufferedSubChunk(MemorySegment memorySegment, ArrayList<IBlockState> blockStatePalette) {
this.memorySegment = memorySegment;
this.blockStatePalette = blockStatePalette;
}

@Override
public int getWidth() {
return 16;
}

@Override
public int getHeight() {
return 16;
}

@Override
public IBlockState getBlockState(IWorld world, int x, int y, int z) {
return blockStatePalette.get(memorySegment.get(ValueLayout.JAVA_SHORT, getIndex(x, y, z)));
}

@Override
public IBlockState setBlockState(IWorld world, int x, int y, int z, IBlockState blockState) {
IBlockState old = getBlockState(world, x, y, z);
memorySegment.set(ValueLayout.JAVA_SHORT, getIndex(x,y,z), (short)blockState.getBlockStateID());
return old;
}

@Override
public boolean isEmpty() {
return false;
}

public static int getIndex(int x, int y, int z) {
return ((x * 16) + y) * 16 + z;
}

@Override
public ISubChunk canInsertOrGetNext(IBlockState blockState) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.hilligans.ourcraft.world.newworldsystem;

import java.lang.foreign.MemorySegment;

public class MMapContainer {

MemorySegment masterSegment;

public IWorld world;

public int x;
public int y;
public int z;

public int width;
public int height;

public MMapContainer(IWorld world, int x, int y, int z, int width, int height) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.width = width;
this.height = height;
}

public CubicChunk createChunk(int chunkX, int chunkY, int chunkZ) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.hilligans.ourcraft.world.newworldsystem;

public class MMappedSubChunk {



}

0 comments on commit e0b0e6c

Please sign in to comment.