optimized faces

This commit is contained in:
maxwes08
2025-12-15 10:14:16 +01:00
parent 0641d22c9b
commit f532eddfbb
11 changed files with 107 additions and 141 deletions

View File

@@ -2,25 +2,42 @@
namespace Voxel
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct FaceData
{
public Orientation Facing;
public byte X, Y, Z;
public Textures Texture;
public byte LightLevel;
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 new byte[]
{
X,
Y,
Z,
(byte)Facing,
(byte)Texture,
LightLevel,
0,0 // two bits empty
};
return BitConverter.GetBytes(_data);
}
}
}