mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
@@ -24,7 +24,7 @@ internal sealed partial class PvsSystem
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
@@ -48,17 +48,28 @@ internal sealed partial class PvsSystem
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user