MCPcopy Create free account
hub / github.com/ZDoom/Raze / BuildFlatPointers

Method BuildFlatPointers

source/common/objects/dobjtype.cpp:769–846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

767//==========================================================================
768
769void 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

Callers 2

PropagateMarkMethod · 0.80
PointerSubstitutionMethod · 0.80

Calls 5

PushMethod · 0.45
SizeMethod · 0.45
AllocMethod · 0.45
DataMethod · 0.45
SetPointerMethod · 0.45

Tested by

no test coverage detected