Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MethodSemanticsTableReader.cs
Go to the documentation of this file.
2
4
5internal readonly struct MethodSemanticsTableReader
6{
7 internal readonly int NumberOfRows;
8
9 private readonly bool _IsMethodTableRowRefSizeSmall;
10
11 private readonly bool _IsHasSemanticRefSizeSmall;
12
13 private readonly int _SemanticsFlagOffset;
14
15 private readonly int _MethodOffset;
16
17 private readonly int _AssociationOffset;
18
19 internal readonly int RowSize;
20
21 internal readonly MemoryBlock Block;
22
23 internal MethodSemanticsTableReader(int numberOfRows, bool declaredSorted, int methodTableRowRefSize, int hasSemanticRefSize, MemoryBlock containingBlock, int containingBlockOffset)
24 {
25 NumberOfRows = numberOfRows;
26 _IsMethodTableRowRefSizeSmall = methodTableRowRefSize == 2;
27 _IsHasSemanticRefSizeSmall = hasSemanticRefSize == 2;
30 _AssociationOffset = _MethodOffset + methodTableRowRefSize;
31 RowSize = _AssociationOffset + hasSemanticRefSize;
32 Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
33 if (!declaredSorted && !CheckSorted())
34 {
35 Throw.TableNotSorted(TableIndex.MethodSemantics);
36 }
37 }
38
40 {
41 int num = (rowId - 1) * RowSize;
43 }
44
46 {
47 int num = (rowId - 1) * RowSize;
49 }
50
56
57 internal int FindSemanticMethodsForEvent(EventDefinitionHandle eventDef, out ushort methodCount)
58 {
59 methodCount = 0;
60 uint searchCodedTag = HasSemanticsTag.ConvertEventHandleToTag(eventDef);
61 return BinarySearchTag(searchCodedTag, ref methodCount);
62 }
63
64 internal int FindSemanticMethodsForProperty(PropertyDefinitionHandle propertyDef, out ushort methodCount)
65 {
66 methodCount = 0;
67 uint searchCodedTag = HasSemanticsTag.ConvertPropertyHandleToTag(propertyDef);
68 return BinarySearchTag(searchCodedTag, ref methodCount);
69 }
70
71 private int BinarySearchTag(uint searchCodedTag, ref ushort methodCount)
72 {
73 Block.BinarySearchReferenceRange(NumberOfRows, RowSize, _AssociationOffset, searchCodedTag, _IsHasSemanticRefSizeSmall, out var startRowNumber, out var endRowNumber);
74 if (startRowNumber == -1)
75 {
76 methodCount = 0;
77 return 0;
78 }
79 methodCount = (ushort)(endRowNumber - startRowNumber + 1);
80 return startRowNumber + 1;
81 }
82
87}
static EntityHandle ConvertToHandle(uint hasSemantic)
static uint ConvertEventHandleToTag(EventDefinitionHandle eventDef)
static uint ConvertPropertyHandleToTag(PropertyDefinitionHandle propertyDef)
static void TableNotSorted(TableIndex tableIndex)
Definition Throw.cs:250
int PeekReference(int offset, bool smallRefSize)
unsafe ushort PeekUInt16(int offset)
unsafe MemoryBlock GetMemoryBlockAt(int offset, int length)
bool IsOrderedByReferenceAscending(int rowSize, int referenceOffset, bool isReferenceSmall)
void BinarySearchReferenceRange(int rowCount, int rowSize, int referenceOffset, uint referenceValue, bool isReferenceSmall, out int startRowNumber, out int endRowNumber)
uint PeekTaggedReference(int offset, bool smallRefSize)
int FindSemanticMethodsForEvent(EventDefinitionHandle eventDef, out ushort methodCount)
MethodSemanticsTableReader(int numberOfRows, bool declaredSorted, int methodTableRowRefSize, int hasSemanticRefSize, MemoryBlock containingBlock, int containingBlockOffset)
int BinarySearchTag(uint searchCodedTag, ref ushort methodCount)
int FindSemanticMethodsForProperty(PropertyDefinitionHandle propertyDef, out ushort methodCount)
static MethodDefinitionHandle FromRowId(int rowId)