public void Read(Stream input, Endian endian = Endian.Little) { RoadGraphRoadToJunctionEdgeMappingCount = input.ReadValueU16(endian); RoadGraphEdgeCount = input.ReadValueU16(endian); for (int i = 0; i < RoadGraphEdgeCount; i++) { RoadGraphEdges.Add(new Tuple <ushort, ushort>(input.ReadValueU16(endian), input.ReadValueU16(endian))); } ushort roadCount = input.ReadValueU16(endian); for (int i = 0; i < roadCount; i++) { var road = new RoadDefinitionDe(); road.Read(input, endian); Roads.Add(road); } for (int i = 0; i < RoadGraphEdgeCount; i++) { var costMapping = new CostMapEntryDe(); costMapping.Read(input, endian); CostMap.Add(costMapping); } byte magic0 = input.ReadValueU8(); byte magic1 = input.ReadValueU8(); byte magic2 = input.ReadValueU8(); byte magic3 = input.ReadValueU8(); if (magic0 != 0x11 && magic1 != 0x11 && magic2 != 0x11 && magic3 != 0) { throw new IOException($"Unexpected magic values ({magic0}, {magic1}, {magic2}, {magic3})"); } ushort splineCount = input.ReadValueU16(endian); for (int i = 0; i < splineCount; i++) { var spline = new RoadSplineDe(); spline.Read(input, endian); Splines.Add(spline); } for (int i = 0; i < roadCount * 2; i++) { RoadToCrossroadMapping.Add(input.ReadValueU16(endian)); } ushort crossroadCount = input.ReadValueU16(endian); for (int i = 0; i < crossroadCount; i++) { var crossroad = new CrossroadDe(); crossroad.Read(input, endian); Crossroads.Add(crossroad); } }
/// <summary> /// Set the motion for this spline. /// </summary> /// <param name="target">The object the motion should target. Must be non-null and a reference type.</param> /// <param name="duration">How long the motion should take, in seconds.</param> /// <param name="points">The points that the motion should spline between.</param> /// <returns>A reference to this, for specifying additional parameters.</returns> public Spliner Spline <TTarget, TPoint>(TTarget target, float duration, params TPoint[] points) where TTarget : class { if (target == null) { throw new ArgumentNullException(nameof(target)); } var targetType = target.GetType(); if (targetType.IsValueType) { throw new ArgumentException("Target may not be a struct"); } Target = target; Duration = duration; var path = new List <float[]>(); // float[] here is one object's properties var cross = new List <float[]>(); // float[] here is one property's value at each point GetDefinitions(target, points[0], out accessor, out var pointDef); buffer = new float[accessor.Length]; for (int i = 0; i < points.Length; i++) { path.Add(new float[pointDef.Length]); for (int j = 0; j < pointDef.Length; j++) { path[i][j] = pointDef[j].GetValue(points[i]); } } for (int i = 0; i < pointDef.Length; i++) { var splinePoints = new float[path.Count]; cross.Add(splinePoints); for (int j = 0; j < path.Count; j++) { splinePoints[j] = path[j][i]; } } Splines.Clear(); for (int i = 0; i < cross.Count; i++) { Splines.Add(new Spline(cross[i])); } return(this); }