static private void OnTick() { // Resort the timer update lists if they have been changed. if (_resort) { _frameTimers.Sort((f, s) => f.FrameActionOrder - s.FrameActionOrder); _drawTimers.Sort((f, s) => f.DrawOrder - s.DrawOrder); _updateTimers.Sort((f, s) => f.UpdateOrder - s.UpdateOrder); _resort = false; } // Do we need to initialize the window event handlers? if (_windowEvents == null && Window.Current != null) _windowEvents = new InputEvents(Window.Current.CoreWindow, SharedGraphicsDeviceManager.Current.SwapChainBackgroundPanel, MetroGamePlatform.TouchQueue); if (_windowEvents != null) _windowEvents.UpdateState(); // First call all the frame events... we do this // every frame regardless of the elapsed time. foreach (var timer in _frameTimers) timer.FrameAction(timer, EventArgs.Empty); // Next do update events. var elapsed = _gameTimer.Elapsed; _gameTimer.Reset(); _gameTimer.Start(); foreach (var timer in _updateTimers) timer.DoUpdate(elapsed); // Timers that have been updated can now draw. var deviceManager = SharedGraphicsDeviceManager.Current; if (deviceManager != null && deviceManager.GraphicsDevice != null) { // We gotta reapply the render targets on update // for some reason... i guess the OS changes them? deviceManager.GraphicsDevice.ResetRenderTargets(); var doPresent = false; foreach (var timer in _drawTimers) { if (!timer._doDraw) continue; timer.Draw(timer, timer._gameTime); doPresent = true; timer._doDraw = false; } // If nothing was drawn then we don't present and // the swap chain will contain whatever was last rendered. if (doPresent) deviceManager.GraphicsDevice.Present(); } }
public void Initialize(CoreWindow coreWindow, UIElement inputElement, TouchQueue touchQueue) { _coreWindow = coreWindow; _windowEvents = new InputEvents(_coreWindow, inputElement, touchQueue); _dinfo = DisplayInformation.GetForCurrentView(); _appView = ApplicationView.GetForCurrentView(); // Set a min size that is reasonable knowing someone might try // to use some old school resolution like 640x480. var minSize = new Windows.Foundation.Size(640 / _dinfo.RawPixelsPerViewPixel, 480 / _dinfo.RawPixelsPerViewPixel); _appView.SetPreferredMinSize(minSize); _orientation = ToOrientation(_dinfo.CurrentOrientation); _dinfo.OrientationChanged += DisplayProperties_OrientationChanged; _swapChainPanel = inputElement as SwapChainPanel; _swapChainPanel.SizeChanged += SwapChain_SizeChanged; _coreWindow.Closed += Window_Closed; _coreWindow.Activated += Window_FocusChanged; _coreWindow.CharacterReceived += Window_CharacterReceived; SetViewBounds(_appView.VisibleBounds.Width, _appView.VisibleBounds.Height); SetCursor(false); }
static private void OnTick() { // Resort the timer update lists if they have been changed. if (_resort) { _frameTimers.Sort((f, s) => f.FrameActionOrder - s.FrameActionOrder); _drawTimers.Sort((f, s) => f.DrawOrder - s.DrawOrder); _updateTimers.Sort((f, s) => f.UpdateOrder - s.UpdateOrder); _resort = false; } // Do we need to initialize the window event handlers? if (_windowEvents == null && Window.Current != null) { _windowEvents = new InputEvents(Window.Current.CoreWindow, SharedGraphicsDeviceManager.Current.SwapChainBackgroundPanel); } if (_windowEvents != null) { _windowEvents.UpdateState(); } // First call all the frame events... we do this // every frame regardless of the elapsed time. foreach (var timer in _frameTimers) { timer.FrameAction(timer, EventArgs.Empty); } // Next do update events. var elapsed = _gameTimer.Elapsed; _gameTimer.Reset(); _gameTimer.Start(); foreach (var timer in _updateTimers) { timer.DoUpdate(elapsed); } // Timers that have been updated can now draw. var deviceManager = SharedGraphicsDeviceManager.Current; if (deviceManager != null && deviceManager.GraphicsDevice != null) { // We gotta reapply the render targets on update // for some reason... i guess the OS changes them? deviceManager.GraphicsDevice.ResetRenderTargets(); var doPresent = false; foreach (var timer in _drawTimers) { if (!timer._doDraw) { continue; } timer.Draw(timer, timer._gameTime); doPresent = true; timer._doDraw = false; } // If nothing was drawn then we don't present and // the swap chain will contain whatever was last rendered. if (doPresent) { deviceManager.GraphicsDevice.Present(); } } }
public void Initialize(CoreWindow coreWindow, UIElement inputElement, TouchQueue touchQueue) { _coreWindow = coreWindow; _windowEvents = new InputEvents(_coreWindow, inputElement, touchQueue); _orientation = ToOrientation(DisplayProperties.CurrentOrientation); DisplayProperties.OrientationChanged += DisplayProperties_OrientationChanged; _coreWindow.SizeChanged += Window_SizeChanged; _coreWindow.Closed += Window_Closed; _coreWindow.Activated += Window_FocusChanged; #if !WINDOWS_PHONE81 _currentViewState = ApplicationView.Value; #endif var bounds = _coreWindow.Bounds; SetClientBounds(bounds.Width, bounds.Height); SetCursor(false); }
public void Initialize(CoreWindow coreWindow, UIElement inputElement) { _coreWindow = coreWindow; _windowEvents = new InputEvents(_coreWindow, inputElement); _orientation = ToOrientation(DisplayProperties.CurrentOrientation); DisplayProperties.OrientationChanged += DisplayProperties_OrientationChanged; _coreWindow.SizeChanged += Window_SizeChanged; _coreWindow.Closed += Window_Closed; _coreWindow.Activated += Window_FocusChanged; _currentViewState = ApplicationView.Value; var bounds = _coreWindow.Bounds; SetClientBounds(bounds.Width, bounds.Height); }