private ColumnsMetadata chunkTopMetadata;
private PointsOfInterest POIs = new PointsOfInterest();
private EntitiesOfInterest EOIs = new EntitiesOfInterest();
- private string jsonPreBuilt;
internal Dictionary<int, BlockDesignator> BlockID_Designators { get; private set; }
internal Dictionary<AssetLocation, EntityDesignator> Entity_Designators { get; private set; }
public static string AutomapStatusEventKey = @"AutomapStatus";
public static string AutomapCommandEventKey = @"AutomapCommand";
- PersistedConfiguration cachedConfiguration;
public AutomapSystem(ICoreClientAPI clientAPI, ILogger logger, PersistedConfiguration config)
{
if (chunkTopMetadata.Contains(mostActiveCol.Key))
{
chunkMeta = chunkTopMetadata[mostActiveCol.Key];
+#if DEBUG
+ Logger.VerboseDebug("Loaded chunk {0}", mostActiveCol.Key);
+ //Console.WriteLine($"Load {mostActiveCol.Key}");
+#endif
}
else
{
chunkMeta = CreateColumnMetadata(mostActiveCol, mapChunk);
+#if DEBUG
+ Logger.VerboseDebug("Created chunk {0}", mostActiveCol.Key);
+ //Console.WriteLine($"Created chunk {mostActiveCol.Key}");
+#endif
}
ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta);
if (updatedPixels > 0)
{
-
- #if DEBUG
+#if DEBUG
Logger.VerboseDebug("Wrote chunk shard: ({0}) - Edits#:{1}, Pixels#:{2}", mostActiveCol.Key, mostActiveCol.Value, updatedPixels);
- #endif
+#endif
updatedChunks++;
chunkTopMetadata.Update(chunkMeta);
columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
finally
{
Logger.VerboseDebug("Thread '{0}' executing finally block.", Thread.CurrentThread.Name);
- PersistPointsData( );
+ PersistPointsData();
}
}
private ColumnMeta CreateColumnMetadata(KeyValuePair<Vec2i, uint> mostActiveCol, IMapChunk mapChunk)
{
- ColumnMeta data = new ColumnMeta(mostActiveCol.Key.Copy(), (byte) chunkSize);
+ ColumnMeta data = new ColumnMeta(mostActiveCol.Key.Copy(), ClientAPI, (byte) chunkSize);
BlockPos equivBP = new BlockPos(mostActiveCol.Key.X * chunkSize,
mapChunk.YMax,
mostActiveCol.Key.Y * chunkSize);
{
var worldmapDir = new DirectoryInfo(path);
- if (worldmapDir.Exists)
+ if (!worldmapDir.Exists)
{
+#if DEBUG
+ Logger.VerboseDebug("Could not open world map directory");
+#endif
+ return;
+ }
+ var shardFiles = worldmapDir.GetFiles(chunkFile_filter);
- var shardFiles = worldmapDir.GetFiles(chunkFile_filter);
+ if (shardFiles.Length > 0)
+ {
+#if DEBUG
+ Logger.VerboseDebug("Metadata reloading from {0} shards", shardFiles.Length);
+#endif
- if (shardFiles.Length > 0)
+ foreach (var shardFile in shardFiles)
{
- #if DEBUG
- Logger.VerboseDebug("Metadata reloading from {0} shards", shardFiles.Length);
- #endif
-
- foreach (var shardFile in shardFiles) {
if (shardFile.Length < 1024) continue;
var result = chunkShardRegex.Match(shardFile.Name);
- if (result.Success) {
- int X_chunk_pos = int.Parse(result.Groups["X"].Value);
- int Z_chunk_pos = int.Parse(result.Groups["Z"].Value);
+ if (result.Success)
+ {
+ int X_chunk_pos = int.Parse(result.Groups["X"].Value);
+ int Z_chunk_pos = int.Parse(result.Groups["Z"].Value);
- try
+ try
{
- using (var fileStream = shardFile.OpenRead( )) {
-
- PngReader pngRead = new PngReader(fileStream);
- pngRead.ReadSkippingAllRows( );
- pngRead.End( );
- //Parse PNG chunks for METADATA in shard
- PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk;
+ using (var fileStream = shardFile.OpenRead())
+ {
- chunkTopMetadata.Add(metadataFromPng.ChunkMetadata);
- }
+ PngReader pngRead = new PngReader(fileStream);
+ pngRead.ReadSkippingAllRows();
+ pngRead.End();
+ //Parse PNG chunks for METADATA in shard
+ PngMetadataChunk metadataFromPng = pngRead.GetChunksList().GetById1(PngMetadataChunk.ID) as PngMetadataChunk;
+ var column = metadataFromPng.ChunkMetadata;
+ if (column.PrettyLocation == null)
+ column = column.Reload(ClientAPI);
+ chunkTopMetadata.Add(column);
+ }
}
catch (PngjException someEx)
Logger.Error("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx);
continue;
}
- }
-
}
+
}
+ }
- //POI and EOI raw dump files ~ reload em!
- //var poiRawFile = File.
- string poiPath = Path.Combine(path, poiFileName);
- string eoiPath = Path.Combine(path, eoiFileName);
+ //POI and EOI raw dump files ~ reload em!
+ //var poiRawFile = File.
+ string poiPath = Path.Combine(path, poiFileName);
+ string eoiPath = Path.Combine(path, eoiFileName);
- if (File.Exists(poiPath)) {
- using (var poiFile = File.OpenRead(poiPath)) {
+ if (File.Exists(poiPath))
+ {
+ using (var poiFile = File.OpenRead(poiPath))
+ {
this.POIs = Serializer.Deserialize<PointsOfInterest>(poiFile);
Logger.VerboseDebug("Reloaded {0} POIs from file.", this.POIs.Count);
- }
}
+ }
- if (File.Exists(eoiPath)) {
- using (var eoiFile = File.OpenRead(eoiPath)) {
+ if (File.Exists(eoiPath))
+ {
+ using (var eoiFile = File.OpenRead(eoiPath))
+ {
this.EOIs = Serializer.Deserialize<EntitiesOfInterest>(eoiFile);
Logger.VerboseDebug("Reloaded {0} EOIs from file.", this.EOIs.Count);
- }
}
-
- }
- else
- {
- #if DEBUG
- Logger.VerboseDebug("Could not open world map directory");
- #endif
}
-
-
}
- private PngWriter SetupPngImage(Vec2i coord, ColumnMeta metadata)
+ private PngWriter SetupPngImage(Vec2i coord, ref ColumnMeta metadata)
{
ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false);
ChunkMetadata = metadata
};
pngWriter.GetChunksList().Queue(pngChunkMeta);
- pngWriter.CompLevel = 9;// 9 is the maximum compression
+ pngWriter.CompLevel = 5;// 9 is the maximum compression but thats too high for the small benefit it gives
pngWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman;
return pngWriter;
int targetChunkY = mapChunk.YMax / chunkSize;//Surface ...
for (; targetChunkY > 0; targetChunkY--)
{
- WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk;
+ WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk;
if (chunkData == null || chunkData.BlockEntities == null) {
#if DEBUG
/*************** Chunk Entities Scanning *********************/
if (chunkData.BlockEntities != null && chunkData.BlockEntities.Length > 0)
{
- #if DEBUG
+#if DEBUG
Logger.VerboseDebug("Surface@ {0} = BlockEntities: {1}", key, chunkData.BlockEntities.Length);
- #endif
+#endif
foreach (var blockEnt in chunkData.BlockEntities)
{
foreach (var loadedEntity in ClientAPI.World.LoadedEntities.ToArray())
{
- #if DEBUG
+#if DEBUG
//Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos} <<<<<<<<<<<<");
- #endif
+#endif
var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Value.Code));
if (dMatch.Value != null)
{
switch (cmdData.State)
{
- case CommandType.Run:
+ case CommandType.Run:
case CommandType.Stop:
- if (CurrentState != cmdData.State) {
- CurrentState = cmdData.State;
- AwakenCartographer(0.0f);
+ if (CurrentState != cmdData.State)
+ {
+ CurrentState = cmdData.State;
+ AwakenCartographer(0.0f);
}
break;