Terrarium.Game.WorldState.buildIndexInternal C# (CSharp) Method

buildIndexInternal() private method

Builds the cell index.
private buildIndexInternal ( bool isDeserializing ) : void
isDeserializing bool Determines if the engine is in the state of deserializing.
return void
        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;
        }