Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,12 @@
foreach (var entity in entities)
{
float distanceThreshold = entity.GetScopeRange();
var currentlyScoped = ScopedPlayersByEntity[entity.EntityId];
if (!ScopedPlayersByEntity.TryGetValue(entity.EntityId, out var currentlyScoped))
{
// Entity has no scoped players, skip
continue;
}

var entityPosition = entity.Position;
foreach (var player in players)
{
Expand Down Expand Up @@ -1640,30 +1645,41 @@
if (shouldFlush)
{
view.SerializeChangesToMemory(out var update);
foreach (var client in ScopedPlayersByEntity[entityId])

if (ScopedPlayersByEntity.TryGetValue(entityId, out var scopedPlayers))
{
bool shouldSend = client.Status.Equals(IPlayer.PlayerStatus.Playing) || client.Status.Equals(IPlayer.PlayerStatus.Loading);
if (shouldSend)
foreach (var client in ScopedPlayersByEntity[entityId])
{
client.NetChannels[ChannelType.UnreliableGss].SendChanges(view, entityId, update);
bool shouldSend = client.Status.Equals(IPlayer.PlayerStatus.Playing) || client.Status.Equals(IPlayer.PlayerStatus.Loading);
if (shouldSend && client?.NetChannels != null)
{
client.NetChannels[ChannelType.UnreliableGss].SendChanges(view, entityId, update);
}
}
}
}
}

public void SendToScoped<TNormal>(IEntity entity, TNormal message)
where TNormal : class, IAero
where TNormal : class, IAero
{
var entityId = entity.EntityId;
foreach (var client in ScopedPlayersByEntity[entityId])
if (!ScopedPlayersByEntity.TryGetValue(entityId, out var scopedPlayers))
{
if (client.CanReceiveGSS)
// No players are scoped to this entity - nothing to send to
return;
}

foreach (var client in scopedPlayers)
{
if (client?.CanReceiveGSS == true &&
client.NetChannels?.TryGetValue(ChannelType.UnreliableGss, out var channel) == true)
{
client.NetChannels[ChannelType.UnreliableGss].SendMessage(message, entityId);
channel.SendMessage(message, entityId);
}
}
}

private void OnAddedEntity(IEntity entity)
{
// TEMP: Hack to introduce new entities to connected players. This should be replaced with tick logic that sends down entities based on scope and distance.
Expand All @@ -1679,9 +1695,15 @@

private void OnRemovedEntity(IEntity entity)
{
foreach (var client in ScopedPlayersByEntity[entity.EntityId])
if (ScopedPlayersByEntity.TryGetValue(entity.EntityId, out var scopedPlayers))
{
ScopeOut(client, entity);
foreach (var client in scopedPlayers.ToList()) // ToList() to avoid modification during iteration

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / Linux .NET 11

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / Linux .NET 11

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / macOS .NET 11

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / macOS .NET 11

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / Linux .NET 10

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / Linux .NET 10

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 10

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 10

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 10

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / macOS .NET 10

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / macOS .NET 10

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 11

Check warning on line 1700 in UdpHosts/GameServer/Systems/EntityManager/EntityManager.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 11

{
if (client != null)
{
ScopeOut(client, entity);
}
}
}
}

Expand Down
Loading