void IMyStorageDataProvider.WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(m_state.Version);
     stream.WriteNoAlloc(m_state.Generator);
     stream.WriteNoAlloc(m_state.Seed);
     stream.WriteNoAlloc(m_state.Size);
 }
Example #2
0
 public void WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(this.m_data.Version);
     stream.WriteNoAlloc(this.m_data.Seed);
     stream.WriteNoAlloc(this.m_data.Radius);
     stream.WriteNoAlloc(this.Generator.Id.SubtypeName, null);
 }
 public void WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(Seed);
     stream.WriteNoAlloc(Radius);
     stream.WriteNoAlloc(DeviationScale);
     stream.WriteNoAlloc(AveragePlanetRadius);
 }
 public void WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(Seed);
     stream.WriteNoAlloc(Radius);
     stream.WriteNoAlloc(DeviationScale);
     stream.WriteNoAlloc(AveragePlanetRadius);
 }
 public void WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(BlendTreshold);
     stream.WriteNoAlloc(Treshold);
     stream.WriteNoAlloc(SizeRatio);
     stream.WriteNoAlloc(NumNoises);
     stream.WriteNoAlloc(Frequency);
 }
Example #6
0
 internal void WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(m_treeHeight);
     stream.WriteNoAlloc(m_defaultContent);
     foreach (var entry in m_nodes)
     {
         stream.WriteNoAlloc(entry.Key);
         var node = entry.Value;
         stream.WriteNoAlloc(node.ChildMask);
         unsafe { stream.WriteNoAlloc(node.Data, 0, MyOctreeNode.CHILD_COUNT); }
     }
 }
Example #7
0
 internal unsafe void WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(this.m_treeHeight);
     stream.WriteNoAlloc(this.m_defaultContent);
     foreach (KeyValuePair <uint, MyOctreeNode> pair in this.m_nodes)
     {
         stream.WriteNoAlloc(pair.Key);
         MyOctreeNode node = pair.Value;
         stream.WriteNoAlloc(node.ChildMask);
         stream.WriteNoAlloc(&node.Data.FixedElementField, 0, 8);
     }
 }
Example #8
0
        private void WriteStorageMetaData(Stream stream)
        {
            new ChunkHeader()
            {
                ChunkType = ChunkTypeEnum.StorageMetaData,
                Version   = 1,
                Size      = sizeof(Int32) * 4 + 1,
            }.WriteTo(stream);

            stream.WriteNoAlloc(LeafLodCount);
            stream.WriteNoAlloc(Size.X);
            stream.WriteNoAlloc(Size.Y);
            stream.WriteNoAlloc(Size.Z);
            stream.WriteNoAlloc(m_defaultMaterial);
        }
        void IMyStorageDataProvider.WriteTo(Stream stream)
        {
            stream.WriteNoAlloc(m_state.Version);
            stream.WriteNoAlloc(m_state.Generator);
            stream.WriteNoAlloc(m_state.Seed);
            stream.WriteNoAlloc(m_state.Size);
            stream.WriteNoAlloc(m_state.IsPlanet);

            if (m_state.IsPlanet == 1)
            { // DA: Try to reduce saved data for planets to just seed, as is done for normal asteroids.
                m_materialAttributes.WriteTo(stream);
                m_shapeAttributes.WriteTo(stream);
                m_hillAttributes.WriteTo(stream);
                m_canyonAttributes.WriteTo(stream);
            }
        }
