コード例 #1
0
ファイル: ZoneGrid.cs プロジェクト: pallmall/WCell
        private static MH2O ProcessMH2O(BinaryReader fileReader, MH2OHeader header, long waterSegmentBase)
        {
            var water = new MH2O();

            if (header.LayerCount == 0)
            {
                water.Used = false;
                return water;
            }

            water.Used = true;

            fileReader.BaseStream.Position = waterSegmentBase + header.ofsData1;

            water.Flags = (MH2OFlags)fileReader.ReadUInt16();
            
            water.Type = (FluidType)fileReader.ReadUInt16();
            water.HeightLevel1 = fileReader.ReadSingle();
            water.HeightLevel2 = fileReader.ReadSingle();
            water.XOffset = fileReader.ReadByte();
            water.YOffset = fileReader.ReadByte();
            water.Width = fileReader.ReadByte();
            water.Height = fileReader.ReadByte();

            var ofsWaterFlags = fileReader.ReadUInt32();
            var ofsWaterHeightMap = fileReader.ReadUInt32();

            var heightMapLen = (water.Width + 1) * (water.Height + 1);
            var heights = new float[heightMapLen];

            // If flags is 2, the chunk is for an ocean, and there is no heightmap
            if (ofsWaterHeightMap != 0 && (water.Flags & MH2OFlags.Ocean) == 0)
            {
                fileReader.BaseStream.Position = waterSegmentBase + ofsWaterHeightMap;
                
                for (var i = 0; i < heightMapLen; i++)
                {
                    heights[i] = fileReader.ReadSingle();
                    if (heights[i] == 0)
                    {
                        heights[i] = water.HeightLevel1;
                    }
                }
                
            }
            else
            {
                for (var i = 0; i < heightMapLen; i++)
                {
                    heights[i] = water.HeightLevel1;
                }
            }

            water.Heights = new float[water.Height + 1, water.Width + 1];
            for (var r = 0; r <= water.Height; r++)
            {
                for (var c = 0; c <= water.Width; c++)
                {

                    water.Heights[r, c] = heights[c + r * c];
                }
            }

            return water;
        }
コード例 #2
0
        private static MH2O ProcessMH2O(BinaryReader fileReader, MH2OHeader header, long waterSegmentBase)
        {
            var water = new MH2O();

            if (header.LayerCount == 0)
            {
                water.Used = false;
                return(water);
            }

            water.Used = true;

            fileReader.BaseStream.Position = waterSegmentBase + header.ofsData1;

            water.Flags = (MH2OFlags)fileReader.ReadUInt16();

            water.Type         = (FluidType)fileReader.ReadUInt16();
            water.HeightLevel1 = fileReader.ReadSingle();
            water.HeightLevel2 = fileReader.ReadSingle();
            water.XOffset      = fileReader.ReadByte();
            water.YOffset      = fileReader.ReadByte();
            water.Width        = fileReader.ReadByte();
            water.Height       = fileReader.ReadByte();

            var ofsWaterFlags     = fileReader.ReadUInt32();
            var ofsWaterHeightMap = fileReader.ReadUInt32();

            var heightMapLen = (water.Width + 1) * (water.Height + 1);
            var heights      = new float[heightMapLen];

            // If flags is 2, the chunk is for an ocean, and there is no heightmap
            if (ofsWaterHeightMap != 0 && (water.Flags & MH2OFlags.Ocean) == 0)
            {
                fileReader.BaseStream.Position = waterSegmentBase + ofsWaterHeightMap;

                for (var i = 0; i < heightMapLen; i++)
                {
                    heights[i] = fileReader.ReadSingle();
                    if (heights[i] == 0)
                    {
                        heights[i] = water.HeightLevel1;
                    }
                }
            }
            else
            {
                for (var i = 0; i < heightMapLen; i++)
                {
                    heights[i] = water.HeightLevel1;
                }
            }

            water.Heights = new float[water.Height + 1, water.Width + 1];
            for (var r = 0; r <= water.Height; r++)
            {
                for (var c = 0; c <= water.Width; c++)
                {
                    water.Heights[r, c] = heights[c + r * c];
                }
            }

            return(water);
        }