Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into 2023-11-19-pools
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth committed Nov 20, 2023
2 parents 49290b9 + 96cb52e commit 192dd34
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 77 deletions.
2 changes: 1 addition & 1 deletion MSBuild/Robust.Engine.Version.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<!-- This file automatically reset by Tools/version.py -->
<PropertyGroup><Version>180.0.0</Version></PropertyGroup>
<PropertyGroup><Version>180.1.0</Version></PropertyGroup>
</Project>
Expand Down
14 changes: 14 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ END TEMPLATE-->
*None yet*


## 180.1.0

### New features

* Add the map name to lsmap.
* Add net.pool_size to CVars to control the message data pool size in Lidgren and to also toggle pooling.

### Bugfixes

* Fix physics contraints causing enormous heap allocations.
* Fix potential error when writing a runtime log.
* Fix shape lookups for non-hard fixtures in EntityLookupSystem from 180.0.0


## 180.0.0

### Breaking changes
Expand Down
10 changes: 7 additions & 3 deletions Robust.Server/BaseServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,14 @@ public void Cleanup()
{
// Write down exception log
var logPath = _config.GetCVar(CVars.LogPath);
var relPath = PathHelpers.ExecutableRelativeFile(logPath);
Directory.CreateDirectory(relPath);
var pathToWrite = Path.Combine(relPath,
if (!Path.IsPathRooted(logPath))
{
logPath = PathHelpers.ExecutableRelativeFile(logPath);
}

var pathToWrite = Path.Combine(logPath,
"Runtime-" + DateTime.Now.ToString("yyyy-MM-dd-THH-mm-ss") + ".txt");
Directory.CreateDirectory(logPath);
File.WriteAllText(pathToWrite, _runtimeLog.Display(), EncodingHelpers.UTF8);
}

Expand Down
10 changes: 10 additions & 0 deletions Robust.Shared/CVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ protected CVars()
public static readonly CVarDef<int> NetReceiveBufferSize =
CVarDef.Create("net.receivebuffersize", 131071, CVar.ARCHIVE);

/// <summary>
/// Size of the pool for Lidgren's array buffers to send messages.
/// Set to 0 to disable pooling; max is 8192.
/// </summary>
/// <remarks>
/// Higher just means more potentially wasted space and slower pool retrieval.
/// </remarks>
public static readonly CVarDef<int> NetPoolSize =
CVarDef.Create("net.pool_size", 512, CVar.CLIENT | CVar.SERVER);

/// <summary>
/// Maximum UDP payload size to send.
/// </summary>
Expand Down
10 changes: 7 additions & 3 deletions Robust.Shared/Console/Commands/MapCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args)

internal sealed class ListMapsCommand : LocalizedCommands
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _map = default!;

public override string Command => "lsmap";
Expand All @@ -144,10 +145,13 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args)

