• R/O
  • HTTP
  • SSH
  • HTTPS

标签
No 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]


File Info

Rev. 1c8849af29a916822885541c010ffc4b7bb90d5a
大小 3,252 字节
时间 2022-05-02 03:22:25
作者 melchior
Log Message

2nd Entity processing fix attempt

Content

using System;
using System.Collections.Generic;
using System.IO;

using Hjg.Pngcs;
using Hjg.Pngcs.Chunks;

using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.MathTools;

namespace Automap
{
    public abstract class AChunkRenderer
    {		
		protected readonly int chunkSize;

        public virtual ICoreClientAPI ClientAPI { get; protected set; }
        public virtual ILogger Logger { get; protected set; }
        public virtual Dictionary<int, BlockDesignator> BlockID_Designators { get; set; }
		public virtual bool SeasonalColors { get; }
		public virtual PngWriter PngWriter { get; set;}

		protected AChunkRenderer(ICoreClientAPI clientAPI, ILogger logger, bool useSeasonColor = true)
		{
			this.ClientAPI = clientAPI;
			this.Logger = logger;
			this.SeasonalColors = useSeasonColor;
			this.chunkSize = ClientAPI.World.BlockAccessor.ChunkSize;

		}

        public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta targetColMeta, ref ColumnsMetadata allCols, out uint pixelCount);

		public virtual PngWriter SetupPngImage(Vec2i coord, string path, string chunkPath, ref ColumnMeta metadata)
		{
		ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false);

		string filename = $"{coord.X}_{coord.Y}.png";
		filename = Path.Combine(path, chunkPath, filename);

		this.PngWriter = FileHelper.CreatePngWriter(filename, imageInf, true);
		PngMetadata meta = this.PngWriter.GetMetadata( );
		meta.SetTimeYMDHMS(
				DateTime.UtcNow.Year,
				DateTime.UtcNow.Month,
				DateTime.UtcNow.Day,
				DateTime.UtcNow.Hour,
				DateTime.UtcNow.Minute,
				DateTime.UtcNow.Second);
		meta.SetText("Chunk_X", coord.X.ToString("D"));
		meta.SetText("Chunk_Y", coord.Y.ToString("D"));
		meta.SetText("PxSz", "1");
		var transparencyChunk = meta.CreateTRNSChunk( );
		transparencyChunk.SetRGB(0, 0, 0);//Same as Snapshots
		string gameDate = $"{ClientAPI.World.Calendar.DayOfYear:D3}-{ClientAPI.World.Calendar.Year}";
		meta.SetText("GameDY", gameDate);

		//Setup specialized meta-data PNG chunks here...
		PngMetadataChunk pngChunkMeta = new PngMetadataChunk(this.PngWriter.ImgInfo) {
			ChunkMetadata = metadata
		};
		this.PngWriter.GetChunksList( ).Queue(pngChunkMeta);
		this.PngWriter.CompLevel = 5;// 9 is the maximum compression but thats too high for the small benefit it gives
		this.PngWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman;

		return this.PngWriter;
		}

		protected virtual void ExtractBlockColor(BlockPos tmpPos, Block block, float slopeBoost, out int red, out int green, out int blue)
		{
		int avgCol, rndCol, col, packedFormat;

		if (SeasonalColors) {
		avgCol = block.GetColor(ClientAPI, tmpPos);
		rndCol = block.GetRandomColor(ClientAPI, tmpPos, BlockFacing.UP);
		col = ColorUtil.ColorOverlay(avgCol, rndCol, 0.125f);
		}
		else {
		col = block.GetColorWithoutTint(ClientAPI, tmpPos);
		col = ClientAPI.World.ApplyColorMapOnRgba(block.ClimateColorMapForMap, null, col, tmpPos.X, tmpPos.Y, tmpPos.Z, false);
		}
		packedFormat = ColorUtil.ColorMultiply3Clamped(col, slopeBoost);

		red = ColorUtil.ColorB(packedFormat);
		green = ColorUtil.ColorG(packedFormat);
		blue = ColorUtil.ColorR(packedFormat);
		}
    }
}