• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

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

修訂f2daf9ef05f9f97f40f18a56be811851c4cbe3c0 (tree)
時間2020-11-26 12:11:50
作者melchior <melchior@user...>
Commitermelchior

Log Message

Added configurability for Renderer choice,
*New* Flat Renderer added

Change Summary

差異

--- a/Automap/Automap.csproj
+++ b/Automap/Automap.csproj
@@ -100,6 +100,7 @@
100100 <Compile Include="Subsystems\Snapshot.cs" />
101101 <Compile Include="Data\JSON\BlockPosJson.cs" />
102102 <Compile Include="Data\ColumnCounter.cs" />
103+ <Compile Include="Renderers\FlatRenderer.cs" />
103104 </ItemGroup>
104105 <ItemGroup>
105106 <Folder Include="VS_libs\" />
--- a/Automap/Data/PersistedConfiguration.cs
+++ b/Automap/Data/PersistedConfiguration.cs
@@ -20,7 +20,11 @@ namespace Automap
2020 /// <value>The seasonal colors.</value>
2121 public bool SeasonalColors { get; set; } = true;
2222
23- //public string ChosenRendererName { get; set; }
23+ /// <summary>
24+ /// Which appearance 'theme' should shards have?
25+ /// </summary>
26+ /// <value>'Standard' / 'Alternate' / 'Flat'</value>
27+ public string RendererName { get; set; } = @"Standard";
2428
2529 //All - Designators, setup
2630 public List<BlockDesignator> BlockDesignators { get; set; }
--- a/Automap/Renderers/AlternateRenderer.cs
+++ b/Automap/Renderers/AlternateRenderer.cs
@@ -11,13 +11,14 @@ namespace Automap
1111 {
1212 public class AlternateRenderer : AChunkRenderer
1313 {
14-
14+ public const string Name = @"Alternate";
15+
1516 /// <summary>
1617 /// V.G.D:'s Alternative renderer
1718 /// </summary>
1819 /// <param name="clientAPI">Client API.</param>
1920 /// <param name="logger">Logger.</param>
20- public AlternateRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger)
21+ public AlternateRenderer(ICoreClientAPI clientAPI, ILogger logger, bool seasonalColor) : base(clientAPI, logger)
2122 {
2223
2324 }
--- /dev/null
+++ b/Automap/Renderers/FlatRenderer.cs
@@ -0,0 +1,95 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+
5+using Hjg.Pngcs;
6+
7+using Vintagestory.API.Client;
8+using Vintagestory.API.Common;
9+using Vintagestory.API.MathTools;
10+using Vintagestory.Common;
11+
12+namespace Automap
13+{
14+ public class FlatRenderer : AChunkRenderer
15+ {
16+ public const string Name = @"Flat";
17+
18+ /// <summary>
19+ /// Renders shards similar to the OLD VS (1.8) version, plus P.O.I. markings.
20+ /// </summary>
21+ /// <param name="clientAPI">Client API.</param>
22+ /// <param name="logger">Logger.</param>
23+ public FlatRenderer(ICoreClientAPI clientAPI, ILogger logger, bool seasonalColor) : base(clientAPI, logger, seasonalColor)
24+ {
25+
26+ }
27+
28+ public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta targetColMeta, ref ColumnsMetadata allCols, out uint pixelCount)
29+ {
30+ pixelCount = 0;
31+ BlockPos tmpPos = new BlockPos( );
32+ Vec2i localpos = new Vec2i( );
33+
34+ var chunksColumn = new IWorldChunk[ClientAPI.World.BlockAccessor.MapSizeY / chunkSize];
35+
36+ //pre-create PNG line slices...
37+ ImageLine[ ] lines = Enumerable.Repeat(new object( ), chunkSize).Select(l => new ImageLine(this.PngWriter.ImgInfo)).ToArray( );
38+
39+ int topChunkY = targetColMeta.YMax / chunkSize;
40+
41+ for (int chunkY = 0; chunkY <= topChunkY; chunkY++) {
42+ chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y);
43+ WorldChunk ownChunk = chunksColumn[chunkY] as WorldChunk;
44+ if (ownChunk != null) {
45+ if (ownChunk.IsPacked( )) ownChunk.Unpack( );//Gah - probably done already by chunk processor
46+ }
47+ else {
48+ Logger.Warning("CHUNK A.W.O.L. : X{0} Y{1} Z{2} - Missing slice FOR COLUMN", chunkPos.X, chunkY, chunkPos.Y);
49+ //return;
50+ }
51+ }
52+
53+ for (int pixelIndex = 0; pixelIndex < (chunkSize * chunkSize); pixelIndex++) {
54+ MapUtil.PosInt2d(pixelIndex, chunkSize, localpos);
55+ int localX = localpos.X;
56+ int localZ = localpos.Y;
57+ ushort localY = targetColMeta.HeightMap[localX, localZ];
58+
59+ int localChunkY = localY / chunkSize;
60+ if (localChunkY >= (chunksColumn.Length)) continue;//Out of range!
61+ if (chunksColumn[localChunkY] == null) continue;//BIG Gaps!
62+
63+ int blockId = chunksColumn[localChunkY].MaybeBlocks[MapUtil.Index3d(localX, (localY % chunkSize), localZ, chunkSize, chunkSize)];
64+
65+ Block block = ClientAPI.World.Blocks[blockId];
66+
67+ tmpPos.Set(chunkSize * chunkPos.X + localpos.X, localY, chunkSize * chunkPos.Y + localpos.Y);
68+
69+ int red = 0, green = 0, blue = 0;
70+
71+ ExtractBlockColor(tmpPos, block, 1.0f, out red, out green, out blue);
72+
73+ //============ POI Population =================
74+ if (BlockID_Designators.ContainsKey(blockId)) {
75+ var desig = BlockID_Designators[blockId];
76+
77+ if (desig.Enabled) {
78+ red = desig.OverwriteColor.R;
79+ green = desig.OverwriteColor.G;
80+ blue = desig.OverwriteColor.B;
81+ }
82+ }
83+
84+ ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue);
85+ pixelCount++;
86+ }
87+
88+ for (int row = 0; row < this.PngWriter.ImgInfo.Rows; row++) {
89+ this.PngWriter.WriteRow(lines[row], row);
90+ }
91+
92+ this.PngWriter.End( );
93+ }
94+ }
95+}
\ No newline at end of file
--- a/Automap/Renderers/StandardRenderer.cs
+++ b/Automap/Renderers/StandardRenderer.cs
@@ -13,6 +13,7 @@ namespace Automap
1313 {
1414 public class StandardRenderer : AChunkRenderer
1515 {
16+ public const string Name = @"Standard";
1617
1718 /// <summary>
1819 /// Renders shards similar to the Default VS version, plus P.O.I. markings.
@@ -21,7 +22,7 @@ namespace Automap
2122 /// <param name="logger">Logger.</param>
2223 public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger, bool seasonalColor) : base(clientAPI, logger, seasonalColor)
2324 {
24-
25+
2526 }
2627
2728 public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta targetColMeta, ref ColumnsMetadata allCols, out uint pixelCount)
--- a/Automap/Subsystems/AutomapSystem.cs
+++ b/Automap/Subsystems/AutomapSystem.cs
@@ -73,8 +73,7 @@ namespace Automap
7373 ClientAPI.Event.LevelFinalize += EngageAutomap;
7474 configuration = config;
7575
76- //TODO:Choose which one from GUI
77- this.ChunkRenderer = new StandardRenderer(clientAPI, logger, this.configuration.SeasonalColors);
76+ this.ChunkRenderer = InstantiateChosenRenderer(config.RendererName);
7877
7978 //Listen on bus for commands
8079 ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey);
@@ -723,12 +722,32 @@ namespace Automap
723722 AddNote(cmdData.Notation);
724723 break;
725724 }
726-#if DEBUG
725+ #if DEBUG
727726 ClientAPI.TriggerChatMessage($"Automap commanded to: {cmdData.State} ");
728-#endif
727+ #endif
729728 }
730729 #endregion
731730
731+ private AChunkRenderer InstantiateChosenRenderer(string rendererName )
732+ {
733+ Logger.VerboseDebug("Using '{0}' style Shard Renderer", rendererName);
734+ switch (rendererName)
735+ {
736+ case StandardRenderer.Name:
737+ return new StandardRenderer(ClientAPI, Logger, this.configuration.SeasonalColors);
738+
739+ case AlternateRenderer.Name:
740+ return new AlternateRenderer(ClientAPI, Logger, this.configuration.SeasonalColors);
741+
742+ case FlatRenderer.Name:
743+ return new FlatRenderer(ClientAPI, Logger, this.configuration.SeasonalColors);
744+
745+ default:
746+ throw new ArgumentOutOfRangeException("rendererName",rendererName,"That value isn't supported or known...");
747+ }
748+
749+ return null;
750+ }
732751 }
733752
734753 }