public void Load(Wadfile.DirectoryEntry wad) { Chunks = wad.Chunks; if (wad.Chunks.ContainsKey(MapInfo.Tag)) { LoadChunk(mapInfo, wad.Chunks[MapInfo.Tag]); } else { throw new Wadfile.BadMapException("Incomplete level: missing map info chunk"); } if (wad.Chunks.ContainsKey(Point.Tag)) { LoadChunkList <Point>(Endpoints, wad.Chunks[Point.Tag]); } else if (wad.Chunks.ContainsKey(Endpoint.Tag)) { Endpoints.Clear(); List <Endpoint> endpointList = new List <Endpoint>(); LoadChunkList <Endpoint>(endpointList, wad.Chunks[Endpoint.Tag]); foreach (Endpoint e in endpointList) { Endpoints.Add(e.Vertex); } } else { throw new Wadfile.BadMapException("Incomplete level: missing points chunk"); } if (wad.Chunks.ContainsKey(Line.Tag)) { LoadChunkList <Line>(Lines, wad.Chunks[Line.Tag]); } else { throw new Wadfile.BadMapException("Incomplete level: missing lines chunk"); } if (wad.Chunks.ContainsKey(Polygon.Tag)) { LoadChunkList <Polygon>(Polygons, wad.Chunks[Polygon.Tag]); } else { throw new Wadfile.BadMapException("Incomplete level: missing polygons chunk"); } if (wad.Chunks.ContainsKey(Side.Tag)) { LoadChunkList <Side>(Sides, wad.Chunks[Side.Tag]); } if (wad.Chunks.ContainsKey(Platform.StaticTag)) { LoadChunkList <Platform>(Platforms, wad.Chunks[Platform.StaticTag]); } else if (wad.Chunks.ContainsKey(Platform.DynamicTag)) { BinaryReaderBE reader = new BinaryReaderBE(new MemoryStream(wad.Chunks[Platform.DynamicTag])); Platforms.Clear(); while (reader.BaseStream.Position < reader.BaseStream.Length) { Platform platform = new Platform(); platform.LoadDynamic(reader); Platforms.Add(platform); // open up the polygon if (platform.PolygonIndex >= 0 && platform.PolygonIndex < Polygons.Count) { Polygon polygon = Polygons[platform.PolygonIndex]; if (platform.ComesFromFloor) { polygon.FloorHeight = platform.MinimumHeight; } if (platform.ComesFromCeiling) { polygon.CeilingHeight = platform.MaximumHeight; } } } } if (wad.Chunks.ContainsKey(Light.Tag)) { LoadChunkList <Light>(Lights, wad.Chunks[Light.Tag]); } if (wad.Chunks.ContainsKey(Placement.Tag)) { BinaryReaderBE reader = new BinaryReaderBE(new MemoryStream(wad.Chunks[Placement.Tag])); ItemPlacement.Clear(); for (int i = 0; i < Placement.Count; ++i) { Placement placement = new Placement(); placement.Load(reader); ItemPlacement.Add(placement); } MonsterPlacement.Clear(); for (int i = 0; i < Placement.Count; ++i) { Placement placement = new Placement(); placement.Load(reader); MonsterPlacement.Add(placement); } } if (wad.Chunks.ContainsKey(Annotation.Tag)) { LoadChunkList <Annotation>(Annotations, wad.Chunks[Annotation.Tag]); } EndpointPolygons.Clear(); EndpointLines.Clear(); for (int i = 0; i < Endpoints.Count; ++i) { EndpointPolygons.Add(new HashSet <Polygon>()); EndpointLines.Add(new HashSet <Line>()); } foreach (Polygon polygon in Polygons) { UpdatePolygonConcavity(polygon); for (int i = 0; i < polygon.VertexCount; ++i) { Line line = Lines[polygon.LineIndexes[i]]; EndpointPolygons[line.EndpointIndexes[0]].Add(polygon); EndpointPolygons[line.EndpointIndexes[1]].Add(polygon); } } foreach (Line line in Lines) { EndpointLines[line.EndpointIndexes[0]].Add(line); EndpointLines[line.EndpointIndexes[1]].Add(line); } for (int i = 0; i < Polygons.Count; ++i) { Polygon polygon = Polygons[i]; if (polygon.Type == PolygonType.Platform) { bool found = false; for (int j = 0; j < Platforms.Count; ++j) { Platform platform = Platforms[j]; if (platform.PolygonIndex == i) { polygon.Permutation = (short)j; found = true; break; } } if (!found) { Platform platform = new Platform(); platform.SetTypeWithDefaults(PlatformType.SphtDoor); platform.PolygonIndex = (short)i; polygon.Permutation = (short)Platforms.Count; Platforms.Add(platform); } } } foreach (Side side in Sides) { side.PolygonIndex = -1; side.LineIndex = -1; } for (short index = 0; index < Lines.Count; ++index) { Line line = Lines[index]; Polygon p1 = null; Polygon p2 = null; if (line.ClockwisePolygonOwner != -1) { p1 = Polygons[line.ClockwisePolygonOwner]; } if (line.CounterclockwisePolygonOwner != -1) { p2 = Polygons[line.CounterclockwisePolygonOwner]; } if (p1 != null && p2 != null) { line.HighestAdjacentFloor = Math.Max(p1.FloorHeight, p2.FloorHeight); line.LowestAdjacentCeiling = Math.Min(p1.CeilingHeight, p2.CeilingHeight); } else if (p1 != null) { line.HighestAdjacentFloor = p1.FloorHeight; line.LowestAdjacentCeiling = p1.CeilingHeight; } else if (p2 != null) { line.HighestAdjacentFloor = p2.FloorHeight; line.LowestAdjacentCeiling = p2.CeilingHeight; } else { line.HighestAdjacentFloor = 0; line.LowestAdjacentCeiling = 0; } if (line.VariableElevation) { line.Solid = (line.HighestAdjacentFloor >= line.LowestAdjacentCeiling); } if (line.ClockwisePolygonSideIndex != -1) { Side side = Sides[line.ClockwisePolygonSideIndex]; side.LineIndex = index; side.PolygonIndex = line.ClockwisePolygonOwner; } if (line.CounterclockwisePolygonSideIndex != -1) { Side side = Sides[line.CounterclockwisePolygonSideIndex]; side.LineIndex = index; side.PolygonIndex = line.CounterclockwisePolygonOwner; } } if (wad.Chunks.ContainsKey(MapObject.Tag)) { LoadChunkList <MapObject>(Objects, wad.Chunks[MapObject.Tag]); } else { throw new Wadfile.BadMapException("Incomplete level: missing map objects chunk"); } if (wad.Chunks.ContainsKey(Media.Tag)) { LoadChunkList <Media>(Medias, wad.Chunks[Media.Tag]); } if (wad.Chunks.ContainsKey(AmbientSound.Tag)) { LoadChunkList <AmbientSound>(AmbientSounds, wad.Chunks[AmbientSound.Tag]); } if (wad.Chunks.ContainsKey(RandomSound.Tag)) { LoadChunkList <RandomSound>(RandomSounds, wad.Chunks[RandomSound.Tag]); } }
void InsertLineFaces(Line line, Polygon p) { int left; int right; Polygon opposite = null; Side side = null; if (line.ClockwisePolygonOwner != -1 && level.Polygons[line.ClockwisePolygonOwner] == p) { left = line.EndpointIndexes[0]; right = line.EndpointIndexes[1]; if (line.CounterclockwisePolygonOwner != -1) { opposite = level.Polygons[line.CounterclockwisePolygonOwner]; } if (line.ClockwisePolygonSideIndex != -1) { side = level.Sides[line.ClockwisePolygonSideIndex]; } } else { left = line.EndpointIndexes[1]; right = line.EndpointIndexes[0]; if (line.ClockwisePolygonOwner != -1) { opposite = level.Polygons[line.ClockwisePolygonOwner]; } if (line.CounterclockwisePolygonSideIndex != -1) { side = level.Sides[line.CounterclockwisePolygonSideIndex]; } } bool landscapeTop = false; bool landscapeBottom = false; if (side != null) { if (side.Type == SideType.Low) { if (side.PrimaryTransferMode == 9) { landscapeBottom = true; } } else { if (side.PrimaryTransferMode == 9) { landscapeTop = true; } if (side.SecondaryTransferMode == 9) { landscapeBottom = true; } } } if (opposite == null || (opposite.FloorHeight > p.CeilingHeight || opposite.CeilingHeight < p.FloorHeight)) { if (!landscapeTop) { faces.Add(BuildFace(left, right, p.FloorHeight, p.CeilingHeight)); } } else { if (opposite.FloorHeight > p.FloorHeight) { if (!landscapeBottom) { faces.Add(BuildFace(left, right, p.FloorHeight, opposite.FloorHeight)); } } if (opposite.CeilingHeight < p.CeilingHeight) { if (!landscapeTop) { faces.Add(BuildFace(left, right, opposite.CeilingHeight, p.CeilingHeight)); } } } }