public void Read(Stream stream) { var reader = new OptReader(stream, Logger) { Vector2T = typeof(TVector2), Vector3T = typeof(TVector3), V2Adapter = new Vector2Adapter <TVector2>(), V3Adapter = new Vector3Adapter <TVector3>() { RotateFromOptSpace = RotateFromOptSpace, } }; // Version is stored as negative int, or is omitted if version is 0. var version = reader.ReadInt32(); int size; if (version < 0) { reader.version = Version = Math.Abs(version); size = reader.ReadInt32() + preGlobalOffsetHeaderLength; } else { size = version; version = 0; } // Sanity check file size. if (size != reader.BaseStream.Length) { var msg = String.Format(CultureInfo.CurrentCulture, "File length expected is {0} but actual length is {1}. File may be corrupt.", size, reader.BaseStream.Length); Logger?.Invoke(msg); throw new InvalidDataException(msg); } // The bytes preceding this don't count when calculating the offset. preGlobalOffsetHeaderLength = (int)reader.BaseStream.Position; reader.globalOffset = GlobalOffset = reader.ReadInt32() - preGlobalOffsetHeaderLength; // Usually 2 in TIE98 UnknownWord = reader.ReadInt16(); var partCount = reader.ReadInt32(); var partListOffset = reader.ReadInt32(); RootNodes = new Collection <BaseNode>(); foreach (var child in reader.ReadChildren(partCount, partListOffset, this)) { RootNodes.Add(child); } }
internal CoordinateReferenceTuple(OptReader reader) { for (int i = 0; i < values.Length; i++) { values[i] = reader.ReadInt32(); } }