Error PhysicsWorld::updateAsync(F32 dt) { m_dt = dt; // Do cleanup of marked for deletion cleanupMarkedForDeletion(); // Update NewtonUpdateAsync(m_world, dt); return ErrorCode::NONE; }
void dNewton::UpdateAsync (dFloat timestepInSecunds) { dLong timestepMicrosecunds = (dLong) (double (timestepInSecunds) * 1000000.0f); dLong currentTime = GetTimeInMicrosenconds (); dLong nextTime = currentTime - m_microseconds; int loops = 0; while ((nextTime >= timestepMicrosecunds) && (loops < m_maxUpdatePerIterations)) { loops ++; NewtonUpdateAsync (m_world, timestepInSecunds); nextTime -= timestepMicrosecunds; m_microseconds += timestepMicrosecunds; } }
void iPhysics::handle() { const float32 timeDelta = 1.0f / static_cast<float64>(_simulationRate); const uint32 maxUpdateCount = 2; uint32 updateCount = 0; float64 currentTime = iTimer::getInstance().getSeconds(); while ((_lastTime + timeDelta < currentTime) && (updateCount < maxUpdateCount)) { NewtonUpdateAsync(static_cast<const NewtonWorld*>(_defaultWorld), timeDelta); _lastTime += timeDelta; updateCount++; }; }
void DemoEntityManager::UpdatePhysics(float timestep) { // update the physics if (m_world) { dFloat timestepInSecunds = 1.0f / MAX_PHYSICS_FPS; unsigned64 timestepMicrosecunds = unsigned64 (timestepInSecunds * 1000000.0f); unsigned64 currentTime = dGetTimeInMicrosenconds (); unsigned64 nextTime = currentTime - m_microsecunds; int loops = 0; while ((nextTime >= timestepMicrosecunds) && (loops < MAX_PHYSICS_LOOPS)) { loops ++; dTimeTrackerEvent(__FUNCTION__); // run the newton update function if (!m_reEntrantUpdate) { m_reEntrantUpdate = true; if (m_physicsUpdate && m_world) { ClearDebugDisplay(m_world); // update the physics world if (!m_mainWindow->m_physicsUpdateMode) { NewtonUpdate (m_world, timestepInSecunds); } else { NewtonUpdateAsync(m_world, timestepInSecunds); } } m_reEntrantUpdate = false; } nextTime -= timestepMicrosecunds; m_microsecunds += timestepMicrosecunds; } if (loops) { m_physicsTime = dFloat (dGetTimeInMicrosenconds () - currentTime) / 1000000.0f; if (m_physicsTime >= MAX_PHYSICS_LOOPS * (1.0f / MAX_PHYSICS_FPS)) { m_microsecunds = currentTime; } } } }