Ejemplo n.º 1
0
        /// <summary>
        /// Updates DirectX objects and calls.
        /// Layers are updated first, then the derived control is updated.
        /// </summary>
        protected virtual void UpdateDx(RenderTime updateTime)
        {
            OnUpdating(updateTime);

            lock (Layers)
            {
                Stopwatch sw = Stopwatch.StartNew();
                foreach (var layer in Layers)
                {
                    RenderProfile profile;
                    if (!ProfileStats.TryGetValue(layer.Name, out profile))
                    {
                        profile = new RenderProfile();
                        ProfileStats.Add(layer.Name, profile);
                    }

                    var start = sw.Elapsed;
                    layer.Update(updateTime);
                    profile.UpdateTime = (float)(sw.Elapsed - start).TotalMilliseconds;
                }
            }

            // Update our derived control
            OnUpdated(updateTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize graphics components when the control is created.
        /// </summary>
        protected override void OnCreateControl()
        {
            base.OnCreateControl();

            if (DesignMode)
            {
                return;
            }

            _lastUpdate       = DateTime.Now;
            _renderTimer      = new RenderTime();
            _updateTimer      = new RenderTime();
            _renderDebugTimer = new RenderTime();
            _updateDebugTimer = new RenderTime();
            InitGraphics();
            LoadContent();

            RenderLoop();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Local render. Performs timing calculations and debug rendering if required then calls <see cref="OnRendering"/> for inheriting controls. Presents the swap chain when ready.
        /// </summary>
        protected void Render(RenderTime renderTime)
        {
            if (!PresenterReady)
            {
                return;
            }
            // Update our derived control

            RenderTarget2D.BeginDraw();
            OnRendering(renderTime);

            lock (Layers)
            {
                Stopwatch sw = Stopwatch.StartNew();
                foreach (var layer in Layers)
                {
                    RenderProfile profile;
                    if (!ProfileStats.TryGetValue(layer.Name, out profile))
                    {
                        profile = new RenderProfile();
                        ProfileStats.Add(layer.Name, profile);
                    }

                    var start = sw.Elapsed;
                    layer.Render(renderTime);
                    profile.RenderTime = (float)(sw.Elapsed - start).TotalMilliseconds;
                }
                sw.Stop();
            }

            OnRendered(renderTime);
            RenderTarget2D.EndDraw();

            OnRender3D();

            _swapChain.Present(0, PresentFlags.None);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Render cycle: only perform drawing code here. Use OnUpdateDx to perform calculations.
 /// </summary>
 protected virtual void OnRendered(RenderTime renderTime)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Update cycle: perform calculations and update data here.
 /// </summary>
 protected virtual void OnUpdated(RenderTime updateTime)
 {
 }