More parallax debugging stuff.
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Content.Client.Parallax
|
|||||||
{
|
{
|
||||||
private readonly List<Layer> Layers = new List<Layer>();
|
private readonly List<Layer> Layers = new List<Layer>();
|
||||||
|
|
||||||
public static Image<Rgba32> GenerateParallax(TomlTable config, Size size, ISawmill sawmill)
|
public static Image<Rgba32> GenerateParallax(TomlTable config, Size size, ISawmill sawmill, List<Image<Rgba32>> debugLayerDump)
|
||||||
{
|
{
|
||||||
sawmill.Debug("Generating parallax!");
|
sawmill.Debug("Generating parallax!");
|
||||||
var generator = new ParallaxGenerator();
|
var generator = new ParallaxGenerator();
|
||||||
@@ -34,6 +34,7 @@ namespace Content.Client.Parallax
|
|||||||
foreach (var layer in generator.Layers)
|
foreach (var layer in generator.Layers)
|
||||||
{
|
{
|
||||||
layer.Apply(image);
|
layer.Apply(image);
|
||||||
|
debugLayerDump?.Add(image.Clone());
|
||||||
sawmill.Debug("Layer {0} done!", count++);
|
sawmill.Debug("Layer {0} done!", count++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.Client.Interfaces.Parallax;
|
using Content.Client.Interfaces.Parallax;
|
||||||
@@ -11,6 +12,7 @@ using Robust.Shared.IoC;
|
|||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using SixLabors.ImageSharp;
|
using SixLabors.ImageSharp;
|
||||||
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
using SixLabors.Primitives;
|
using SixLabors.Primitives;
|
||||||
|
|
||||||
namespace Content.Client.Parallax
|
namespace Content.Client.Parallax
|
||||||
@@ -39,24 +41,24 @@ namespace Content.Client.Parallax
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream configStream = null;
|
var debugParallax = _configurationManager.GetCVar<bool>("parallax.debug");
|
||||||
string contents;
|
string contents;
|
||||||
TomlTable table;
|
TomlTable table;
|
||||||
try
|
|
||||||
{
|
|
||||||
// Load normal config into memory
|
// Load normal config into memory
|
||||||
if (!_resourceCache.TryContentFileRead(ParallaxConfigPath, out configStream))
|
if (!_resourceCache.TryContentFileRead(ParallaxConfigPath, out var configStream))
|
||||||
{
|
{
|
||||||
Logger.ErrorS("parallax", "Parallax config not found.");
|
Logger.ErrorS("parallax", "Parallax config not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using (configStream)
|
||||||
|
{
|
||||||
using (var reader = new StreamReader(configStream, EncodingHelpers.UTF8))
|
using (var reader = new StreamReader(configStream, EncodingHelpers.UTF8))
|
||||||
{
|
{
|
||||||
contents = reader.ReadToEnd();
|
contents = reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_resourceCache.UserData.Exists(ParallaxConfigOld))
|
if (!debugParallax && _resourceCache.UserData.Exists(ParallaxConfigOld))
|
||||||
{
|
{
|
||||||
bool match;
|
bool match;
|
||||||
using (var data = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Open))
|
using (var data = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Open))
|
||||||
@@ -79,14 +81,17 @@ namespace Content.Client.Parallax
|
|||||||
|
|
||||||
table = Toml.ReadString(contents);
|
table = Toml.ReadString(contents);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
|
List<Image<Rgba32>> debugImages = null;
|
||||||
|
if (debugParallax)
|
||||||
{
|
{
|
||||||
configStream?.Dispose();
|
debugImages = new List<Image<Rgba32>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var sawmill = _logManager.GetSawmill("parallax");
|
var sawmill = _logManager.GetSawmill("parallax");
|
||||||
// Generate the parallax in the thread pool.
|
// 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.
|
// And load it in the main thread for safety reasons.
|
||||||
ParallaxTexture = Texture.LoadFromImage(image, "Parallax");
|
ParallaxTexture = Texture.LoadFromImage(image, "Parallax");
|
||||||
|
|
||||||
@@ -96,6 +101,21 @@ namespace Content.Client.Parallax
|
|||||||
image.SaveAsPng(stream);
|
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();
|
image.Dispose();
|
||||||
|
|
||||||
using (var stream = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Create))
|
using (var stream = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Create))
|
||||||
@@ -110,6 +130,7 @@ namespace Content.Client.Parallax
|
|||||||
public void PostInject()
|
public void PostInject()
|
||||||
{
|
{
|
||||||
_configurationManager.RegisterCVar("parallax.enabled", true);
|
_configurationManager.RegisterCVar("parallax.enabled", true);
|
||||||
|
_configurationManager.RegisterCVar("parallax.debug", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user