コード例 #1
0
 void SaveToFileI(byte[] blks)
 {
     try
     {
         ChunkDetails det = new ChunkDetails();
         det.Version    = 2;
         det.X          = (int)WorldPosition.X;
         det.Y          = (int)WorldPosition.Y;
         det.Z          = (int)WorldPosition.Z;
         det.Flags      = Flags;
         det.Blocks     = blks;
         det.Reachables = new byte[(int)ChunkReachability.COUNT];
         for (int i = 0; i < det.Reachables.Length; i++)
         {
             det.Reachables[i] = (byte)(Reachability[i] ? 1 : 0);
         }
         byte[] lod = LODBytes(5);
         lock (GetLocker())
         {
             OwningRegion.ChunkManager.WriteChunkDetails(det);
             OwningRegion.ChunkManager.WriteLODChunkDetails(det.X, det.Y, det.Z, lod);
         }
         OwningRegion.TheServer.BlockImages.RenderChunk(OwningRegion, WorldPosition, this);
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.ERROR, "Saving chunk " + WorldPosition.ToString() + " to file: " + ex.ToString());
     }
 }
コード例 #2
0
 /// <summary>
 /// Internally saves chunk blocks to file.
 /// </summary>
 /// <param name="blks">The block data.</param>
 void SaveToFileI(byte[] blks)
 {
     try
     {
         ChunkDetails det = new ChunkDetails()
         {
             Version    = 2,
             X          = WorldPosition.X,
             Y          = WorldPosition.Y,
             Z          = WorldPosition.Z,
             Flags      = Flags,
             Blocks     = blks,
             Reachables = new byte[(int)ChunkReachability.COUNT]
         };
         for (int i = 0; i < det.Reachables.Length; i++)
         {
             det.Reachables[i] = (byte)(Reachability[i] ? 1 : 0);
         }
         byte[] lod    = LODBytes(5);
         byte[] lodsix = LODBytes(6);
         byte[] slod   = SLODBytes(lod);
         lock (GetLocker())
         {
             OwningRegion.ChunkManager.WriteChunkDetails(det);
             OwningRegion.ChunkManager.WriteLODChunkDetails(det.X, det.Y, det.Z, lod);
             OwningRegion.ChunkManager.WriteSuperLODChunkDetails(det.X, det.Y, det.Z, slod);
             OwningRegion.ChunkManager.WriteLODSixChunkDetails(det.X, det.Y, det.Z, lodsix);
         }
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.ERROR, "Saving chunk " + WorldPosition.ToString() + " to file: " + ex.ToString());
     }
 }
