Esempio n. 1
0
        partial void PointsCustomParse(OverlayStream stream, long finalPos, int offset, RecordType type, PreviousParse lastParsed)
        {
            if (stream.Complete)
            {
                return;
            }
            var subMeta = stream.GetSubrecord();

            if (subMeta.RecordType != RecordTypes.PGRP)
            {
                return;
            }
            stream.Position += subMeta.HeaderLength;
            var pointBytes = stream.ReadMemory(subMeta.ContentLength);

            subMeta = stream.GetSubrecord();
            switch (subMeta.RecordTypeInt)
            {
            case 0x52524750:     // "PGRR":
                stream.Position += subMeta.HeaderLength;
                var connBytes = stream.ReadMemory(subMeta.ContentLength);
                this.Points = BinaryOverlayList.FactoryByLazyParse <IRoadPointGetter>(
                    pointBytes,
                    _package,
                    getter: (s, p) =>
                {
                    int numPts         = pointBytes.Length / RoadBinaryCreateTranslation.POINT_LEN;
                    RoadPoint[] points = new RoadPoint[numPts];
                    var connFloats     = connBytes.Span.AsFloatSpan();
                    for (int i = 0; i < numPts; i++)
                    {
                        var pt          = RoadBinaryCreateTranslation.ReadPathGridPoint(s, out var numConn);
                        s               = s.Slice(RoadBinaryCreateTranslation.POINT_LEN);
                        P3Float[] conns = new P3Float[numConn];
                        for (int j = 0; j < numConn; j++)
                        {
                            conns[j] = new P3Float(
                                x: connFloats[0],
                                y: connFloats[1],
                                z: connFloats[2]);
                            connFloats = connFloats.Slice(3);
                        }
                        pt.Connections.AddRange(conns);
                        points[i] = pt;
                    }
                    return(points);
                });
                break;

            default:
                this.Points = BinaryOverlayList.FactoryByStartIndex <IRoadPointGetter>(
                    pointBytes,
                    _package,
                    itemLength: RoadBinaryCreateTranslation.POINT_LEN,
                    getter: (s, p) => RoadBinaryCreateTranslation.ReadPathGridPoint(s, out var numConn));
                break;
            }
        }
Esempio n. 2
0
        public static partial void FillBinaryPointsCustom(MutagenFrame frame, IRoadInternal item)
        {
            if (!frame.Reader.TryReadSubrecord(PGRP, out var subMeta))
            {
                return;
            }
            var pointBytes = frame.Reader.ReadSpan(subMeta.ContentLength);

            subMeta = frame.ReadSubrecord();
            switch (subMeta.RecordType.TypeInt)
            {
            case 0x52524750:     // "PGRR":
                var         connBytes  = frame.Reader.ReadSpan(subMeta.ContentLength);
                var         connFloats = connBytes.AsFloatSpan();
                int         numPts     = pointBytes.Length / POINT_LEN;
                RoadPoint[] points     = new RoadPoint[numPts];
                for (int i = 0; i < numPts; i++)
                {
                    var pt = ReadPathGridPoint(pointBytes, out var numConn);
                    pointBytes = pointBytes.Slice(16);
                    P3Float[] conns = new P3Float[numConn];
                    for (int j = 0; j < numConn; j++)
                    {
                        conns[j] = new P3Float(
                            x: connFloats[0],
                            y: connFloats[1],
                            z: connFloats[2]);
                        connFloats = connFloats.Slice(3);
                    }
                    pt.Connections.AddRange(conns);
                    points[i] = pt;
                }
                item.Points = points.ToExtendedList();
                if (connFloats.Length > 0)
                {
                    throw new ArgumentException("Connection reader did not complete as expected.");
                }
                break;

            default:
                frame.Reader.Position -= subMeta.HeaderLength;
                item.Points            = new ExtendedList <RoadPoint>();
                while (pointBytes.Length > 0)
                {
                    item.Points.Add(
                        ReadPathGridPoint(pointBytes, out var numConn));
                    pointBytes = pointBytes.Slice(16);
                }
                break;
            }
        }