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

Function SlSetLength

src/saveload/saveload.cpp:731–775  ·  view source on GitHub ↗

* Sets the length of either a RIFF object or the number of items in an array. * This lets us load an object or an array of arbitrary size * @param length The length of the sought object/array */

Source from the content-addressed store, hash-verified

729 * @param length The length of the sought object/array
730 */
731void SlSetLength(size_t length)
732{
733 assert(_sl.action == SLA_SAVE);
734
735 switch (_sl.need_length) {
736 case NL_WANTLENGTH:
737 _sl.need_length = NL_NONE;
738 if ((_sl.block_mode == CH_TABLE || _sl.block_mode == CH_SPARSE_TABLE) && _sl.expect_table_header) {
739 _sl.expect_table_header = false;
740 SlWriteArrayLength(length + 1);
741 break;
742 }
743
744 switch (_sl.block_mode) {
745 case CH_RIFF:
746 /* Ugly encoding of >16M RIFF chunks
747 * The lower 24 bits are normal
748 * The uppermost 4 bits are bits 24:27 */
749 assert(length < (1 << 28));
750 SlWriteUint32((uint32_t)((length & 0xFFFFFF) | ((length >> 24) << 28)));
751 break;
752 case CH_TABLE:
753 case CH_ARRAY:
754 assert(_sl.last_array_index <= _sl.array_index);
755 while (++_sl.last_array_index <= _sl.array_index) {
756 SlWriteArrayLength(1);
757 }
758 SlWriteArrayLength(length + 1);
759 break;
760 case CH_SPARSE_TABLE:
761 case CH_SPARSE_ARRAY:
762 SlWriteArrayLength(length + 1 + SlGetArrayLength(_sl.array_index)); // Also include length of sparse index.
763 SlWriteSparseIndex(_sl.array_index);
764 break;
765 default: NOT_REACHED();
766 }
767 break;
768
769 case NL_CALCLENGTH:
770 _sl.obj_len += (int)length;
771 break;
772
773 default: NOT_REACHED();
774 }
775}
776
777/**
778 * Save/Load bytes. These do not need to be converted to Little/Big Endian

Callers 15

SlCopyFunction · 0.85
SlRefListFunction · 0.85
SlRefVectorFunction · 0.85
SlSetStructListLengthFunction · 0.85
SlObjectFunction · 0.85
SlTableHeaderFunction · 0.85
SlAutolengthFunction · 0.85
SaveMethod · 0.85
SaveMethod · 0.85
SaveMethod · 0.85
SaveMethod · 0.85
SaveMethod · 0.85

Calls 5

SlWriteArrayLengthFunction · 0.85
SlWriteUint32Function · 0.85
SlGetArrayLengthFunction · 0.85
SlWriteSparseIndexFunction · 0.85
NOT_REACHEDFunction · 0.85

Tested by

no test coverage detected