Esempio n. 1
0
        protected override void Draw(GameTime gameTime)
        {
            DrawTimer.Restart();

#if DEBUG
            ReloadWatcher.Check();
#endif

            GraphicsDevice.Clear(Color.Black);
            SpriteBatch.Begin(blendState: BlendState.NonPremultiplied);

            var allocatedBytes = ThisProcess.PrivateMemorySize64;

            using (var renderState = FrameManager.CaptureFrom(State, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight, allocatedBytes))
            {
                var background           = Rooms.GetBackground(renderState.Background);
                var visibleWidth         = Math.Min(Graphics.PreferredBackBufferWidth, background.Width - renderState.BackgroundOffsetX);
                var visibleHeight        = Math.Min(Graphics.PreferredBackBufferHeight, background.Height - renderState.BackgroundOffsetY);
                var backgroundSourceRect =
                    new Rectangle(
                        renderState.BackgroundOffsetX,
                        renderState.BackgroundOffsetY,
                        visibleWidth,
                        visibleHeight
                        );
                var backgroundDestPoint = new Vector2(renderState.OffsetInWindowX, renderState.OffsetInWindowY);

                SpriteBatch.Draw(background, backgroundDestPoint, backgroundSourceRect, Color.White);

                if (renderState.TransitionBackground.HasValue)
                {
                    var transitionBackground = Rooms.GetBackground(renderState.TransitionBackground.Value);
                    var transitionSourceRect =
                        new Rectangle(
                            renderState.TransitionBackgroundSourceX,
                            renderState.TransitionBackgroundSourceY,
                            transitionBackground.Width - renderState.TransitionBackgroundSourceX,
                            transitionBackground.Height - renderState.TransitionBackgroundSourceY
                            );

                    var transitionDestPoint =
                        new Vector2(
                            renderState.TransitionBackgroundDestX + renderState.OffsetInWindowX,
                            renderState.TransitionBackgroundDestY + renderState.OffsetInWindowY
                            );

                    SpriteBatch.Draw(transitionBackground, transitionDestPoint, transitionSourceRect, Color.White);
                }

                for (var i = 0; i < renderState.EntityCount; i++)
                {
                    var toRender = renderState.Get(i);
                    var vec      = new Vector2(renderState.OffsetInWindowX + toRender.X, renderState.OffsetInWindowY + toRender.Y);
                    var sprite   = Assets.Get(toRender.ToRender);

                    SpriteBatch.Draw(sprite, vec, Color.White);
                }

                if (renderState.FadePercent != 0)
                {
                    var scale       = renderState.FadePercent / 100f;
                    var scaleColor  = Color.White * scale;
                    var wholeScreen = new Rectangle(0, 0, GameState.WIDTH_HACK, GameState.HEIGHT_HACK);

                    SpriteBatch.Draw(Black, wholeScreen, scaleColor);
                }

                RenderDebugOverlay(renderState);
            }

            SpriteBatch.End();

            base.Draw(gameTime);

            DrawTimer.Stop();
            var renderTime = DrawTimer.Elapsed;

            FPSTracker.PushRenderTime(renderTime);
            FPSTracker.FrameFinished();
        }