public Window(WindowOptions options) { if (Application.MainWindow != null) { throw new Lime.Exception("Attempt to set Application.MainWindow twice"); } Application.MainWindow = this; Active = true; fpsCounter = new FPSCounter(); ActivityDelegate.Instance.Paused += activity => { Active = false; RaiseDeactivated(); }; ActivityDelegate.Instance.Resumed += activity => { Active = true; RaiseActivated(); }; ActivityDelegate.Instance.GameView.Resize += (sender, e) => { RaiseResized(((ResizeEventArgs)e).DeviceRotated); }; ActivityDelegate.Instance.GameView.RenderFrame += (sender, e) => { RaiseRendering(); fpsCounter.Refresh(); }; ActivityDelegate.Instance.GameView.UpdateFrame += (sender, e) => { RaiseUpdating((float)e.Time); }; PixelScale = Resources.System.DisplayMetrics.Density; }
public Window(WindowOptions options) { if (Application.MainWindow != null) { throw new Lime.Exception("Attempt to set Application.MainWindow twice"); } Application.MainWindow = this; Active = true; fpsCounter = new FPSCounter(); input = new Input(); UnityApplicationDelegate.Instance.Updating += delta => { Input.Refresh(); RaiseUpdating(delta); AudioSystem.Update(); Input.TextInput = null; Input.CopyKeysState(); if (LastSize != ClientSize) { RaiseResized(false); LastSize = ClientSize; } }; UnityApplicationDelegate.Instance.Rendering += () => { RaiseRendering(); fpsCounter.Refresh(); }; UnityApplicationDelegate.Instance.Destroying += () => { RaiseClosed(); }; }
public Window(WindowOptions options) { if (Application.MainWindow != null) { throw new Lime.Exception("Attempt to set Application.MainWindow twice"); } Application.MainWindow = this; Input = new WindowInput(this); Active = true; AsyncRendering = options.AsyncRendering; fpsCounter = new FPSCounter(); ActivityDelegate.Instance.Paused += activity => { Active = false; RaiseDeactivated(); }; ActivityDelegate.Instance.Resumed += activity => { Active = true; RaiseActivated(); }; ActivityDelegate.Instance.GameView.Resize += (sender, e) => { RaiseResized(((ResizeEventArgs)e).DeviceRotated); }; PixelScale = Resources.System.DisplayMetrics.Density; if (AsyncRendering) { renderThread = new Thread(RenderLoop); renderThread.IsBackground = true; renderThread.Start(); } Application.WindowUnderMouse = this; var ccb = new ChoreographerCallback(); long prevFrameTime = Java.Lang.JavaSystem.NanoTime(); ccb.OnFrame += frameTimeNanos => { var delta = (float)((frameTimeNanos - prevFrameTime) / 1000000000d); prevFrameTime = frameTimeNanos; if (Active && ActivityDelegate.Instance.GameView.IsSurfaceCreated) { fpsCounter.Refresh(); Update(delta); if (AsyncRendering) { renderCompleted.WaitOne(); renderCompleted.Reset(); RaiseSync(); renderReady.Set(); } else { RaiseSync(); Render(); } } }; Choreographer.Instance.PostFrameCallback(ccb); }
private void OnRenderFrame(object s, Xamarin.FrameEventArgs e) { if (!Active || UIViewController.SoftKeyboardBeingShownOrHid) { return; } UIView.MakeCurrent(); RaiseRendering(); UIView.SwapBuffers(); fpsCounter.Refresh(); }
private void HandleRenderFrame() { if (invalidated) { fpsCounter.Refresh(); View.MakeCurrent(); RaiseRendering(); View.SwapBuffers(); invalidated = false; } }
internal void HandleRenderFrame() { if (invalidated) { fpsCounter.Refresh(); // Workaround macOS 10.14 issue: UpdateGLContext should be called on render frame, not on DidResize. if (needUpdateGLContext) { needUpdateGLContext = false; View.UpdateGLContext(); } View.MakeCurrent(); RaiseRendering(); View.SwapBuffers(); invalidated = false; } }
private void Update() { var wasInvalidated = isInvalidated; isInvalidated = false; if (!form.Visible || !form.CanFocus) { return; } UnclampedDelta = (float)stopwatch.Elapsed.TotalSeconds; float delta = Mathf.Clamp(UnclampedDelta, 0, Application.MaxDelta); stopwatch.Restart(); if (this == Application.MainWindow && Application.MainMenu != null) { Application.MainMenu.Refresh(); } fpsCounter.Refresh(); // Refresh mouse position of every frame to make HitTest work properly if mouse is outside of the screen. RefreshMousePosition(); RaiseUpdating(delta); AudioSystem.Update(); if (active || Input.IsSimulationRunning) { Input.CopyKeysState(); Input.ProcessPendingKeyEvents(delta); Input.TextInput = null; } if (wasInvalidated || renderingState == RenderingState.RenderDeferred) { glControl.Invalidate(); } renderingState = RenderingState.Updated; if (AsyncRendering) { renderCompleted.WaitOne(); renderCompleted.Reset(); } RaiseSync(); if (AsyncRendering) { renderReady.Set(); } }
private void OnPaint(object sender, PaintEventArgs e) { switch (renderingState) { case RenderingState.Updated: if (glControl.IsHandleCreated && form.Visible && !glControl.IsDisposed) { glControl.MakeCurrent(); PixelScale = CalcPixelScale(e.Graphics.DpiX); fpsCounter.Refresh(); RaiseRendering(); glControl.SwapBuffers(); } renderingState = RenderingState.Rendered; break; case RenderingState.Rendered: renderingState = RenderingState.RenderDeferred; break; case RenderingState.RenderDeferred: break; } }
private void Update() { var wasInvalidated = isInvalidated; isInvalidated = false; if (!form.Visible || !form.CanFocus || !renderControl.IsHandleCreated) { return; } UnclampedDelta = (float)stopwatch.Elapsed.TotalSeconds; float delta = Mathf.Clamp(UnclampedDelta, 0, Application.MaxDelta); stopwatch.Restart(); if (this == Application.MainWindow && Application.MainMenu != null) { Application.MainMenu.Refresh(); } fpsCounter.Refresh(); // Refresh mouse position of every frame to make HitTest work properly if mouse is outside of the screen. RefreshMousePosition(); if (active || Input.IsSimulationRunning) { Input.ProcessPendingInputEvents(delta); } if (Input.IsSimulationRunning) { Application.Input.Simulator.OnProcessingPendingInputEvents(); } RaiseUpdating(delta); AudioSystem.Update(); if (active || Input.IsSimulationRunning) { Input.CopyKeysState(); Input.TextInput = null; } if (wasInvalidated || renderingState == RenderingState.RenderDeferred) { renderControl.Invalidate(); } // We give one update cycle to handle files drop // (files dropped event may be fired inside update) if (Input.DroppedFiles.Count > 0 || shouldCleanDroppedFiles) { if (shouldCleanDroppedFiles) { Input.DroppedFiles.Clear(); } shouldCleanDroppedFiles = !shouldCleanDroppedFiles; } renderingState = renderControl.CanRender ? RenderingState.Updated : RenderingState.Rendered; WaitForRendering(); if (renderControl.CanRender) { RaiseSync(); if (AsyncRendering) { renderCompleted.Reset(); renderReady.Set(); } } }