• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

Automap (client) [VS plugin mod]


Commit MetaInfo

Revisionedc76b96b63c2ed2affd067281ebbe37bfcdcd6a (tree)
Time2020-09-21 05:23:03
Authormelchior <melchior@user...>
Commitermelchior

Log Message

W.I.P. Changes for non-Seasonal color on map, default spawn coords

Change Summary

Incremental Difference

--- a/Automap/Automap.csproj
+++ b/Automap/Automap.csproj
@@ -88,7 +88,7 @@
8888 <Compile Include="Designators\DefaultDesignators.cs" />
8989 <Compile Include="Subsystems\AutomapSystem.cs" />
9090 <Compile Include="Subsystems\AutomapGUIDialog.cs" />
91- <Compile Include="Renderers\IChunkRenderer.cs" />
91+ <Compile Include="Renderers\AChunkRenderer.cs" />
9292 <Compile Include="Renderers\StandardRenderer.cs" />
9393 <Compile Include="Renderers\AlternateRenderer.cs" />
9494 <Compile Include="Data\StatusData.cs" />
--- a/Automap/Data/PersistedConfiguration.cs
+++ b/Automap/Data/PersistedConfiguration.cs
@@ -14,6 +14,12 @@ namespace Automap
1414 /// <value>To autostart.</value>
1515 public bool Autostart { get; set; } = false;
1616
17+ /// <summary>
18+ /// Use Same season effected colors as ingame-map.
19+ /// </summary>
20+ /// <value>The seasonal colors.</value>
21+ public bool SeasonalColors { get; set; } = true;
22+
1723 //public string ChosenRendererName { get; set; }
1824
1925 //All - Designators, setup
--- /dev/null
+++ b/Automap/Renderers/AChunkRenderer.cs
@@ -0,0 +1,91 @@
1+using System;
2+using System.Collections.Generic;
3+using System.IO;
4+
5+using Hjg.Pngcs;
6+using Hjg.Pngcs.Chunks;
7+
8+using Vintagestory.API.Client;
9+using Vintagestory.API.Common;
10+using Vintagestory.API.MathTools;
11+
12+namespace Automap
13+{
14+ public abstract class AChunkRenderer
15+ {
16+ protected readonly int chunkSize;
17+
18+ public virtual ICoreClientAPI ClientAPI { get; protected set; }
19+ public virtual ILogger Logger { get; protected set; }
20+ public virtual Dictionary<int, BlockDesignator> BlockID_Designators { get; set; }
21+ public virtual bool SeasonalColors { get; }
22+ //private PngWriter pngWriter;
23+
24+ protected AChunkRenderer(ICoreClientAPI clientAPI, ILogger logger, bool useSeasonColor = true)
25+ {
26+ this.ClientAPI = clientAPI;
27+ this.Logger = logger;
28+ this.SeasonalColors = useSeasonColor;
29+ this.chunkSize = ClientAPI.World.BlockAccessor.ChunkSize;
30+
31+ }
32+
33+ public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount);
34+
35+ public virtual PngWriter SetupPngImage(Vec2i coord, string path, string chunkPath, ref ColumnMeta metadata)
36+ {
37+ ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false);
38+
39+ string filename = $"{coord.X}_{coord.Y}.png";
40+ filename = Path.Combine(path, chunkPath, filename);
41+
42+ PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true);
43+ PngMetadata meta = pngWriter.GetMetadata( );
44+ meta.SetTimeNow( );
45+ meta.SetText("Chunk_X", coord.X.ToString("D"));
46+ meta.SetText("Chunk_Y", coord.Y.ToString("D"));
47+ meta.SetText("PxSz", "1");
48+ //Setup specialized meta-data PNG chunks here...
49+ PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo) {
50+ ChunkMetadata = metadata
51+ };
52+ pngWriter.GetChunksList( ).Queue(pngChunkMeta);
53+ pngWriter.CompLevel = 5;// 9 is the maximum compression but thats too high for the small benefit it gives
54+ pngWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman;
55+
56+ return pngWriter;
57+ }
58+
59+ protected virtual void ExtractBlockColor(BlockPos tmpPos, Block block, float slopeBoost,out int red, out int green, out int blue )
60+ {
61+ int avgCol, rndCol, col, packedFormat;
62+
63+ if (SeasonalColors) {
64+ avgCol = block.GetColor(ClientAPI, tmpPos);
65+ rndCol = block.GetRandomColor(ClientAPI, tmpPos, BlockFacing.UP);
66+ col = ColorUtil.ColorOverlay(avgCol, rndCol, 0.125f);
67+ packedFormat = ColorUtil.ColorMultiply3Clamped(col, slopeBoost);
68+
69+ red = ColorUtil.ColorB(packedFormat);
70+ green = ColorUtil.ColorG(packedFormat);
71+ blue = ColorUtil.ColorR(packedFormat);
72+ }
73+ else {
74+ col = block.GetColorWithoutTint(ClientAPI, tmpPos);
75+ //How to set as Eternal-Summer???
76+ //col = ClientAPI.World.ApplyColorMapOnRgba(block.ClimateColorMapForMap, block.SeasonColorMapForMap, col, tmpPos.X, tmpPos.Y, tmpPos.Z);
77+
78+ /*
79+ int greenAmp = ColorUtil.ColorG(127);
80+ col = ColorUtil.ColorOverlay(col, greenAmp, 0.125f);
81+ */
82+ packedFormat = ColorUtil.ColorMultiply3Clamped(col, slopeBoost);
83+
84+ red = ColorUtil.ColorB(packedFormat);
85+ green = ColorUtil.ColorG(packedFormat);
86+ blue = ColorUtil.ColorR(packedFormat);
87+ }
88+ }
89+ }
90+}
91+
--- a/Automap/Renderers/AlternateRenderer.cs
+++ b/Automap/Renderers/AlternateRenderer.cs
@@ -9,11 +9,9 @@ using Vintagestory.API.MathTools;
99
1010 namespace Automap
1111 {
12- public class AlternateRenderer : IChunkRenderer
12+ public class AlternateRenderer : AChunkRenderer
1313 {
14- private readonly int chunkSize;
15-
16-
14+
1715 /// <summary>
1816 /// V.G.D:'s Alternative renderer
1917 /// </summary>
@@ -21,7 +19,7 @@ namespace Automap
2119 /// <param name="logger">Logger.</param>
2220 public AlternateRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger)
2321 {
24- chunkSize = ClientAPI.World.BlockAccessor.ChunkSize;
22+
2523 }
2624
2725 public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount)
--- a/Automap/Renderers/IChunkRenderer.cs
+++ /dev/null
@@ -1,27 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-
4-using Hjg.Pngcs;
5-
6-using Vintagestory.API.Client;
7-using Vintagestory.API.Common;
8-using Vintagestory.API.MathTools;
9-
10-namespace Automap
11-{
12- public abstract class IChunkRenderer
13- {
14- public virtual ICoreClientAPI ClientAPI { get; protected set; }
15- public virtual ILogger Logger { get; protected set; }
16- public virtual Dictionary<int, BlockDesignator> BlockID_Designators { get; set; }
17-
18- protected IChunkRenderer(ICoreClientAPI clientAPI, ILogger logger)
19- {
20- this.ClientAPI = clientAPI;
21- this.Logger = logger;
22- }
23-
24- public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount);
25- }
26-}
27-
--- a/Automap/Renderers/StandardRenderer.cs
+++ b/Automap/Renderers/StandardRenderer.cs
@@ -9,9 +9,9 @@ using Vintagestory.API.MathTools;
99
1010 namespace Automap
1111 {
12- public class StandardRenderer : IChunkRenderer
12+ public class StandardRenderer : AChunkRenderer
1313 {
14- private readonly int chunkSize;
14+
1515
1616
1717 /// <summary>
@@ -19,9 +19,9 @@ namespace Automap
1919 /// </summary>
2020 /// <param name="clientAPI">Client API.</param>
2121 /// <param name="logger">Logger.</param>
22- public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger)
22+ public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger, bool seasonalColor) : base(clientAPI, logger, seasonalColor)
2323 {
24- chunkSize = ClientAPI.World.BlockAccessor.ChunkSize;
24+
2525 }
2626
2727 public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount)
@@ -61,7 +61,7 @@ namespace Automap
6161 int localX = localpos.X;
6262 int localZ = localpos.Y;
6363
64- float b = 1;
64+ float slopeBoost = 1;
6565 int leftTop, rightTop, leftBot;
6666
6767 IMapChunk leftTopMapChunk = mc;
@@ -102,10 +102,10 @@ namespace Automap
102102
103103 float slopeness = (leftTop + rightTop + leftBot);
104104
105- if (slopeness > 0) b = 1.2f;
106- if (slopeness < 0) b = 0.8f;
105+ if (slopeness > 0) slopeBoost = 1.2f;
106+ if (slopeness < 0) slopeBoost = 0.8f;
107107
108- b -= 0.15f; //Slope boost value
108+ slopeBoost -= 0.15f; //Slope boost value
109109
110110 if (chunksColumn[localChunkY] == null)
111111 {
@@ -120,15 +120,9 @@ namespace Automap
120120
121121 tmpPos.Set(chunkSize * chunkPos.X + localpos.X, mapY, chunkSize * chunkPos.Y + localpos.Y);
122122
123- int avgCol = block.GetColor(ClientAPI, tmpPos);
124- int rndCol = block.GetRandomColor(ClientAPI, tmpPos, BlockFacing.UP);
125- int col = ColorUtil.ColorOverlay(avgCol, rndCol, 0.125f);
126- var packedFormat = ColorUtil.ColorMultiply3Clamped(col, b);
127-
128- int red = ColorUtil.ColorB(packedFormat);
129- int green = ColorUtil.ColorG(packedFormat);
130- int blue = ColorUtil.ColorR(packedFormat);
123+ int red, green, blue;
131124
125+ ExtractBlockColor(tmpPos, block, slopeBoost, out red, out green, out blue);
132126
133127 //============ POI Population =================
134128 if (BlockID_Designators.ContainsKey(blockId))
--- a/Automap/Subsystems/AutomapSystem.cs
+++ b/Automap/Subsystems/AutomapSystem.cs
@@ -28,7 +28,7 @@ namespace Automap
2828 private Snapshotter snapshot;
2929 private ICoreClientAPI ClientAPI { get; set; }
3030 private ILogger Logger { get; set; }
31- private IChunkRenderer ChunkRenderer { get; set; }
31+ private AChunkRenderer ChunkRenderer { get; set; }
3232 private JsonGenerator JsonGenerator { get; set; }
3333
3434 internal const string _mapPath = @"Maps";
@@ -72,7 +72,7 @@ namespace Automap
7272 configuration = config;
7373
7474 //TODO:Choose which one from GUI
75- this.ChunkRenderer = new StandardRenderer(clientAPI, logger);
75+ this.ChunkRenderer = new StandardRenderer(clientAPI, logger, this.configuration.SeasonalColors);
7676
7777 //Listen on bus for commands
7878 ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey);
@@ -218,7 +218,7 @@ namespace Automap
218218 }
219219 ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta);
220220
221- PngWriter pngWriter = SetupPngImage(mostActiveCol.Key, ref chunkMeta);
221+ PngWriter pngWriter = ChunkRenderer.SetupPngImage(mostActiveCol.Key, path, _chunkPath, ref chunkMeta);
222222 ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter, out updatedPixels);
223223
224224 if (updatedPixels > 0)
@@ -526,29 +526,7 @@ namespace Automap
526526
527527 }
528528
529- private PngWriter SetupPngImage(Vec2i coord, ref ColumnMeta metadata)
530- {
531- ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false);
532-
533- string filename = $"{coord.X}_{coord.Y}.png";
534- filename = Path.Combine(path, _chunkPath ,filename);
535-
536- PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true);
537- PngMetadata meta = pngWriter.GetMetadata();
538- meta.SetTimeNow();
539- meta.SetText("Chunk_X", coord.X.ToString("D"));
540- meta.SetText("Chunk_Y", coord.Y.ToString("D"));
541- //Setup specialized meta-data PNG chunks here...
542- PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo)
543- {
544- ChunkMetadata = metadata
545- };
546- pngWriter.GetChunksList().Queue(pngChunkMeta);
547- pngWriter.CompLevel = 5;// 9 is the maximum compression but thats too high for the small benefit it gives
548- pngWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman;
549529
550- return pngWriter;
551- }
552530
553531 /// <summary>
554532 /// Does the heavy lifting of Scanning columns of chunks - scans for BlockEntity, creates Heightmap and stats...
--- a/Automap/Subsystems/JsonGenerator.cs
+++ b/Automap/Subsystems/JsonGenerator.cs
@@ -77,7 +77,7 @@ namespace Automap
7777 jsonWriter.WriteKeyValue("genTime", DateTimeOffset.UtcNow);
7878
7979 jsonWriter.WriteKeyRawValue("startCoords", $"[{startChunkColumn.X},{startChunkColumn.Y}]");
80-
80+ jsonWriter.WriteKeyRawValue("defaultSpawnPos", $"[{ClientAPI.World.DefaultSpawnPosition.AsBlockPos.X},{ClientAPI.World.DefaultSpawnPosition.AsBlockPos.Y},{ClientAPI.World.DefaultSpawnPosition.AsBlockPos.Z}]" );
8181 jsonWriter.WriteKeyValue("chunkSize", chunkSize);
8282
8383 jsonWriter.WriteArray("edges", new int[]{