Skip to content

Commit 4e34fe7

Browse files
Make normals not load when the CVar is disabled
1 parent 7638708 commit 4e34fe7

File tree

12 files changed

+53
-36
lines changed

12 files changed

+53
-36
lines changed

Robust.Client/Console/Commands/Debug.cs

-12
Original file line numberDiff line numberDiff line change
@@ -694,18 +694,6 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args)
694694
}
695695
}
696696

697-
internal sealed class ToggleNormals : LocalizedCommands
698-
{
699-
[Dependency] private readonly ILightManager _light = default!;
700-
701-
public override string Command => "togglenormals";
702-
703-
public override void Execute(IConsoleShell shell, string argStr, string[] args)
704-
{
705-
_light.DrawNormals = !_light.DrawNormals;
706-
}
707-
}
708-
709697
internal sealed class ChunkInfoCommand : LocalizedEntityCommands
710698
{
711699
[Dependency] private readonly IMapManager _map = default!;

Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using OpenToolkit.Graphics.OpenGL4;
5+
using Robust.Shared;
6+
using Robust.Shared.Configuration;
57
using Robust.Shared.Enums;
68
using Robust.Shared.GameObjects;
79
using Robust.Shared.Graphics;
@@ -29,7 +31,10 @@ internal partial class Clyde
2931

3032
private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBounds, IEye eye, bool normal = false)
3133
{
32-
if (normal && (!_lightManager.Enabled || !_lightManager.DrawLighting || !_lightManager.DrawNormals))
34+
if (normal && (!_lightManager.Enabled
35+
|| !_lightManager.DrawLighting
36+
|| !_cfg.GetCVar(CVars.LightNormals)
37+
|| !_resourceCache.GetNormalsEnabled()))
3338
return;
3439

3540
var mapId = eye.Position.MapId;

Robust.Client/Graphics/Clyde/Clyde.HLR.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ private List<Overlay> GetOverlaysForSpace(OverlaySpace space)
250250

251251
private void DrawEntities(Viewport viewport, Box2Rotated worldBounds, Box2 worldAABB, IEye eye, bool normal = false)
252252
{
253-
if (normal && (!_lightManager.Enabled || !_lightManager.DrawLighting || !_lightManager.DrawNormals))
253+
if (normal && (!_lightManager.Enabled
254+
|| !_lightManager.DrawLighting
255+
|| !_cfg.GetCVar(CVars.LightNormals)
256+
|| !_resourceCache.GetNormalsEnabled()))
254257
return;
255258

256259
var mapId = eye.Position.MapId;

Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ private void DrawLightsAndFov(Viewport viewport, Box2Rotated worldBounds, Box2 w
497497

498498
lightShader.SetUniformMaybe("eyeZoom", eye.Zoom / viewport.RenderScale);
499499
lightShader.SetUniformMaybe("eyeCenter", eye.Position.Position + eye.Offset);
500-
lightShader.SetUniformMaybe("useNormals", _lightManager.DrawNormals ? (int)1 : (int)0); // me when shaders do not support boolean values
500+
lightShader.SetUniformMaybe("useNormals", (_cfg.GetCVar(CVars.LightNormals) && _resourceCache.GetNormalsEnabled()) ? (int)1 : (int)0); // me when shaders do not support boolean values
501501

502502
var offset = new Vector2(component.Radius, component.Radius);
503503

Robust.Client/Graphics/Lighting/ILightManager.cs

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ public interface ILightManager
2121
/// </summary>
2222
bool DrawLighting { get; set; }
2323
/// <summary>
24-
/// Enables/disables rendering with normals instead of rendering flatly.
25-
/// </summary>
26-
bool DrawNormals { get; set; }
27-
/// <summary>
2824
/// This is useful to prevent players messing with lighting setup when they shouldn't.
2925
/// </summary>
3026
bool LockConsoleAccess { get; set; }

Robust.Client/Graphics/Lighting/LightManager.cs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public sealed class LightManager : ILightManager
88
public bool DrawShadows { get; set; } = true;
99
public bool DrawHardFov { get; set; } = true;
1010
public bool DrawLighting { get; set; } = true;
11-
public bool DrawNormals { get; set; } = false;
1211
public bool LockConsoleAccess { get; set; } = false;
1312
public Color AmbientLightColor { get; set; } = Color.FromSrgb(Color.Black);
1413
}

Robust.Client/ResourceManagement/BaseResource.cs

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public virtual void Dispose()
2727
/// </summary>
2828
public abstract void Load(IDependencyCollection dependencies, ResPath path);
2929

30+
public virtual void Load(IDependencyCollection dependencies, ResPath path, bool normalLoading)
31+
=> Load(dependencies, path);
32+
3033
public virtual void Reload(IDependencyCollection dependencies, ResPath path, CancellationToken ct = default)
3134
{
3235

Robust.Client/ResourceManagement/IResourceCache.cs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Robust.Client.ResourceManagement;
1313
/// </summary>
1414
public interface IResourceCache : IResourceManager
1515
{
16+
bool GetNormalsEnabled();
1617
T GetResource<T>(string path, bool useFallback = true)
1718
where T : BaseResource, new();
1819

Robust.Client/ResourceManagement/ResourceCache.Preload.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void PreloadTextures()
4545

4646
private void PreloadTextures(ISawmill sawmill)
4747
{
48+
NormalsEnabled = _configurationManager.GetCVar(CVars.LightNormals);
4849
sawmill.Debug("Preloading textures...");
4950
var sw = Stopwatch.StartNew();
5051
var resList = GetTypeData<TextureResource>().Resources;
@@ -132,7 +133,7 @@ private void PreloadRsis(ISawmill sawmill)
132133
{
133134
try
134135
{
135-
RSIResource.LoadPreTexture(_manager, data);
136+
RSIResource.LoadPreTexture(_manager, data, _configurationManager.GetCVar(CVars.LightNormals));
136137
}
137138
catch (Exception e)
138139
{

Robust.Client/ResourceManagement/ResourceCache.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Runtime.CompilerServices;
77
using Robust.Client.Audio;
8+
using Robust.Shared;
89
using Robust.Shared.ContentPack;
910
using Robust.Shared.IoC;
1011
using Robust.Shared.Log;
@@ -19,6 +20,12 @@ internal sealed partial class ResourceCache : ResourceManager, IResourceCacheInt
1920
{
2021
private readonly Dictionary<Type, TypeData> _cachedResources = new();
2122
private readonly Dictionary<Type, BaseResource> _fallbacks = new();
23+
public bool NormalsEnabled { get; private set; }
24+
25+
public bool GetNormalsEnabled()
26+
{
27+
return NormalsEnabled;
28+
}
2229

2330
public T GetResource<T>(string path, bool useFallback = true) where T : BaseResource, new()
2431
{
@@ -37,7 +44,7 @@ internal sealed partial class ResourceCache : ResourceManager, IResourceCacheInt
3744
try
3845
{
3946
var dependencies = IoCManager.Instance!;
40-
resource.Load(dependencies, path);
47+
resource.Load(dependencies, path, _configurationManager.GetCVar(CVars.LightNormals));
4148
cache.Resources[path] = resource;
4249
return resource;
4350
}
@@ -82,7 +89,7 @@ internal sealed partial class ResourceCache : ResourceManager, IResourceCacheInt
8289
try
8390
{
8491
var dependencies = IoCManager.Instance!;
85-
_resource.Load(dependencies, path);
92+
_resource.Load(dependencies, path, _configurationManager.GetCVar(CVars.LightNormals));
8693
resource = _resource;
8794
cache.Resources[path] = resource;
8895
return true;

Robust.Client/ResourceManagement/ResourceTypes/RSIResource.cs

+21-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Robust.Shared.Utility;
1212
using SixLabors.ImageSharp;
1313
using SixLabors.ImageSharp.PixelFormats;
14+
using TerraFX.Interop.Windows;
1415
using IResourceManager = Robust.Shared.ContentPack.IResourceManager;
1516

1617
namespace Robust.Client.ResourceManagement
@@ -36,10 +37,13 @@ public sealed class RSIResource : BaseResource
3637
public const uint MAXIMUM_RSI_VERSION = RsiLoading.MAXIMUM_RSI_VERSION;
3738

3839
public override void Load(IDependencyCollection dependencies, ResPath path)
40+
=> Load(dependencies, path, false);
41+
42+
public override void Load(IDependencyCollection dependencies, ResPath path, bool normalLoading)
3943
{
4044
var loadStepData = new LoadStepData {Path = path};
4145
var manager = dependencies.Resolve<IResourceManager>();
42-
LoadPreTexture(manager, loadStepData);
46+
LoadPreTexture(manager, loadStepData, normalLoading);
4347
LoadTexture(dependencies.Resolve<IClyde>(), loadStepData);
4448
LoadPostTexture(loadStepData);
4549
LoadFinish(dependencies.Resolve<IResourceCacheInternal>(), loadStepData);
@@ -145,7 +149,7 @@ internal static void CreatePlaceholderNormal(Image<Rgba32> original, Vector2i bl
145149
bumpmap.Dispose();
146150
}
147151

148-
internal static void LoadPreTexture(IResourceManager manager, LoadStepData data)
152+
internal static void LoadPreTexture(IResourceManager manager, LoadStepData data, bool normalLoading = false)
149153
{
150154
var manifestPath = data.Path / "meta.json";
151155
RsiLoading.RsiMetadata metadata;
@@ -188,7 +192,8 @@ internal static void LoadPreTexture(IResourceManager manager, LoadStepData data)
188192
{
189193
var texture = Image.Load<Rgba32>(stream);
190194
Image<Rgba32> normalImage;
191-
if (stateObject.NormalId is {})
195+
if (!normalLoading) normalImage = texture;
196+
else if (stateObject.NormalId is {})
192197
{
193198
using (var normalStream = manager.ContentFileRead(normalPath))
194199
{
@@ -211,13 +216,14 @@ internal static void LoadPreTexture(IResourceManager manager, LoadStepData data)
211216
CreatePlaceholderNormal(texture, stateObject.Size, out normalImage);
212217
}
213218
}
214-
for (int nX = 0; nX < texture.Width; nX++)
215-
for (int nY = 0; nY < texture.Height; nY++)
216-
{
217-
var T = normalImage[nX, nY];
218-
T.A = texture[nX, nY].A;
219-
normalImage[nX, nY] = T;
220-
}
219+
if (normalLoading)
220+
for (int nX = 0; nX < texture.Width; nX++)
221+
for (int nY = 0; nY < texture.Height; nY++)
222+
{
223+
var T = normalImage[nX, nY];
224+
T.A = texture[nX, nY].A;
225+
normalImage[nX, nY] = T;
226+
}
221227

222228
reg.Src = (texture, normalImage);
223229
}
@@ -269,7 +275,7 @@ internal static void LoadPreTexture(IResourceManager manager, LoadStepData data)
269275
var dimensionY = (int) MathF.Ceiling((float) totalFrameCount / dimensionX);
270276

271277
var sheetHalfWidth = dimensionX * frameSize.X;
272-
var sheet = new Image<Rgba32>(sheetHalfWidth * 2, dimensionY * frameSize.Y);
278+
var sheet = new Image<Rgba32>(sheetHalfWidth * (normalLoading ? 2 : 1), dimensionY * frameSize.Y);
273279

274280
var sheetIndex = 0;
275281
for (var index = 0; index < toAtlas.Length; index++)
@@ -291,7 +297,8 @@ internal static void LoadPreTexture(IResourceManager manager, LoadStepData data)
291297
var srcBox = UIBox2i.FromDimensions(srcPos, frameSize);
292298

293299
reg.Src.Item1.Blit(srcBox, sheet, sheetPos);
294-
reg.Src.Item2.Blit(srcBox, sheet, sheetNPos);
300+
if (normalLoading)
301+
reg.Src.Item2.Blit(srcBox, sheet, sheetNPos);
295302
}
296303

297304
sheetIndex += reg.TotalFrameCount;
@@ -301,7 +308,8 @@ internal static void LoadPreTexture(IResourceManager manager, LoadStepData data)
301308
{
302309
ref var reg = ref toAtlas[i];
303310
reg.Src.Item1.Dispose();
304-
reg.Src.Item2.Dispose();
311+
if (normalLoading)
312+
reg.Src.Item2.Dispose();
305313
}
306314

307315
data.Rsi = rsi;

Robust.Shared/CVars.cs

+6
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,12 @@ protected CVars()
879879
public static readonly CVarDef<float> LightBlurFactor =
880880
CVarDef.Create("light.blur_factor", 0.001f, CVar.CLIENTONLY | CVar.ARCHIVE);
881881

882+
/// <summary>
883+
/// If we render and load normals.
884+
/// </summary>
885+
public static readonly CVarDef<bool> LightNormals =
886+
CVarDef.Create("light.normals", false, CVar.CLIENTONLY | CVar.ARCHIVE);
887+
882888
/*
883889
* Lookup
884890
*/

0 commit comments

Comments
 (0)