コード例 #1
0
        /// <summary>
        /// The main render loop callback that is cached in a delegate and is invoked to process main game loop.
        /// </summary>
        private void RenderLoopCallback()
        {
            if (Exiting)
            {
                CompositionTarget.Rendering -= OnCompositionTargetRendering;
                if (element != null)
                {
                    element.Dispose();
                    element = null;
                }
                return;
            }

            // run render loop once
            RunCallback();
            // mark completion of drawing operations
            deviceContext.End(queryForCompletion);

            // wait until drawing completes
            Bool completed;

            while (!(deviceContext.GetData(queryForCompletion, out completed) &&
                     completed))
            {
                Thread.Yield();
            }

            // syncronize D3D surface with WPF
            if (!element.IsDisposed)
            {
                element.InvalidateRendering();
            }
        }
コード例 #2
0
        private static void HandleGameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var view = d as GameView;
            if (view == null) return;

            var newGame = e.NewValue as Game;

            view.Content = null; // old element will be unloaded and will disable the game

            if(newGame != null)
            {
                // new element will reactivate the game on loading
                var element = new SharpDXElement
                              {
                                  SendResizeToGame = true,
                                  SendResizeDelay = TimeSpan.FromSeconds(1),
                                  LowPriorityRendering = false
                              };
                view.Content = element;

                if(newGame.IsRunning)
                    newGame.Switch(element);
                else
                    newGame.Run(element);
            }
        }
コード例 #3
0
        /// <inheritdoc />
        internal override void Initialize(GameContext gameContext)
        {
            if (gameContext == null)
            {
                throw new ArgumentNullException("gameContext");
            }

            element = gameContext.Control as SharpDXElement;
            if (element == null)
            {
                throw new ArgumentException("Only SharpDXElement is supported at this time", "gameContext");
            }

            var width = gameContext.RequestedWidth;

            if (width <= 0)
            {
                width = GraphicsDeviceManager.DefaultBackBufferWidth;
            }

            var height = gameContext.RequestedHeight;

            if (height <= 0)
            {
                height = GraphicsDeviceManager.DefaultBackBufferHeight;
            }

            element.TrySetSize(width, height);

            element.ResizeCompleted += OnClientSizeChanged;
            element.MouseEnter      += OnMouseEnter;
            element.MouseLeave      += OnMouseLeave;
            element.Loaded          += HandleElementLoaded;
            element.Unloaded        += HandleElementUnloaded;
        }
コード例 #4
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
 {
     switch (connectionId)
     {
     case 1:
         this.surface = ((SharpDX.Toolkit.SharpDXElement)(target));
         return;
     }
     this._contentLoaded = true;
 }
コード例 #5
0
        /// <inheritdoc />
        internal override void Switch(GameContext context)
        {
            element.ResizeCompleted -= OnClientSizeChanged;
            element.MouseEnter      -= OnMouseEnter;
            element.MouseLeave      -= OnMouseLeave;
            element.Loaded          -= HandleElementLoaded;
            element.Unloaded        -= HandleElementUnloaded;

            element = null;

            Initialize(context);
        }
コード例 #6
0
        private void RunGameOn(UIElement disableButton, UIElement enableButton, ContentControl contentContainer)
        {
            DisposeContent(contentContainer1);
            DisposeContent(contentContainer2);

            disableButton.IsEnabled = false;
            enableButton.IsEnabled = true;

            var element = new SharpDXElement
                          {
                              SendResizeToGame = true,
                              SendResizeDelay = TimeSpan.FromSeconds(2),
                              LowPriorityRendering = false,
                          };

            contentContainer.Content = element;

            if (_game.IsRunning)
                _game.Switch(element);
            else
                _game.Run(element);
        }
コード例 #7
0
        private void RenderLoopCallback()
        {
            if (Exiting)
            {
                CompositionTarget.Rendering -= OnCompositionTargetRendering;
                if (element != null)
                {
                    element.Dispose();
                    element = null;
                }
                return;
            }

            // run render loop once
            RunCallback();
            // mark completion of drawing operations
            deviceContext.End(queryForCompletion);

            // wait until drawing completes
            Bool completed;
            while (!(deviceContext.GetData(queryForCompletion, out completed)
                   && completed)) Thread.Yield();

            // syncronize D3D surface with WPF
            element.InvalidateRendering();
        }
コード例 #8
0
        internal override void Initialize(GameContext gameContext)
        {
            if (gameContext == null) throw new ArgumentNullException("gameContext");

            element = gameContext.Control as SharpDXElement;
            if (element == null) throw new ArgumentException("Only SharpDXElement is supported at this time", "gameContext");

            var width = gameContext.RequestedWidth;
            if (width <= 0)
                width = GraphicsDeviceManager.DefaultBackBufferWidth;

            var height = gameContext.RequestedHeight;
            if (height <= 0)
                height = GraphicsDeviceManager.DefaultBackBufferHeight;

            element.TrySetSize(width, height);

            element.ResizeCompleted += OnClientSizeChanged;
            element.MouseEnter += OnMouseEnter;
            element.MouseLeave += OnMouseLeave;
        }
コード例 #9
0
        /// <inheritdoc />
        internal override void Switch(GameContext context)
        {
            element.ResizeCompleted -= OnClientSizeChanged;
            element.MouseEnter -= OnMouseEnter;
            element.MouseLeave -= OnMouseLeave;
            element.Loaded -= HandleElementLoaded;
            element.Unloaded -= HandleElementUnloaded;

            element = null;

            Initialize(context);
        }
コード例 #10
0
ファイル: GameWindowDesktopWpf.cs プロジェクト: pH200/SharpDX
        private void RenderLoopCallback()
        {
            if (Exiting)
            {
                CompositionTarget.Rendering -= OnCompositionTargetRendering;
                if (element != null)
                {
                    element.Dispose();
                    element = null;
                }
                return;
            }

            RunCallback();

            element.InvalidateRendering();
        }