private void OnRenderingLock(object sender, SKNativePaintGLSurfaceEventArgs e)
 {
     lock (_renderLock)
     {
         OnRendering(sender, e);
     }
 }
        private void InitializeGameLoop(Action onUpdate, SKNativePaintGLSurfaceEventArgs e, bool isMultiThreaded)
        {
            // Run update loop and register for rendering events.
            onUpdate();

            _renderLoop = new RenderLoop();
            _renderLoop.Start(onUpdate);
            Initialized?.Invoke(this, e.Surface);
        }
        private void OnRendering(object sender, SKNativePaintGLSurfaceEventArgs e)
        {
            _shouldRender = false;
            var surface = e.Surface;
            var canvas  = surface.Canvas;

            var worldMatrix = SKMatrix.MakeIdentity();

            // Apply DPI scaling.
            SKMatrix.Concat(ref worldMatrix, worldMatrix, SKMatrix.MakeScale(ScaleFactor, ScaleFactor));

            canvas.ResetMatrix();
            canvas.SetMatrix(worldMatrix);

            Draw?.Invoke(this, e.Surface);
        }
 /// <summary>
 /// Performs custom initialization and starts game time.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="e">Event args.</param>
 private void Initialize(object sender, SKNativePaintGLSurfaceEventArgs e)
 {
     SetupInput();
     PlatformInitalize(sender, e);
     if (Thread.CurrentThread.ManagedThreadId == _uiThreadId)
     {
         this.PaintSurface += OnRendering;
         InitializeGameLoop(() => OnUpdate(), e, false);
     }
     else
     {
         this.PaintSurface += OnRenderingLock;
         RunOnUiThread(() =>
         {
             InitializeGameLoop(() => OnUpdateLock(), e, true);
         });
     }
 }
Esempio n. 5
0
            protected override void OnPaintSurface(SkiaSharp.Views.UWP.SKPaintGLSurfaceEventArgs e)
            {
                base.OnPaintSurface(e);

                controller.OnPaintSurface(new SKPaintGLSurfaceEventArgs(e.Surface, e.RenderTarget));
            }
 partial void PlatformInitalize(object sender, SKNativePaintGLSurfaceEventArgs e)
 {
     EnableRenderLoop = false;
     DrawInBackground = false;
 }
 /// <summary>
 /// Platform-specific initialization steps.
 /// </summary>
 partial void PlatformInitalize(object sender, SKNativePaintGLSurfaceEventArgs e);
 /// <summary>
 /// Runs when the underlying control is done initializing (first rendering goes through).
 /// </summary>
 /// <param name="sender">Native control.</param>
 /// <param name="e">Event args.</param>
 private void OnNativeControlInitialized(object sender, SKNativePaintGLSurfaceEventArgs e)
 {
     this.PaintSurface -= OnNativeControlInitialized;
     Initialize(sender, e);
 }