当前位置: 首页>>代码示例>>C#>>正文


C# GZipStream.Read7BitEncodedInt方法代码示例

本文整理汇总了C#中System.IO.Compression.GZipStream.Read7BitEncodedInt方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.Read7BitEncodedInt方法的具体用法?C# GZipStream.Read7BitEncodedInt怎么用?C# GZipStream.Read7BitEncodedInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Compression.GZipStream的用法示例。


在下文中一共展示了GZipStream.Read7BitEncodedInt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MergeVoxelMaterialsInternal

        //  Merges specified materials (from file) into our actual voxel map - overwriting materials only.
        //  We are using a regular voxel map to define areas where we want to set a specified material. Empty voxels are ignored and 
        //  only mixed/full voxels are used to tell us that that voxel will contain new material - 'materialToSet'.
        //  If we are seting indestructible material, voxel content values from merged voxel map will be used to define indestructible content.
        //  Parameter 'voxelPosition' - place where we will place merged voxel map withing actual voxel map. It's in voxel coords.
        //  IMPORTANT: THIS METHOD WILL WORK ONLY IF WE PLACE THE MAP THAT WE TRY TO MERGE FROM IN VOXEL COORDINATES THAT ARE MULTIPLY OF DATA CELL SIZE
        //  This method is used to load small material areas, overwriting actual material only if value from file is 1. Zeros are ignored (it's empty space).
        //  This method is quite fast, even on large maps - 512x512x512, so we can do more overwrites.
        //  Parameter 'materialToSet' tells us what material to set at places which are full in file. Empty are ignored - so stay as they were before this method was called.
        //  IMPORTANT: THIS MERGE MATERIAL CAN BE CALLED ONLY AFTER ALL VOXEL CONTENTS ARE LOADED. THAT'S BECAUSE WE NEED TO KNOW THEM FOR MIN CONTENT / INDESTRUCTIBLE CONTENT.
        //  Voxel map we are trying to merge into existing voxel map can be bigger or outside of area of existing voxel map. This method will just ignore those parts.
        // mk:TODO move to Data storage, hide behind interface and make sure this does not overwrite empty area material (in target voxel map)
        protected override void MergeVoxelMaterialsInternal(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet)
        {
            Profiler.Begin("MyVoxelMap.MergeVoxelMaterials");

            using (var fileStream = File.OpenRead(MyVoxelFiles.Get(voxelFile).GetVoxFilePath()))
            using (var gzip = new GZipStream(fileStream, CompressionMode.Decompress))
            {
                var storage = gzip.ReadString();
                Debug.Assert(storage == "Cell");

                //  Version of a VOX file
                int fileVersion = gzip.Read7BitEncodedInt();

                //  Not supported VOX file version
                Debug.Assert(fileVersion == CURRENT_FILE_VERSION);

                //  Size of this voxel map (in voxels)
                int sizeX = gzip.ReadInt32();
                int sizeY = gzip.ReadInt32();
                int sizeZ = gzip.ReadInt32();

                //  Size of data cell in voxels, doesn't have to be same as current size specified by our constants.
                int cellSizeX = gzip.ReadInt32();
                int cellSizeY = gzip.ReadInt32();
                int cellSizeZ = gzip.ReadInt32();

                int cellsCountX = sizeX / cellSizeX;
                int cellsCountY = sizeY / cellSizeY;
                int cellsCountZ = sizeZ / cellSizeZ;

                //  This method will work only if we place the map that we try to merge from in voxel coordinates that are multiply of data cell size
                Debug.Assert((voxelPosition.X & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
                Debug.Assert((voxelPosition.Y & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
                Debug.Assert((voxelPosition.Z & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
                Vector3I cellFullForVoxelPosition;
                MyCellStorage.ComputeCellCoord(ref voxelPosition, out cellFullForVoxelPosition);

                Vector3I cellCoord;
                for (cellCoord.X = 0; cellCoord.X < cellsCountX; cellCoord.X++)
                {
                    for (cellCoord.Y = 0; cellCoord.Y < cellsCountY; cellCoord.Y++)
                    {
                        for (cellCoord.Z = 0; cellCoord.Z < cellsCountZ; cellCoord.Z++)
                        {
                            MyVoxelRangeType cellType = (MyVoxelRangeType)gzip.ReadByteNoAlloc();

                            //  We can do "continue" here, becase we need to read this file properly, even if we will ignore that data
                            var tmp = new Vector3I(
                                    cellFullForVoxelPosition.X + cellCoord.X,
                                    cellFullForVoxelPosition.Y + cellCoord.Y,
                                    cellFullForVoxelPosition.Z + cellCoord.Z);
                            bool isDataCellInVoxelMap = IsValidCellCoord(ref tmp);

                            if (cellType == MyVoxelRangeType.EMPTY)
                            {
                                //  If merged cell is empty, there is nothing to overwrite, so we can skip this cell
                                continue;
                            }
                            else if (cellType == MyVoxelRangeType.FULL)
                            {
                                //  If merged cell is full, than we reset whole material cell to 'materialToSet'
                                if (isDataCellInVoxelMap)
                                {

                                    var coord = cellFullForVoxelPosition + cellCoord;
                                    ResetCellMaterial(ref coord, materialToSet);
                                }
                            }
                            else
                            {
                                //Vector3I cellCoordInVoxels = GetVoxelCoordinatesOfDataCell(ref cellCoord);
                                Vector3I cellCoordInVoxels;
                                MyCellStorage.ComputeVoxelCoordOfCell(ref cellCoord, out cellCoordInVoxels);

                                Vector3I voxelCoordRelative;
                                voxelCoordRelative.X = voxelPosition.X + cellCoordInVoxels.X;
                                voxelCoordRelative.Y = voxelPosition.Y + cellCoordInVoxels.Y;
                                voxelCoordRelative.Z = voxelPosition.Z + cellCoordInVoxels.Z;

                                Vector3I voxelCoordInCell;
                                for (voxelCoordInCell.X = 0; voxelCoordInCell.X < cellSizeX; voxelCoordInCell.X++)
                                {
                                    for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < cellSizeY; voxelCoordInCell.Y++)
                                    {
                                        for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < cellSizeZ; voxelCoordInCell.Z++)
                                        {
                                            byte voxelFromFile = gzip.ReadByteNoAlloc();

//.........这里部分代码省略.........
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:101,代码来源:MyCellStorage.cs


注:本文中的System.IO.Compression.GZipStream.Read7BitEncodedInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。