コード例 #3
0
 public bool PopulateChunk(Chunk chunk, bool allowFile, bool fileOnly = false, bool async = false)
 {
     try
     {
         if (allowFile)
         {
             ChunkDetails dat;
             lock (chunk.GetLocker())
             {
                 dat = ChunkManager.GetChunkDetails((int)chunk.WorldPosition.X, (int)chunk.WorldPosition.Y, (int)chunk.WorldPosition.Z);
             }
             ChunkDetails ents;
             lock (chunk.GetLocker())
             {
                 ents = ChunkManager.GetChunkEntities((int)chunk.WorldPosition.X, (int)chunk.WorldPosition.Y, (int)chunk.WorldPosition.Z);
             }
             if (dat != null)
             {
                 if (ents == null)
                 {
                     ents = new ChunkDetails()
                     {
                         X = dat.X, Y = dat.Y, Z = dat.Z, Version = dat.Version, Flags = dat.Flags, Reachables = null, Blocks = new byte[0]
                     };
                 }
                 chunk.LoadFromSaveData(dat, ents);
                 if (!chunk.Flags.HasFlag(ChunkFlags.ISCUSTOM))
                 {
                     chunk.Flags &= ~ChunkFlags.POPULATING;
                 }
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Utilities.CheckException(ex);
         SysConsole.Output(OutputType.ERROR, "Loading chunk: " + chunk.WorldPosition.ToString() + ": " + ex.ToString());
         return(false);
     }
     if (fileOnly)
     {
         return(false);
     }
     try
     {
         Generator.Populate(TheWorld.Seed, TheWorld.Seed2, TheWorld.Seed3, TheWorld.Seed4, TheWorld.Seed5, chunk);
         chunk.LastEdited = GlobalTickTime;
         chunk.Flags     &= ~(ChunkFlags.POPULATING | ChunkFlags.ISCUSTOM);
         chunk.Flags     |= ChunkFlags.NEEDS_DETECT;
     }
     catch (Exception ex)
     {
         Utilities.CheckException(ex);
         SysConsole.Output(OutputType.ERROR, "Loading chunk" + chunk.WorldPosition.ToString() + ": " + ex.ToString());
         return(false);
     }
     return(true);
 }
コード例 #4
0
        public void WriteChunkEntities(ChunkDetails details)
        {
            BsonValue    id     = GetIDFor(details.X, details.Y, details.Z);
            BsonDocument newdoc = new BsonDocument();

            newdoc["_id"]      = id;
            newdoc["version"]  = new BsonValue(details.Version);
            newdoc["entities"] = new BsonValue(/*FileHandler.GZip(*/ details.Blocks /*)*/);
            lock (EntLock)
            {
                DBEnts.Delete(id);
                DBEnts.Insert(newdoc);
            }
        }
コード例 #5
0
 /// <summary>
 /// Loads the chunk from save data.
 /// </summary>
 /// <param name="det">The block data.</param>
 /// <param name="ents">The entity data.</param>
 public void LoadFromSaveData(ChunkDetails det, ChunkDetails ents)
 {
     if (det.Version != 2 || ents.Version != 2)
     {
         throw new Exception("invalid save data VERSION: " + det.Version + " and " + ents.Version + "!");
     }
     Flags = det.Flags & ~(ChunkFlags.POPULATING);
     SetBlockAt(0, 0, 0, BlockInternal.AIR); // Ensure generated
     if (det.Blocks.Length > 0)
     {
         for (int i = 0; i < BlocksInternal.Length; i++)
         {
             BlocksInternal[i]._BlockMaterialInternal = Utilities.BytesToUShort(Utilities.BytesPartial(det.Blocks, i * 2, 2));
             BlocksInternal[i].BlockData           = det.Blocks[BlocksInternal.Length * 2 + i];
             BlocksInternal[i].BlockLocalData      = det.Blocks[BlocksInternal.Length * 3 + i];
             BlocksInternal[i]._BlockPaintInternal = det.Blocks[BlocksInternal.Length * 4 + i];
         }
         FromFile = true;
     }
     for (int i = 0; i < Reachability.Length; i++)
     {
         Reachability[i] = det.Reachables[i] == 1;
     }
     if (ents.Blocks != null && ents.Blocks.Length > 0 && entsToSpawn.Count == 0)
     {
         BsonDocument bsd = BsonSerializer.Deserialize(ents.Blocks);
         if (bsd.ContainsKey("list"))
         {
             List <BsonValue> docs = bsd["list"];
             for (int i = 0; i < docs.Count; i++)
             {
                 BsonDocument ent   = (BsonDocument)docs[i];
                 EntityType   etype = (EntityType)Enum.Parse(typeof(EntityType), ent["ENTITY_TYPE"].AsString);
                 try
                 {
                     Entity e = OwningRegion.ConstructorFor(etype).Create(OwningRegion, ent);
                     e.EID = ent["ENTITY_ID"].AsInt64;
                     entsToSpawn.Add(e);
                 }
                 catch (Exception ex)
                 {
                     Utilities.CheckException(ex);
                     SysConsole.Output("Spawning an entity of type " + etype, ex);
                 }
             }
         }
     }
 }
コード例 #6
0
        public void WriteChunkDetails(ChunkDetails details)
        {
            BsonValue    id     = GetIDFor(details.X, details.Y, details.Z);
            BsonDocument newdoc = new BsonDocument();

            newdoc["_id"]     = id;
            newdoc["version"] = new BsonValue(details.Version);
            newdoc["flags"]   = new BsonValue((int)details.Flags);
            newdoc["blocks"]  = new BsonValue(FileHandler.Compress(details.Blocks));
            newdoc["reach"]   = new BsonValue(details.Reachables);
            lock (FSLock)
            {
                DBChunks.Delete(id);
                DBChunks.Insert(newdoc);
            }
        }
コード例 #7
0
 /// <summary>
 /// Internally saves chunk entities to file.
 /// </summary>
 /// <param name="ents">The entity data.</param>
 void SaveToFileE(BsonDocument ents)
 {
     try
     {
         ChunkDetails det = new ChunkDetails()
         {
             Version = 2, X = WorldPosition.X, Y = WorldPosition.Y, Z = WorldPosition.Z, Blocks = BsonSerializer.Serialize(ents)
         };
         lock (GetLocker())
         {
             OwningRegion.ChunkManager.WriteChunkEntities(det);
         }
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.ERROR, "Saving entities for chunk " + WorldPosition.ToString() + " to file: " + ex.ToString());
     }
 }
コード例 #8
0
        public ChunkDetails GetChunkEntities(int x, int y, int z)
        {
            BsonDocument doc;

            lock (EntLock)
            {
                doc = DBEnts.FindById(GetIDFor(x, y, z));
            }
            if (doc == null)
            {
                return(null);
            }
            ChunkDetails det = new ChunkDetails();

            det.X       = x;
            det.Y       = y;
            det.Z       = z;
            det.Version = doc["version"].AsInt32;
            det.Blocks  = /*FileHandler.UnGZip(*/ doc["entities"].AsBinary /*)*/;
            return(det);
        }
コード例 #9
0
ファイル: ChunkDataManager.cs プロジェクト: Morphan1/Voxalia
 public ChunkDetails GetChunkDetails(int x, int y, int z)
 {
     BsonDocument doc;
     lock (FSLock)
     {
         doc = DBChunks.FindById(GetIDFor(x, y, z));
     }
     if (doc == null)
     {
         return null;
     }
     ChunkDetails det = new ChunkDetails();
     det.X = x;
     det.Y = y;
     det.Z = z;
     det.Version = doc["version"].AsInt32;
     det.Flags = (ChunkFlags)doc["flags"].AsInt32;
     det.Blocks = FileHandler.Uncompress(doc["blocks"].AsBinary);
     det.Reachables = doc["reach"].AsBinary;
     return det;
 }
コード例 #10
0
        public ChunkDetails GetChunkDetails(int x, int y, int z)
        {
            BsonDocument doc;

            lock (FSLock)
            {
                doc = DBChunks.FindById(GetIDFor(x, y, z));
            }
            if (doc == null)
            {
                return(null);
            }
            ChunkDetails det = new ChunkDetails();

            det.X          = x;
            det.Y          = y;
            det.Z          = z;
            det.Version    = doc["version"].AsInt32;
            det.Flags      = (ChunkFlags)doc["flags"].AsInt32;
            det.Blocks     = FileHandler.Uncompress(doc["blocks"].AsBinary);
            det.Reachables = doc["reach"].AsBinary;
            return(det);
        }
コード例 #11
0
ファイル: Chunk.cs プロジェクト: Morphan1/Voxalia
 void SaveToFileE(BsonDocument ents)
 {
     try
     {
         ChunkDetails det = new ChunkDetails();
         det.Version = 2;
         det.X = (int)WorldPosition.X;
         det.Y = (int)WorldPosition.Y;
         det.Z = (int)WorldPosition.Z;
         det.Blocks = BsonSerializer.Serialize(ents);
         lock (GetLocker())
         {
             OwningRegion.ChunkManager.WriteChunkEntities(det);
         }
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.ERROR, "Saving entities for chunk " + WorldPosition.ToString() + " to file: " + ex.ToString());
     }
 }
