Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Handle.cs
Go to the documentation of this file.
2
4
5public readonly struct Handle : IEquatable<Handle>
6{
7 private readonly int _value;
8
9 private readonly byte _vType;
10
12
14
15 internal int RowId => _value;
16
17 internal int Offset => _value;
18
19 internal uint EntityHandleType => Type << 24;
20
21 internal uint Type => _vType & 0x7Fu;
22
23 internal uint EntityHandleValue => (uint)((_vType << 24) | _value);
24
25 internal uint SpecificEntityHandleValue => (uint)(((_vType & 0x80) << 24) | _value);
26
27 internal byte VType => _vType;
28
29 internal bool IsVirtual => (_vType & 0x80) != 0;
30
31 internal bool IsHeapHandle => (_vType & 0x70) == 112;
32
34 {
35 get
36 {
37 uint type = Type;
38 if ((type & 0xFFFFFFFCu) == 120)
39 {
40 return HandleKind.String;
41 }
42 return (HandleKind)type;
43 }
44 }
45
46 public bool IsNil => (_value | (_vType & 0x80)) == 0;
47
48 internal bool IsEntityOrUserStringHandle => Type <= 112;
49
50 internal int Token => (_vType << 24) | _value;
51
52 internal static Handle FromVToken(uint vToken)
53 {
54 return new Handle((byte)(vToken >> 24), (int)(vToken & 0xFFFFFF));
55 }
56
57 internal Handle(byte vType, int value)
58 {
59 _vType = vType;
60 _value = value;
61 }
62
63 public override bool Equals([NotNullWhen(true)] object? obj)
64 {
65 if (obj is Handle other)
66 {
67 return Equals(other);
68 }
69 return false;
70 }
71
72 public bool Equals(Handle other)
73 {
74 if (_value == other._value)
75 {
76 return _vType == other._vType;
77 }
78 return false;
79 }
80
81 public override int GetHashCode()
82 {
83 return _value ^ (_vType << 24);
84 }
85
86 public static bool operator ==(Handle left, Handle right)
87 {
88 return left.Equals(right);
89 }
90
91 public static bool operator !=(Handle left, Handle right)
92 {
93 return !left.Equals(right);
94 }
95
96 internal static int Compare(Handle left, Handle right)
97 {
98 return ((long)((uint)left._value | ((ulong)left._vType << 32))).CompareTo((long)((uint)right._value | ((ulong)right._vType << 32)));
99 }
100}
static bool operator!=(Handle left, Handle right)
Definition Handle.cs:91
static int Compare(Handle left, Handle right)
Definition Handle.cs:96
static Handle FromVToken(uint vToken)
Definition Handle.cs:52
bool Equals(Handle other)
Definition Handle.cs:72
Handle(byte vType, int value)
Definition Handle.cs:57
override bool Equals([NotNullWhen(true)] object? obj)
Definition Handle.cs:63
static bool operator==(Handle left, Handle right)
Definition Handle.cs:86