Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed server starting with errored entities (1.7.1.0) #2165

Open
wants to merge 4 commits into
base: 1.7.0.0
Choose a base branch
from
Open
Changes from 1 commit
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: 39 additions & 7 deletions NitroxServer/GameLogic/Entities/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,46 @@ public class EntityManager

public EntityManager(List<Entity> entities, BatchEntitySpawner batchEntitySpawner)
{
entitiesById = entities.ToDictionary(entity => entity.Id);
entitiesById = new Dictionary<NitroxId, Entity>(entities.Count);
globalRootEntitiesById = new Dictionary<NitroxId, Entity>();
phasingEntitiesByAbsoluteCell = new Dictionary<AbsoluteEntityCell, List<Entity>>();
bool toWarn = false;

globalRootEntitiesById = entities.FindAll(entity => entity.ExistsInGlobalRoot)
.ToDictionary(entity => entity.Id);

phasingEntitiesByAbsoluteCell = entities.FindAll(entity => !entity.ExistsInGlobalRoot)
.GroupBy(entity => entity.AbsoluteEntityCell)
.ToDictionary(group => group.Key, group => group.ToList());
for (int i = 0; i < entities.Count; i++)
uGuardian marked this conversation as resolved.
Show resolved Hide resolved
{
Entity entity = entities[i];
uGuardian marked this conversation as resolved.
Show resolved Hide resolved
try
{
if (entity.ExistsInGlobalRoot)
{
globalRootEntitiesById.Add(entity.Id, entity);
}
else
{
AbsoluteEntityCell cell = entity.AbsoluteEntityCell;
if (phasingEntitiesByAbsoluteCell.TryGetValue(cell, out List<Entity> list))
{
list.Add(entity);
uGuardian marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
list = new List<Entity> {entity};
phasingEntitiesByAbsoluteCell.Add(cell, list);
}
}
// At the end since we don't want entities that cause an error
entitiesById.Add(entity.Id, entity);
}
catch (System.Exception ex)
{
toWarn = true;
Log.Error(ex);
}
}
if (toWarn)
{
Log.Warn("One or more entities have failed to load");
uGuardian marked this conversation as resolved.
Show resolved Hide resolved
}

this.batchEntitySpawner = batchEntitySpawner;
}
Expand Down