コード例 #12
0
ファイル: ChunkDataManager.cs プロジェクト: Morphan1/Voxalia
 public void WriteChunkEntities(ChunkDetails details)
 {
     BsonValue id = GetIDFor(details.X, details.Y, details.Z);
     BsonDocument newdoc = new BsonDocument();
     newdoc["_id"] = id;
     newdoc["version"] = new BsonValue(details.Version);
     newdoc["entities"] = new BsonValue(/*FileHandler.GZip(*/details.Blocks/*)*/);
     lock (EntLock)
     {
         DBEnts.Delete(id);
         DBEnts.Insert(newdoc);
     }
 }
コード例 #13
0
ファイル: ChunkDataManager.cs プロジェクト: Morphan1/Voxalia
 public void WriteChunkDetails(ChunkDetails details)
 {
     BsonValue id = GetIDFor(details.X, details.Y, details.Z);
     BsonDocument newdoc = new BsonDocument();
     newdoc["_id"] = id;
     newdoc["version"] = new BsonValue(details.Version);
     newdoc["flags"] = new BsonValue((int)details.Flags);
     newdoc["blocks"] = new BsonValue(FileHandler.Compress(details.Blocks));
     newdoc["reach"] = new BsonValue(details.Reachables);
     lock (FSLock)
     {
         DBChunks.Delete(id);
         DBChunks.Insert(newdoc);
     }
 }
