• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Automap (client) [VS plugin mod]


Commit MetaInfo

Revision6f21853a9ca96dc7cd115f471e296e6f8d3ab655 (tree)
Zeit2022-01-15 06:24:39
Autormelchior <melchior@user...>
Commitermelchior

Log Message

Snapshots crash fix

moved snappies to main thread - now also singular use,
fixes multi-click exception

Ändern Zusammenfassung

Diff

--- a/Automap/Automap.csproj
+++ b/Automap/Automap.csproj
@@ -7,7 +7,7 @@
77 <OutputType>Library</OutputType>
88 <RootNamespace>Automap</RootNamespace>
99 <AssemblyName>Automap</AssemblyName>
10- <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
10+ <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1111 </PropertyGroup>
1212 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1313 <DebugSymbols>true</DebugSymbols>
--- a/Automap/Designators/DefaultDesignators.cs
+++ b/Automap/Designators/DefaultDesignators.cs
@@ -239,9 +239,9 @@ namespace Automap
239239
240240 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
241241 {
242-#if DEBUG
242+ #if DEBUG
243243 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
244-#endif
244+ #endif
245245 //Where to? and from!
246246
247247 BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
@@ -249,9 +249,9 @@ namespace Automap
249249 if (te != null) {
250250 //FIXME: Delayed rescan ?
251251 StringBuilder textTarget = new StringBuilder( );
252- //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
252+
253253 textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
254- textTarget.Append(te.Activated ? "Online, " : "Offline, ");
254+ textTarget.Append(te.Activated ? "Online, " : "Offline, ");//Property hardcoded TRUE ?!
255255 textTarget.Append(" Target: [ ");
256256 textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?
257257 textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
--- a/Automap/Subsystems/AutomapSystem.cs
+++ b/Automap/Subsystems/AutomapSystem.cs
@@ -24,7 +24,7 @@ namespace Automap
2424 public class AutomapSystem
2525 {
2626 private Thread cartographer_thread;
27- private Thread snapshotThread;
27+
2828 private Snapshotter snapshot;
2929 private ICoreClientAPI ClientAPI { get; set; }
3030 private ILogger Logger { get; set; }
@@ -84,7 +84,7 @@ namespace Automap
8484 if (configuration.Autostart)
8585 {
8686 CurrentState = CommandType.Run;
87- Logger.Debug("Autostart is Enabled.");
87+ Logger.Notification("Autostart is Enabled.");
8888 }
8989
9090 }
@@ -121,15 +121,7 @@ namespace Automap
121121 IsBackground = true
122122 };
123123
124- snapshot = new Snapshotter(path, chunkTopMetadata, chunkSize,ClientAPI.World.Seed );
125- snapshotThread = new Thread(Snap)
126- {
127- Name = "Snapshot",
128- Priority = ThreadPriority.Lowest,
129- IsBackground = true
130- };
131-
132- ClientAPI.Event.RegisterGameTickListener(AwakenCartographer, 6000);
124+ ClientAPI.Event.RegisterGameTickListener(ThreadDecider, 6000);
133125 }
134126
135127 private void ChunkAChanging(Vec3i chunkCoord, IWorldChunk chunk, EnumChunkDirtyReason reason)
@@ -144,14 +136,18 @@ namespace Automap
144136
145137 }
146138
147- private void AwakenCartographer(float delayed)
139+ /// <summary>
140+ /// Cartographer Thread 'decider'
141+ /// </summary>
142+ /// <param name="delayed">called delay offset</param>
143+ private void ThreadDecider(float delayed)
148144 {
149145
150146 if (CurrentState == CommandType.Run && (ClientAPI.IsGamePaused != false || ClientAPI.IsShuttingDown != true))
151147 {
152-#if DEBUG
153- Logger.VerboseDebug("Cartographer re-trigger from [{0}]", cartographer_thread.ThreadState);
154-#endif
148+ #if DEBUG
149+ Logger.VerboseDebug("ThreadDecider re-trigger from [{0}]", cartographer_thread.ThreadState);
150+ #endif
155151
156152 if (cartographer_thread.ThreadState.HasFlag(ThreadState.Unstarted))
157153 {
@@ -168,15 +164,22 @@ namespace Automap
168164 }
169165 else if (CurrentState == CommandType.Snapshot)
170166 {
171- if (snapshotThread.ThreadState.HasFlag(ThreadState.Unstarted))
172- {
173- snapshotThread.Start();
174- } else if (snapshotThread.ThreadState.HasFlag(ThreadState.WaitSleepJoin))
175- {
176- snapshotThread.Interrupt();
167+ //Prepare for taking a snopshot
168+ if (snapshot == null) {
169+ snapshot = new Snapshotter(path, chunkTopMetadata, chunkSize, ClientAPI.World.Seed);
170+ #if DEBUG
171+ Logger.VerboseDebug("Starting new Snapshot: {0} Wx{1} Hx{2}", snapshot.fileName, snapshot.Width, snapshot.Height);
172+ #endif
173+ snapshot.Take( );
174+ }
175+ else if (snapshot != null && snapshot.Finished) {
176+ #if DEBUG
177+ Logger.VerboseDebug("COMPLETED Snapshot: {0} Wx{1} Hx{2}, taking {3}", snapshot.fileName, snapshot.Width, snapshot.Height, snapshot.Timer.Elapsed);
178+ #endif
179+ snapshot = null;
180+ CurrentState = CommandType.Run;
177181 }
178182 }
179-
180183 }
181184
182185
@@ -468,6 +471,7 @@ namespace Automap
468471 mdWriter.WriteLine("WorldSeed {0}", ClientAPI.World.Seed);
469472 mdWriter.WriteLine("PlayerChunkCoords {0:D} {1:D}", startChunkColumn.X, startChunkColumn.Y);
470473 mdWriter.WriteLine("DefaultSpawnPos {0:D} {1:D} {2:D}", ClientAPI.World.DefaultSpawnPosition.AsBlockPos.X,ClientAPI.World.DefaultSpawnPosition.AsBlockPos.Y,ClientAPI.World.DefaultSpawnPosition.AsBlockPos.Z);
474+ //mdWriter.WriteLine("CurrentPlayerSpawn", ClientAPI.World.Player.WorldData.EntityPlayer.);
471475 mdWriter.WriteLine("ChunkSize {0}", chunkSize);
472476 mdWriter.WriteLine("SeaLevel {0:D}", ClientAPI.World.SeaLevel);
473477 mdWriter.WriteLine("WorldSize {0:D} {1:D} {2:D}", ClientAPI.World.BulkBlockAccessor.MapSizeX, ClientAPI.World.BulkBlockAccessor.MapSizeY,ClientAPI.World.BulkBlockAccessor.MapSizeZ);
@@ -761,7 +765,7 @@ namespace Automap
761765 if (CurrentState != cmdData.State)
762766 {
763767 CurrentState = cmdData.State;
764- AwakenCartographer(0.0f);
768+ ThreadDecider(0.0f);
765769 }
766770 break;
767771
--- a/Automap/Subsystems/Snapshot.cs
+++ b/Automap/Subsystems/Snapshot.cs
@@ -13,37 +13,50 @@ namespace Automap
1313 {
1414 public class Snapshotter
1515 {
16- public readonly int chunkSize;
1716 private const string customTimeFormat = @"yyyy.MM.dd.HH.mm.ssZzz";
18- public string fileName;
19- public string chunkPath;
20- public ColumnsMetadata cols;
21- //TODO: Refactor - so Edges are set at construction time, as ColumnsMetadata is async updating in real time!
22- public int NorthEdge => cols.North_mostChunk;
23- public int WestEdge => cols.West_mostChunk;
24- public int Width => (cols.East_mostChunk - WestEdge + 1);
25- public int Height => (cols.South_mostChunk - NorthEdge + 1);
26-
17+ public readonly int chunkSize;
18+ public readonly int worldSeed;
19+ public readonly string fileName;
20+ public readonly string chunkPath;
21+ public readonly int NorthEdge;
22+ public readonly int WestEdge;
23+ public readonly int Width;
24+ public readonly int Height;
25+
26+ public ColumnsMetadata colMetadata;
27+ public bool Imaging { get; private set; }
28+ public bool Finished { get; private set; }
29+ public Stopwatch Timer { get; private set;}
2730
28- public Snapshotter(string path, ColumnsMetadata cols, int chunkSize, int worldSeed)
29- {
30- this.fileName = Path.Combine(path, $"snapshot_{worldSeed}_{DateTime.Now.ToString(customTimeFormat)}.png");
31- this.chunkPath = Path.Combine(path, AutomapSystem._chunkPath);
32- this.cols = cols;
33- this.chunkSize = chunkSize;
31+ /// <summary>
32+ /// Prepares class to take "snapshot" (single use!)
33+ /// </summary>
34+ /// <param name="path">path to the map dir</param>
35+ /// <param name="cols">Input metadata</param>
36+ /// <param name="chunkSizeP">size in blocks of std. chunk</param>
37+ /// <param name="worldSeedP">World Seed #</param>
38+ public Snapshotter(string path, ColumnsMetadata cols, int chunkSizeP, int worldSeedP)
39+ {
40+ colMetadata = cols;
41+ chunkSize = chunkSizeP;
42+ worldSeed = worldSeedP;
43+ NorthEdge = cols.North_mostChunk;
44+ WestEdge = cols.West_mostChunk;
45+ Width = (cols.East_mostChunk - WestEdge + 1);
46+ Height = (cols.South_mostChunk - NorthEdge + 1);
47+ fileName = Path.Combine(path, $"snapshot_{worldSeed}_{DateTime.Now.ToString(customTimeFormat)}.png");
48+ chunkPath = Path.Combine(path, AutomapSystem._chunkPath);
3449 }
3550
3651 /// <summary>
3752 /// takes a snapshot. this should be called from an extra thread.
3853 /// </summary>
39- /// <param name="path">path to the map dir</param>
40- /// <param name="chunkPath">name of the chunks dir part thing</param>
41- /// <param name="cols"></param>
42- /// <param name="chunkSize"></param>
4354 public async void Take()
4455 {
45- var t = new Stopwatch();
46- t.Start();
56+ if (Imaging || Finished) return;//Can't take annother photo...this one is started or complete
57+ Imaging = true;
58+ Timer = new Stopwatch();
59+ Timer.Start();
4760
4861 Debug.WriteLine("snapshot started");
4962
@@ -73,7 +86,7 @@ namespace Automap
7386
7487
7588 var orderedList =
76- from ch in cols
89+ from ch in colMetadata
7790 group ch by ch.Location.Y into g
7891 orderby g.Key
7992 select g;
@@ -111,12 +124,15 @@ namespace Automap
111124 try
112125 {
113126 snapWriter.End();
127+ Timer.Stop( );
128+ Imaging = false;
129+ Finished = true;
114130 }
115131 catch (Exception)
116132 {
117133 Debug.WriteLine("Snapshot exception!");
118134 }
119- Debug.WriteLine($"snapshot finished in {t.ElapsedMilliseconds}");
135+ Debug.WriteLine($"snapshot finished in {Timer.ElapsedMilliseconds}");
120136 }
121137
122138 private async Task<Dictionary<int, byte[][]>> ReadAllInGroup(IGrouping<int, ColumnMeta> group)
--- a/Automap/modinfo.json
+++ b/Automap/modinfo.json
@@ -4,10 +4,10 @@
44 "description" : "Automap; Generates a static HTML5 map dynamically, with P.O.I. Tracking & more.",
55 "authors": ["Melchior","VeryGoodDog"],
66 "contributors":["VeryGoodDog"],
7- "version": "0.1.7",
7+ "version": "0.1.8",
88 "side":"Client",
99 "dependencies": {
10- "game": "1.14.10"
10+ "game": "1.16.0"
1111 },
1212 "website": "http://automap.osdn.io/"
1313 }
\ No newline at end of file