Example #10
0
        private static unsafe void WriteOctreeNodes(Stream stream, ChunkTypeEnum type, Dictionary <UInt64, MyOctreeNode> nodes)
        {
            new ChunkHeader()
            {
                ChunkType = type,
                Version   = CURRENT_VERSION_OCTREE_NODES,
                Size      = nodes.Count * (sizeof(UInt64) + MyOctreeNode.SERIALIZED_SIZE)
            }.WriteTo(stream);

            foreach (var entry in nodes)
            {
                stream.WriteNoAlloc(entry.Key);
                var node = entry.Value;
                stream.WriteNoAlloc(node.ChildMask);
                stream.WriteNoAlloc(node.Data, 0, MyOctreeNode.CHILD_COUNT);
            }
        }
 public void WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(Seed);
     stream.WriteNoAlloc(Radius);
     stream.WriteNoAlloc(NoiseFrequency);
     stream.WriteNoAlloc(DeviationScale);
     stream.WriteNoAlloc(NormalNoiseFrequency);
     stream.WriteNoAlloc(LayerDeviationNoiseFrequency);
     stream.WriteNoAlloc(LayerDeviationSeed);
 }
Example #12
0
        private static void WriteDataProvider(Stream stream, IMyStorageDataProvider provider)
        {
            if (provider == null)
            {
                return;
            }

            ChunkHeader header = new ChunkHeader()
            {
                ChunkType = ChunkTypeEnum.DataProvider,
                Version   = 2,
                Size      = provider.SerializedSize + sizeof(Int32),
            };

            header.WriteTo(stream);
            stream.WriteNoAlloc(m_attributesByType[provider.GetType()].ProviderTypeId);
            provider.WriteTo(stream);
        }
Example #13
0
        private static void WriteOctreeLeaves <TLeaf>(Stream stream, Dictionary <UInt64, TLeaf> leaves) where TLeaf : IMyOctreeLeafNode
        {
            foreach (var entry in leaves)
            {
                var header = new ChunkHeader()
                {
                    ChunkType = entry.Value.SerializedChunkType,
                    Size      = entry.Value.SerializedChunkSize + sizeof(UInt64), // increase chunk size by the size of key (which is inserted before it)
                    Version   = CURRENT_VERSION_OCTREE_LEAVES,
                };
                header.WriteTo(stream);

                stream.WriteNoAlloc(entry.Key);
                switch (header.ChunkType)
                {
                case ChunkTypeEnum.ContentLeafOctree:
                    (entry.Value as MyMicroOctreeLeaf).WriteTo(stream);
                    break;

                case ChunkTypeEnum.ContentLeafProvider:
                    Debug.Assert(header.Size == sizeof(UInt64), "Provider leaf should not serialize any data.");
                    break;

                case ChunkTypeEnum.MaterialLeafOctree:
                    (entry.Value as MyMicroOctreeLeaf).WriteTo(stream);
                    break;

                case ChunkTypeEnum.MaterialLeafProvider:
                    Debug.Assert(header.Size == sizeof(UInt64), "Provider leaf should not serialize any data.");
                    break;

                default:
                    throw new InvalidBranchException();
                }
            }
        }
        public void WriteTo(Stream stream)
        {
            if (OreProbabilities != null)
            {
                stream.WriteNoAlloc(OreProbabilities.Length);
                for (int i = 0; i < OreProbabilities.Length; ++i)
                {
                    stream.WriteNoAlloc(OreProbabilities[i].CummulativeProbability);
                    stream.WriteNoAlloc(OreProbabilities[i].OreName);
                }
            }
            else
            {
                stream.WriteNoAlloc((int)0);
            }

            stream.WriteNoAlloc(OreStartDepth);
            stream.WriteNoAlloc(OreEndDepth);
        }
Example #15
0
        public void WriteTo(Stream stream)
        {
            if (OreProbabilities != null)
            {
                stream.WriteNoAlloc(OreProbabilities.Length);
                for (int i = 0; i < OreProbabilities.Length; ++i)
                {
                    stream.WriteNoAlloc(OreProbabilities[i].CummulativeProbability);
                    stream.WriteNoAlloc(OreProbabilities[i].OreName);
                }
            }
            else
            {
                stream.WriteNoAlloc((int)0);
            }

            stream.WriteNoAlloc(OreStartDepth);
            stream.WriteNoAlloc(OreEndDepth);
        }
Example #16
0
 public void WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(Seed);
     stream.WriteNoAlloc(Radius);
     stream.WriteNoAlloc(NoiseFrequency);
     stream.WriteNoAlloc(DeviationScale);
     stream.WriteNoAlloc(NormalNoiseFrequency);
     stream.WriteNoAlloc(LayerDeviationNoiseFrequency);
     stream.WriteNoAlloc(LayerDeviationSeed);
 }
Example #17
0
 public void WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(BlendTreshold);
     stream.WriteNoAlloc(Treshold);
     stream.WriteNoAlloc(SizeRatio);
     stream.WriteNoAlloc(NumNoises);
     stream.WriteNoAlloc(Frequency);
 }
        public void WriteTo(Stream stream)
        {
            if (Layers != null)
            {
                stream.WriteNoAlloc(Layers.Length);
                for (int i = 0; i < Layers.Length; ++i)
                {
                    stream.WriteNoAlloc(Layers[i].StartHeight);
                    stream.WriteNoAlloc(Layers[i].EndHeight);
                    stream.WriteNoAlloc(Layers[i].StartAngle);
                    stream.WriteNoAlloc(Layers[i].EndAngle);
                    stream.WriteNoAlloc(Layers[i].HeightStartDeviation);
                    stream.WriteNoAlloc(Layers[i].AngleStartDeviation);
                    stream.WriteNoAlloc(Layers[i].HeightEndDeviation);
                    stream.WriteNoAlloc(Layers[i].AngleEndDeviation);
                    stream.WriteNoAlloc(Layers[i].MaterialDefinition.Id.SubtypeName);
                }
            }
            else
            {
                stream.WriteNoAlloc((int)0);
            }

            if (OreProbabilities != null)
            {
                stream.WriteNoAlloc(OreProbabilities.Length);
                for (int i = 0; i < OreProbabilities.Length; ++i)
                {
                    stream.WriteNoAlloc(OreProbabilities[i].CummulativeProbability);
                    stream.WriteNoAlloc(OreProbabilities[i].OreName);
                }
            }
            else
            {
                stream.WriteNoAlloc((int)0);
            }

            stream.WriteNoAlloc(OreStartDepth);
            stream.WriteNoAlloc(OreEndDepth);
        }
        void IMyStorageDataProvider.WriteTo(Stream stream)
        {
            stream.WriteNoAlloc(m_state.Version);
            stream.WriteNoAlloc(m_state.Generator);
            stream.WriteNoAlloc(m_state.Seed);
            stream.WriteNoAlloc(m_state.Size);
            stream.WriteNoAlloc(m_state.IsPlanet);

            if (m_state.IsPlanet == 1)
            { // DA: Try to reduce saved data for planets to just seed, as is done for normal asteroids.
                if (m_materialLayers != null)
                {
                    stream.WriteNoAlloc(m_materialLayers.Length);
                    for (int i = 0; i < m_materialLayers.Length; ++i)
                    {
                        stream.WriteNoAlloc(m_materialLayers[i].StartHeight);
                        stream.WriteNoAlloc(m_materialLayers[i].EndHeight);
                        stream.WriteNoAlloc(m_materialLayers[i].MaterialName);
                        stream.WriteNoAlloc(m_materialLayers[i].StartAngle);
                        stream.WriteNoAlloc(m_materialLayers[i].EndAngle);
                        stream.WriteNoAlloc(m_materialLayers[i].HeightStartDeviation);
                        stream.WriteNoAlloc(m_materialLayers[i].AngleStartDeviation);
                        stream.WriteNoAlloc(m_materialLayers[i].HeightEndDeviation);
                        stream.WriteNoAlloc(m_materialLayers[i].AngleEndDeviation);
                    }
                }
                else
                {
                    stream.WriteNoAlloc((int)0);
                }

                stream.WriteNoAlloc(m_shapeAttributes.Seed);
                stream.WriteNoAlloc(m_shapeAttributes.Radius);
                stream.WriteNoAlloc(m_shapeAttributes.NoiseFrequency);
                stream.WriteNoAlloc(m_shapeAttributes.DeviationScale);
                stream.WriteNoAlloc(m_shapeAttributes.NormalNoiseFrequency);
                stream.WriteNoAlloc(m_shapeAttributes.LayerDeviationNoiseFreqeuncy);
                stream.WriteNoAlloc(m_shapeAttributes.LayerDeviationSeed);

                stream.WriteNoAlloc(m_hillAttributes.BlendTreshold);
                stream.WriteNoAlloc(m_hillAttributes.Treshold);
                stream.WriteNoAlloc(m_hillAttributes.SizeRatio);
                stream.WriteNoAlloc(m_hillAttributes.NumNoises);
                stream.WriteNoAlloc(m_hillAttributes.Frequency);

                stream.WriteNoAlloc(m_canyonAttributes.BlendTreshold);
                stream.WriteNoAlloc(m_canyonAttributes.Treshold);
                stream.WriteNoAlloc(m_canyonAttributes.SizeRatio);
                stream.WriteNoAlloc(m_canyonAttributes.NumNoises);
                stream.WriteNoAlloc(m_canyonAttributes.Frequency);
            }
        }
        protected override void SaveInternal(Stream stream)
        {
            //  Size of this voxel map (in voxels)
            stream.WriteNoAlloc(Size.X);
            stream.WriteNoAlloc(Size.Y);
            stream.WriteNoAlloc(Size.Z);

            //  Size of data cell in voxels, doesn't have to be same as current size specified by our constants.
            stream.WriteNoAlloc(MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS);
            stream.WriteNoAlloc(MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS);
            stream.WriteNoAlloc(MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS);

            Vector3I cellCoord;
            for (cellCoord.X = 0; cellCoord.X < DataCellsCount.X; cellCoord.X++)
            {
                for (cellCoord.Y = 0; cellCoord.Y < DataCellsCount.Y; cellCoord.Y++)
                {
                    for (cellCoord.Z = 0; cellCoord.Z < DataCellsCount.Z; cellCoord.Z++)
                    {
                        MyVoxelContentCell voxelCell = GetContentCell(ref cellCoord);
                        if (voxelCell == null)
                        {
                            stream.WriteNoAlloc((byte)MyVoxelRangeType.FULL);
                        }
                        else
                        {
                            stream.WriteNoAlloc((byte)voxelCell.CellType);

                            //  If we are here, cell is empty or mixed. If empty, we don't need to save each individual voxel.
                            //  But if it is mixed, we will do it here.
                            if (voxelCell.CellType == MyVoxelRangeType.MIXED)
                            {
                                Vector3I voxelCoordInCell;
                                for (voxelCoordInCell.X = 0; voxelCoordInCell.X < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.X++)
                                {
                                    for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Y++)
                                    {
                                        for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Z++)
                                        {
                                            stream.WriteNoAlloc(voxelCell.GetContent(ref voxelCoordInCell));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Save material cells
            for (cellCoord.X = 0; cellCoord.X < DataCellsCount.X; cellCoord.X++)
            {
                for (cellCoord.Y = 0; cellCoord.Y < DataCellsCount.Y; cellCoord.Y++)
                {
                    for (cellCoord.Z = 0; cellCoord.Z < DataCellsCount.Z; cellCoord.Z++)
                    {
                        var matCell = GetMaterialCell(ref cellCoord);

                        Vector3I voxelCoordInCell = new Vector3I(0, 0, 0);

                        bool isWholeMaterial = matCell.IsSingleMaterial;
                        stream.WriteNoAlloc((byte)(isWholeMaterial ? 1 : 0));
                        if (isWholeMaterial)
                        {
                            var cellMaterial = matCell.GetMaterial(ref voxelCoordInCell);
                            SaveVoxelMaterial(stream, cellMaterial);
                        }
                        else
                        {
                            const byte INDESTRUCTIBLE_CONTENT = 0;
                            for (voxelCoordInCell.X = 0; voxelCoordInCell.X < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.X++)
                            {
                                for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Y++)
                                {
                                    for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Z++)
                                    {
                                        var cellMaterial = matCell.GetMaterial(ref voxelCoordInCell);
                                        SaveVoxelMaterial(stream, cellMaterial);
                                        stream.WriteNoAlloc(INDESTRUCTIBLE_CONTENT);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        void IMyStorageDataProvider.WriteTo(Stream stream)
        {
            stream.WriteNoAlloc(m_state.Version);
            stream.WriteNoAlloc(m_state.Generator);
            stream.WriteNoAlloc(m_state.Seed);
            stream.WriteNoAlloc(m_state.Size);
            stream.WriteNoAlloc(m_state.IsPlanet);

            if (m_state.IsPlanet == 1)
            { // DA: Try to reduce saved data for planets to just seed, as is done for normal asteroids.

                m_materialAttributes.WriteTo(stream);
                m_shapeAttributes.WriteTo(stream);
                m_hillAttributes.WriteTo(stream);
                m_canyonAttributes.WriteTo(stream);          
            }
        }
 void IMyStorageDataProvider.WriteTo(Stream stream)
 {
     stream.WriteNoAlloc(m_state.Version);
     stream.WriteNoAlloc(m_state.Generator);
     stream.WriteNoAlloc(m_state.Seed);
     stream.WriteNoAlloc(m_state.Size);
     stream.WriteNoAlloc(m_state.UnusedCompat);
 }
        private void SaveVoxelMaterial(Stream stream, MyVoxelMaterialDefinition cellMaterial)
        {
            var encoding = Encoding.UTF8;

            // Old file format stored material index as byte. Replaces old index with 0xFF, followed by number of bytes for name and then name itself.
            // Names are limited to 256 bytes of UTF8 text.
            //compressFile.Add((byte)cellMaterial.Index);
            int byteLength = encoding.GetByteCount(cellMaterial.Id.SubtypeName);
            Trace.Assert(0 < byteLength && byteLength < MAX_ENCODED_NAME_LENGTH, "Length of encoded voxel material name must fit inside single byte.");
            int written = encoding.GetBytes(cellMaterial.Id.SubtypeName, 0, cellMaterial.Id.SubtypeName.Length, m_encodedNameBuffer, 0);
            Debug.Assert(written == byteLength);

            stream.WriteNoAlloc((byte)0xFF); // special value replacing old index.
            stream.WriteNoAlloc((byte)byteLength);
            stream.Write(m_encodedNameBuffer, 0, byteLength);
        }
Example #24
0
 public static unsafe void WriteNoAlloc(this Stream stream, decimal v)
 {
     stream.WriteNoAlloc((byte *)&v, 0, sizeof(decimal));
 }
Example #25
0
 public static unsafe void WriteNoAlloc(this Stream stream, double v)
 {
     stream.WriteNoAlloc((byte *)&v, 0, sizeof(double));
 }
Example #26
0
 public static unsafe void WriteNoAlloc(this Stream stream, float v)
 {
     stream.WriteNoAlloc((byte *)&v, 0, sizeof(float));
 }
Example #27
0
 public static unsafe void WriteNoAlloc(this Stream stream, UInt64 v)
 {
     stream.WriteNoAlloc((byte *)&v, 0, sizeof(UInt64));
 }
Example #28
0
        public void WriteTo(Stream stream)
        {
            if (Layers != null)
            {
                stream.WriteNoAlloc(Layers.Length);
                for (int i = 0; i < Layers.Length; ++i)
                {
                    stream.WriteNoAlloc(Layers[i].StartHeight);
                    stream.WriteNoAlloc(Layers[i].EndHeight);
                    stream.WriteNoAlloc(Layers[i].StartAngle);
                    stream.WriteNoAlloc(Layers[i].EndAngle);
                    stream.WriteNoAlloc(Layers[i].HeightStartDeviation);
                    stream.WriteNoAlloc(Layers[i].AngleStartDeviation);
                    stream.WriteNoAlloc(Layers[i].HeightEndDeviation);
                    stream.WriteNoAlloc(Layers[i].AngleEndDeviation);
                    stream.WriteNoAlloc(Layers[i].MaterialDefinition.Id.SubtypeName);
                }
            }
            else
            {
                stream.WriteNoAlloc((int)0);
            }

            if (OreProbabilities != null)
            {
                stream.WriteNoAlloc(OreProbabilities.Length);
                for (int i = 0; i < OreProbabilities.Length; ++i)
                {
                    stream.WriteNoAlloc(OreProbabilities[i].CummulativeProbability);
                    stream.WriteNoAlloc(OreProbabilities[i].OreName);
                }
            }
            else
            {
                stream.WriteNoAlloc((int)0);
            }

            stream.WriteNoAlloc(OreStartDepth);
            stream.WriteNoAlloc(OreEndDepth);
        }
        void IMyStorageDataProvider.WriteTo(Stream stream)
        {
            stream.WriteNoAlloc(m_state.Version);
            stream.WriteNoAlloc(m_state.Generator);
            stream.WriteNoAlloc(m_state.Seed);
            stream.WriteNoAlloc(m_state.Size);
            stream.WriteNoAlloc(m_state.IsPlanet);

            if (m_state.IsPlanet == 1)
            { // DA: Try to reduce saved data for planets to just seed, as is done for normal asteroids.
                if (m_materialLayers != null)
                {
                    stream.WriteNoAlloc(m_materialLayers.Length);
                    for (int i = 0; i < m_materialLayers.Length; ++i)
                    {
                        stream.WriteNoAlloc(m_materialLayers[i].StartHeight);
                        stream.WriteNoAlloc(m_materialLayers[i].EndHeight);
                        stream.WriteNoAlloc(m_materialLayers[i].MaterialName);
                        stream.WriteNoAlloc(m_materialLayers[i].StartAngle);
                        stream.WriteNoAlloc(m_materialLayers[i].EndAngle);
                        stream.WriteNoAlloc(m_materialLayers[i].HeightStartDeviation);
                        stream.WriteNoAlloc(m_materialLayers[i].AngleStartDeviation);
                        stream.WriteNoAlloc(m_materialLayers[i].HeightEndDeviation);
                        stream.WriteNoAlloc(m_materialLayers[i].AngleEndDeviation);
                    }
                }
                else
                {
                    stream.WriteNoAlloc((int)0);
                }

                stream.WriteNoAlloc(m_shapeAttributes.Seed);
                stream.WriteNoAlloc(m_shapeAttributes.Radius);
                stream.WriteNoAlloc(m_shapeAttributes.NoiseFrequency);
                stream.WriteNoAlloc(m_shapeAttributes.DeviationScale);
                stream.WriteNoAlloc(m_shapeAttributes.NormalNoiseFrequency);
                stream.WriteNoAlloc(m_shapeAttributes.LayerDeviationNoiseFreqeuncy);
                stream.WriteNoAlloc(m_shapeAttributes.LayerDeviationSeed);

                stream.WriteNoAlloc(m_hillAttributes.BlendTreshold);
                stream.WriteNoAlloc(m_hillAttributes.Treshold);
                stream.WriteNoAlloc(m_hillAttributes.SizeRatio);
                stream.WriteNoAlloc(m_hillAttributes.NumNoises);
                stream.WriteNoAlloc(m_hillAttributes.Frequency);

                stream.WriteNoAlloc(m_canyonAttributes.BlendTreshold);
                stream.WriteNoAlloc(m_canyonAttributes.Treshold);
                stream.WriteNoAlloc(m_canyonAttributes.SizeRatio);
                stream.WriteNoAlloc(m_canyonAttributes.NumNoises);
                stream.WriteNoAlloc(m_canyonAttributes.Frequency);
            }
        }
Example #30
0
 public static unsafe void WriteNoAlloc(this Stream stream, Int32 v)
 {
     stream.WriteNoAlloc((byte *)&v, 0, sizeof(Int32));
 }