MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SlIterateArray

Function SlIterateArray

src/saveload/saveload.cpp:677–714  ·  view source on GitHub ↗

* Iterate through the elements of an array and read the whole thing * @return The index of the object, or -1 if we have reached the end of current block */

Source from the content-addressed store, hash-verified

675 * @return The index of the object, or -1 if we have reached the end of current block
676 */
677int SlIterateArray()
678{
679 /* After reading in the whole array inside the loop
680 * we must have read in all the data, so we must be at end of current block. */
681 if (_next_offs != 0 && _sl.reader->GetSize() != _next_offs) {
682 SlErrorCorruptFmt("Invalid chunk size iterating array - expected to be at position {}, actually at {}", _next_offs, _sl.reader->GetSize());
683 }
684
685 for (;;) {
686 uint length = SlReadArrayLength();
687 if (length == 0) {
688 assert(!_sl.expect_table_header);
689 _next_offs = 0;
690 return -1;
691 }
692
693 _sl.obj_len = --length;
694 _next_offs = _sl.reader->GetSize() + length;
695
696 if (_sl.expect_table_header) {
697 _sl.expect_table_header = false;
698 return INT32_MAX;
699 }
700
701 int index;
702 switch (_sl.block_mode) {
703 case CH_SPARSE_TABLE:
704 case CH_SPARSE_ARRAY: index = (int)SlReadSparseIndex(); break;
705 case CH_TABLE:
706 case CH_ARRAY: index = _sl.array_index++; break;
707 default:
708 Debug(sl, 0, "SlIterateArray error");
709 return -1; // error
710 }
711
712 if (length != 0) return index;
713 }
714}
715
716/**
717 * Skip an array or sparse array

Callers 15

LoadCommonMethod · 0.85
SlSkipArrayFunction · 0.85
SlLoadChunkFunction · 0.85
SlLoadCheckChunkFunction · 0.85
LoadMethod · 0.85
LoadMethod · 0.85
LoadMethod · 0.85
LoadMethod · 0.85
LoadMethod · 0.85
LoadMethod · 0.85
LoadMethod · 0.85
LoadMethod · 0.85

Calls 4

SlErrorCorruptFmtFunction · 0.85
SlReadArrayLengthFunction · 0.85
SlReadSparseIndexFunction · 0.85
GetSizeMethod · 0.45

Tested by

no test coverage detected