Example #1
0
        /// <summary>
        /// Allows derived classes to handle when the <see cref="RenderWindow"/> changes.
        /// </summary>
        /// <param name="newRenderWindow">The new <see cref="RenderWindow"/>.</param>
        protected virtual void OnRenderWindowChanged(RenderWindow newRenderWindow)
        {
            if (_sb != null)
            {
                _sb.RenderTarget = newRenderWindow;
            }

            if (LightManager != null)
            {
                LightManager.Initialize(newRenderWindow);
            }

            if (RefractionManager != null)
            {
                RefractionManager.Initialize(newRenderWindow);
            }
        }
Example #2
0
 /// <summary>
 /// Updates the <see cref="IDrawingManager"/> and all components inside of it.
 /// </summary>
 /// <param name="currentTime">The current game time in milliseconds.</param>
 public void Update(TickCount currentTime)
 {
     LightManager.Update(currentTime);
     RefractionManager.Update(currentTime);
 }
Example #3
0
        public void EndDrawWorld()
        {
            if (State != DrawingManagerState.DrawingWorld)
            {
                throw new InvalidOperationException("This method can only be called after BeginDrawWorld.");
            }

            try
            {
                _state = DrawingManagerState.Idle;

                // Ensure the RenderWindow is available
                if (!IsRenderWindowAvailable())
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Skipping EndDrawWorld() call - the RenderWindow is not available.");
                    }
                    return;
                }

                // Ensure the buffer is available
                if (_buffer == null || _buffer.IsDisposed)
                {
                    const string errmsg = "Skipping EndDrawWorld() call - the _buffer is not available.";
                    if (log.IsWarnEnabled)
                    {
                        log.WarnFormat(errmsg);
                    }
                    return;
                }

                SafeEndSpriteBatch(_sb);

                // Draw the lights
                try
                {
                    if (LightManager.IsEnabled)
                    {
                        // Copy the lights onto the buffer
                        LightManager.DrawToTarget(_worldCamera, _buffer);
                        _buffer.Display();
                    }
                    else
                    {
                        // Don't have to take any alternate drawing route since lights are just drawn on top of the screen buffer
                    }
                }
                catch (Exception ex)
                {
                    // Do not catch AccessViolationException - let that be handled by the outer block
                    if (ex is AccessViolationException)
                    {
                        throw;
                    }

                    const string errmsg =
                        "Error on `{0}` while trying to draw the LightManager `{1}`." +
                        " Lights will have to be skipped this frame. Exception: {2}";
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg, this, LightManager, ex);
                    }
                }

                // Have to display the buffer since we will start referencing the texture for it
                _buffer.Display();

                // Draw the refractions
                try
                {
                    if (RefractionManager.IsEnabled)
                    {
                        // Pass the buffer to the refraction manager to draw to the screen
                        RefractionManager.DrawToTarget(_worldCamera, _rw, _buffer.Texture);
                    }
                    else
                    {
                        // Since the RefractionManager won't be handling copying to the screen for us, we will have to draw
                        // to the screen manually
                        DrawBufferToScreen(_buffer.Texture, BlendMode.None);
                    }
                }
                catch (Exception ex)
                {
                    // Do not catch AccessViolationException - let that be handled by the outer block
                    if (ex is AccessViolationException)
                    {
                        throw;
                    }

                    const string errmsg =
                        "Error on `{0}` while trying to draw the RefractionManager `{1}`." +
                        " Refractions will have to be skipped this frame. Exception: {2}";
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg, this, RefractionManager, ex);
                    }
                }

                _view.Reset(new FloatRect(0, 0, _rw.Size.X, _rw.Size.Y));
                _rw.SetView(_view);
            }
            catch (AccessViolationException ex)
            {
                // More frequently and less concerning exception
                const string errmsg =
                    "EndDrawWorld failed on `{0}`. Device was probably lost. The world will have to skip being drawn this frame. Exception: {1}";
                if (log.IsInfoEnabled)
                {
                    log.InfoFormat(errmsg, this, ex);
                }
            }
            catch (Exception ex)
            {
                // Unexpected exception
                const string errmsg =
                    "EndDrawWorld failed on `{0}` due to unexpected exception. The world will have to skip being drawn this frame. Exception: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, this, ex);
                }
            }
        }