internal void Simulate(float deltaTime) { if (collisionWorld == null) { return; } simulationArgs.DeltaTime = deltaTime; UpdatedRigidbodies = 0; OnSimulationBegin(simulationArgs); SimulationProfiler = Profiler.Begin(PhysicsProfilingKeys.SimulationProfilingKey); if (discreteDynamicsWorld != null) { discreteDynamicsWorld.StepSimulation(deltaTime, MaxSubSteps, FixedTimeStep); } else { collisionWorld.PerformDiscreteCollisionDetection(); } SimulationProfiler.End("Alive rigidbodies: {0}", UpdatedRigidbodies); OnSimulationEnd(simulationArgs); }
private void ConnectComplete() { m_state = ProfilingState.Connected; buttonConnect.Text = c_Disconnect; checkAllocations.Checked = checkAllocations.Checked && m_engine.Capabilities.ProfilingAllocations; checkCalls.Checked = checkCalls.Checked && m_engine.Capabilities.ProfilingCalls; }
public GcProfiling() { collectionCountState = Profiler.New(GcCollectionCountKey); gen0Count = GC.CollectionCount(0); gen1Count = GC.CollectionCount(1); gen2Count = GC.CollectionCount(2); collectionCountState.Begin(gen0Count, gen1Count, gen2Count); gcMemoryState = Profiler.New(GcMemoryKey); memoryPeak = lastFrameMemory = GC.GetTotalMemory(false); gcMemoryState.Begin(lastFrameMemory, lastFrameMemory, memoryPeak); }
private void Disconnect() { if (m_state == ProfilingState.Disconnected) { return; } if (m_state == ProfilingState.Connected) { if (m_session != null) { m_session.Disconnect(); } if (m_exporter != null) { m_exporter.Close(); } } try { lock (m_engine) { m_engine.Stop(); } } catch { } //Depending on when we get called, stopping the engine throws anything from NullReferenceException, ArgumentNullException, IOException, etc. m_engine = null; if (m_state == ProfilingState.Connected) { LogText("Disconnected from TinyCLR."); } KillEmulator(); ProfilingState oldstate = m_state; m_state = ProfilingState.Disconnected; EnableUI(); if (!m_closing && oldstate == ProfilingState.Connected && m_exporter is _PRF.Exporter_CLRProfiler) { clrProfiler.LoadLogFile(m_exporter.FileName); EnableDisableViewMenuItems(); } }
private void DrawFrame() { if (SlowDownDrawCalls && (UpdateTime.FrameCount & 1) == 1) // skip the draw call about one frame over two. { return; } try { // Initialized if (!profilingDraw.IsInitialized) { profilingDraw = Profiler.Begin(GameProfilingKeys.GameDrawFPS); } // Update profiling data profilingDraw.CheckIfEnabled(); if (!isExiting && GameSystems.IsFirstUpdateDone && !Window.IsMinimized) { drawTime.Update(totalDrawTime, lastFrameElapsedGameTime, singleFrameUpdateTime, drawRunningSlowly, true); if (drawTime.FramePerSecondUpdated) { // TODO: store some GameTime information as attributes in the Profiling using profilingDraw.SetAttribute(..) profilingDraw.Mark("Frame = {0}, Update = {1:0.000}ms, Draw = {2:0.000}ms, FPS = {3:0.00}", drawTime.FrameCount, updateTime.TimePerFrame.TotalMilliseconds, drawTime.TimePerFrame.TotalMilliseconds, drawTime.FramePerSecond); } using (Profiler.Begin(GameProfilingKeys.GameDraw)) { Draw(drawTime); } } } finally { lastFrameElapsedGameTime = TimeSpan.Zero; } }
internal void CacheContacts() { contactsProfilingState = Profiler.Begin(PhysicsProfilingKeys.ContactsProfilingKey); var pastFrameContacts = frameContacts.Select(x => x.ContactPoint).ToList(); frameContacts.Clear(); var numManifolds = collisionWorld.Dispatcher.NumManifolds; for (var i = 0; i < numManifolds; i++) { var manifold = collisionWorld.Dispatcher.GetManifoldByIndexInternal(i); var numContacts = manifold.NumContacts; var bodyA = manifold.Body0; var bodyB = manifold.Body1; var colA = (PhysicsComponent)bodyA?.UserObject; var colB = (PhysicsComponent)bodyB?.UserObject; if (colA == null || colB == null) { continue; } if (!colA.ProcessCollisions && !colB.ProcessCollisions) { continue; } for (var y = 0; y < numContacts; y++) { var cp = manifold.GetContactPoint(y); if (cp.Distance > 0.0f) { continue; } var info = new ContactInfo { ColA = colA, ColB = colB }; //this can be recycled by bullet so its not very correct.. need to figure if it is really new.. comparing life times might help if (!manifoldToContact.TryGetValue(cp, out info.ContactPoint)) { info.ContactPoint = new ContactPoint { Collision = null }; info.NewContact = true; manifoldToContact[cp] = info.ContactPoint; } if (info.ContactPoint.LifeTime > cp.LifeTime || cp.LifeTime == 1) { RemoveContact(info.ContactPoint); //this is a new contact as well info.ContactPoint.Collision = null; info.NewContact = true; } info.ContactPoint.Valid = true; info.ContactPoint.LifeTime = cp.LifeTime; info.ContactPoint.Distance = cp.Distance; info.ContactPoint.Normal = cp.NormalWorldOnB; info.ContactPoint.PositionOnA = cp.PositionWorldOnA; info.ContactPoint.PositionOnB = cp.PositionWorldOnB; frameContacts.Add(info); pastFrameContacts.Remove(info.ContactPoint); } } foreach (var contact in pastFrameContacts) { RemoveContact(contact); } }
public PhysicsProcessor() : base(PhysicsComponent.Key, TransformComponent.Key) { charactersProfilingState = Profiler.New(CharactersProfilingKey); }
private void Connect() { _DBG.PortDefinition port = comboBoxDevice.PortDefinition; if (port == null) { SetInvalidDevice(); return; } try { comboBoxTransport.Enabled = false; comboBoxDevice.Enabled = false; buttonConnect.Enabled = false; groupBoxOutput.Enabled = false; groupBoxOptions.Enabled = false; m_state = ProfilingState.Connecting; if (port is _DBG.PortDefinition_Emulator) { _DBG.PortDefinition_Emulator emuport = port as _DBG.PortDefinition_Emulator; if (emuport.Pid == 0) { OpenFileDialog fd = new OpenFileDialog(); fd.DefaultExt = "exe"; fd.Filter = ".NET MF Exe files (*.exe)|*.exe"; fd.Title = "Choose an application to emulate"; if (fd.ShowDialog(this) == DialogResult.OK) { m_emuProcess = EmulatorLauncher.LaunchEmulator(emuport, true, fd.FileName); if (m_emuProcess == null) { LogText("Could not launch emulator."); Disconnect(); return; } else { m_emuLaunched = true; LogText(string.Format("Started emulator process {0}", m_emuProcess.Id)); _DBG.PlatformInfo pi = new _DBG.PlatformInfo(null); port = new _DBG.PortDefinition_Emulator("Emulator - pid " + m_emuProcess.Id, m_emuProcess.Id); comboBoxDevice.SelectLaunchedEmulator((_DBG.PortDefinition_Emulator)port); } } else { Disconnect(); return; } } else { try { m_emuProcess = Process.GetProcessById(emuport.Pid); } catch { m_state = ProfilingState.Disconnected; EnableUI(); SetInvalidDevice(); return; } } } buttonConnect.Text = c_Cancel; buttonConnect.Enabled = true; BackgroundConnectorArguments bca = new BackgroundConnectorArguments(); bca.connectPort = port; bca.outputFileName = textLogFile.Text; #if DEBUG if (radioOffProf.Checked) { bca.exporter = BackgroundConnectorArguments.ExporterType.OffProf; } else { bca.exporter = BackgroundConnectorArguments.ExporterType.CLRProfiler; } #else bca.exporter = BackgroundConnectorArguments.ExporterType.CLRProfiler; #endif //Rebooting the emulator just makes it quit. bca.reboot = checkReboot.Checked && !(port is _DBG.PortDefinition_Emulator); bwConnecter.RunWorkerAsync(bca); } catch (ApplicationException e) { comboBoxTransport.Enabled = true; comboBoxDevice.Enabled = true; buttonConnect.Enabled = true; groupBoxOutput.Enabled = true; groupBoxOptions.Enabled = true; m_state = ProfilingState.Disconnected; MessageBox.Show(this, e.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Disconnect() { if (m_state == ProfilingState.Disconnected) return; if (m_state == ProfilingState.Connected) { if (m_session != null) { m_session.Disconnect(); } if (m_exporter != null) { m_exporter.Close(); } } try { lock (m_engine) { m_engine.Stop(); } } catch { } //Depending on when we get called, stopping the engine throws anything from NullReferenceException, ArgumentNullException, IOException, etc. m_engine = null; if (m_state == ProfilingState.Connected) { LogText("Disconnected from TinyCLR."); } KillEmulator(); ProfilingState oldstate = m_state; m_state = ProfilingState.Disconnected; EnableUI(); if (!m_closing && oldstate == ProfilingState.Connected && m_exporter is _PRF.Exporter_CLRProfiler) { clrProfiler.LoadLogFile(m_exporter.FileName); EnableDisableViewMenuItems(); } }
private void ConnectComplete() { m_state = ProfilingState.Connected; buttonConnect.Text = c_Disconnect; checkAllocations.Checked = checkAllocations.Checked && m_engine.Capabilities.ProfilingAllocations; checkCalls.Checked = checkCalls.Checked && m_engine.Capabilities.ProfilingCalls; }
private void Connect() { _DBG.PortDefinition port = comboBoxDevice.PortDefinition; if (port == null) { SetInvalidDevice(); return; } try { comboBoxTransport.Enabled = false; comboBoxDevice.Enabled = false; buttonConnect.Enabled = false; groupBoxOutput.Enabled = false; groupBoxOptions.Enabled = false; m_state = ProfilingState.Connecting; if (port is _DBG.PortDefinition_Emulator) { _DBG.PortDefinition_Emulator emuport = port as _DBG.PortDefinition_Emulator; if (emuport.Pid == 0) { OpenFileDialog fd = new OpenFileDialog(); fd.DefaultExt = "exe"; fd.Filter = ".NET MF Exe files (*.exe)|*.exe"; fd.Title = "Choose an application to emulate"; if (fd.ShowDialog(this) == DialogResult.OK) { m_emuProcess = EmulatorLauncher.LaunchEmulator(emuport, true, fd.FileName); if (m_emuProcess == null) { LogText("Could not launch emulator."); Disconnect(); return; } else { m_emuLaunched = true; LogText(string.Format("Started emulator process {0}", m_emuProcess.Id)); _DBG.PlatformInfo pi = new _DBG.PlatformInfo(null); port = new _DBG.PortDefinition_Emulator("Emulator - pid " + m_emuProcess.Id, m_emuProcess.Id); comboBoxDevice.SelectLaunchedEmulator((_DBG.PortDefinition_Emulator)port); } } else { Disconnect(); return; } } else { try { m_emuProcess = Process.GetProcessById(emuport.Pid); } catch { m_state = ProfilingState.Disconnected; EnableUI(); SetInvalidDevice(); return; } } } buttonConnect.Text = c_Cancel; buttonConnect.Enabled = true; BackgroundConnectorArguments bca = new BackgroundConnectorArguments(); bca.connectPort = port; bca.outputFileName = textLogFile.Text; #if DEBUG if (radioOffProf.Checked) { bca.exporter = BackgroundConnectorArguments.ExporterType.OffProf; } else { bca.exporter = BackgroundConnectorArguments.ExporterType.CLRProfiler; } #else bca.exporter = BackgroundConnectorArguments.ExporterType.CLRProfiler; #endif //Rebooting the emulator just makes it quit. bca.reboot = checkReboot.Checked && !(port is _DBG.PortDefinition_Emulator); bwConnecter.RunWorkerAsync(bca); } catch (ApplicationException e) { comboBoxTransport.Enabled = true; comboBoxDevice.Enabled = true; buttonConnect.Enabled = true; groupBoxOutput.Enabled = true; groupBoxOptions.Enabled = true; m_state = ProfilingState.Disconnected; MessageBox.Show(this, e.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Initializes the Physics engine using the specified flags. /// </summary> /// <param name="flags">The flags.</param> /// <exception cref="System.NotImplementedException">SoftBody processing is not yet available</exception> internal Simulation(PhysicsEngineFlags flags = PhysicsEngineFlags.None) { if (flags == PhysicsEngineFlags.None) { if (OnSimulationCreation != null) { flags = OnSimulationCreation(); } } simulationProfilingState = Profiler.New(SimulationProfilingKey); contactsProfilingState = Profiler.New(ContactsProfilingKey); MaxSubSteps = 1; FixedTimeStep = 1.0f / 60.0f; collisionConfiguration = new BulletSharp.DefaultCollisionConfiguration(); dispatcher = new BulletSharp.CollisionDispatcher(collisionConfiguration); broadphase = new BulletSharp.DbvtBroadphase(); //this allows characters to have proper physics behavior broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new BulletSharp.GhostPairCallback()); //2D pipeline var simplex = new BulletSharp.VoronoiSimplexSolver(); var pdSolver = new BulletSharp.MinkowskiPenetrationDepthSolver(); var convexAlgo = new BulletSharp.Convex2DConvex2DAlgorithm.CreateFunc(simplex, pdSolver); dispatcher.RegisterCollisionCreateFunc(BulletSharp.BroadphaseNativeType.Convex2DShape, BulletSharp.BroadphaseNativeType.Convex2DShape, convexAlgo); //this is the ONLY one that we are actually using dispatcher.RegisterCollisionCreateFunc(BulletSharp.BroadphaseNativeType.Box2DShape, BulletSharp.BroadphaseNativeType.Convex2DShape, convexAlgo); dispatcher.RegisterCollisionCreateFunc(BulletSharp.BroadphaseNativeType.Convex2DShape, BulletSharp.BroadphaseNativeType.Box2DShape, convexAlgo); dispatcher.RegisterCollisionCreateFunc(BulletSharp.BroadphaseNativeType.Box2DShape, BulletSharp.BroadphaseNativeType.Box2DShape, new BulletSharp.Box2DBox2DCollisionAlgorithm.CreateFunc()); //~2D pipeline //default solver var solver = new BulletSharp.SequentialImpulseConstraintSolver(); if (flags.HasFlag(PhysicsEngineFlags.CollisionsOnly)) { collisionWorld = new BulletSharp.CollisionWorld(dispatcher, broadphase, collisionConfiguration); } else if (flags.HasFlag(PhysicsEngineFlags.SoftBodySupport)) { //mSoftRigidDynamicsWorld = new BulletSharp.SoftBody.SoftRigidDynamicsWorld(mDispatcher, mBroadphase, solver, mCollisionConf); //mDiscreteDynamicsWorld = mSoftRigidDynamicsWorld; //mCollisionWorld = mSoftRigidDynamicsWorld; throw new NotImplementedException("SoftBody processing is not yet available"); } else { discreteDynamicsWorld = new BulletSharp.DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); collisionWorld = discreteDynamicsWorld; } if (discreteDynamicsWorld != null) { solverInfo = discreteDynamicsWorld.SolverInfo; //we are required to keep this reference, or the GC will mess up dispatchInfo = discreteDynamicsWorld.DispatchInfo; solverInfo.SolverMode |= BulletSharp.SolverModes.CacheFriendly; //todo test if helps with performance or not if (flags.HasFlag(PhysicsEngineFlags.ContinuosCollisionDetection)) { canCcd = true; solverInfo.SolverMode |= BulletSharp.SolverModes.Use2FrictionDirections | BulletSharp.SolverModes.RandomizeOrder; dispatchInfo.UseContinuous = true; } } }