コード例 #1
0
        /// <summary>
        /// Sets the world matrix.
        /// </summary>
        /// <param name="worldMatrix">The world matrix.</param>
        /// <param name="source">The source object that caused this change or null when not important.</param>
        public override void SetWorldMatrix(MatrixD worldMatrix, object source = null)
        {
            MyUtils.AssertIsValid(worldMatrix);

            ProfilerShort.Begin("Scale");
            if (Scale != null)
            {
                MyUtils.Normalize(ref worldMatrix, out worldMatrix);
                worldMatrix = MatrixD.CreateScale(Scale.Value) * worldMatrix;
            }
            ProfilerShort.End();
            MatrixD localMatrix;

            if (this.Container.Entity.Parent == null)
            {
                m_previousParentWorldMatrix = this.m_worldMatrix;
                this.m_worldMatrix          = worldMatrix;
                localMatrix = worldMatrix;
            }
            else
            {
                MatrixD matParentInv = MatrixD.Invert(this.Container.Entity.Parent.WorldMatrix);
                localMatrix = (Matrix)(worldMatrix * matParentInv);
            }

            ProfilerShort.Begin("EqualsFast");
            if (!m_localMatrix.EqualsFast(ref localMatrix) || !m_previousParentWorldMatrix.EqualsFast(ref worldMatrix))
            {
                ProfilerShort.BeginNextBlock("UpdateWM");
                m_localMatrixChanged = true;
                this.m_localMatrix   = localMatrix;
                UpdateWorldMatrix(source);
                ProfilerShort.BeginNextBlock("sync");
                if (MyPerGameSettings.MultiplayerEnabled)
                {
                    if (this.Container.Entity.InScene && source != m_syncObject && ShouldSync && this.Container.Entity.Parent == null)
                    {
                        m_syncObject.UpdatePosition();
                    }
                }
            }
            ProfilerShort.End();
        }
コード例 #2
0
        /// <summary>
        /// Called when [world position changed].
        /// </summary>
        /// <param name="source">The source object that caused this event.</param>
        public override void OnWorldPositionChanged(object source)
        {
            Debug.Assert(source != this && (Container.Entity == null || source != Container.Entity), "Recursion detected!");
            ProfilerShort.Begin("Volume");
            UpdateWorldVolume();
            ProfilerShort.BeginNextBlock("Prunning.Move");
            MyGamePruningStructure.Move(Container.Entity as MyEntity);

            ProfilerShort.BeginNextBlock("Children");
            UpdateChildren(source);

            ProfilerShort.BeginNextBlock("Raise");
            RaiseOnPositionChanged(this);

            ProfilerShort.BeginNextBlock("Action");
            if (WorldPositionChanged != null)
            {
                WorldPositionChanged(source);
            }
            ProfilerShort.End();
        }
コード例 #3
0
        /// <summary>
        /// Updates the world matrix (change caused by this entity)
        /// </summary>
        public override void UpdateWorldMatrix(object source = null)
        {
            if (this.Container.Entity.Parent != null)
            {
                MatrixD parentWorldMatrix = this.Container.Entity.Parent.WorldMatrix;
                UpdateWorldMatrix(ref parentWorldMatrix, source);
                return;
            }

            //UpdateWorldVolume();
            ProfilerShort.Begin("OnChanged");
            OnWorldPositionChanged(source);

            ProfilerShort.BeginNextBlock("Physics.Onchanged");
            if (this.Container.Entity.Physics != null && this.m_physics.Enabled && this.m_physics != source)
            {
                this.m_physics.OnWorldPositionChanged(source);
            }
            ProfilerShort.End();
            m_normalizedInvMatrixDirty = true;
            m_invScaledMatrixDirty     = true;
            // NotifyEntityChange(source);
        }
