Ejemplo n.º 1
0
        ///<summary>
        /// Removes an entity from the manager.
        ///</summary>
        ///<param name="e">Entity to remove.</param>
        ///<exception cref="InvalidOperationException">Thrown if the entity does not belong to this manager.</exception>
        public void Remove(Entity e)
        {
            lock (InterpolatedStates.FlipLocker)
            {
                lock (ReadBuffers.FlipLocker)
                {
                    if (e.BufferedStates.BufferedStatesManager == this)
                    {
                        int index = entities.IndexOf(e);

                        int endIndex = entities.Count - 1;
                        entities[index] = entities[endIndex];
                        entities.RemoveAt(endIndex);
                        if (index < entities.Count)
                        {
                            entities[index].BufferedStates.motionStateIndex = index;
                        }
                        if (ReadBuffers.Enabled)
                        {
                            ReadBuffers.Remove(index, endIndex);
                        }
                        if (InterpolatedStates.Enabled)
                        {
                            InterpolatedStates.Remove(index, endIndex);
                        }

                        e.BufferedStates.BufferedStatesManager = null;
                    }
                    else
                    {
                        throw new InvalidOperationException("Entity does not belong to this BufferedStatesManager; cannot remove.");
                    }
                }
            }
        }