Major refactor and organization, optimizations to chunk, world and renderer
This commit is contained in:
44
Graphics/FaceData.cs
Normal file
44
Graphics/FaceData.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Voxel.Core;
|
||||
|
||||
namespace Voxel.Graphics
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct FaceData
|
||||
{
|
||||
public uint _data;
|
||||
|
||||
// Bit layout:
|
||||
// [31-24]: Y (8 bits) 0-255
|
||||
// [23-20]: Z (4 bits) 0-15
|
||||
// [19-16]: X (4 bits) 0-15
|
||||
// [15-10]: Texture (6 bits) 0-63
|
||||
// [9-7]: Facing (3 bits) 0-7
|
||||
// [6-3]: Light (4 bits) 0-15
|
||||
// [2-0]: unused (3 bits)
|
||||
|
||||
public FaceData(byte x, byte y, byte z, Orientation facing, Textures texture, byte lightLevel)
|
||||
{
|
||||
_data = (uint)(
|
||||
((y & 0xFF) << 24) | // 8 bits
|
||||
((z & 0x0F) << 20) | // 4 bits
|
||||
((x & 0x0F) << 16) | // 4 bits
|
||||
(((byte)texture & 0x3F) << 10) | // 6 bits (0-63)
|
||||
(((byte)facing & 0x07) << 7) | // 3 bits
|
||||
((lightLevel & 0x0F) << 3) // 4 bits
|
||||
);
|
||||
}
|
||||
|
||||
public byte X => (byte)((_data >> 16) & 0x0F);
|
||||
public byte Y => (byte)((_data >> 24) & 0xFF);
|
||||
public byte Z => (byte)((_data >> 20) & 0x0F);
|
||||
public Orientation Facing => (Orientation)((_data >> 7) & 0x07);
|
||||
public Textures Texture => (Textures)((_data >> 10) & 0x3F);
|
||||
public byte LightLevel => (byte)((_data >> 3) & 0x0F);
|
||||
|
||||
public byte[] Pack()
|
||||
{
|
||||
return BitConverter.GetBytes(_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user