| 767 | //========================================================================== |
| 768 | |
| 769 | void PClass::BuildFlatPointers() const |
| 770 | { |
| 771 | using pairType = std::pair<size_t, PObjectPointer *>; |
| 772 | |
| 773 | if (FlatPointers != nullptr) |
| 774 | { // Already built: Do nothing. |
| 775 | return; |
| 776 | } |
| 777 | else |
| 778 | { |
| 779 | TArray<pairType> NativePointers; |
| 780 | if (Pointers != nullptr) |
| 781 | { |
| 782 | for (size_t i = 0; Pointers[i] != ~(size_t)0; i++) |
| 783 | { |
| 784 | NativePointers.Push({Pointers[i], nullptr}); // native pointers have a null type |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | if (ParentClass == nullptr) |
| 789 | { // No parent (i.e. DObject): FlatPointers is the same as Pointers. |
| 790 | if (NativePointers.Size() == 0) |
| 791 | { // No pointers: Make FlatPointers a harmless non-nullptr. |
| 792 | FlatPointers = (pairType*)(&TheEnd); |
| 793 | FlatPointersSize = 0; |
| 794 | } |
| 795 | else |
| 796 | { |
| 797 | pairType *flat = (pairType*)ClassDataAllocator.Alloc(sizeof(pairType) * NativePointers.Size()); |
| 798 | memcpy(flat, NativePointers.Data(), sizeof(pairType) * NativePointers.Size()); |
| 799 | |
| 800 | FlatPointers = flat; |
| 801 | FlatPointersSize = NativePointers.Size(); |
| 802 | } |
| 803 | } |
| 804 | else |
| 805 | { |
| 806 | ParentClass->BuildFlatPointers(); |
| 807 | |
| 808 | TArray<pairType> ScriptPointers; |
| 809 | |
| 810 | // Collect all pointers in scripted fields. These are not part of the Pointers list. |
| 811 | for (auto field : Fields) |
| 812 | { |
| 813 | if (!(field->Flags & VARF_Native)) |
| 814 | { |
| 815 | field->Type->SetPointer(Defaults, unsigned(field->Offset), &ScriptPointers); |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | if (NativePointers.Size() == 0 && ScriptPointers.Size() == 0) |
| 820 | { // No new pointers: Just use the same FlatPointers as the parent. |
| 821 | FlatPointers = ParentClass->FlatPointers; |
| 822 | FlatPointersSize = ParentClass->FlatPointersSize; |
| 823 | } |
| 824 | else |
| 825 | { // New pointers: Create a new FlatPointers array and add them. |
| 826 | // Concatenate them into a new array |
no test coverage detected