Exemplo n.º 1
0
        // This reads the vertices
        private Dictionary <int, Vertex> ReadVertices(MapSet map, UniversalParser textmap)
        {
            Dictionary <int, Vertex> link;

            // Get list of entries
            List <UniversalCollection> collections = GetNamedCollections(textmap.Root, "vertex");

            // Create lookup table
            link = new Dictionary <int, Vertex>(collections.Count);

            // Go for all collections
            map.SetCapacity(map.Vertices.Count + collections.Count, 0, 0, 0, 0);
            for (int i = 0; i < collections.Count; i++)
            {
                // Read fields
                UniversalCollection c = collections[i];
                string where = "vertex " + i;
                float x = GetCollectionEntry <float>(c, "x", true, 0.0f, where);
                float y = GetCollectionEntry <float>(c, "y", true, 0.0f, where);

                // Create new item
                Vertex v = map.CreateVertex(new Vector2D(x, y));
                if (v != null)
                {
                    // Custom fields
                    ReadCustomFields(c, v, "vertex");

                    // Add it to the lookup table
                    link.Add(i, v);
                }
            }

            // Return lookup table
            return(link);
        }
Exemplo n.º 2
0
        private static Dictionary <int, Vertex> ReadVertices(MapSet map, BinaryReader reader)
        {
            int count = reader.ReadInt32();

            // Create lookup table
            Dictionary <int, Vertex> link = new Dictionary <int, Vertex>(count);

            // Go for all collections
            map.SetCapacity(map.Vertices.Count + count, 0, 0, 0, 0);
            for (int i = 0; i < count; i++)
            {
                float x = reader.ReadSingle();
                float y = reader.ReadSingle();

                // Create new item
                Vertex v = map.CreateVertex(new Vector2D(x, y));

                // Add it to the lookup table
                if (v != null)
                {
                    link.Add(i, v);
                }
            }

            // Return lookup table
            return(link);
        }
Exemplo n.º 3
0
        // This reads the VERTICES from WAD file
        // Returns a lookup table with indices
        private Dictionary <int, Vertex> ReadVertices(MapSet map, int firstindex)
        {
            MemoryStream             mem;
            Dictionary <int, Vertex> link;
            BinaryReader             reader;
            int    num, i, x, y;
            Vertex v;

            // Get the lump from wad file
            Lump lump = wad.FindLump("VERTEXES", firstindex);

            if (lump == null)
            {
                throw new Exception("Could not find required lump VERTEXES!");
            }

            // Prepare to read the items
            mem    = new MemoryStream(lump.Stream.ReadAllBytes());
            num    = (int)lump.Stream.Length / 4;
            reader = new BinaryReader(mem);

            // Create lookup table
            link = new Dictionary <int, Vertex>(num);

            // Read items from the lump
            map.SetCapacity(map.Vertices.Count + num, 0, 0, 0, 0);
            for (i = 0; i < num; i++)
            {
                // Read properties from stream
                x = reader.ReadInt16();
                y = reader.ReadInt16();

                // Create new item
                v = map.CreateVertex(new Vector2D((float)x, (float)y));

                // Add it to the lookup table
                link.Add(i, v);
            }

            // Done
            mem.Dispose();

            // Return lookup table
            return(link);
        }
Exemplo n.º 4
0
        // This reads the vertices
        private Dictionary <int, Vertex> ReadVertices(MapSet map, UniversalParser textmap)
        {
            // Get list of entries
            List <UniversalCollection> collections = GetNamedCollections(textmap.Root, "vertex");

            // Create lookup table
            Dictionary <int, Vertex> link = new Dictionary <int, Vertex>(collections.Count);

            // Go for all collections
            map.SetCapacity(map.Vertices.Count + collections.Count, 0, 0, 0, 0);
            for (int i = 0; i < collections.Count; i++)
            {
                // Read fields
                UniversalCollection c = collections[i];
                string where = "vertex " + i;
                float x = GetCollectionEntry(c, "x", true, 0.0f, where);
                float y = GetCollectionEntry(c, "y", true, 0.0f, where);

                // [ZZ] Correct location if it's NaN. Note that there cannot be any meaningful value here, so I just reset it to 0,0 to avoid triggering the NaN exception
                //      TODO: remove once the cause of NaN is reported
                if (float.IsNaN(x) || float.IsNaN(y))
                {
                    x = y = 0f;
                    General.ErrorLogger.Add(ErrorType.Warning, string.Format("Vertex {0} has NaN coordinates, resetting to 0,0", i));
                }

                // Create new item
                Vertex v = map.CreateVertex(new Vector2D(x, y));
                if (v != null)
                {
                    //mxd. zoffsets
                    v.ZCeiling = GetCollectionEntry(c, "zceiling", false, float.NaN, where);                 //mxd
                    v.ZFloor   = GetCollectionEntry(c, "zfloor", false, float.NaN, where);                   //mxd

                    // Custom fields
                    ReadCustomFields(c, v, "vertex");

                    // Add it to the lookup table
                    link.Add(i, v);
                }
            }

            // Return lookup table
            return(link);
        }