foreach (var mapId in _map.GetAllMapIds().OrderBy(id => id.Value))
{
msg.AppendFormat("{0}: init: {1}, paused: {2}, ent: {3}, grids: {4}\n",
mapId, _map.IsMapInitialized(mapId),
var mapUid = _map.GetMapEntityId(mapId);

msg.AppendFormat("{0}: {1}, init: {2}, paused: {3}, nent: {4}, grids: {5}\n",
mapId, _entManager.GetComponent<MetaDataComponent>(mapUid).EntityName,
_map.IsMapInitialized(mapId),
_map.IsMapPaused(mapId),
_map.GetMapEntityId(mapId),
_entManager.GetNetEntity(_map.GetMapEntityId(mapId)),
string.Join(",", _map.GetAllGrids(mapId).Select(grid => grid.Owner)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,35 @@ private void AddEntitiesIntersecting<T>(
if (!state.Query.TryGetComponent(value, out var comp))
return true;

if (!state.FixturesQuery.TryGetComponent(value, out var fixtures))
{
var position = state.TransformSystem.GetWorldPosition(value);
if (state.Fixtures.TestPoint(state.Shape, state.Transform, position))
goto found;

return true;
}

var intersectingTransform = state.Physics.GetPhysicsTransform(value);
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!state.Sensors && !fixture.Hard)
continue;

for (var i = 0; i < fixture.Shape.ChildCount; i++)
if (state.FixturesQuery.TryGetComponent(value, out var fixtures))
{
bool anyFixture = false;
foreach (var fixture in fixtures.Fixtures.Values)
{
if (state.Manifolds.TestOverlap(state.Shape, 0, fixture.Shape, i, state.Transform, intersectingTransform))
if (!state.Sensors && !fixture.Hard)
continue;

anyFixture = true;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
goto found;
if (state.Manifolds.TestOverlap(state.Shape, 0, fixture.Shape, i, state.Transform,
intersectingTransform))
{
state.Intersecting.Add((value, comp));
return true;
}
}
}

if (anyFixture)
return true;
}

return true;
if (state.Fixtures.TestPoint(state.Shape, state.Transform, intersectingTransform.Position))
state.Intersecting.Add((value, comp));

found:
state.Intersecting.Add((value, comp));
return true;
}, localAABB, (flags & LookupFlags.Approximate) != 0x0);
}
Expand All @@ -194,34 +195,35 @@ private void AddEntitiesIntersecting<T>(
if (!state.Query.TryGetComponent(value, out var comp))
return true;

if (!state.FixturesQuery.TryGetComponent(value, out var fixtures))
{
var position = state.TransformSystem.GetWorldPosition(value);
if (state.Fixtures.TestPoint(state.Shape, state.Transform, position))
goto found;

return true;
}

var intersectingTransform = state.Physics.GetPhysicsTransform(value);
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!state.Sensors && !fixture.Hard)
continue;

for (var i = 0; i < fixture.Shape.ChildCount; i++)
if (state.FixturesQuery.TryGetComponent(value, out var fixtures))
{
bool anyFixture = false;
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!state.Manifolds.TestOverlap(state.Shape, 0, fixture.Shape, i, state.Transform, intersectingTransform))
if (!state.Sensors && !fixture.Hard)
continue;

anyFixture = true;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
goto found;
if (state.Manifolds.TestOverlap(state.Shape, 0, fixture.Shape, i, state.Transform,
intersectingTransform))
{
state.Intersecting.Add((value, comp));
return true;
}
}
}

if (anyFixture)
return true;
}

return true;
if (state.Fixtures.TestPoint(state.Shape, state.Transform, intersectingTransform.Position))
state.Intersecting.Add((value, comp));

found:
state.Intersecting.Add((value, comp));
return true;
}, localAABB, (flags & LookupFlags.Approximate) != 0x0);
}
Expand Down Expand Up @@ -554,10 +556,10 @@ public void GetEntitiesIntersecting(Type type, MapId mapId, IPhysShape shape, Ha
foreach (var (uid, comp) in EntityManager.GetAllComponents(type, true))
{
var xform = _xformQuery.GetComponent(uid);
var xFormPosition = _transform.GetWorldPosition(xform);
var (pos, rot) = _transform.GetWorldPositionRotation(xform);

if (xform.MapID != mapId ||
!worldAABB.Contains(xFormPosition) ||
!worldAABB.Contains(pos) ||
((flags & LookupFlags.Contained) == 0x0 &&
_container.IsEntityOrParentInContainer(uid, _metaQuery.GetComponent(uid), xform)))
{
Expand All @@ -566,14 +568,15 @@ public void GetEntitiesIntersecting(Type type, MapId mapId, IPhysShape shape, Ha

if (_fixturesQuery.TryGetComponent(uid, out var fixtures))
{
var xFormRotation = _transform.GetWorldRotation(xform, _xformQuery);
var transform = new Transform(xFormPosition, xFormRotation);
var transform = new Transform(pos, rot);

bool anyFixture = false;
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!sensors && !fixture.Hard)
continue;

anyFixture = true;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
if (_manifoldManager.TestOverlap(shape, 0, fixture.Shape, i, shapeTransform, transform))
Expand All @@ -583,16 +586,14 @@ public void GetEntitiesIntersecting(Type type, MapId mapId, IPhysShape shape, Ha
}
}

continue;
}
else
{
if (!_fixtures.TestPoint(shape, shapeTransform, xFormPosition))
if (anyFixture)
continue;
}

found:
if (!_fixtures.TestPoint(shape, shapeTransform, pos))
continue;

found:
intersecting.Add((uid, comp));
}
}
Expand Down Expand Up @@ -630,24 +631,21 @@ public void GetEntitiesIntersecting<T>(MapId mapId, IPhysShape shape, HashSet<En

while (query.MoveNext(out var uid, out var comp, out var xform))
{
var xFormPosition = _transform.GetWorldPosition(xform);
var (pos, rot) = _transform.GetWorldPositionRotation(xform);

if (xform.MapID != mapId ||
!worldAABB.Contains(xFormPosition))
{
if (xform.MapID != mapId || !worldAABB.Contains(pos))
continue;
}

if (_fixturesQuery.TryGetComponent(uid, out var fixtures))
{
var xFormRotation = _transform.GetWorldRotation(xform, _xformQuery);
var transform = new Transform(xFormPosition, xFormRotation);

var transform = new Transform(pos, rot);
bool anyFixture = false;
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!sensors && !fixture.Hard)
continue;

anyFixture = true;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
if (_manifoldManager.TestOverlap(shape, 0, fixture.Shape, i, shapeTransform, transform))
Expand All @@ -657,14 +655,13 @@ public void GetEntitiesIntersecting<T>(MapId mapId, IPhysShape shape, HashSet<En
}
}

continue;
}
else
{
if (!_fixtures.TestPoint(shape, shapeTransform, xFormPosition))
if (anyFixture)
continue;
}

