mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
pvsrange vec2 + eyezoom (#2676)
Co-authored-by: Paul <ritter.paul1+git@googlemail.com>
This commit is contained in:
@@ -11,7 +11,7 @@ public struct ChunkIndicesEnumerator
|
||||
private int _x;
|
||||
private int _y;
|
||||
|
||||
public ChunkIndicesEnumerator(Vector2 viewPos, float range, float chunkSize)
|
||||
public ChunkIndicesEnumerator(Vector2 viewPos, Vector2 range, float chunkSize)
|
||||
{
|
||||
_bottomLeft = ((viewPos - range) / chunkSize).Floored();
|
||||
// Also floor this as we get the whole chunk anyway.
|
||||
|
||||
@@ -43,7 +43,7 @@ internal sealed partial class PVSSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Size of the side of the view bounds square.
|
||||
/// </summary>
|
||||
private float _viewSize;
|
||||
private Vector2 _viewSize;
|
||||
|
||||
/// <summary>
|
||||
/// If PVS disabled then we'll track if we've dumped all entities on the player.
|
||||
@@ -118,7 +118,7 @@ internal sealed partial class PVSSystem : EntitySystem
|
||||
EntityManager.EntityDeleted += OnEntityDeleted;
|
||||
|
||||
_configManager.OnValueChanged(CVars.NetPVS, SetPvs, true);
|
||||
_configManager.OnValueChanged(CVars.NetMaxUpdateRange, OnViewsizeChanged, true);
|
||||
_configManager.OnValueChanged(CVars.NetDefaultUpdateRange, OnViewsizeChanged, true);
|
||||
|
||||
InitializeDirty();
|
||||
}
|
||||
@@ -144,14 +144,14 @@ internal sealed partial class PVSSystem : EntitySystem
|
||||
EntityManager.EntityDeleted -= OnEntityDeleted;
|
||||
|
||||
_configManager.UnsubValueChanged(CVars.NetPVS, SetPvs);
|
||||
_configManager.UnsubValueChanged(CVars.NetMaxUpdateRange, OnViewsizeChanged);
|
||||
_configManager.UnsubValueChanged(CVars.NetDefaultUpdateRange, OnViewsizeChanged);
|
||||
|
||||
ShutdownDirty();
|
||||
}
|
||||
|
||||
private void OnViewsizeChanged(float obj)
|
||||
private void OnViewsizeChanged(Vector2 obj)
|
||||
{
|
||||
_viewSize = obj * 2;
|
||||
_viewSize = obj;
|
||||
}
|
||||
|
||||
private void SetPvs(bool value)
|
||||
@@ -323,7 +323,6 @@ internal sealed partial class PVSSystem : EntitySystem
|
||||
{
|
||||
var playerChunks = new HashSet<int>[sessions.Length];
|
||||
var eyeQuery = EntityManager.GetEntityQuery<EyeComponent>();
|
||||
var transformQuery = EntityManager.GetEntityQuery<TransformComponent>();
|
||||
var viewerEntities = new EntityUid[sessions.Length][];
|
||||
|
||||
_chunkList.Clear();
|
||||
@@ -350,11 +349,17 @@ internal sealed partial class PVSSystem : EntitySystem
|
||||
|
||||
foreach (var eyeEuid in viewers)
|
||||
{
|
||||
var (viewPos, range, mapId) = CalcViewBounds(in eyeEuid, transformQuery);
|
||||
var xform = xformQuery.GetComponent(eyeEuid);
|
||||
var viewPos = xform.WorldPosition;
|
||||
var range = _viewSize;
|
||||
var mapId = xform.MapID;
|
||||
|
||||
uint visMask = EyeComponent.DefaultVisibilityMask;
|
||||
if (eyeQuery.TryGetComponent(eyeEuid, out var eyeComp))
|
||||
{
|
||||
visMask = eyeComp.VisibilityMask;
|
||||
range *= eyeComp.Zoom;
|
||||
}
|
||||
|
||||
// Get the nyoom dictionary for index lookups.
|
||||
if (!_mapIndices.TryGetValue(visMask, out var mapDict))
|
||||
@@ -399,7 +404,7 @@ internal sealed partial class PVSSystem : EntitySystem
|
||||
physicsQuery,
|
||||
true))
|
||||
{
|
||||
var localPos = transformQuery.GetComponent(mapGrid.GridEntityId).InvWorldMatrix.Transform(viewPos);
|
||||
var localPos = xformQuery.GetComponent(mapGrid.GridEntityId).InvWorldMatrix.Transform(viewPos);
|
||||
|
||||
var gridChunkEnumerator =
|
||||
new ChunkIndicesEnumerator(localPos, range, ChunkSize);
|
||||
@@ -963,13 +968,6 @@ internal sealed partial class PVSSystem : EntitySystem
|
||||
return viewerArray;
|
||||
}
|
||||
|
||||
// Read Safe
|
||||
private (Vector2 worldPos, float range, MapId mapId) CalcViewBounds(in EntityUid euid, EntityQuery<TransformComponent> transformQuery)
|
||||
{
|
||||
var xform = transformQuery.GetComponent(euid);
|
||||
return (xform.WorldPosition, _viewSize / 2f, xform.MapID);
|
||||
}
|
||||
|
||||
public sealed class SetPolicy<T> : PooledObjectPolicy<HashSet<T>>
|
||||
{
|
||||
public override HashSet<T> Create()
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Threading;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
@@ -121,8 +122,8 @@ namespace Robust.Shared
|
||||
/// View size to take for PVS calculations,
|
||||
/// as the size of the sides of a square centered on the view points of clients.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> NetMaxUpdateRange =
|
||||
CVarDef.Create("net.maxupdaterange", 12.5f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
|
||||
public static readonly CVarDef<Vector2> NetDefaultUpdateRange =
|
||||
CVarDef.Create("net.defaultupdaterange", new Vector2(12.5f, 12.5f), CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
|
||||
|
||||
/// <summary>
|
||||
/// The amount of new entities that can be sent to a client in a single game state, under PVS.
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Lidgren.Network;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -66,6 +68,11 @@ namespace Robust.Shared.Network.Messages
|
||||
case CvarType.Double:
|
||||
value = buffer.ReadDouble();
|
||||
break;
|
||||
case CvarType.Vector2:
|
||||
var valX = buffer.ReadFloat();
|
||||
var valY = buffer.ReadFloat();
|
||||
value = new Vector2(valX, valY);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
@@ -116,6 +123,11 @@ namespace Robust.Shared.Network.Messages
|
||||
buffer.Write((byte)CvarType.Double);
|
||||
buffer.Write(val);
|
||||
break;
|
||||
case Vector2 val:
|
||||
buffer.Write((byte)CvarType.Vector2);
|
||||
buffer.Write(val.X);
|
||||
buffer.Write(val.Y);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
@@ -126,13 +138,13 @@ namespace Robust.Shared.Network.Messages
|
||||
{
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
None,
|
||||
|
||||
Int,
|
||||
Long,
|
||||
Bool,
|
||||
String,
|
||||
Float,
|
||||
Double
|
||||
Double,
|
||||
Vector2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Players;
|
||||
|
||||
@@ -78,7 +79,7 @@ namespace Robust.Shared.Player
|
||||
if (!cfgMan.GetCVar(CVars.NetPVS))
|
||||
return AddAllPlayers();
|
||||
|
||||
var pvsRange = cfgMan.GetCVar(CVars.NetMaxUpdateRange) * rangeMultiplier;
|
||||
var pvsRange = cfgMan.GetCVar(CVars.NetDefaultUpdateRange) * rangeMultiplier;
|
||||
|
||||
return AddInRange(origin, pvsRange, playerMan);
|
||||
}
|
||||
@@ -175,6 +176,13 @@ namespace Robust.Shared.Player
|
||||
(xform.WorldPosition - position.Position).Length < range, playerMan);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds all players in range of a position.
|
||||
/// </summary>
|
||||
public Filter AddInRange(MapCoordinates position, Vector2 range, ISharedPlayerManager? playerMan = null,
|
||||
IEntityManager? entMan = null)
|
||||
=> AddInRange(position, range.Length, playerMan, entMan);
|
||||
|
||||
/// <summary>
|
||||
/// Removes all players without the specified visibility flag.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user