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

Method ReadObjects

source/common/engine/serializer.cpp:669–762  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

667//==========================================================================
668
669void FSerializer::ReadObjects(bool hubtravel)
670{
671 bool founderrors = false;
672
673 if (isReading() && BeginArray("objects"))
674 {
675 // Do not link any thinker that's being created here. This will be done by deserializing the thinker list later.
676 try
677 {
678 r->mDObjects.Resize(ArraySize());
679 for (auto &p : r->mDObjects)
680 {
681 p = nullptr;
682 }
683
684 // First iteration: create all the objects but do nothing with them yet.
685 for (unsigned i = 0; i < r->mDObjects.Size(); i++)
686 {
687 if (BeginObject(nullptr))
688 {
689 FString clsname; // do not deserialize the class type directly so that we can print appropriate errors.
690
691 Serialize(*this, "classtype", clsname, nullptr);
692 PClass *cls = PClass::FindClass(clsname);
693 if (cls == nullptr)
694 {
695 Printf(TEXTCOLOR_RED "Unknown object class '%s' in savegame\n", clsname.GetChars());
696 founderrors = true;
697 r->mDObjects[i] = RUNTIME_CLASS(DObject)->CreateNew(); // make sure we got at least a valid pointer for the duration of the loading process.
698 r->mDObjects[i]->Destroy(); // but we do not want to keep this around, so destroy it right away.
699 }
700 else
701 {
702 r->mDObjects[i] = cls->CreateNew();
703 }
704 EndObject();
705 }
706 }
707 // Now that everything has been created and we can retrieve the pointers we can deserialize it.
708 r->mObjectsRead = true;
709
710 if (!founderrors)
711 {
712 // Reset to start;
713 unsigned size = r->mObjects.Size();
714 r->mObjects.Last().mIndex = 0;
715
716 for (unsigned i = 0; i < r->mDObjects.Size(); i++)
717 {
718 auto obj = r->mDObjects[i];
719 if (BeginObject(nullptr))
720 {
721 if (obj != nullptr)
722 {
723 try
724 {
725 obj->SerializeUserVars(*this);
726 obj->Serialize(*this);

Callers 1

SerializeSessionFunction · 0.80

Calls 12

PrintfFunction · 0.85
CreateNewMethod · 0.80
SerializeUserVarsMethod · 0.80
ClampMethod · 0.80
GetClassMethod · 0.80
ResizeMethod · 0.45
SizeMethod · 0.45
GetCharsMethod · 0.45
DestroyMethod · 0.45
SerializeMethod · 0.45
GetMessageMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected