Beispiel #1
0
        private static Dictionary <int, BuildWall> ReadWalls(BinaryReader reader)
        {
            var sidedeflink = new Dictionary <int, BuildWall>();
            int count       = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                BuildWall bw = new BuildWall();

                // Read Build proeprties
                bw.OffsetX         = reader.ReadInt32();
                bw.OffsetY         = reader.ReadInt32();
                bw.RepeatX         = reader.ReadInt32();
                bw.RepeatY         = reader.ReadInt32();
                bw.TileIndex       = reader.ReadInt32();
                bw.MaskedTileIndex = reader.ReadInt32();
                bw.Shade           = reader.ReadInt32();
                bw.PaletteIndex    = reader.ReadInt32();

                bw.HiTag = reader.ReadInt32();
                bw.LoTag = reader.ReadInt32();
                bw.Extra = reader.ReadInt32();

                // Read internal properties
                bw.SectorID = reader.ReadInt32();

                // Read flags
                bw.Flags = ReadFlags(reader, General.Map.Config.WallFlags.Keys);

                // Add to the lookup table
                sidedeflink.Add(i, bw);
            }

            return(sidedeflink);
        }
Beispiel #2
0
        private List <BuildWall> ReadWalls(BinaryReader reader)
        {
            // Read walls count
            int num = reader.ReadUInt16();

            // Prepare collection
            var result = new List <BuildWall>(num);

            // Read walls
            for (int i = 0; i < num; i++)
            {
                // Read properties from stream
                BuildWall w = new BuildWall();

                // Start vertex
                w.StartX = reader.ReadInt32();
                w.StartY = -reader.ReadInt32();                 // Transform to match DB2 coords...

                w.NextWallIndex    = reader.ReadInt16();
                w.OtherWallIndex   = reader.ReadInt16();
                w.OtherSectorIndex = reader.ReadInt16();

                // Make string flags
                int cstat = reader.ReadUInt16();
                foreach (int flag in manager.Config.SortedWallFlags)
                {
                    w.Flags[flag.ToString()] = ((cstat & flag) == flag);
                }

                w.TileIndex       = reader.ReadInt16();
                w.MaskedTileIndex = reader.ReadInt16();
                w.Shade           = reader.ReadSByte();
                w.PaletteIndex    = reader.ReadByte();
                w.RepeatX         = reader.ReadByte();
                w.RepeatY         = reader.ReadByte();
                w.OffsetX         = reader.ReadByte();
                w.OffsetY         = reader.ReadByte();

                w.LoTag = reader.ReadInt16();
                w.HiTag = reader.ReadInt16();
                w.Extra = reader.ReadInt16();

                // Add to collection
                result.Add(w);
            }

            return(result);
        }
Beispiel #3
0
 private static void AddWall(MapSet map, BuildWall data, Linedef ld, bool front, Dictionary <int, BuildSector> sectorlink)
 {
     // Create sidedef
     if (sectorlink.ContainsKey(data.SectorID))
     {
         Sidedef s = map.CreateSidedef(ld, front, sectorlink[data.SectorID].Sector);
         if (s != null)
         {
             s.Update(data);
         }
     }
     else
     {
         General.ErrorLogger.Add(ErrorType.Warning, "Wall references invalid sector " + data.SectorID + ". Wall has been removed.");
     }
 }
