コード例 #1
0
ファイル: DukeMapSetIO.cs プロジェクト: Kizoky/Duke-Builder
        private List <BuildSprite> ReadSprites(BinaryReader reader)
        {
            // Read sprites count
            int num = reader.ReadUInt16();

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

            // Read sprites
            for (int i = 0; i < num; i++)
            {
                // Read properties from stream
                BuildSprite s = new BuildSprite();

                s.X = reader.ReadInt32();
                s.Y = -reader.ReadInt32();                 // Transform to match DB2 coords...
                s.Z = GetEditorHeight(reader.ReadInt32()); // Transform to match DB2 model/XY map units

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

                s.TileIndex    = reader.ReadInt16();
                s.Shade        = reader.ReadSByte();
                s.PaletteIndex = reader.ReadByte();
                s.ClipDistance = reader.ReadByte();

                reader.BaseStream.Position += 1;                 // Skip filler byte

                s.RepeatX = reader.ReadByte();
                s.RepeatY = reader.ReadByte();
                s.OffsetX = reader.ReadByte();
                s.OffsetY = reader.ReadByte();

                s.SectorIndex = reader.ReadInt16();
                s.Status      = reader.ReadInt16();
                s.Angle       = reader.ReadInt16();           // Stored in radians!
                s.Owner       = reader.ReadInt16();

                s.VelX = reader.ReadInt16();
                s.VelY = reader.ReadInt16();
                s.VelZ = reader.ReadInt16();

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

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

            return(result);
        }
コード例 #2
0
        private static void ReadSprites(MapSet map, BinaryReader reader)
        {
            int count = reader.ReadInt32();

            // Go for all sprites
            map.SetCapacity(0, 0, 0, 0, map.Things.Count + count);
            for (int i = 0; i < count; i++)
            {
                BuildSprite bs = new BuildSprite();

                // Read Build properties
                bs.X = reader.ReadInt32();
                bs.Y = reader.ReadInt32();
                bs.Z = reader.ReadInt32();

                bs.TileIndex    = reader.ReadInt32();
                bs.Shade        = reader.ReadInt32();
                bs.PaletteIndex = reader.ReadInt32();
                bs.ClipDistance = reader.ReadInt32();
                bs.RepeatX      = reader.ReadInt32();
                bs.RepeatY      = reader.ReadInt32();
                bs.OffsetX      = reader.ReadInt32();
                bs.OffsetY      = reader.ReadInt32();
                bs.Angle        = reader.ReadInt32();

                bs.Owner = reader.ReadInt32();
                bs.VelX  = reader.ReadInt32();
                bs.VelY  = reader.ReadInt32();
                bs.VelZ  = reader.ReadInt32();

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

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

                // Create new item
                Thing t = map.CreateThing();
                if (t != null)
                {
                    t.Update(bs);
                }
            }
        }
コード例 #3
0
ファイル: DukeMapSetIO.cs プロジェクト: Kizoky/Duke-Builder
        public override void Read(MapSet map, Stream mapdata)
        {
            using (BinaryReader reader = new BinaryReader(mapdata))
            {
                // Read version
                int version = reader.ReadInt32();
                if (version != Version)
                {
                    throw new NotSupportedException("Unsupported map format version: expected " + Version + ", got " + version);
                }

                // Read player start position
                var playersprite = new BuildSprite();
                playersprite.X = reader.ReadInt32();
                playersprite.Y = -reader.ReadInt32();                 // Transform to match DB2 coords...
                playersprite.Z = GetEditorHeight(reader.ReadInt32()); // Transform to match DB2 model/XY map units

                if (playersprite.X < MinCoordinate || playersprite.X > MaxCoordinate ||
                    playersprite.Y < MinCoordinate || playersprite.Y > MaxCoordinate ||
                    playersprite.Z < MinCoordinate || playersprite.Z > MaxCoordinate)
                {
                    throw new NotSupportedException("Invalid player start position: " + playersprite.X + " " + playersprite.Y + " " + playersprite.Z);
                }

                // Read player angle
                playersprite.Angle = reader.ReadUInt16();
                if (playersprite.Angle < MinSpriteAngle || playersprite.Angle > MaxSpriteAngle)
                {
                    throw new NotSupportedException("Invalid player start angle: " + playersprite.Angle);
                }

                // Read player start sector
                playersprite.SectorIndex = reader.ReadUInt16();

                // Set player tile index
                playersprite.TileIndex = General.Map.Config.PlayerStartTileIndex;

                // Read sectors
                List <BuildSector> buildsectors = ReadSectors(reader);

                // Read walls
                List <BuildWall> buildwalls = ReadWalls(reader);

                // Add player start, because I REALLY don't want to manage it separately...
                List <BuildSprite> buildsprites = new List <BuildSprite> {
                    playersprite
                };
                // Read sprites
                buildsprites.AddRange(ReadSprites(reader));

                // Create vertices
                CreateVertices(map, buildwalls);

                // Create sectors
                CreateSectors(map, buildsectors);

                // Create lines and walls
                CreateWalls(map, buildwalls, buildsectors);

                // Create sprites
                CreateSprites(map, buildsprites, buildsectors);
            }
        }