Revert "use hilbert curve for better compression"
This reverts commit 3cb0a0529c
.
treemaps-chunkstates-iteration
parent
f48abfbe7f
commit
4332210e90
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -35,14 +35,14 @@ public class Voxel extends SimpleApplication {
|
|||
|
||||
pos.set(this.getCamera().getLocation());
|
||||
worldManager.initWorld();
|
||||
// worldManager.benchmark();
|
||||
worldManager.benchmark();
|
||||
}
|
||||
public void simpleUpdate(float tpf) {
|
||||
pos.set(this.getCamera().getLocation());
|
||||
// if (!(pos.equals(oldCamPos))) System.out.println(pos);
|
||||
oldCamPos.set(pos);
|
||||
|
||||
worldManager.update();
|
||||
// worldManager.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.emamaker.voxeltest.intervaltrees.renderer;
|
||||
|
||||
import com.emamaker.voxeltest.intervaltrees.utils.Config;
|
||||
import com.emamaker.voxeltest.intervaltrees.utils.Utils;
|
||||
import com.emamaker.voxeltest.intervaltrees.world.Chunk;
|
||||
import com.emamaker.voxeltest.intervaltrees.world.WorldManager;
|
||||
import com.emamaker.voxeltest.intervaltrees.world.blocks.Blocks;
|
||||
|
@ -131,9 +130,9 @@ public class ChunkRenderer {
|
|||
|
||||
for (x[v] = 0; x[v] < Config.CHUNK_SIZE; x[v]++) {
|
||||
for (x[u] = 0; x[u] < Config.CHUNK_SIZE; x[u]++) {
|
||||
Blocks b1 = (x[dim] >= 0) ? blocks[Utils.MortonToHilbert3D(Utils.Morton_3D_Encode_10bit((short)x[0], (short)x[1], (short)x[2]), Config.HILBERT_BITS)] : null;
|
||||
Blocks b1 = (x[dim] >= 0) ? blocks[Chunk.coord3DTo1D(x[0], x[1], x[2])] : null;
|
||||
Blocks b2 = (x[dim] < Config.CHUNK_SIZE - 1)
|
||||
? blocks[Utils.MortonToHilbert3D(Utils.Morton_3D_Encode_10bit((short)(x[0] + q[0]),(short)( x[1] + q[1]), (short) (x[2] + q[2])), Config.HILBERT_BITS)]
|
||||
? blocks[Chunk.coord3DTo1D(x[0] + q[0], x[1] + q[1], x[2] + q[2])]
|
||||
: null;
|
||||
|
||||
// This is the original line taken from rob's code, readapted (replace voxelFace
|
||||
|
|
|
@ -5,12 +5,11 @@ import com.emamaker.voxeltest.intervaltrees.Voxel;
|
|||
public class Config {
|
||||
public Voxel game;
|
||||
|
||||
public static int CHUNK_SIZE = 16;
|
||||
public static int CHUNK_SIZE = 32;
|
||||
// return x + maxX * (y + z * maxY);
|
||||
public static int CHUNK_3DCOORD_MAX_INDEX = (CHUNK_SIZE-1) + CHUNK_SIZE * ( (CHUNK_SIZE - 1) + (CHUNK_SIZE - 1) * CHUNK_SIZE);
|
||||
public static int RENDER_DISTANCE = 8;
|
||||
public static int VOXEL_SIZE = 1 ;
|
||||
public static int CHUNK_LENGTH = CHUNK_SIZE * VOXEL_SIZE;
|
||||
|
||||
public static int HILBERT_BITS = 2;
|
||||
}
|
||||
|
|
|
@ -19,132 +19,5 @@ public class Utils {
|
|||
final int x = idx % maxX;
|
||||
return new int[]{ x, y, z };
|
||||
}
|
||||
// http://and-what-happened.blogspot.com/2011/08/fast-2d-and-3d-hilbert-curves-and.html
|
||||
|
||||
public static int Morton_3D_Encode_10bit( short index1, short index2, short index3 )
|
||||
{ // pack 3 10-bit indices into a 30-bit Morton code
|
||||
index1 &= 0x000003ff;
|
||||
index2 &= 0x000003ff;
|
||||
index3 &= 0x000003ff;
|
||||
index1 |= ( index1 << 16 );
|
||||
index2 |= ( index2 << 16 );
|
||||
index3 |= ( index3 << 16 );
|
||||
index1 &= 0x030000ff;
|
||||
index2 &= 0x030000ff;
|
||||
index3 &= 0x030000ff;
|
||||
index1 |= ( index1 << 8 );
|
||||
index2 |= ( index2 << 8 );
|
||||
index3 |= ( index3 << 8 );
|
||||
index1 &= 0x0300f00f;
|
||||
index2 &= 0x0300f00f;
|
||||
index3 &= 0x0300f00f;
|
||||
index1 |= ( index1 << 4 );
|
||||
index2 |= ( index2 << 4 );
|
||||
index3 |= ( index3 << 4 );
|
||||
index1 &= 0x030c30c3;
|
||||
index2 &= 0x030c30c3;
|
||||
index3 &= 0x030c30c3;
|
||||
index1 |= ( index1 << 2 );
|
||||
index2 |= ( index2 << 2 );
|
||||
index3 |= ( index3 << 2 );
|
||||
index1 &= 0x09249249;
|
||||
index2 &= 0x09249249;
|
||||
index3 &= 0x09249249;
|
||||
return( index1 | ( index2 << 1 ) | ( index3 << 2 ) );
|
||||
}
|
||||
|
||||
public static short[] Morton_3D_Decode_10bit(int morton)
|
||||
{ // unpack 3 10-bit indices from a 30-bit Morton code
|
||||
int value1 = morton;
|
||||
int value2 = ( value1 >> 1 );
|
||||
int value3 = ( value1 >> 2 );
|
||||
value1 &= 0x09249249;
|
||||
value2 &= 0x09249249;
|
||||
value3 &= 0x09249249;
|
||||
value1 |= ( value1 >> 2 );
|
||||
value2 |= ( value2 >> 2 );
|
||||
value3 |= ( value3 >> 2 );
|
||||
value1 &= 0x030c30c3;
|
||||
value2 &= 0x030c30c3;
|
||||
value3 &= 0x030c30c3;
|
||||
value1 |= ( value1 >> 4 );
|
||||
value2 |= ( value2 >> 4 );
|
||||
value3 |= ( value3 >> 4 );
|
||||
value1 &= 0x0300f00f;
|
||||
value2 &= 0x0300f00f;
|
||||
value3 &= 0x0300f00f;
|
||||
value1 |= ( value1 >> 8 );
|
||||
value2 |= ( value2 >> 8 );
|
||||
value3 |= ( value3 >> 8 );
|
||||
value1 &= 0x030000ff;
|
||||
value2 &= 0x030000ff;
|
||||
value3 &= 0x030000ff;
|
||||
value1 |= ( value1 >> 16 );
|
||||
value2 |= ( value2 >> 16 );
|
||||
value3 |= ( value3 >> 16 );
|
||||
value1 &= 0x000003ff;
|
||||
value2 &= 0x000003ff;
|
||||
value3 &= 0x000003ff;
|
||||
|
||||
return new short[]{(short)value1, (short)value2, (short)value3};
|
||||
}
|
||||
|
||||
public static int MortonToHilbert3D( int morton, int bits )
|
||||
{
|
||||
int hilbert = morton;
|
||||
if ( bits > 1 )
|
||||
{
|
||||
int block = ( ( bits * 3 ) - 3 );
|
||||
int hcode = ( ( hilbert >> block ) & 7 );
|
||||
int mcode, shift, signs;
|
||||
shift = signs = 0;
|
||||
while ( block > 0 )
|
||||
{
|
||||
block -= 3;
|
||||
hcode <<= 2;
|
||||
mcode = ( ( 0x20212021 >> hcode ) & 3 );
|
||||
shift = ( ( 0x48 >> ( 7 - shift - mcode ) ) & 3 );
|
||||
signs = ( ( signs | ( signs << 3 ) ) >> mcode );
|
||||
signs = ( ( signs ^ ( 0x53560300 >> hcode ) ) & 7 );
|
||||
mcode = ( ( hilbert >> block ) & 7 );
|
||||
hcode = mcode;
|
||||
hcode = ( ( ( hcode | ( hcode << 3 ) ) >> shift ) & 7 );
|
||||
hcode ^= signs;
|
||||
hilbert ^= ( ( mcode ^ hcode ) << block );
|
||||
}
|
||||
}
|
||||
hilbert ^= ( ( hilbert >> 1 ) & 0x92492492 );
|
||||
hilbert ^= ( ( hilbert & 0x92492492 ) >> 1 );
|
||||
return( hilbert );
|
||||
}
|
||||
|
||||
public static int HilbertToMorton3D( int hilbert, int bits )
|
||||
{
|
||||
int morton = hilbert;
|
||||
morton ^= ( ( morton & 0x92492492 ) >> 1 );
|
||||
morton ^= ( ( morton >> 1 ) & 0x92492492 );
|
||||
if ( bits > 1 )
|
||||
{
|
||||
int block = ( ( bits * 3 ) - 3 );
|
||||
int hcode = ( ( morton >> block ) & 7 );
|
||||
int mcode, shift, signs;
|
||||
shift = signs = 0;
|
||||
while ( block > 0 )
|
||||
{
|
||||
block -= 3;
|
||||
hcode <<= 2;
|
||||
mcode = ( ( 0x20212021 >> hcode ) & 3 );
|
||||
shift = ( ( 0x48 >> ( 4 - shift + mcode ) ) & 3 );
|
||||
signs = ( ( signs | ( signs << 3 ) ) >> mcode );
|
||||
signs = ( ( signs ^ ( 0x53560300 >> hcode ) ) & 7 );
|
||||
hcode = ( ( morton >> block ) & 7 );
|
||||
mcode = hcode;
|
||||
mcode ^= signs;
|
||||
mcode = ( ( ( mcode | ( mcode << 3 ) ) >> shift ) & 7 );
|
||||
morton ^= ( ( hcode ^ mcode ) << block );
|
||||
}
|
||||
}
|
||||
return( morton );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,22 +104,22 @@ public class Chunk {
|
|||
public void arrayGenerateCorner() {
|
||||
Blocks[] array = new Blocks[Config.CHUNK_3DCOORD_MAX_INDEX + 1];
|
||||
|
||||
int dist, hilbert;
|
||||
int dist;
|
||||
|
||||
for (int i = 0; i < Config.CHUNK_SIZE; i++) {
|
||||
for (int j = 0; j < Config.CHUNK_SIZE; j++) {
|
||||
for (int k = 0; k < Config.CHUNK_SIZE; k++) {
|
||||
// Distance from 0,0,0
|
||||
dist = (int) Math.sqrt((i * i) + (j * j) + (k * k));
|
||||
hilbert = Utils.MortonToHilbert3D(Utils.Morton_3D_Encode_10bit((short)i,(short)j,(short)k), Config.HILBERT_BITS);
|
||||
|
||||
if (dist <= (int) (Config.CHUNK_SIZE / 3))
|
||||
array[hilbert] = Blocks.STONE;
|
||||
array[Chunk.coord3DTo1D(i, j, k)] = Blocks.STONE;
|
||||
else if (dist > (int) (Config.CHUNK_SIZE / 3) && dist <= (int) (2 * Config.CHUNK_SIZE / 3))
|
||||
array[hilbert] = Blocks.DIRT;
|
||||
array[Chunk.coord3DTo1D(i, j, k)] = Blocks.DIRT;
|
||||
else if (dist > (int) (2 * Config.CHUNK_SIZE / 3) && dist <= (int) (Config.CHUNK_SIZE))
|
||||
array[hilbert] = Blocks.GRASS;
|
||||
array[Chunk.coord3DTo1D(i, j, k)] = Blocks.GRASS;
|
||||
else
|
||||
array[hilbert] = Blocks.AIR;
|
||||
array[Chunk.coord3DTo1D(i, j, k)] = Blocks.AIR;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ public class WorldManager {
|
|||
|
||||
s = i + "," + j + "," + k;
|
||||
if (!chunks.containsKey(s)) chunks.put(s, new Chunk(i,j,k));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue