private static void Load(Stream stream, out MyStorageBase storage, out bool isOldFormat) { ProfilerShort.Begin("MyStorageBase.Load"); try { isOldFormat = false; string storageType = stream.ReadString(); int version = stream.Read7BitEncodedInt(); if (storageType == STORAGE_TYPE_NAME_CELL) { storage = Compatibility_LoadCellStorage(version, stream); isOldFormat = true; } else if (storageType == STORAGE_TYPE_NAME_OCTREE) { storage = new MyOctreeStorage(); storage.LoadInternal(version, stream, ref isOldFormat); storage.m_geometry.Init(storage); } else { throw new InvalidBranchException(); } } finally { ProfilerShort.End(); } }
public static MyStorageBase LoadFromFile(string absoluteFilePath) { const string loadingMessage = "Loading voxel storage from file '{0}'"; if (!MyFileSystem.FileExists(absoluteFilePath)) { var oldPath = Path.ChangeExtension(absoluteFilePath, "vox"); MySandboxGame.Log.WriteLine(string.Format(loadingMessage, oldPath)); UpdateFileFormat(oldPath); Debug.Assert(MyFileSystem.FileExists(absoluteFilePath)); } else { MySandboxGame.Log.WriteLine(string.Format(loadingMessage, absoluteFilePath)); } Debug.Assert(absoluteFilePath.EndsWith(MyVoxelConstants.FILE_EXTENSION)); byte[] compressedData = null; using (var file = MyFileSystem.OpenRead(absoluteFilePath)) { compressedData = new byte[file.Length]; file.Read(compressedData, 0, compressedData.Length); } MyStorageBase result = Load(compressedData); return(result); }
public static MyStorageBase Load(string name) { Debug.Assert(name != null, "Name shouldn't be null"); MyStorageBase result = null; //If there are some voxels from multiplayer, use them (because it appears that we changed to server from client) if (MyMultiplayer.Static == null || MyMultiplayer.Static.IsServer) { var filePath = Path.IsPathRooted(name) ? name : Path.Combine(MySession.Static.CurrentPath, name + MyVoxelConstants.FILE_EXTENSION); //By Gregory: Added for compatibility with old saves if (File.Exists(filePath)) { result = LoadFromFile(filePath); } } else { if (MyMultiplayer.Static.VoxelMapData.ContainsKey(name)) { result = Load(MyMultiplayer.Static.VoxelMapData[name]); } else { Debug.Fail("Missing voxel map data! : " + name); Sandbox.Engine.Networking.MyAnalyticsHelper.ReportActivityStart(null, "Missing voxel map data!", name, "DevNote", "", false); } } return(result); }
public void Init(MyStorageBase storage) { this.m_storage = storage; this.m_storage.RangeChanged += new Action <Vector3I, Vector3I, MyStorageDataTypeFlags>(this.storage_RangeChanged); Vector3I size = this.m_storage.Size; this.m_cellsCount.X = size.X >> 3; this.m_cellsCount.Y = size.Y >> 3; this.m_cellsCount.Z = size.Z >> 3; }
public void Init(MyStorageBase storage) { MyPrecalcComponent.AssertUpdateThread(); m_storage = storage; m_storage.RangeChanged += storage_RangeChanged; var size = m_storage.Size; m_cellsCount.X = size.X >> MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS_BITS; m_cellsCount.Y = size.Y >> MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS_BITS; m_cellsCount.Z = size.Z >> MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS_BITS; }
public StoragePin(MyStorageBase myStorageBase) { m_storage = myStorageBase; }
public static MyStorageBase LoadFromFile(string absoluteFilePath, byte[] materialChangeFrom = null, byte[] materialChangeTo = null) { //get hash code MyVoxelObjectDefinition definition; definition.filePath = absoluteFilePath; definition.materialChangeFrom = materialChangeFrom; definition.materialChangeTo = materialChangeTo; int sh = definition.GetHashCode(); MyStorageBase result = null; if (UseStorageCache) { result = m_storageCache.Read(sh); if (result != null) { result.Shared = true; return(result); } } const string loadingMessage = "Loading voxel storage from file '{0}'"; if (!MyFileSystem.FileExists(absoluteFilePath)) { var oldPath = Path.ChangeExtension(absoluteFilePath, "vox"); MySandboxGame.Log.WriteLine(string.Format(loadingMessage, oldPath)); UpdateFileFormat(oldPath); Debug.Assert(MyFileSystem.FileExists(absoluteFilePath)); } else { MySandboxGame.Log.WriteLine(string.Format(loadingMessage, absoluteFilePath)); } Debug.Assert(absoluteFilePath.EndsWith(MyVoxelConstants.FILE_EXTENSION)); byte[] compressedData = null; using (var file = MyFileSystem.OpenRead(absoluteFilePath)) { compressedData = new byte[file.Length]; file.Read(compressedData, 0, compressedData.Length); } result = Load(compressedData); //change materials result.ChangeMaterials(definition.materialChangeFrom, definition.materialChangeTo); if (UseStorageCache) { m_storageCache.Write(sh, result); result.Shared = true; } else { m_storageCache.Reset(); } return(result); }
public static MyVoxelMap AddVoxelMap(string storageName, MyStorageBase storage, Vector3 positionMinCorner, long entityId = 0) { var voxelMap = new MyVoxelMap(); voxelMap.EntityId = entityId; voxelMap.Init(storageName, storage, positionMinCorner); MyEntities.Add(voxelMap); return voxelMap; }
public static MyVoxelMap AddVoxelMap(string storageName, MyStorageBase storage, MatrixD worldMatrix, long entityId=0, bool lazyPhysics = false) { ProfilerShort.Begin("AddVoxelMap"); var voxelMap = new MyVoxelMap(); if (entityId != 0) { voxelMap.EntityId = entityId; } voxelMap.DelayRigidBodyCreation = lazyPhysics; voxelMap.Init(storageName, storage, worldMatrix); MyEntities.Add(voxelMap); MyEntities.RaiseEntityCreated(voxelMap); ProfilerShort.End(); return voxelMap; }
public static MyStorageBase LoadFromFile(string absoluteFilePath, Dictionary <byte, byte> modifiers = null) { //get hash code MyVoxelObjectDefinition definition = new MyVoxelObjectDefinition(absoluteFilePath, modifiers); int sh = definition.GetHashCode(); MyStorageBase result = null; if (UseStorageCache) { result = m_storageCache.Read(sh); if (result != null) { result.Shared = true; return(result); } } const string loadingMessage = "Loading voxel storage from file '{0}'"; if (!MyFileSystem.FileExists(absoluteFilePath)) { var oldPath = Path.ChangeExtension(absoluteFilePath, "vox"); MySandboxGame.Log.WriteLine(string.Format(loadingMessage, oldPath)); if (!MyFileSystem.FileExists(oldPath)) { //Debug.Fail("Voxel map could not be loaded! " + absoluteFilePath); return(null); } UpdateFileFormat(oldPath); } else { MySandboxGame.Log.WriteLine(string.Format(loadingMessage, absoluteFilePath)); } Debug.Assert(absoluteFilePath.EndsWith(MyVoxelConstants.FILE_EXTENSION)); byte[] compressedData = null; using (var file = MyFileSystem.OpenRead(absoluteFilePath)) { compressedData = new byte[file.Length]; file.Read(compressedData, 0, compressedData.Length); } // JC: with Parallelization, it was crashing the game here, without lock using (m_loadCompressLock.AcquireExclusiveUsing()) { result = Load(compressedData); } //change materials if (definition.Changes != null) { result.ChangeMaterials(definition.Changes); } if (UseStorageCache) { m_storageCache.Write(sh, result); result.Shared = true; } else { m_storageCache.Reset(); } return(result); }
public static MyVoxelGeometry GetGeometry(this VRage.Game.Voxels.IMyStorage self) { MyStorageBase base2 = self as MyStorageBase; return(base2?.Geometry); }
public static MyVoxelMap AddVoxelMap(string storageName, MyStorageBase storage, MatrixD worldMatrix, long entityId = 0) { var voxelMap = new MyVoxelMap(); voxelMap.EntityId = entityId; voxelMap.Init(storageName, storage, worldMatrix); MyEntities.Add(voxelMap); MyEntities.RaiseEntityCreated(voxelMap); return voxelMap; }