示例#1
0
        public override void Simulate()
        {
            if (MyFakes.PAUSE_PHYSICS && !MyFakes.STEP_PHYSICS)
            {
                return;
            }
            MyFakes.STEP_PHYSICS = false;

            if (!MySandboxGame.IsGameReady)
            {
                return;
            }

            AddTimestamp();

            InsideSimulation = true;
            ProcessDestructions();

            ProfilerShort.Begin("HavokWorld.Step");

            foreach (HkWorld world in Clusters.GetList())
            {
                //VRageRender.MyRenderProxy.DebugDrawText2D(new Vector2(100, 100), "Constr:" + world.GetConstraintCount(), Color.Red, 0.9f);
                world.UnmarkForWrite();
                world.StepSimulation(MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED);
                world.MarkForWrite();
            }

            ProfilerShort.End();
            InsideSimulation = false;

            ProfilerShort.Begin("Update rigid bodies");

            long activeRigidBodies = 0;

            foreach (HkWorld world in Clusters.GetList())
            {
                activeRigidBodies += world.ActiveRigidBodies.Count;
            }

            VRageRender.MyPerformanceCounter.PerCameraDrawWrite["Active rigid bodies"] = activeRigidBodies;

            ProfilerShort.CustomValue("Active bodies", activeRigidBodies, null);

            foreach (HkWorld world in Clusters.GetList())
            {
                IterateBodies(world);
            }


            //ParallelTasks.Parallel.For(0, m_iterationBodies.Count, (rb) =>
            //{
            //    MyPhysicsBody body = (MyPhysicsBody)m_iterationBodies[rb].UserObject;
            //    if (body == null)
            //        return;
            //    body.OnMotion(m_iterationBodies[rb], MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
            //}, Math.Max(1, m_iterationBodies.Count / 16));

            foreach (var rb in m_iterationBodies)
            {
                MyPhysicsBody body = (MyPhysicsBody)rb.UserObject;
                if (body == null)
                {
                    return;
                }
                body.OnMotion(rb, MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
            }

            foreach (HkCharacterRigidBody rb in m_characterIterationBodies)
            {
                var body = (MyPhysicsBody)rb.GetHitRigidBody().UserObject;
                if (body.Entity.WorldMatrix.Translation != body.GetWorldMatrix().Translation)
                {
                    body.UpdateCluster();
                }
            }

            m_iterationBodies.Clear();
            m_characterIterationBodies.Clear();

            ProfilerShort.End();

            ProfilerShort.Begin("HavokWorld.StepVDB");
            foreach (HkWorld world in Clusters.GetList())
            {
                world.StepVDB(MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
            }

            ProfilerShort.End();
        }
示例#2
0
        public override void Simulate()
        {
            if (MyFakes.PAUSE_PHYSICS && !MyFakes.STEP_PHYSICS)
            {
                return;
            }
            MyFakes.STEP_PHYSICS = false;

            if (!MySandboxGame.IsGameReady)
            {
                return;
            }

            AddTimestamp();

            InsideSimulation = true;
            ProcessDestructions();

            ProfilerShort.Begin("HavokWorld.Step");

            if (MyFakes.CLIENTS_SIMULATE_SINGLE_WORLD && !Sync.IsServer)
            {
                var world = Clusters.GetClusterForPosition(MySector.MainCamera.Position);
                if (world != null)
                {
                    StepWorld((HkWorld)world);
                }
            }
            else
            {
                foreach (HkWorld world in Clusters.GetList())
                {
                    StepWorld(world);
                }
            }

            ProfilerShort.End();
            InsideSimulation = false;

            ProfilerShort.Begin("Update rigid bodies");

            long activeRigidBodies = 0;

            foreach (HkWorld world in Clusters.GetList())
            {
                activeRigidBodies += world.ActiveRigidBodies.Count;
            }

            VRageRender.MyPerformanceCounter.PerCameraDrawWrite["Active rigid bodies"] = activeRigidBodies;

            ProfilerShort.CustomValue("Active bodies", activeRigidBodies, null);

            foreach (HkWorld world in Clusters.GetList())
            {
                IterateBodies(world);
            }


            //ParallelTasks.Parallel.For(0, m_iterationBodies.Count, (rb) =>
            //{
            //    MyPhysicsBody body = (MyPhysicsBody)m_iterationBodies[rb].UserObject;
            //    if (body == null)
            //        return;
            //    body.OnMotion(m_iterationBodies[rb], MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
            //}, Math.Max(1, m_iterationBodies.Count / 16));

            foreach (var rb in m_iterationBodies)
            {
                MyPhysicsBody body = (MyPhysicsBody)rb.UserObject;
                if (body == null)
                {
                    return;
                }
                body.OnMotion(rb, MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
            }

            foreach (HkCharacterRigidBody rb in m_characterIterationBodies)
            {
                var body = (MyPhysicsBody)rb.GetHitRigidBody().UserObject;
                if (body.Entity.WorldMatrix.Translation != body.GetWorldMatrix().Translation)
                {
                    body.UpdateCluster();
                }
            }

            m_iterationBodies.Clear();
            m_characterIterationBodies.Clear();

            ProfilerShort.End();

            ProfilerShort.Begin("HavokWorld.StepVDB");
            foreach (HkWorld world in Clusters.GetList())
            {
                //if (MySession.ControlledEntity.Entity.GetTopMostParent().Physics.HavokWorld == world)
                world.StepVDB(MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
            }

            ProfilerShort.End();
        }