| 854 | //========================================================================== |
| 855 | |
| 856 | void PClass::BuildArrayPointers() const |
| 857 | { |
| 858 | using pairType = std::pair<size_t, PDynArray *>; |
| 859 | |
| 860 | if (ArrayPointers != nullptr) |
| 861 | { // Already built: Do nothing. |
| 862 | return; |
| 863 | } |
| 864 | else if (ParentClass == nullptr) |
| 865 | { // No parent (i.e. DObject): Make ArrayPointers a harmless non-nullptr. |
| 866 | ArrayPointers = (pairType*)(&TheEnd); |
| 867 | ArrayPointersSize = 0; |
| 868 | } |
| 869 | else |
| 870 | { |
| 871 | ParentClass->BuildArrayPointers(); |
| 872 | |
| 873 | TArray<pairType> ScriptPointers; |
| 874 | |
| 875 | // Collect all arrays to pointers in scripted fields. |
| 876 | for (auto field : Fields) |
| 877 | { |
| 878 | if (!(field->Flags & VARF_Native)) |
| 879 | { |
| 880 | field->Type->SetPointerArray(Defaults, unsigned(field->Offset), &ScriptPointers); |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | if (ScriptPointers.Size() == 0) |
| 885 | { // No new pointers: Just use the same ArrayPointers as the parent. |
| 886 | ArrayPointers = ParentClass->ArrayPointers; |
| 887 | ArrayPointersSize = ParentClass->ArrayPointersSize; |
| 888 | } |
| 889 | else |
| 890 | { // New pointers: Create a new ArrayPointers array and add them. |
| 891 | // Concatenate them into a new array |
| 892 | pairType *flat = (pairType*)ClassDataAllocator.Alloc(sizeof(pairType) * (ParentClass->ArrayPointersSize + ScriptPointers.Size())); |
| 893 | if (ParentClass->ArrayPointersSize > 0) |
| 894 | { |
| 895 | memcpy(flat, ParentClass->ArrayPointers, sizeof(pairType) * ParentClass->ArrayPointersSize); |
| 896 | } |
| 897 | |
| 898 | if (ScriptPointers.Size() > 0) |
| 899 | { |
| 900 | memcpy(flat + ParentClass->ArrayPointersSize, ScriptPointers.Data(), sizeof(pairType) * ScriptPointers.Size()); |
| 901 | } |
| 902 | |
| 903 | ArrayPointers = flat; |
| 904 | ArrayPointersSize = ParentClass->ArrayPointersSize + ScriptPointers.Size(); |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | //========================================================================== |
| 910 | // |
no test coverage detected