Esempio n. 1
0
            /// <summary>
            /// Load sky texture
            /// </summary>
            /// <param name="stream">The <see cref="FileStream"/></param>
            /// <returns>Sky texture</returns>
            private static Bitmap LoadSky(FileStream stream)
            {
                Powerslave.Skybox skyData = Powerslave.LoadStruct <Powerslave.Skybox>(stream);
                List <Color>      pallet  = skyData.Pallet.Select(rgb => Color.FromArgb((byte)(((rgb >> 0) & 31) * 8), (byte)(((rgb >> 5) & 31) * 8), (byte)((rgb >> 10 & 31) * 8))).ToList();

                Bitmap sky = new Bitmap((byte.MaxValue + 1) * 2, byte.MaxValue + 1);

                for (int y = 0; y < sky.Height; y++)
                {
                    for (int x = 0; x < sky.Width; x++)
                    {
                        sky.SetPixel(x, y, pallet[skyData.Bitmap[(y * sky.Width) + x]]);
                    }
                }

                // Bitmaps are flipped over Y axis
                sky.RotateFlip(RotateFlipType.RotateNoneFlipY);
                return(sky);
            }
Esempio n. 2
0
            /// <summary>
            /// Load map data
            /// </summary>
            /// <param name="file">Path to the file</param>
            /// <returns>Loaded <see cref="Map"/></returns>
            public static Map Load(string file)
            {
                Exception loadingException = null;
                Map       map = new Map {
                    FileName = file
                };

                using (FileStream stream = File.OpenRead(file))
                {
                    try
                    {
                        // Load sky texture first
                        map.Sky = Map.LoadSky(stream);

                        // Load map header (skip 1292 bytes of unknown/empty space)
                        stream.Position = 0x2070C;
                        Powerslave.FileHeader header = Powerslave.LoadStruct <Powerslave.FileHeader>(stream);

                        // Load map data
                        map.Sectors  = Map.CreateSequence(() => Powerslave.LoadStruct <Powerslave.Sector>(stream), header.SectorCount).ToList();
                        map.Planes   = Map.CreateSequence(() => Powerslave.LoadStruct <Powerslave.Plane>(stream), header.PlaneCount).ToList();
                        map.Vertices = Map.CreateSequence(() => Powerslave.LoadStruct <Powerslave.Vertex>(stream), header.VertexCount).ToList();
                        map.Quads    = Map.CreateSequence(() => Powerslave.LoadStruct <Powerslave.Quad>(stream), header.QuadCount).ToList();
                    }
                    catch (Exception ex)
                    {
                        loadingException = ex;

                        if (map.Sky != null)
                        {
                            map.Sky.Dispose();
                        }
                    }
                }

                if (loadingException != null)
                {
                    throw loadingException;
                }

                return(map);
            }