• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#windowsobjective-ccocoaqt誰得pythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Automap (client) [VS plugin mod]


Commit MetaInfo

修订版4539caba346d37f8ab34d97be51e21d90faf327b (tree)
时间2020-01-28 08:57:28
作者melchior <melchior@user...>
Commitermelchior

Log Message

W.I.P. for Split Rendering; Working Entity P.O.I. - only traders so far

更改概述

差异

--- a/Automap/Automap.csproj
+++ b/Automap/Automap.csproj
@@ -75,7 +75,7 @@
7575 <Compile Include="Properties\AssemblyInfo.cs" />
7676 <Compile Include="Helpers.cs" />
7777 <Compile Include="Data\PointOfInterest.cs" />
78- <Compile Include="Data\Designator.cs" />
78+ <Compile Include="Data\BlockDesignator.cs" />
7979 <Compile Include="Designators\DefaultDesignators.cs" />
8080 <Compile Include="Data\ColumnMeta.cs" />
8181 <Compile Include="Data\PngMetadataChunk.cs" />
@@ -84,6 +84,8 @@
8484 <Compile Include="Renderers\IChunkRenderer.cs" />
8585 <Compile Include="Renderers\StandardRenerer.cs" />
8686 <Compile Include="Renderers\AlternateRenderer.cs" />
87+ <Compile Include="Data\EntitiesOfInterest.cs" />
88+ <Compile Include="Data\EntityDesignator.cs" />
8789 </ItemGroup>
8890 <ItemGroup>
8991 <Folder Include="VS_libs\" />
--- a/Automap/Data/Designator.cs
+++ b/Automap/Data/BlockDesignator.cs
@@ -9,25 +9,25 @@ using Vintagestory.API.MathTools;
99
1010 namespace Automap
1111 {
12- public delegate void DesignatonAction(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block);
12+ public delegate void BlockDesignatonAction(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block);
1313
1414 /// <summary>
1515 /// Point of Interest Rule Designator
1616 /// </summary>
17- public class Designator
17+ public class BlockDesignator
1818 {
1919 public Color OverwriteColor;
20- public DesignatonAction SpecialAction;
20+ public BlockDesignatonAction SpecialAction;
2121 public AssetLocation Pattern;
2222 public EnumBlockMaterial? Material;
2323 public bool Enabled { get; set; }
2424
25- private Designator( )
25+ private BlockDesignator( )
2626 {
2727 throw new NotSupportedException( );
2828 }
2929
30- public Designator( AssetLocation pattern , Color overwriteColor, EnumBlockMaterial? material)
30+ public BlockDesignator( AssetLocation pattern , Color overwriteColor, EnumBlockMaterial? material)
3131 {
3232 this.Pattern = pattern;
3333 this.OverwriteColor = overwriteColor;
@@ -35,7 +35,7 @@ namespace Automap
3535 this.Enabled = true;
3636 }
3737
38- public Designator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material ,DesignatonAction specialAct )
38+ public BlockDesignator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material ,BlockDesignatonAction specialAct )
3939 {
4040 this.Pattern = pattern;
4141 this.OverwriteColor = overwriteColor;
--- a/Automap/Data/ColumnMeta.cs
+++ b/Automap/Data/ColumnMeta.cs
@@ -47,7 +47,8 @@ namespace Automap
4747 [ProtoMember(11)]
4848 public ushort NonAirBlocks;
4949
50- [ProtoMember(12)]
50+ //[ProtoMember(12,OverwriteList = true)]
51+ [ProtoIgnore]
5152 public ushort[ , ] HeightMap;
5253
5354 public ColumnMeta(Vec2i loc, int chunkSize = 32)
--- /dev/null
+++ b/Automap/Data/EntitiesOfInterest.cs
@@ -0,0 +1,48 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Collections.ObjectModel;
4+
5+using System.Linq;
6+
7+using Vintagestory.API.Common.Entities;
8+
9+namespace Automap
10+{
11+ /// <summary>
12+ /// Entities of interest.
13+ /// </summary>
14+ /// <remarks>Tracked by ID - these never leave.</remarks>
15+ public class EntitiesOfInterest
16+ {
17+ private Dictionary<long, PointOfInterest> entitySet = new Dictionary<long, PointOfInterest>(50);
18+
19+
20+ internal void Upsert(Entity something, string message = @"")
21+ {
22+ if (entitySet.ContainsKey(something.EntityId)) {
23+ var movingPOI = entitySet[something.EntityId];
24+ movingPOI.Location = something.Pos.AsBlockPos.Copy( );
25+ movingPOI.Timestamp = DateTimeOffset.UtcNow;
26+ }
27+ else {
28+ PointOfInterest newPOI = new PointOfInterest( );
29+ newPOI.EntityId = something.EntityId;
30+ newPOI.Location = something.Pos.AsBlockPos.Copy( );
31+ newPOI.Timestamp = DateTimeOffset.UtcNow;
32+ newPOI.Notes = message;
33+ entitySet.Add(something.EntityId, newPOI );
34+ }
35+
36+ }
37+
38+
39+ public List<PointOfInterest> PointsList {
40+ get
41+ {
42+ return entitySet.Values.ToList();
43+ }
44+ }
45+
46+ }
47+}
48+
--- /dev/null
+++ b/Automap/Data/EntityDesignator.cs
@@ -0,0 +1,54 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Collections.ObjectModel;
4+using System.Drawing;
5+
6+using Vintagestory.API.Client;
7+using Vintagestory.API.Common;
8+using Vintagestory.API.Common.Entities;
9+using Vintagestory.API.MathTools;
10+
11+namespace Automap
12+{
13+ public delegate void EntityDesignatonAction(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity);
14+
15+ /// <summary>
16+ /// Point of Interest Rule Designator
17+ /// </summary>
18+ public class EntityDesignator
19+ {
20+ public Color OverwriteColor;
21+ public EntityDesignatonAction SpecialAction;
22+ public AssetLocation Pattern;
23+ public EnumEntityState? StateCheck;//Needed?
24+ public bool Enabled { get; set; }
25+
26+ private EntityDesignator( )
27+ {
28+ throw new NotSupportedException( );
29+ }
30+
31+ public EntityDesignator(AssetLocation pattern, Color overwriteColor, EnumEntityState? state)
32+ {
33+ this.Pattern = pattern;
34+ this.OverwriteColor = overwriteColor;
35+ this.StateCheck = state;
36+ this.Enabled = true;
37+ }
38+
39+ public EntityDesignator(AssetLocation pattern, Color overwriteColor, EnumEntityState? state, EntityDesignatonAction specialAct)
40+ {
41+ this.Pattern = pattern;
42+ this.OverwriteColor = overwriteColor;
43+ this.StateCheck = state;
44+ this.SpecialAction = specialAct;
45+ this.Enabled = true;
46+ }
47+
48+ public override string ToString( )
49+ {
50+ return Pattern.ToShortString( ) + "|" + OverwriteColor.Name + "|" + StateCheck ?? "";
51+ }
52+ }
53+}
54+
--- a/Automap/Data/PointOfInterest.cs
+++ b/Automap/Data/PointOfInterest.cs
@@ -10,11 +10,11 @@ namespace Automap
1010 /// Actual Physical Point in space - that is interesting.
1111 /// </summary>
1212 public struct PointOfInterest
13- {
14- //public CollectibleObject Thing;
13+ {
1514 public string Notes;
1615 public BlockPos Location;
1716 public DateTimeOffset Timestamp;
17+ public long? EntityId;
1818 }
1919
2020 public class PointsOfInterest : KeyedCollection<BlockPos, PointOfInterest>
--- a/Automap/Designators/DefaultDesignators.cs
+++ b/Automap/Designators/DefaultDesignators.cs
@@ -4,6 +4,7 @@ using System.Drawing;
44
55 using Vintagestory.API.Client;
66 using Vintagestory.API.Common;
7+using Vintagestory.API.Common.Entities;
78 using Vintagestory.API.MathTools;
89 using Vintagestory.GameContent;
910
@@ -11,45 +12,71 @@ namespace Automap
1112 {
1213 public static class DefaultDesignators
1314 {
14- public static Designator Roads =
15- new Designator(
15+ public static BlockDesignator Roads =
16+ new BlockDesignator(
1617 new AssetLocation("game", "stonepath"),
1718 Color.Yellow,
1819 EnumBlockMaterial.Gravel
1920 );
2021
21- public static Designator GroundSigns =
22- new Designator(
22+ public static BlockDesignator GroundSigns =
23+ new BlockDesignator(
2324 new AssetLocation("game", "sign-ground"),
2425 Color.Teal,
2526 EnumBlockMaterial.Wood,
2627 DecodeSign
2728 );
2829
29- public static Designator WallSigns =
30- new Designator(
30+ public static BlockDesignator WallSigns =
31+ new BlockDesignator(
3132 new AssetLocation("game", "sign-wall"),
3233 Color.Teal,
3334 EnumBlockMaterial.Wood,
3435 DecodeSign
3536 );
3637
37- public static Designator PostSigns =
38- new Designator(
38+ public static BlockDesignator PostSigns =
39+ new BlockDesignator(
3940 new AssetLocation("game", "signpost"),
4041 Color.Teal,
4142 EnumBlockMaterial.Wood,
4243 DecodePostSign
4344 );
4445
45- public static Designator Translocators =
46- new Designator(
46+ public static BlockDesignator Translocators =
47+ new BlockDesignator(
4748 new AssetLocation("game", "statictranslocator-normal"),
4849 Color.Violet,
4950 EnumBlockMaterial.Metal
5051 //DecodeTranslocator
5152 );
5253
54+ public static EntityDesignator Traders =
55+ new EntityDesignator(
56+ new AssetLocation("game", "humanoid-trader"),
57+ Color.LightGoldenrodYellow,
58+ EnumEntityState.Active,
59+ KeepTrackOfMerchant
60+ );
61+
62+
63+ public static List<BlockDesignator> DefaultBlockDesignators( )
64+ {
65+ return new List<BlockDesignator>{
66+ DefaultDesignators.Roads,
67+ DefaultDesignators.GroundSigns,
68+ DefaultDesignators.WallSigns,
69+ DefaultDesignators.PostSigns,
70+ };
71+ }
72+
73+ public static List<EntityDesignator> DefaultEntityDesignators( )
74+ {
75+ return new List<EntityDesignator>{
76+ DefaultDesignators.Traders,
77+ };
78+ }
79+
5380 internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
5481 {
5582 clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
@@ -91,8 +118,17 @@ namespace Automap
91118 }
92119 }
93120
121+ internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
122+ {
123+ clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName( ), posn);
94124
95-
125+ var message = $"{entity.GetName( )}";
126+ var traderJoe = entity as EntityTrader;
127+ if (traderJoe.TradeProps != null) {
128+ message = $"{traderJoe.GetName( )} Alive:{traderJoe.Alive} - Gears: {traderJoe.TradeProps.Money}, ";
129+ }
130+ poi.Upsert(entity, message);
131+ }
96132 }
97133 }
98134
--- a/Automap/Renderers/IChunkRenderer.cs
+++ b/Automap/Renderers/IChunkRenderer.cs
@@ -13,7 +13,7 @@ namespace Automap
1313 {
1414 public virtual ICoreClientAPI ClientAPI { get; protected set; }
1515 public virtual ILogger Logger { get; protected set; }
16- public virtual Dictionary<int, Designator> BlockID_Designators { get; set; }
16+ public virtual Dictionary<int, BlockDesignator> BlockID_Designators { get; set; }
1717
1818 protected IChunkRenderer(ICoreClientAPI clientAPI, ILogger logger)
1919 {
--- a/Automap/Renderers/StandardRenerer.cs
+++ b/Automap/Renderers/StandardRenerer.cs
@@ -33,8 +33,7 @@ namespace Automap
3333 var chunksColumn = new IWorldChunk[ClientAPI.World.BlockAccessor.MapSizeY / chunkSize];
3434
3535 int topChunkY = mc.YMax / chunkSize;//Heywaitaminute -- this isn't a highest FEATURE, if Rainmap isn't accurate!
36- //Metadata of DateTime chunk was edited, chunk coords.,world-seed? Y-Max feature height
37- //Grab a chunk COLUMN... Topmost Y down...
36+
3837 for (int chunkY = 0; chunkY <= topChunkY; chunkY++) {
3938 chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y);
4039 //What to do if chunk is a void? invalid?
@@ -125,11 +124,15 @@ namespace Automap
125124
126125
127126 //============ POI Population =================
128- if (BlockID_Designators.ContainsKey(blockId)) {
127+ if (BlockID_Designators.ContainsKey(blockId)) {
129128 var desig = BlockID_Designators[blockId];
130- red = desig.OverwriteColor.R;
131- green = desig.OverwriteColor.G;
132- blue = desig.OverwriteColor.B;
129+
130+ if (desig.Enabled)
131+ {
132+ red = desig.OverwriteColor.R;
133+ green = desig.OverwriteColor.G;
134+ blue = desig.OverwriteColor.B;
135+ }
133136 }
134137
135138 ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue);
--- a/Automap/Subsystems/AutomapSystem.cs
+++ b/Automap/Subsystems/AutomapSystem.cs
@@ -15,9 +15,9 @@ using Hjg.Pngcs.Chunks;
1515
1616 using Vintagestory.API.Client;
1717 using Vintagestory.API.Common;
18+using Vintagestory.API.Common.Entities;
1819 using Vintagestory.API.MathTools;
19-
20-
20+using Vintagestory.Common;
2121
2222 namespace Automap
2323 {
@@ -37,12 +37,14 @@ namespace Automap
3737 private ConcurrentDictionary<Vec2i, uint> columnCounter = new ConcurrentDictionary<Vec2i, uint>(3, 150 );
3838 private ColumnsMetadata chunkTopMetadata;
3939 private PointsOfInterest POIs;
40+ private EntitiesOfInterest EOIs;
41+
42+ internal Dictionary<int, BlockDesignator> BlockID_Designators { get; private set;}
43+ internal Dictionary<AssetLocation, EntityDesignator> Entity_Designators { get; private set; }
4044
41- internal Dictionary<int, Designator> BlockID_Designators { get; private set;}
4245 internal bool Enabled { get; set; }
4346 //Run status, Chunks processed, stats, center of map....
44- internal uint nullChunkCount;
45- internal uint updatedChunksTotal;
47+ internal uint nullChunkCount, updatedChunksTotal;
4648 internal Vec2i startChunkColumn;
4749
4850 private readonly int chunkSize;
@@ -141,6 +143,7 @@ namespace Automap
141143
142144 ColumnMeta chunkMeta = CreateColumnMetadata(mostActiveCol,mapChunk);
143145 PngWriter pngWriter = SetupPngImage(mostActiveCol.Key, chunkMeta);
146+ UpdateEntityMetadata( );
144147 ProcessChunkBlocks(mostActiveCol.Key, mapChunk, chunkMeta);
145148
146149 uint updatedPixels = 0;
@@ -193,24 +196,19 @@ namespace Automap
193196 private void Prefill_POI_Designators( )
194197 {
195198 this.POIs = new PointsOfInterest( );
196- this.BlockID_Designators = new Dictionary<int, Designator>( );
199+ this.EOIs = new EntitiesOfInterest( );
200+ this.BlockID_Designators = new Dictionary<int, BlockDesignator>( );
201+ this.Entity_Designators = new Dictionary<AssetLocation, EntityDesignator>( );
197202
198203 //Add special marker types for BlockID's of "Interest", overwrite colour, and method
199204
200- var standardDesignators = new List<Designator>{
201- DefaultDesignators.Roads,
202- DefaultDesignators.GroundSigns,
203- DefaultDesignators.WallSigns,
204- DefaultDesignators.PostSigns,
205- };
206-
207- Install_POI_Designators(standardDesignators);
205+ Install_POI_Designators(DefaultDesignators.DefaultBlockDesignators(), DefaultDesignators.DefaultEntityDesignators());
208206 }
209207
210- private void Install_POI_Designators(ICollection<Designator> designators)
208+ private void Install_POI_Designators(ICollection<BlockDesignator> blockDesig, List<EntityDesignator> entDesig)
211209 {
212- Logger.VerboseDebug("Connecting {0} configured Designators", designators.Count);
213- foreach (var designator in designators) {
210+ Logger.VerboseDebug("Connecting {0} standard Block-Designators", blockDesig.Count);
211+ foreach (var designator in blockDesig) {
214212 var blockIDs = Helpers.ArbitrarytBlockIdHunter(ClientAPI, designator.Pattern, designator.Material);
215213 if (blockIDs.Count > 0) { Logger.VerboseDebug("Designator {0} has {1} associated blockIDs", designator.ToString( ), blockIDs.Count); }
216214 foreach (var entry in blockIDs) {
@@ -218,6 +216,24 @@ namespace Automap
218216 }
219217 }
220218 this.ChunkRenderer.BlockID_Designators = BlockID_Designators;
219+
220+
221+ Logger.VerboseDebug("Connecting {0} standard Entity-Designators", entDesig.Count);
222+ foreach (var designator in entDesig) {
223+ //Get Variants first, from EntityTypes...better be populated!
224+ var matched = ClientAPI.World.EntityTypes.FindAll(entp => entp.Code.BeginsWith(designator.Pattern.Domain, designator.Pattern.Path));
225+
226+ foreach (var match in matched) {
227+ Logger.VerboseDebug("Linked Entity: {0} Designator: {1}", match.Code, designator);
228+ this.Entity_Designators.Add(match.Code, designator);
229+ }
230+
231+
232+
233+ //EntityProperties props = ClientAPI.World.GetEntityType(designator.Pattern);
234+ }
235+
236+
221237 }
222238
223239 //TODO: Convert to RAZOR model
@@ -384,14 +400,25 @@ namespace Automap
384400
385401
386402 tableWriter.RenderEndTag( );//</table>
387-
403+
388404 //############## POI list #####################
405+ tableWriter.RenderBeginTag(HtmlTextWriterTag.P);
406+ tableWriter.WriteLine("Points of Interest");
407+ tableWriter.RenderEndTag( );
389408 tableWriter.RenderBeginTag(HtmlTextWriterTag.Ul);
390409 foreach (var poi in this.POIs) {
391410 tableWriter.RenderBeginTag(HtmlTextWriterTag.Li);
392- tableWriter.WriteEncodedText(poi.Timestamp.ToString("u"));
393- tableWriter.WriteEncodedText(poi.Notes);
394411 tableWriter.WriteEncodedText(poi.Location.PrettyCoords(this.ClientAPI));
412+ tableWriter.WriteEncodedText(poi.Notes);
413+ tableWriter.WriteEncodedText(poi.Timestamp.ToString("u"));
414+ tableWriter.RenderEndTag( );
415+ }
416+
417+ foreach (var eoi in this.EOIs.PointsList) {
418+ tableWriter.RenderBeginTag(HtmlTextWriterTag.Li);
419+ tableWriter.WriteEncodedText(eoi.Location.PrettyCoords(this.ClientAPI));
420+ tableWriter.WriteEncodedText(eoi.Notes);
421+ tableWriter.WriteEncodedText(eoi.Timestamp.ToString("u") );
395422 tableWriter.RenderEndTag( );
396423 }
397424
@@ -421,10 +448,7 @@ namespace Automap
421448 mostActiveCol.Key.Y * chunkSize);
422449
423450 var climate = ClientAPI.World.BlockAccessor.GetClimateAt(equivBP);
424- data.UpdateFieldsFrom(climate, mapChunk,TimeSpan.FromHours(ClientAPI.World.Calendar.TotalHours));
425-
426-
427-
451+ data.UpdateFieldsFrom(climate, mapChunk,TimeSpan.FromHours(ClientAPI.World.Calendar.TotalHours));
428452
429453 return data;
430454 }
@@ -449,6 +473,8 @@ namespace Automap
449473
450474
451475 foreach (var shardFile in files) {
476+
477+ if (shardFile.Length < 1000) continue;
452478 var result = chunkShardRegex.Match(shardFile.Name);
453479 if (result.Success) {
454480 int X_chunk_pos = int.Parse(result.Groups["X"].Value );
@@ -502,16 +528,43 @@ namespace Automap
502528 }
503529
504530 /// <summary>
505- /// Does the heavy lifting of Scanning the whole (surface) chunk - creates Heightmap and Processes POIs, and stats...
531+ /// Does the heavy lifting of Scanning the whole (surface) chunk - creates Heightmap and Processes POIs, Entities, and stats...
506532 /// </summary>
507533 /// <param name="key">Chunk Coordinate</param>
508534 /// <param name="mapChunk">Map chunk.</param>
509535 /// <param name="chunkMeta">Chunk metadata</param>
510536 private void ProcessChunkBlocks(Vec2i key, IMapChunk mapChunk, ColumnMeta chunkMeta)
511537 {
538+ int topChunkY = mapChunk.YMax / chunkSize;
539+ WorldChunk chunkData = ( Vintagestory.Common.WorldChunk )ClientAPI.World.BlockAccessor.GetChunk(key.X, topChunkY, key.Y);
540+
541+
542+
543+ }
544+
545+ private void UpdateEntityMetadata( )
546+ {
547+ Logger.Debug("Presently {0} Entities", ClientAPI.World.LoadedEntities.Count);
548+ //Mabey scan only for 'new' entities by tracking ID in set?
549+ foreach (var loadedEntity in ClientAPI.World.LoadedEntities.ToList()) {
550+
551+ #if DEBUG
552+ //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos} <<<<<<<<<<<<");
553+ #endif
512554
555+ var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Value.Code));
556+ if (dMatch.Value != null) {
557+ if (dMatch.Value.Enabled) {
558+ dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Value.LocalPos.AsBlockPos.Copy( ), loadedEntity.Value);
559+ }
513560 }
514561
562+ }
563+
564+
565+ }
566+
567+
515568
516569
517570