Пример #1
0
        private void RenderFeatures_CollectionChanged(object sender, ref FastTrackingCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                for (int index = 0; index < renderObjectsWithoutFeatures.Count; index++)
                {
                    var renderObject = renderObjectsWithoutFeatures[index];

                    // Try to reprocess object that didn't have any stage before
                    if (renderObject.RenderFeature == null)
                    {
                        RenderSystem.AddRenderObject(renderObject);
                        if (renderObject.RenderFeature != null)
                        {
                            renderObjectsWithoutFeatures.SwapRemoveAt(index--);
                            ReevaluateActiveRenderStages(renderObject);
                        }
                    }
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (var renderObject in RenderObjects)
                {
                    if (renderObject.RenderFeature == e.Item)
                    {
                        RenderSystem.RemoveRenderObject(renderObject);
                        renderObjectsWithoutFeatures.Add(renderObject);
                    }
                }
                break;
            }
        }
Пример #2
0
        internal bool RemoveRenderObject(List <RenderObject> renderObjects, [NotNull] RenderObject renderObject)
        {
            if (renderObject.RenderFeature == null)
            {
                renderObjectsWithoutFeatures.Remove(renderObject);
            }

            RenderSystem.RemoveRenderObject(renderObject);

            // Get and clear ordered node index
            var orderedRenderNodeIndex = renderObject.VisibilityObjectNode.Index;

            if (renderObject.VisibilityObjectNode == StaticObjectNodeReference.Invalid)
            {
                return(false);
            }

            renderObject.VisibilityObjectNode = StaticObjectNodeReference.Invalid;

            // SwapRemove each items in dataArrays
            RenderData.SwapRemoveItem(DataType.StaticObject, orderedRenderNodeIndex, renderObjects.Count - 1);

            // Remove entry from ordered node index
            renderObjects.SwapRemoveAt(orderedRenderNodeIndex);

            // If last item was moved, update its index
            if (orderedRenderNodeIndex < renderObjects.Count)
            {
                renderObjects[orderedRenderNodeIndex].VisibilityObjectNode = new StaticObjectNodeReference(orderedRenderNodeIndex);
            }

            return(true);
        }