Exemplo n.º 5
0
        private static Dictionary <int, Vertex> ReadVertices(MapSet map, BinaryReader reader)
        {
            int count = reader.ReadInt32();

            // Create lookup table
            Dictionary <int, Vertex> link = new Dictionary <int, Vertex>(count);

            // Go for all collections
            map.SetCapacity(map.Vertices.Count + count, 0, 0, 0, 0);
            for (int i = 0; i < count; i++)
            {
                float x  = reader.ReadSingle();
                float y  = reader.ReadSingle();
                float zc = reader.ReadSingle();
                float zf = reader.ReadSingle();

                // Create new item
                Dictionary <string, UniValue> fields = ReadCustomFields(reader);
                Vertex v = map.CreateVertex(new Vector2D(x, y));
                if (v != null)
                {
                    //zoffsets
                    v.ZCeiling = zc;
                    v.ZFloor   = zf;

                    // Add custom fields
                    v.Fields.BeforeFieldsChange();
                    foreach (KeyValuePair <string, UniValue> group in fields)
                    {
                        v.Fields.Add(group.Key, group.Value);
                    }

                    // Add it to the lookup table
                    link.Add(i, v);
                }
            }

            // Return lookup table
            return(link);
        }
Exemplo n.º 6
0
        private static void CreateVertices(MapSet map, List <BuildWall> walls)
        {
            // Count how many verts we will actually create...
            int numverts = walls.Count;
            Dictionary <int, BuildWall> prevwalls = new Dictionary <int, BuildWall>();

            foreach (var w in walls)
            {
                if (w.OtherWallIndex > -1)
                {
                    numverts--;
                }

#if DEBUG
                if (prevwalls.ContainsKey(w.NextWallIndex))
                {
                    throw new NotSupportedException("Invalid OtherWallIndex!");
                }
#endif

                prevwalls[w.NextWallIndex] = w;
            }

            // Always expect the impossible...
            if (numverts < 1)
            {
                throw new NotSupportedException("Map has no vertices!");
            }

            // Create vertices
            map.SetCapacity(map.Vertices.Count + numverts, 0, 0, 0, 0);
            for (int i = 0; i < walls.Count; i++)
            {
                var w = walls[i];

                // Create or set start vertex?
                if (w.Start == null)
                {
                    var prev = prevwalls[i];

                    // The other side of previous wall already created?
                    if (prev.End == null && prev.OtherWallIndex > -1 && walls[prev.OtherWallIndex].Start != null)
                    {
                        w.Start = walls[prev.OtherWallIndex].Start;
                    }
                    // Previous wall already created?
                    else if (prev.End != null)
                    {
                        w.Start = prevwalls[i].End;
                    }
                    // Create new vertex
                    else
                    {
                        Vertex v = map.CreateVertex(new Vector2D(w.StartX, w.StartY));
                        prev.End = v;
                        w.Start  = v;
                    }
                }

                // Create or set end vertex?
                if (w.End == null)
                {
                    var next = walls[w.NextWallIndex];

                    // The other side of next wall already created?
                    if (next.Start == null && next.OtherWallIndex > -1 && walls[next.OtherWallIndex].End != null)
                    {
                        w.End = walls[next.OtherWallIndex].End;
                    }
                    // Next wall already created?
                    else if (next.Start != null)
                    {
                        w.End = next.Start;
                    }
                    // Create new vertex
                    else
                    {
                        Vertex v = map.CreateVertex(new Vector2D(next.StartX, next.StartY));
                        next.Start = v;
                        w.End      = v;
                    }
                }

                // Transfer verts to other side?
                if (w.OtherWallIndex > -1)
                {
                    var other = walls[w.OtherWallIndex];
                    other.End   = w.Start;
                    other.Start = w.End;

                    // Also assign to other's prev/next walls (and their backsides)...
                    var otherprev = walls[other.NextWallIndex];
                    otherprev.Start = other.End;
                    if (otherprev.OtherWallIndex > -1)
                    {
                        walls[otherprev.OtherWallIndex].End = other.End;
                    }

                    var othernext = prevwalls[w.OtherWallIndex];
                    othernext.End = other.Start;
                    if (othernext.OtherWallIndex > -1)
                    {
                        walls[othernext.OtherWallIndex].Start = other.Start;
                    }
                }
            }

            // Integrity checks...
            for (int i = 0; i < walls.Count; i++)
            {
                var w = walls[i];

                // Check verts existance
                if (w.Start == null)
                {
                    throw new InvalidDataException("Wall is missing start vertex!");
                }
                if (w.End == null)
                {
                    throw new InvalidDataException("Wall is missing end vertex!");
                }

                // Check length
                if (w.Start.Position == w.End.Position)
                {
                    // Find the wall connected to this one...
                    foreach (BuildWall o in walls)
                    {
                        // Re-connect it to the next one...
                        if (o != null && o.NextWallIndex == i)
                        {
                            o.NextWallIndex = w.NextWallIndex;
                            break;
                        }
                    }

                    // Remove without altering the array size...
                    walls[i] = null;

                    // Log warning
                    General.ErrorLogger.Add(ErrorType.Warning, "Zero-length wall " + i + " was removed.");
                }
            }
        }