Created
February 22, 2024 02:42
-
-
Save UgurkanTech/4d4f7cbdde601ac5ba618a8d3d8a631d to your computer and use it in GitHub Desktop.
A low level block struct.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct Block | |
{ | |
uint data; //8 bytes | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public Block(BlockType id, ushort metaData, bool isOpaque) | |
{ | |
data = (uint)((ushort)id << 16) | (uint)(metaData << 1) | (uint)(isOpaque ? 0x1 : 0x0); | |
} | |
//Id 0-65535 | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public BlockType GetID() | |
{ | |
return (BlockType)((ushort)(data >> 16)); | |
} | |
//Meta 0-32766 | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public ushort GetMetaData() | |
{ | |
return (ushort)((data & 0x0000FFFF) >> 1); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public bool GetIsOpaque() | |
{ | |
return data % 2 == 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment