]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Use pvs range for biomes (#14048)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sun, 12 Feb 2023 05:37:02 +0000 (16:37 +1100)
committerGitHub <noreply@github.com>
Sun, 12 Feb 2023 05:37:02 +0000 (05:37 +0000)
Forgot it wasn't on that branch

Content.Server/Parallax/BiomeSystem.cs
Content.Shared/Parallax/Biomes/SharedBiomeSystem.cs

index 9f8c9c1c4cfba80d9b5e773bce55180e412db6ef..01e818b9c76a02332fc302c2247dab27ebeff0ae 100644 (file)
@@ -2,26 +2,28 @@ using Content.Server.Decals;
 using Content.Shared.Decals;
 using Content.Shared.Parallax.Biomes;
 using Robust.Server.Player;
+using Robust.Shared;
+using Robust.Shared.Configuration;
 using Robust.Shared.Map;
 using Robust.Shared.Map.Components;
 using Robust.Shared.Noise;
 using Robust.Shared.Player;
-using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
-using Robust.Shared.Serialization.Manager;
 
 namespace Content.Server.Parallax;
 
 public sealed class BiomeSystem : SharedBiomeSystem
 {
+    [Dependency] private readonly IConfigurationManager _configManager = default!;
     [Dependency] private readonly IPlayerManager _playerManager = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly DecalSystem _decals = default!;
     [Dependency] private readonly SharedTransformSystem _transform = default!;
 
     private readonly HashSet<EntityUid> _handledEntities = new();
-    private const float LoadRange = ChunkSize * 2f;
-    private readonly Box2 _loadArea = new(-LoadRange, -LoadRange, LoadRange, LoadRange);
+    private const float DefaultLoadRange = 16f;
+    private float _loadRange = DefaultLoadRange;
+    private Box2 _loadArea = new(-DefaultLoadRange, -DefaultLoadRange, DefaultLoadRange, DefaultLoadRange);
 
     private readonly Dictionary<BiomeComponent, HashSet<Vector2i>> _activeChunks = new();
 
@@ -29,6 +31,20 @@ public sealed class BiomeSystem : SharedBiomeSystem
     {
         base.Initialize();
         SubscribeLocalEvent<BiomeComponent, MapInitEvent>(OnBiomeMapInit);
+        _configManager.OnValueChanged(CVars.NetMaxUpdateRange, SetLoadRange, true);
+    }
+
+    public override void Shutdown()
+    {
+        base.Shutdown();
+        _configManager.UnsubValueChanged(CVars.NetMaxUpdateRange, SetLoadRange);
+    }
+
+    private void SetLoadRange(float obj)
+    {
+        // Round it up
+        _loadRange = MathF.Ceiling(obj / ChunkSize) * ChunkSize;
+        _loadArea = new Box2(-_loadRange, -_loadRange, _loadRange, _loadRange);
     }
 
     private void OnBiomeMapInit(EntityUid uid, BiomeComponent component, MapInitEvent args)
index eefc772c17040d90cf7a1a53075e30aee176919a..5cdba8f5ec8210e2662fcdd0cd340142e3aa8a62 100644 (file)
@@ -18,7 +18,7 @@ public abstract class SharedBiomeSystem : EntitySystem
     [Dependency] protected readonly IPrototypeManager ProtoManager = default!;
     [Dependency] protected readonly ITileDefinitionManager TileDefManager = default!;
 
-    protected const byte ChunkSize = 4;
+    protected const byte ChunkSize = 8;
 
     // TODO: After I wrote all of this FastNoiseLite got ported so this needs updating for that don't @ me