public RenderableLayerPair(Renderable aRenderable, int aiLayer)
 {
     _renderable = aRenderable;
     _layer = aiLayer;
 }
 public virtual bool IsProtectedFromUnloadAll(Renderable renderable)
 {
     return false;
 }
        private void Remove(Renderable oldElement, bool isLayerChange)
        {
            if (oldElement == null)
                return;

            if (_elementsLocked)
            {
                _deferredRemoves.Add(oldElement);
                return;
            }

            // First, make sure that it isn't deferred in the _deferredAdds list.
            for (LinkedListNode<RenderableLayerPair> node = _deferredAdds.First;
                node != null; node = node.Next)
            {
                if (node.Value._renderable == oldElement)
                {
                    _deferredAdds.Remove(node);

                    if(!isLayerChange)
                        node.Value._renderable.RemovedFromWorld();

                    return;
                }
            }

            // If we didn't find it in the deferred list, find/remove it from the layers.
            bool found = false;
            // Find the layer that matches the elements layer.
            LinkedList<Renderable> layer = _layers[oldElement.Layer];
            // Found the layer (list of renderables).
            // First, make sure that it isn't deferred in the _deferredAdds list.
            for (LinkedListNode<Renderable> node = layer.First;
                node != null; node = node.Next)
            {
                // Found it.
                if (node.Value == oldElement)
                {
                    // Remove the element.
                    layer.Remove(node);

                    if(!isLayerChange)
                        node.Value.RemovedFromWorld();

                    found = true;
                    // Nothing else to do.
                    break;
                }
            }

            if (!found)
            {
                //TODO: log or error handle
                Log.Instance.Log("[World] Remove(): Entity was not found: " + oldElement.ToString());
            }
        }
        public void UpdateLayer(Renderable element, int newLayer)
        {
            if (element.Layer == newLayer)
                return;

            RenderableLayerPair layerChange;
            layerChange._layer = newLayer;
            layerChange._renderable = element;
            _deferredLayerChanges.Add(layerChange);
        }
 public void Remove(Renderable oldElement)
 {
     Remove(oldElement, false);
 }
        public void Add(Renderable newElement, int layer)
        {
            // If we're not locked, add directly to _elements.
            if (!_elementsLocked)
            {
                newElement.Layer = layer;
                if (_layers.ContainsKey(layer))
                    _layers[layer].AddLast(newElement);
                else
                {
                    LinkedList<Renderable> list = new LinkedList<Renderable>();
                    list.AddLast(newElement);
                    _layers.Add(layer, list);
                }

                newElement.AddedToWorld();
            }
            // If we're locked, add to _deferredAdds and we'll add the new
            // Renderable after we're done updating all the _elements.
            else
            {
                RenderableLayerPair addMe = new RenderableLayerPair(newElement, layer);
                _deferredAdds.AddLast(addMe);
            }
        }
 public void Add(Renderable newElement)
 {
     Add(newElement, 0);
 }