Skip to content

Commit

Permalink
Fix pvs error (space-wizards#4812)
Browse files Browse the repository at this point in the history
* Fix pvs error

* rename variable
  • Loading branch information
ElectroJr committed Jan 5, 2024
1 parent f2e9ed0 commit f2f8824
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Robust.Server/GameStates/PvsSystem.ToSendSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void AddPvsChunks(PvsSession pvsSession)
}

/// <summary>
/// A chunks that is visible to a player and add entities to the game-state.
/// Add all entities on a given PVS chunk to a clients game-state.
/// </summary>
private void AddPvsChunk(PvsChunk chunk, float distance, PvsSession session)
{
Expand All @@ -48,17 +48,28 @@ private void AddPvsChunk(PvsChunk chunk, float distance, PvsSession session)
// We add chunk-size here so that its consistent with the normal PVS range setting.
// I.e., distance here is the Chebyshev distance to the centre of each chunk, but the normal pvs range only
// required that the chunk be touching the box, not the centre.
var count = distance < (_lowLodDistance + ChunkSize) / 2
var limit = distance < (_lowLodDistance + ChunkSize) / 2
? chunk.Contents.Count
: chunk.LodCounts[0];

// If the PVS budget is exceeded, it should still be safe to send all of the chunk's direct children, though
// after that we have no guarantee that an entity's parent got sent.
var directChildren = Math.Min(limit, chunk.LodCounts[2]);

// Send entities on the chunk.
var span = CollectionsMarshal.AsSpan(chunk.Contents);
for (var i = 0; i < count; i++)
for (var i = 0; i < limit; i++)
{
var ent = span[i];
if ((mask & ent.Comp.VisibilityMask) == ent.Comp.VisibilityMask)
AddEntity(session, ent, fromTick);
if ((mask & ent.Comp.VisibilityMask) != ent.Comp.VisibilityMask)
continue;

// TODO PVS improve this somehow
// Having entities "leave" pvs view just because the pvs entry budget was exceeded sucks.
// This probably requires changing client game state manager to support receiving entities with unknown parents.
// Probably needs to do something similar to pending net entity states, but for entity spawning.
if (!AddEntity(session, ent, fromTick))
limit = directChildren;
}
}

Expand Down

0 comments on commit f2f8824

Please sign in to comment.