MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / LoadState

Method LoadState

Source/ModuleContainer.cpp:640–729  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

638}
639
640void ModuleContainer::LoadState(FileStreamIn& in)
641{
642 Prefab::sLastLoadWasPrefab = Prefab::sLoadingPrefab;
643
644 bool wasLoadingState = TheSynth->IsLoadingState();
645 TheSynth->SetIsLoadingState(true);
646
647 static int sModuleContainerLoadStack = 0;
648 ++sModuleContainerLoadStack;
649
650 int header;
651 in >> header;
652 assert(header <= ModularSynth::kSaveStateRev);
653 ModularSynth::sLoadingFileSaveStateRev = header;
654 ModularSynth::sLastLoadedFileSaveStateRev = header;
655
656 int savedModules;
657 in >> savedModules;
658
659 if (mOwner)
660 IClickable::SetLoadContext(mOwner);
661
662 for (int i = 0; i < savedModules; ++i)
663 {
664 std::string moduleName;
665 in >> moduleName;
666 //ofLog() << "Loading " << moduleName;
667 IDrawableModule* module = FindModule(moduleName, false);
668 try
669 {
670 if (module == nullptr)
671 throw LoadStateException();
672
673 module->LoadState(in, module->LoadModuleSaveStateRev(in));
674
675 for (int j = 0; j < GetModuleSeparatorLength(); ++j)
676 {
677 char separatorChar;
678 in >> separatorChar;
679 if (separatorChar != GetModuleSeparator()[j])
680 {
681 ofLog() << "Error loading state for " << module->Name();
682 //something went wrong, let's print some info to try to figure it out
683 ofLog() << "Read char " + ofToString(separatorChar) + " but expected " + GetModuleSeparator()[j] + "!";
684 ofLog() << "Save state file position is " + ofToString(in.GetFilePosition()) + ", EoF is " + (in.Eof() ? "true" : "false");
685 std::string nextFewChars = "Next 10 characters are:";
686 for (int c = 0; c < 10; ++c)
687 {
688 char ch;
689 in >> ch;
690 nextFewChars += ofToString(ch);
691 }
692 ofLog() << nextFewChars;
693 }
694 assert(separatorChar == GetModuleSeparator()[j]);
695 }
696 }
697 catch (LoadStateException& e)

Callers

nothing calls this directly

Calls 11

LoadStateExceptionClass · 0.85
ofLogClass · 0.85
ofToStringFunction · 0.85
IsLoadingStateMethod · 0.80
SetIsLoadingStateMethod · 0.80
GetFilePositionMethod · 0.80
EofMethod · 0.80
LogEventMethod · 0.80
PostLoadStateMethod · 0.80
NameMethod · 0.45

Tested by

no test coverage detected