<Compile Include="Data\EntitiesOfInterest.cs" />
<Compile Include="Data\EntityDesignator.cs" />
<Compile Include="Data\StatusData.cs" />
+ <Compile Include="Data\CommandData.cs" />
+ <Compile Include="Data\RunState.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="VS_libs\" />
--- /dev/null
+using System;
+using System.IO;
+
+using Vintagestory.API.Common;
+using Vintagestory.API.Datastructures;
+
+namespace Automap
+{
+ public class CommandData : IAttribute
+ {
+ public RunState State { get; set; }//Run , Stop, SingleSnapshot -> Stop
+
+ //POI Delegate list {enabled/Disable}
+ //Other params...? Tick rate?
+ //Choose : Renderer(s)
+
+
+ public CommandData( RunState assumeState)
+ {
+ State = assumeState;
+
+ }
+
+
+
+ public void FromBytes(BinaryReader stream)
+ {
+ State = ( RunState )stream.ReadByte( );
+
+
+ }
+
+ public int GetAttributeId( )
+ {
+ return 12346;
+ }
+
+ public object GetValue( )
+ {
+ return this;
+ }
+
+ public void ToBytes(BinaryWriter stream)
+ {
+ stream.Write(( byte )State);
+
+ }
+
+ public string ToJsonToken( )
+ {
+ return $"New-State:{State}, ";
+ }
+
+ public bool Equals(IWorldAccessor worldForResolve, IAttribute attr)
+ {
+ var other = attr.GetValue( ) as CommandData;
+
+ if (this.State == other.State )
+ {
+ return true;
+ }
+
+ return false;
+ }
+ }
+}
+
--- /dev/null
+using System;
+namespace Automap
+{
+ public enum RunState : byte
+ {
+ Stop = 0x00,
+ Run = 0x01,
+ Snapshot = 0x02,
+ }
+}
+
public uint TotalUpdates { get; set; }
public uint VoidChunks { get; set; }
public uint Delta { get; set; }
+ public uint Max_N, Max_E, Max_S, Max_W;
+ public RunState CurrentState { get; set; }
-
- public StatusData(uint totalUpdates, uint voidChunks, uint delta )
+ public StatusData(uint totalUpdates, uint voidChunks, uint delta, RunState currently )
{
TotalUpdates = totalUpdates;
VoidChunks = voidChunks;
Delta = delta;
+ CurrentState = currently;
}
-
-
public void FromBytes(BinaryReader stream)
{
TotalUpdates = stream.ReadUInt32( );
VoidChunks = stream.ReadUInt32( );
Delta = stream.ReadUInt32( );
+ CurrentState = ( RunState )stream.ReadByte( );
}
public int GetAttributeId( )
stream.Write(TotalUpdates);
stream.Write(VoidChunks);
stream.Write(Delta);
+ stream.Write((byte)CurrentState);
}
public string ToJsonToken( )
if (this.TotalUpdates == other.TotalUpdates &&
this.VoidChunks == other.VoidChunks &&
- this.Delta == other.Delta) {
+ this.Delta == other.Delta &&
+ this.CurrentState == other.CurrentState) {
return true;
}
return false;
private const string _statusTextKey = @"txtStatus";
private ILogger Logger;
- private AutomapSystem _automapSystem;
private long dashTickHandle;
}
private uint totalShards, voidShards, changesThisTick;
+ private RunState lastState;
+
public AutomapGUIDialog(ICoreClientAPI capi,AutomapSystem ams) : base(capi)
{
- _automapSystem = ams;
+
Logger = capi.Logger;
SetupDialog( );
- capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.automapStatusEventKey);
+ capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.AutomapStatusEventKey);
}
bgBounds.BothSizing = ElementSizing.FitToChildren;
bgBounds.WithChildren(textBounds);
- ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(3, 26, 5, 2);
+ ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(3, 64, 5, 2);
toggleBounds.fixedHeight = 24;
toggleBounds.fixedWidth = 64;
- ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 64, 2, 4);
+ ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 26, 2, 4);
txtStatusBounds.fixedHeight = 16;
txtStatusBounds.percentWidth = 1;
/// Toggle Automap from/to RUN state
/// </summary>
/// <returns>The toggle.</returns>
- /// <param name="t1">T1.</param>
+ /// <param name="toggle">Run.</param>
internal void RunToggle(bool toggle)
{
- _automapSystem.Enabled = toggle;
Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle);
var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
- statusText.SetNewText($"Running: {this._automapSystem.Enabled}, Total: ?, Nulls: 0 " );
+ statusText.SetNewText($"State: {(toggle? "Run": "Halt" )}, Total: ?, Nulls: 0 " );
if (toggle) {
dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001);
capi.Event.UnregisterGameTickListener(dashTickHandle);
}
-
+ CommandData cmd = new CommandData(toggle ? RunState.Run : RunState.Stop);
+ capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, cmd);
}
private void AutomapStatusMsg(string eventName, ref EnumHandling handling, IAttribute data)
{
- Logger.VerboseDebug("MsgBus - AutomapStatusMsg");
+ Logger.VerboseDebug("MsgBus RX: AutomapStatusMsg");
StatusData realData = data as StatusData;
totalShards = realData.TotalUpdates;
voidShards = realData.VoidChunks;
changesThisTick = realData.Delta;
-
+ lastState = realData.CurrentState;
}
private void UpdateDashDisplay(float delay )
{
var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
- statusText.SetNewText($"Running: {this._automapSystem.Enabled}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} ");
+ statusText.SetNewText($"State: {lastState}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} ");
}
using Vintagestory.API.Common;
using Vintagestory.API.Common.Entities;
using Vintagestory.API.Config;
+using Vintagestory.API.Datastructures;
using Vintagestory.API.MathTools;
using Vintagestory.Common;
internal Dictionary<AssetLocation, EntityDesignator> Entity_Designators { get; private set; }
internal Dictionary<int, string> RockIdCodes { get; private set; }
- internal bool Enabled { get; set; }
+ internal RunState CurrentState { get; set; }
//Run status, Chunks processed, stats, center of map....
private uint nullChunkCount, updatedChunksTotal;
private Vec2i startChunkColumn;
private string path;
private IAsset stylesFile;
- public static string automapStatusEventKey = @"AutomapStatus";
+ public static string AutomapStatusEventKey = @"AutomapStatus";
+ public static string AutomapCommandEventKey = @"AutomapCommand";
public AutomapSystem(ICoreClientAPI clientAPI, ILogger logger)
//TODO:Choose which one from GUI
this.ChunkRenderer = new StandardRenderer(clientAPI, logger);
+
+ //Listen on bus for commands
+ ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey);
+
}
private void AwakenCartographer(float delayed)
{
- if (Enabled && (ClientAPI.IsGamePaused != false || ClientAPI.IsShuttingDown != true)) {
+ if (CurrentState == RunState.Run && (ClientAPI.IsGamePaused != false || ClientAPI.IsShuttingDown != true)) {
#if DEBUG
Logger.VerboseDebug("Cartographer re-trigger from [{0}]", cartographer_thread.ThreadState);
#endif
//Time to (re)write chunk shards
cartographer_thread.Interrupt( );
}
- #if DEBUG
- ClientAPI.TriggerChatMessage($"Automap {updatedChunksTotal} Updates - MAX (N:{chunkTopMetadata.North_mostChunk},S:{chunkTopMetadata.South_mostChunk},E:{chunkTopMetadata.East_mostChunk}, W:{chunkTopMetadata.West_mostChunk} - TOTAL: {chunkTopMetadata.Count})");
- #endif
+ //#if DEBUG
+ //ClientAPI.TriggerChatMessage($"Automap {updatedChunksTotal} Updates - MAX (N:{chunkTopMetadata.North_mostChunk},S:{chunkTopMetadata.South_mostChunk},E:{chunkTopMetadata.East_mostChunk}, W:{chunkTopMetadata.West_mostChunk} - TOTAL: {chunkTopMetadata.Count})");
+ //#endif
}
}
private void UpdateStatus( uint totalUpdates, uint voidChunks, uint delta)
{
- StatusData updateData = new StatusData(totalUpdates, voidChunks, delta);
+ StatusData updateData = new StatusData(totalUpdates, voidChunks, delta, RunState.Run);
- this.ClientAPI.Event.PushEvent(automapStatusEventKey, updateData);
+ this.ClientAPI.Event.PushEvent(AutomapStatusEventKey, updateData);
}
private void Prefill_POI_Designators( )
//Parse PNG chunks for METADATA in shard
using (var fileStream = shardFile.OpenRead( ))
{
+ //TODO: Add corrupted PNG Exception handing HERE !
PngReader pngRead = new PngReader(fileStream );
pngRead.ReadSkippingAllRows( );
pngRead.End( );
}
+ private void CommandListener(string eventName, ref EnumHandling handling, IAttribute data)
+ {
+ Logger.VerboseDebug("MsgBus RX: AutomapCommandMsg: {0}", data.ToJsonToken() );
+
+ CommandData cmdData = data as CommandData;
+ //TODO: Support snapshot mode
+ if (CurrentState != cmdData.State) {
+ CurrentState = cmdData.State;
+ AwakenCartographer(0.0f);
+ #if DEBUG
+ ClientAPI.TriggerChatMessage($"Automap commanded to: {cmdData.State} ");
+ #endif
+ }
+
+ }
#endregion
+
}
}
\ No newline at end of file