コード例 #14
0
ファイル: RegionChunks.cs プロジェクト: Morphan1/Voxalia
 public bool PopulateChunk(Chunk chunk, bool allowFile, bool fileOnly = false, bool async = false)
 {
     try
     {
         if (allowFile)
         {
             ChunkDetails dat;
             lock (chunk.GetLocker())
             {
                 dat = ChunkManager.GetChunkDetails((int)chunk.WorldPosition.X, (int)chunk.WorldPosition.Y, (int)chunk.WorldPosition.Z);
             }
             ChunkDetails ents;
             lock (chunk.GetLocker())
             {
                 ents = ChunkManager.GetChunkEntities((int)chunk.WorldPosition.X, (int)chunk.WorldPosition.Y, (int)chunk.WorldPosition.Z);
             }
             if (dat != null)
             {
                 if (ents == null)
                 {
                     ents = new ChunkDetails() { X = dat.X, Y = dat.Y, Z = dat.Z, Version = dat.Version, Flags = dat.Flags, Reachables = null, Blocks = new byte[0] };
                 }
                 chunk.LoadFromSaveData(dat, ents);
                 if (!chunk.Flags.HasFlag(ChunkFlags.ISCUSTOM))
                 {
                     chunk.Flags &= ~ChunkFlags.POPULATING;
                 }
                 return true;
             }
         }
     }
     catch (Exception ex)
     {
         Utilities.CheckException(ex);
         SysConsole.Output(OutputType.ERROR, "Loading chunk: " + chunk.WorldPosition.ToString() + ": " + ex.ToString());
         return false;
     }
     if (fileOnly)
     {
         return false;
     }
     try
     {
         Generator.Populate(TheWorld.Seed, TheWorld.Seed2, TheWorld.Seed3, TheWorld.Seed4, TheWorld.Seed5, chunk);
         chunk.LastEdited = GlobalTickTime;
         chunk.Flags &= ~(ChunkFlags.POPULATING | ChunkFlags.ISCUSTOM);
         chunk.Flags |= ChunkFlags.NEEDS_DETECT;
     }
     catch (Exception ex)
     {
         Utilities.CheckException(ex);
         SysConsole.Output(OutputType.ERROR, "Loading chunk" + chunk.WorldPosition.ToString() + ": " + ex.ToString());
         return false;
     }
     return true;
 }
