From 5858de0b0803052539073b82b548d95ac6d11103 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Thu, 29 Aug 2019 14:36:31 +0200 Subject: [PATCH] More parallax debugging stuff. --- Content.Client/Parallax/ParallaxGenerator.cs | 3 +- Content.Client/Parallax/ParallaxManager.cs | 45 ++++++++++++++------ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Content.Client/Parallax/ParallaxGenerator.cs b/Content.Client/Parallax/ParallaxGenerator.cs index 42ff0e2406..76e2d76e9a 100644 --- a/Content.Client/Parallax/ParallaxGenerator.cs +++ b/Content.Client/Parallax/ParallaxGenerator.cs @@ -20,7 +20,7 @@ namespace Content.Client.Parallax { private readonly List Layers = new List(); - public static Image GenerateParallax(TomlTable config, Size size, ISawmill sawmill) + public static Image GenerateParallax(TomlTable config, Size size, ISawmill sawmill, List> debugLayerDump) { sawmill.Debug("Generating parallax!"); var generator = new ParallaxGenerator(); @@ -34,6 +34,7 @@ namespace Content.Client.Parallax foreach (var layer in generator.Layers) { layer.Apply(image); + debugLayerDump?.Add(image.Clone()); sawmill.Debug("Layer {0} done!", count++); } diff --git a/Content.Client/Parallax/ParallaxManager.cs b/Content.Client/Parallax/ParallaxManager.cs index 12967824c8..34e15cd2b5 100644 --- a/Content.Client/Parallax/ParallaxManager.cs +++ b/Content.Client/Parallax/ParallaxManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Content.Client.Interfaces.Parallax; @@ -11,6 +12,7 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Utility; using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; namespace Content.Client.Parallax @@ -39,24 +41,24 @@ namespace Content.Client.Parallax return; } - Stream configStream = null; + var debugParallax = _configurationManager.GetCVar("parallax.debug"); string contents; TomlTable table; - try + // Load normal config into memory + if (!_resourceCache.TryContentFileRead(ParallaxConfigPath, out var configStream)) { - // Load normal config into memory - if (!_resourceCache.TryContentFileRead(ParallaxConfigPath, out configStream)) - { - Logger.ErrorS("parallax", "Parallax config not found."); - return; - } + Logger.ErrorS("parallax", "Parallax config not found."); + return; + } + using (configStream) + { using (var reader = new StreamReader(configStream, EncodingHelpers.UTF8)) { contents = reader.ReadToEnd(); } - if (_resourceCache.UserData.Exists(ParallaxConfigOld)) + if (!debugParallax && _resourceCache.UserData.Exists(ParallaxConfigOld)) { bool match; using (var data = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Open)) @@ -79,14 +81,17 @@ namespace Content.Client.Parallax table = Toml.ReadString(contents); } - finally + + List> debugImages = null; + if (debugParallax) { - configStream?.Dispose(); + debugImages = new List>(); } var sawmill = _logManager.GetSawmill("parallax"); // Generate the parallax in the thread pool. - var image = await Task.Run(() => ParallaxGenerator.GenerateParallax(table, new Size(1920, 1080), sawmill)); + var image = await Task.Run(() => + ParallaxGenerator.GenerateParallax(table, new Size(1920, 1080), sawmill, debugImages)); // And load it in the main thread for safety reasons. ParallaxTexture = Texture.LoadFromImage(image, "Parallax"); @@ -96,6 +101,21 @@ namespace Content.Client.Parallax image.SaveAsPng(stream); } + if (debugParallax) + { + var i = 0; + foreach (var debugImage in debugImages) + { + using (var stream = _resourceCache.UserData.Open(new ResourcePath($"/parallax_debug_{i}.png"), + FileMode.Create)) + { + debugImage.SaveAsPng(stream); + } + + i += 1; + } + } + image.Dispose(); using (var stream = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Create)) @@ -110,6 +130,7 @@ namespace Content.Client.Parallax public void PostInject() { _configurationManager.RegisterCVar("parallax.enabled", true); + _configurationManager.RegisterCVar("parallax.debug", false); } } }