private void buildIndexInternal(bool isDeserializing)
{
if (!isDeserializing && _isImmutable)
{
throw new ApplicationException("WorldState must be mutable to rebuild index.");
}
if (Organisms.Count > 0)
{
foreach (OrganismState state in Organisms)
{
Debug.Assert(state.GridX >= 0 && state.GridX < _gridWidth &&
state.GridY >= 0 && state.GridY < _gridHeight);
Debug.Assert(_cellOrganisms[state.GridX, state.GridY] == null);
FillCells(state, state.GridX, state.GridY, state.CellRadius, false);
// Lock the size and position of the organism so that the index doesn't get out of sync
if (!isDeserializing)
{
state.LockSizeAndPosition();
}
}
}
_indexBuilt = true;
}