/// <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(); } }
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); } }
/// <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; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.surface = ((SharpDX.Toolkit.SharpDXElement)(target)); return; } this._contentLoaded = true; }
/// <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); }
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); }
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(); }
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; }
private void RenderLoopCallback() { if (Exiting) { CompositionTarget.Rendering -= OnCompositionTargetRendering; if (element != null) { element.Dispose(); element = null; } return; } RunCallback(); element.InvalidateRendering(); }