if (!_fixtures.TestPoint(shape, shapeTransform, pos))
continue;

found:
entities.Add((uid, comp));
}
Expand Down
11 changes: 11 additions & 0 deletions Robust.Shared/Network/NetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,17 @@ private NetPeerConfiguration _getBaseNetPeerConfig()
// ping the client once per second.
netConfig.PingInterval = 1f;

var poolSize = _config.GetCVar(CVars.NetPoolSize);

if (poolSize <= 0)
{
netConfig.UseMessageRecycling = false;
}
else
{
netConfig.RecycledCacheMaxCount = Math.Min(poolSize, 8192);
}

netConfig.SendBufferSize = _config.GetCVar(CVars.NetSendBufferSize);
netConfig.ReceiveBufferSize = _config.GetCVar(CVars.NetReceiveBufferSize);
netConfig.MaximumHandshakeAttempts = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

using System.Numerics;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Collision;

namespace Robust.Shared.Physics.Dynamics.Contacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

using System.Numerics;
using Robust.Shared.Maths;

namespace Robust.Shared.Physics.Dynamics.Contacts
{
Expand Down
10 changes: 3 additions & 7 deletions Robust.Shared/Physics/Systems/SharedPhysicsSystem.Solver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ private void ResetSolver(
velocityConstraint.TangentSpeed = contact.TangentSpeed;
velocityConstraint.IndexA = bodyA.IslandIndex[island.Index];
velocityConstraint.IndexB = bodyB.IslandIndex[island.Index];
velocityConstraint.Points = new VelocityConstraintPoint[2];

for (var j = 0; j < 2; j++)
{
velocityConstraint.Points[j] = new VelocityConstraintPoint();
}
Array.Resize(ref velocityConstraint.Points, 2);
// Don't need to reset point data as it all gets set below.

var (invMassA, invMassB) = GetInvMass(bodyA, bodyB);

Expand All @@ -91,7 +87,7 @@ private void ResetSolver(
(positionConstraint.InvMassA, positionConstraint.InvMassB) = (invMassA, invMassB);
positionConstraint.LocalCenterA = bodyA.LocalCenter;
positionConstraint.LocalCenterB = bodyB.LocalCenter;
positionConstraint.LocalPoints = new Vector2[2];
Array.Resize(ref positionConstraint.LocalPoints, 2);

positionConstraint.InvIA = bodyA.InvI;
positionConstraint.InvIB = bodyB.InvI;
Expand Down

0 comments on commit 192dd34

Please sign in to comment.