155 lines
3.8 KiB
C#
155 lines
3.8 KiB
C#
namespace Voxel
|
|
{
|
|
public class Chunk
|
|
{
|
|
public readonly int Size = 16;
|
|
public readonly int Height = 256;
|
|
public readonly int PositionX;
|
|
public readonly int PositionY;
|
|
|
|
private Dictionary<ushort, BlockData> _blockData;
|
|
private byte[] _blocks;
|
|
|
|
public Chunk(int positionX, int positionY)
|
|
{
|
|
PositionX = positionX;
|
|
PositionY = positionY;
|
|
|
|
_blockData = new Dictionary<ushort, BlockData>();
|
|
_blocks = new byte[Size * Size * Height];
|
|
|
|
Initialize();
|
|
}
|
|
|
|
public void SetBlock(int x, int y, int z, byte blockId)
|
|
{
|
|
int i = GetBlockIndex(x, y, z);
|
|
_blocks[i] = blockId;
|
|
}
|
|
|
|
public byte GetBlock(int x, int y, int z)
|
|
{
|
|
int i = GetBlockIndex(x, y, z);
|
|
return _blocks[i];
|
|
}
|
|
|
|
public BlockData GetBlockData(int x, int y, int z)
|
|
{
|
|
return new BlockData();
|
|
}
|
|
|
|
private void Initialize()
|
|
{
|
|
for (int x = 0; x < Size; x++)
|
|
{
|
|
for (int z = 0; z < Size; z++)
|
|
{
|
|
for (int y = 0; y < Size; y++)
|
|
{
|
|
byte blockId = 1;
|
|
SetBlock(x, y, z, blockId);
|
|
Console.WriteLine(
|
|
"Set block "
|
|
+ x.ToString() + ", "
|
|
+ y.ToString() + ", "
|
|
+ z.ToString() + " "
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// todo
|
|
public (int x, int y, int z) IndexToPosition(int i)
|
|
{
|
|
int x = 0;
|
|
int y = 0;
|
|
int z = 0;
|
|
|
|
return (x, y, z);
|
|
}
|
|
|
|
private int GetBlockIndex(int x, int y, int z)
|
|
{
|
|
return x + y * Size + z * Size * Size;
|
|
}
|
|
|
|
public List<FaceData> GetFaces()
|
|
{
|
|
List<FaceData> list = new List<FaceData>();
|
|
|
|
for (byte i = 0; i < 6; i++)
|
|
{
|
|
FaceData faceData = new FaceData();
|
|
|
|
faceData.Facing = (Orientation)i;
|
|
|
|
list.Add(faceData);
|
|
}
|
|
|
|
for (byte i = 0; i < 6; i++)
|
|
{
|
|
FaceData faceData = new FaceData();
|
|
|
|
faceData.Facing = (Orientation)i;
|
|
|
|
faceData.X = 1;
|
|
|
|
list.Add(faceData);
|
|
}
|
|
|
|
for (byte i = 0; i < 6; i++)
|
|
{
|
|
FaceData faceData = new FaceData();
|
|
|
|
faceData.Facing = (Orientation)i;
|
|
|
|
|
|
faceData.X = 1;
|
|
faceData.Y = 1;
|
|
faceData.Z = 1;
|
|
|
|
list.Add(faceData);
|
|
}
|
|
|
|
for (byte i = 0; i < 6; i++)
|
|
{
|
|
FaceData faceData = new FaceData();
|
|
|
|
faceData.Facing = (Orientation)i;
|
|
|
|
|
|
faceData.X = 1;
|
|
faceData.Y = 2;
|
|
faceData.Z = 1;
|
|
|
|
list.Add(faceData);
|
|
}
|
|
|
|
for (int x = 0; x < Size; x++)
|
|
{
|
|
for (int z = 0; z < Size; z++)
|
|
{
|
|
for (int y = 0; y < Height; y++)
|
|
{
|
|
for (byte i = 0; i < 6; i++)
|
|
{
|
|
FaceData faceData = new FaceData();
|
|
|
|
faceData.Facing = (Orientation)i;
|
|
|
|
faceData.X = (byte)x;
|
|
faceData.Y = (byte)y;
|
|
faceData.Z = (byte)z;
|
|
|
|
//list.Add(faceData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|
|
}
|