MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ReadWritePackedObjectsChunk

Method ReadWritePackedObjectsChunk

src/openrct2/park/ParkFile.cpp:775–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

773 }
774
775 void ReadWritePackedObjectsChunk(OrcaStream& os)
776 {
777 static constexpr uint8_t kDescriptorDat = 0;
778 static constexpr uint8_t kDescriptorParkObj = 1;
779
780 if (os.getMode() == OrcaStream::Mode::writing && ExportObjectsList.empty())
781 {
782 // Do not emit chunk if there are no packed objects
783 return;
784 }
785
786 os.readWriteChunk(ParkFileChunkType::packedObjects, [this](OrcaStream::ChunkStream& cs) {
787 if (cs.getMode() == OrcaStream::Mode::reading)
788 {
789 auto& objRepository = GetContext()->GetObjectRepository();
790 auto numObjects = cs.read<uint32_t>();
791 for (uint32_t i = 0; i < numObjects; i++)
792 {
793 auto type = cs.read<uint8_t>();
794 if (type == kDescriptorDat)
795 {
796 RCTObjectEntry entry;
797 cs.read(&entry, sizeof(entry));
798 auto size = cs.read<uint32_t>();
799 std::vector<uint8_t> data;
800 data.resize(size);
801 cs.read(data.data(), data.size());
802
803 auto legacyIdentifier = entry.GetName();
804 if (objRepository.FindObjectLegacy(legacyIdentifier) == nullptr)
805 {
806 objRepository.AddObjectFromFile(
807 ObjectGeneration::DAT, legacyIdentifier, data.data(), data.size());
808 }
809 }
810 else if (type == kDescriptorParkObj)
811 {
812 auto identifier = cs.read<std::string>();
813 auto size = cs.read<uint32_t>();
814 std::vector<uint8_t> data;
815 data.resize(size);
816 cs.read(data.data(), data.size());
817 if (objRepository.FindObject(identifier) == nullptr)
818 {
819 objRepository.AddObjectFromFile(ObjectGeneration::JSON, identifier, data.data(), data.size());
820 }
821 }
822 else
823 {
824 throw std::runtime_error("Unsupported packed object");
825 }
826 }
827 }
828 else
829 {
830 auto& stream = cs.getStream();
831 auto countPosition = stream.GetPosition();
832

Callers

nothing calls this directly

Calls 15

GetContextFunction · 0.85
GetExtensionFunction · 0.85
iequalsFunction · 0.85
WriteLineFunction · 0.85
ReadAllBytesFunction · 0.85
readWriteChunkMethod · 0.80
FindObjectLegacyMethod · 0.80
AddObjectFromFileMethod · 0.80
FindObjectMethod · 0.80
writeMethod · 0.65
getModeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected