Example #1
0
 /// <summary>
 /// Removes a disposable object to the list of the objects to dispose.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="toDisposeArg">To dispose.</param>
 protected internal void RemoveToDispose <T>(T toDisposeArg)
 {
     if (!ReferenceEquals(toDisposeArg, null) && DisposeCollector != null)
     {
         DisposeCollector.Remove(toDisposeArg);
     }
 }
Example #2
0
 public void RecreateWindowSizedResources(GraphicsDevice graphicsDevice)
 {
     _disposer.Remove(_windowSized);
     _windowSized.Dispose();
     _windowSized = new WindowSizedSceneContext(graphicsDevice, MainSceneSampleCount);
     _disposer.Add(_windowSized);
 }
 // Removes an IDisposable object from the collection of disposable objects. Does not
 // dispose of the object before removing it.
 protected internal void RemoveToDispose <T>(T objectToRemove)
 {
     // If objectToRemove is not null, have the DisposeCollector forget about it.
     if (!ReferenceEquals(objectToRemove, null) && (DisposeCollector != null))
     {
         DisposeCollector.Remove(objectToRemove);
     }
 }
Example #4
0
        /// <summary>
        ///     Remove an item from the game.
        /// </summary>
        /// <typeparam name="T"> Generic type parameter. </typeparam>
        /// <param name="item"> item. </param>
        /// <returns>
        ///     The item.
        /// </returns>
        public T Remove <T>(T item)
        {
            // ReSharper disable once InconsistentlySynchronizedField
            if (item is IContentable contentable && _contentableComponent.Contains(contentable))
            {
                lock (_contentableComponent)
                {
                    _contentableComponent.Remove(contentable);
                }
                contentable.UnloadContent(_serviceRegistry);
            }

            // ReSharper disable once InconsistentlySynchronizedField
            if (item is IUpdateable updateable && _updateableComponent.Contains(updateable))
            {
                lock (_updateableComponent)
                {
                    _updateableComponent.Remove(updateable);
                }
                updateable.UpdateOrderChanged -= UpdateableComponent_UpdateOrderChanged;
            }

            // ReSharper disable once InconsistentlySynchronizedField
            if (item is IDrawable drawable && _drawableComponent.Contains(drawable))
            {
                lock (_drawableComponent)
                {
                    _drawableComponent.Remove(drawable);
                }
                drawable.DrawOrderChanged -= DrawableComponent_DrawOrderChanged;
            }

            if (item is IComponent component1 && _gameComponents.ContainsKey(component1.Name))
            {
                lock (_gameComponents)
                {
                    _gameComponents.Remove(component1.Name);
                }
            }

            if (item is IInputHandler inputHandler)
            {
                inputHandler.UnregisterInput(_inputDevice);
            }

            if (item is IDisposable disposable)
            {
                disposable.Dispose();
                _collector.Remove(item);
            }

            return(item);
        }
Example #5
0
        /// <summary>
        ///     Removes the given item.
        /// </summary>
        /// <typeparam name="T"> Generic type parameter. </typeparam>
        /// <param name="item"> The item. </param>
        /// <returns>
        ///     A T.
        /// </returns>
        protected T Remove <T>(T item)
        {
            if (item is IContentable contentable && _contentableComponent.Contains(contentable))
            {
                lock (_contentableComponent)
                {
                    _contentableComponent.Remove(contentable);
                }
                contentable.UnloadContent(_registry !);
            }

            if (item is IUpdateable updateable && _updateableComponent.Contains(updateable))
            {
                lock (_updateableComponent)
                {
                    _updateableComponent.Remove(updateable);
                }
                updateable.UpdateOrderChanged -= UpdateableComponent_UpdateOrderChanged;
            }

            // ReSharper disable once InconsistentlySynchronizedField
            if (item is IDrawable drawable && _drawableComponent.Contains(drawable))
            {
                lock (_drawableComponent)
                {
                    _drawableComponent.Remove(drawable);
                }
                drawable.DrawOrderChanged -= DrawableComponent_DrawOrderChanged;
            }

            if (item is IComponent component && _sceneComponents.ContainsKey(component.Name))
            {
                lock (_sceneComponents)
                {
                    _sceneComponents.Remove(component.Name);
                }
            }

            if (item is IDisposable disposable)
            {
                disposable.Dispose();
                _collector.Remove(item);
            }

            return(item);
        }
Example #6
0
        /// <summary>
        ///     Removes the given <paramref name="control" /> from this ui manager.
        /// </summary>
        /// <typeparam name="T"> Generic type parameter. </typeparam>
        /// <param name="control"> The control to remove. </param>
        /// <param name="dispose"> True to dispose the control after removing. </param>
        /// <returns>The <paramref name="control"/></returns>
        /// <exception cref="InvalidOperationException"> Thrown when the requested operation is invalid. </exception>
        public T Remove <T>(T control, bool dispose = false) where T : Control
        {
            if (control._parent != null)
            {
                throw new InvalidOperationException(
                          $"The control doesn't belongs to this {nameof(UiManager)} instance.");
            }

            RemoveAt(control._uiListIndex);

            _collector.Remove(control);

            if (dispose)
            {
                control.Dispose();
            }

            return(control);
        }