private void WriteStats(List <Tuple <string, NetworkStat> > stats, string name) { ProfilerShort.Begin(name); int totalSize = 0; int totalCount = 0; int partSize = 0; int partCount = 0; bool needsEnd = false; for (int i = 0; i < stats.Count; i++) { if (i > 0 && (i % 15) == 0) { if (needsEnd) { ProfilerShort.End(partCount, partSize * 1.024f / 1000, "{0:.00} KB/s", "Count: {0:.}"); } partCount = partSize = 0; ProfilerShort.Begin("Additional " + i / 15); needsEnd = true; } Tuple <string, NetworkStat> stat = stats[i]; partSize += stat.Item2.TotalSize; partCount += stat.Item2.MessageCount; totalSize += stat.Item2.TotalSize; totalCount += stat.Item2.MessageCount; ProfilerShort.CustomValue(stat.Item1, stat.Item2.MessageCount, stat.Item2.TotalSize * 1.024f / 1000, "{0:.00} KB/s", "Count: {0:.}"); } if (needsEnd) { ProfilerShort.End(partCount, partSize * 1.024f / 1000, "{0:.00} KB/s", "Count: {0:.}"); } ProfilerShort.End(totalCount, totalSize * 1.024f / 1000, "{0:.00} KB/s", "Count: {0:.}"); }
private void RenderCallback() { if (m_messageProcessingStart != MyTimeSpan.Zero) { MyTimeSpan messageQueueDuration = m_timer.Elapsed - m_messageProcessingStart; ProfilerShort.CustomValue("MessageQueue", 0, messageQueueDuration); } ProfilerShort.Begin("Wait"); m_waiter.Wait(); ProfilerShort.End(); 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)"); if (BeforeDraw != null) { BeforeDraw(); } ProfilerShort.End(); ProfilerShort.End(); ProfilerShort.Begin("Draw"); 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.End(); ProfilerShort.Begin("AfterRender"); MyRenderProxy.AfterRender(); ProfilerShort.End(); ProfilerShort.Begin("Present"); if (deviceResult == MyRenderDeviceCooperativeLevel.Ok && m_renderWindow.DrawEnabled) { this.DoBeforePresent(); try { MyRenderProxy.Present(); } catch (MyDeviceErrorException e) { // Present() ended up with an error -- don't try to recover MyRenderProxy.Error(e.Message, shouldTerminate: true); Exit(); } this.DoAfterPresent(); } ProfilerShort.End(); if (m_separateThread) { MyRenderProxy.GetRenderProfiler().Commit(); } m_messageProcessingStart = m_timer.Elapsed; if (MyRenderProxy.Settings.ForceSlowCPU) { Thread.Sleep(200); } }
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(); }
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(); }