Beispiel #4
0
        public override void Write(MapSet map, Stream mapdata)
        {
            // Make collections
            var buildwallids = new Dictionary <int, BuildWall>(map.Sidedefs.Count);
            var wallids      = new Dictionary <Sidedef, int>(map.Sidedefs.Count);
            var sectorids    = new Dictionary <Sector, int>(map.Sectors.Count);

            // Walls must be stored on per-sector basis...
            foreach (Sector s in map.Sectors)
            {
                if (s.Sidedefs == null || s.Sidedefs.Count < 3)
                {
                    continue;
                }

                var sectorsidelists = Tools.GetSortedSectorSides(s);
                if (sectorsidelists.Count == 0)
                {
                    continue;
                }

                foreach (List <Sidedef> sideslist in sectorsidelists)
                {
                    // Add to lookup table
                    for (int i = 0; i < sideslist.Count; i++)
                    {
                        wallids.Add(sideslist[i], wallids.Count);
                    }

                    // Create BuildWalls
                    for (int i = 0; i < sideslist.Count; i++)
                    {
                        var bw   = new BuildWall(sideslist[i]);
                        int next = (i < sideslist.Count - 1 ? i + 1 : 0);                         // Connect last wall to the first one
                        bw.NextWallIndex = wallids[sideslist[next]];
                        bw.Side          = sideslist[i];
                        buildwallids.Add(buildwallids.Count, bw);
                    }
                }

                sectorids.Add(s, sectorids.Count);
            }

            // Fill in OtherWallIndex and OtherSectorIndex
            foreach (var group in wallids)
            {
                if (group.Key.Other != null)
                {
                    buildwallids[group.Value].OtherWallIndex   = wallids[group.Key.Other];
                    buildwallids[group.Value].OtherSectorIndex = sectorids[group.Key.Other.Sector];
                }
            }

            // Write map structures
            using (BinaryWriter writer = new BinaryWriter(mapdata))
            {
                // Write map header
                writer.Write(Version);

                // First sprite must be player start
                Thing playerstart = map.GetThingByIndex(0);

                //TODO: check this BEFORE saving the map!
                if (playerstart == null)
                {
                    throw new InvalidDataException("Map has no Player start!");
                }
                if (playerstart.Sector == null || playerstart.Sector.IsDisposed)
                {
                    playerstart.DetermineSector();
                }
                if (playerstart.Sector == null)
                {
                    throw new InvalidDataException("Player start must be inside a sector!");
                }

                // Write player start point
                writer.Write((int)playerstart.Position.x);
                writer.Write((int)-playerstart.Position.y);                 // Transform to match Build coords...
                writer.Write(GetBuildHeight((int)playerstart.Position.z));  // Transform to match Build coords...

                // Write player starting angle
                writer.Write((ushort)Angle2D.RadToBuild(playerstart.Angle));

                // Write sector number containing the start point
                writer.Write((ushort)sectorids[playerstart.Sector]);

                // Write sectors
                WriteSectors(writer, sectorids.Keys);

                // Write walls
                WriteWalls(writer, buildwallids.Values);

                // Write sprites
                WriteSprites(writer, map.Things, sectorids);
            }
        }
Beispiel #5
0
        private static void CreateWalls(MapSet map, List <BuildWall> walls, List <BuildSector> sectors)
        {
            // Count how many lines and walls we will actually create...
            int numwalls            = walls.Count;
            int numdoublesidedwalls = 0;

            foreach (BuildWall w in walls)
            {
                if (w == null)
                {
                    numwalls--;
                }
                else if (w.OtherWallIndex > -1)
                {
                    numdoublesidedwalls++;
                }
            }

            int numlines = numwalls - (numdoublesidedwalls / 2);

            // Walls are stored per-sector
            map.SetCapacity(0, map.Linedefs.Count + numlines, map.Sidedefs.Count + numwalls, 0, 0);
            Dictionary <int, Linedef> newlines = new Dictionary <int, Linedef>();           // <wall index, line>

            int walloffset = 0;

            foreach (BuildSector bs in sectors)
            {
                for (int i = walloffset; i < walloffset + bs.WallsCount; i++)
                {
                    BuildWall w = walls[i];
                    if (w == null)
                    {
                        continue;
                    }

                    // Line already created?
                    if (w.OtherWallIndex > -1 && newlines.ContainsKey(w.OtherWallIndex))
                    {
                        // Add back side
                        Sidedef back = map.CreateSidedef(newlines[w.OtherWallIndex], false, bs.Sector);
                        back.Update(w);
                        w.Side = back;
                    }
                    else
                    {
                        // Create line
                        Linedef l = map.CreateLinedef(w.Start, w.End);
                        l.Update();
                        l.UpdateCache();

                        // Add front side
                        Sidedef front = map.CreateSidedef(l, true, bs.Sector);
                        front.Update(w);
                        w.Side = front;

                        // Add to collection
                        newlines[i] = l;
                    }
                }

                walloffset += bs.WallsCount;
            }

            // Set Sector FirstWalls
            for (int i = 0; i < sectors.Count; i++)
            {
                int wallindex = sectors[i].FirstWallIndex;
                if (wallindex < 0 || wallindex >= walls.Count)
                {
                    General.ErrorLogger.Add(ErrorType.Error, "Failed to set First Wall " + wallindex + " of sector " + i + ": corresponding wall does not exist!");
                }
                else
                {
                    sectors[i].Sector.FirstWall = walls[wallindex].Side;
                }
            }
        }