| 915 | //========================================================================== |
| 916 | |
| 917 | void PClass::BuildMapPointers() const |
| 918 | { |
| 919 | using pairType = std::pair<size_t, PMap *>; |
| 920 | |
| 921 | if (MapPointers != nullptr) |
| 922 | { // Already built: Do nothing. |
| 923 | return; |
| 924 | } |
| 925 | else if (ParentClass == nullptr) |
| 926 | { // No parent (i.e. DObject): Make MapPointers a harmless non-nullptr. |
| 927 | MapPointers = (pairType*)(&TheEnd); |
| 928 | MapPointersSize = 0; |
| 929 | } |
| 930 | else |
| 931 | { |
| 932 | ParentClass->BuildMapPointers(); |
| 933 | |
| 934 | TArray<pairType> ScriptPointers; |
| 935 | |
| 936 | // Collect all arrays to pointers in scripted fields. |
| 937 | for (auto field : Fields) |
| 938 | { |
| 939 | if (!(field->Flags & VARF_Native)) |
| 940 | { |
| 941 | field->Type->SetPointerMap(Defaults, unsigned(field->Offset), &ScriptPointers); |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | if (ScriptPointers.Size() == 0) |
| 946 | { // No new pointers: Just use the same ArrayPointers as the parent. |
| 947 | MapPointers = ParentClass->MapPointers; |
| 948 | MapPointersSize = ParentClass->MapPointersSize; |
| 949 | } |
| 950 | else |
| 951 | { // New pointers: Create a new FlatPointers array and add them. |
| 952 | // Concatenate them into a new array |
| 953 | pairType *flat = (pairType*)ClassDataAllocator.Alloc(sizeof(pairType) * (ParentClass->MapPointersSize + ScriptPointers.Size())); |
| 954 | if (ParentClass->MapPointersSize > 0) |
| 955 | { |
| 956 | memcpy(flat, ParentClass->MapPointers, sizeof(pairType) * ParentClass->MapPointersSize); |
| 957 | } |
| 958 | |
| 959 | if (ScriptPointers.Size() > 0) |
| 960 | { |
| 961 | memcpy(flat + ParentClass->MapPointersSize, ScriptPointers.Data(), sizeof(pairType) * ScriptPointers.Size()); |
| 962 | } |
| 963 | MapPointers = flat; |
| 964 | MapPointersSize = ParentClass->MapPointersSize + ScriptPointers.Size(); |
| 965 | } |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | //========================================================================== |
| 970 | // |
no test coverage detected