Fix parallax generation.

It broke when IoC got made thread local,
since it is done in the thread pool.
This commit is contained in:
Pieter-Jan Briers
2019-05-08 22:01:14 +02:00
parent 0ccefebc52
commit eacfa34c99
2 changed files with 8 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
using Robust.Client.Utility; using Robust.Client.Utility;
using Robust.Shared.Interfaces.Log;
using Robust.Shared.Log; using Robust.Shared.Log;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Noise; using Robust.Shared.Noise;
@@ -17,9 +18,9 @@ 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) public static Image<Rgba32> GenerateParallax(TomlTable config, Size size, ISawmill sawmill)
{ {
Logger.DebugS("parallax", "Generating parallax!"); sawmill.Debug("Generating parallax!");
var generator = new ParallaxGenerator(); var generator = new ParallaxGenerator();
generator._loadConfig(config); generator._loadConfig(config);
@@ -28,7 +29,7 @@ namespace Content.Client.Parallax
foreach (var layer in generator.Layers) foreach (var layer in generator.Layers)
{ {
layer.Apply(image); layer.Apply(image);
Logger.DebugS("parallax", "Layer {0} done!", count++); sawmill.Debug("Layer {0} done!", count++);
} }
return image; return image;

View File

@@ -9,6 +9,7 @@ using SixLabors.ImageSharp;
using SixLabors.Primitives; using SixLabors.Primitives;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.Interfaces.ResourceManagement; using Robust.Client.Interfaces.ResourceManagement;
using Robust.Shared.Interfaces.Log;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Log; using Robust.Shared.Log;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -19,6 +20,7 @@ namespace Content.Client.Parallax
{ {
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private readonly IResourceCache _resourceCache; [Dependency] private readonly IResourceCache _resourceCache;
[Dependency] private readonly ILogManager _logManager;
#pragma warning restore 649 #pragma warning restore 649
private static readonly ResourcePath ParallaxConfigPath = new ResourcePath("/parallax_config.toml"); private static readonly ResourcePath ParallaxConfigPath = new ResourcePath("/parallax_config.toml");
@@ -77,8 +79,9 @@ namespace Content.Client.Parallax
configStream?.Dispose(); configStream?.Dispose();
} }
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))); var image = await Task.Run(() => ParallaxGenerator.GenerateParallax(table, new Size(1920, 1080), sawmill));
// 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");