44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace Voxel
|
|
{
|
|
[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);
|
|
}
|
|
}
|
|
}
|