コード例 #4
0
        /// <summary>
        /// Called when [world position changed].
        /// </summary>
        /// <param name="source">The source object that caused this event.</param>
        protected override void OnWorldPositionChanged(object source)
        {
            //ProfilerShort.Begin("OnWorldPositionChanged");
            Debug.Assert(source != this && (Container.Entity == null || source != Container.Entity), "Recursion detected!");

            if (Entity.Parent == null)
            {
                Container.Entity.UpdateGamePruningStructure();
            }

            if (Container.Entity.Render != null)
            {
                Container.Entity.Render.InvalidateRenderObjects();
            }

            UpdateChildren(source); //update children WMs
            m_worldVolumeDirty         = true;
            m_normalizedInvMatrixDirty = true;
            m_invScaledMatrixDirty     = true;

            if (this.m_physics != null && this.m_physics.Enabled && this.m_physics != source)
            {
                this.m_physics.OnWorldPositionChanged(source);
            }

            ProfilerShort.Begin("Raise");
            RaiseOnPositionChanged(this);

            //ProfilerShort.BeginNextBlock("Action");
            if (WorldPositionChanged != null)
            {
                WorldPositionChanged(source);
            }
            ProfilerShort.End();
            //ProfilerShort.End();
        }
コード例 #5
0
        private void RenderCallback()
        {
            if (m_messageProcessingStart != MyTimeSpan.Zero)
            {
                MyTimeSpan messageQueueDuration = m_timer.Elapsed - m_messageProcessingStart;
                ProfilerShort.CustomValue("MessageQueue", 0, messageQueueDuration);
            }
            m_waiter.Wait();

            m_frameStart = m_timer.Elapsed;

            ProfilerShort.Begin("PrepareDraw");

            ProfilerShort.Begin("ProcessInvoke");
            Action action;

            while (m_invokeQueue.TryDequeue(out action))
            {
                action();
            }
            ProfilerShort.End();

            ProfilerShort.Begin("ApplyModeChanges");
            ApplySettingsChanges();
            ProfilerShort.End();

            ProfilerShort.Begin("BeforeRender");
            MyRenderStats.Generic.WriteFormat("Available GPU memory: {0} MB", (float)MyRenderProxy.GetAvailableTextureMemory() / 1024 / 1024, MyStatTypeEnum.CurrentValue, 300, 2);
            MyRenderProxy.BeforeRender(m_frameStart);
            ProfilerShort.End();

            ProfilerShort.Begin("RenderWindow.BeforeDraw");
            m_renderWindow.BeforeDraw();
            ProfilerShort.End();

            ProfilerShort.Begin("BeforeDraw(event)");
            var handler = BeforeDraw;

            if (handler != null)
            {
                handler();
            }
            ProfilerShort.End();

            ProfilerShort.End();

            ProfilerShort.Begin("TestCooperativeLevel");
            var deviceResult = MyRenderProxy.TestDeviceCooperativeLevel();

            ProfilerShort.End();

            if (!m_renderWindow.DrawEnabled)
            {
                ProfilerShort.Begin("ProcessMessages");
                MyRenderProxy.ProcessMessages();
                ProfilerShort.End();
            }
            else if (deviceResult == MyRenderDeviceCooperativeLevel.Ok)
            {
                Draw();
            }
            else
            {
                ProfilerShort.Begin("WaitForReset");

                ProfilerShort.Begin("ProcessMessages");
                MyRenderProxy.ProcessMessages();
                ProfilerShort.End();

                if (deviceResult == MyRenderDeviceCooperativeLevel.Lost)
                {
                    ProfilerShort.Begin("DeviceLost");
                    Thread.Sleep(20);
                    ProfilerShort.End();
                }
                else if (deviceResult == MyRenderDeviceCooperativeLevel.NotReset)
                {
                    ProfilerShort.Begin("DeviceReset");
                    Thread.Sleep(20);
                    DeviceReset();
                    ProfilerShort.End();
                }
                else
                {
                    // TODO: OP! Log error code
                }
                ProfilerShort.End();
            }

            ProfilerShort.Begin("AfterRender");
            MyRenderProxy.AfterRender();
            ProfilerShort.End();

            ProfilerShort.Begin("Present");
            if (deviceResult == MyRenderDeviceCooperativeLevel.Ok && m_renderWindow.DrawEnabled)
            {
                this.DoBeforePresent();
                try
                {
                    MyRenderProxy.Present();
                }
                catch (MyDeviceLostException)
                {
                }
                this.DoAfterPresent();
            }
            ProfilerShort.End();

            m_messageProcessingStart = m_timer.Elapsed;
        }