コード例 #15
0
ファイル: Chunk.cs プロジェクト: Morphan1/Voxalia
 void SaveToFileI(byte[] blks)
 {
     try
     {
         ChunkDetails det = new ChunkDetails();
         det.Version = 2;
         det.X = (int)WorldPosition.X;
         det.Y = (int)WorldPosition.Y;
         det.Z = (int)WorldPosition.Z;
         det.Flags = Flags;
         det.Blocks = blks;
         det.Reachables = new byte[(int)ChunkReachability.COUNT];
         for (int i = 0; i < det.Reachables.Length; i++)
         {
             det.Reachables[i] = (byte)(Reachability[i] ? 1 : 0);
         }
         byte[] lod = LODBytes(5);
         lock (GetLocker())
         {
             OwningRegion.ChunkManager.WriteChunkDetails(det);
             OwningRegion.ChunkManager.WriteLODChunkDetails(det.X, det.Y, det.Z, lod);
         }
         OwningRegion.TheServer.BlockImages.RenderChunk(OwningRegion, WorldPosition, this);
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.ERROR, "Saving chunk " + WorldPosition.ToString() + " to file: " + ex.ToString());
     }
 }
コード例 #16
0
ファイル: ChunkDataManager.cs プロジェクト: Morphan1/Voxalia
 public ChunkDetails GetChunkEntities(int x, int y, int z)
 {
     BsonDocument doc;
     lock (EntLock)
     {
         doc = DBEnts.FindById(GetIDFor(x, y, z));
     }
     if (doc == null)
     {
         return null;
     }
     ChunkDetails det = new ChunkDetails();
     det.X = x;
     det.Y = y;
     det.Z = z;
     det.Version = doc["version"].AsInt32;
     det.Blocks = /*FileHandler.UnGZip(*/doc["entities"].AsBinary/*)*/;
     return det;
 }
コード例 #17
0
ファイル: Chunk.cs プロジェクト: Morphan1/Voxalia
 public void LoadFromSaveData(ChunkDetails det, ChunkDetails ents)
 {
     if (det.Version != 2 || ents.Version != 2)
     {
         throw new Exception("invalid save data VERSION: " + det.Version + " and " + ents.Version + "!");
     }
     Flags = det.Flags & ~(ChunkFlags.POPULATING);
     for (int i = 0; i < BlocksInternal.Length; i++)
     {
         BlocksInternal[i]._BlockMaterialInternal = Utilities.BytesToUshort(Utilities.BytesPartial(det.Blocks, i * 2, 2));
         BlocksInternal[i].BlockData = det.Blocks[BlocksInternal.Length * 2 + i];
         BlocksInternal[i].BlockLocalData = det.Blocks[BlocksInternal.Length * 3 + i];
         BlocksInternal[i]._BlockPaintInternal = det.Blocks[BlocksInternal.Length * 4 + i];
     }
     for (int i = 0; i < Reachability.Length; i++)
     {
         Reachability[i] = det.Reachables[i] == 1;
     }
     if (ents.Blocks != null && ents.Blocks.Length > 0 && entsToSpawn.Count == 0)
     {
         BsonDocument bsd = BsonSerializer.Deserialize(ents.Blocks);
         if (bsd.ContainsKey("list"))
         {
             List<BsonValue> docs = bsd["list"];
             for (int i = 0; i < docs.Count; i++)
             {
                 BsonDocument ent = (BsonDocument)docs[i];
                 EntityType etype = (EntityType)Enum.Parse(typeof(EntityType), ent["ENTITY_TYPE"].AsString);
                 try
                 {
                     Entity e = OwningRegion.ConstructorFor(etype).Create(OwningRegion, ent);
                     e.EID = ent["ENTITY_ID"].AsInt64;
                     entsToSpawn.Add(e);
                 }
                 catch (Exception ex)
                 {
                     Utilities.CheckException(ex);
                     SysConsole.Output("Spawning an entity of type " + etype, ex);
                 }
             }
         }
     }
 }