void FPhysScene::ProcessPhysScene(uint32 SceneType) { SCOPE_CYCLE_COUNTER(STAT_TotalPhysicsTime); SCOPE_CYCLE_COUNTER(STAT_PhysicsFetchDynamicsTime); check(SceneType < NumPhysScenes); if (bPhysXSceneExecuting[SceneType] == 0) { // Not executing this scene, must call TickPhysScene before calling this function again. UE_LOG(LogPhysics, Log, TEXT("WaitPhysScene`: Not executing this scene (%d) - aborting."), SceneType); return; } if (FrameLagAsync()) { static_assert(PST_MAX == 3, "Physics scene static test failed."); // Here we assume the PST_Sync is the master and never fame lagged if (SceneType == PST_Sync) { // the one frame lagged one should be done by now. check(!FrameLaggedPhysicsSubsceneCompletion[PST_Async].GetReference() || FrameLaggedPhysicsSubsceneCompletion[PST_Async]->IsComplete()); } else if (SceneType == PST_Async) { FrameLaggedPhysicsSubsceneCompletion[PST_Async] = NULL; } } // Reset execution flag //This fetches and gets active transforms. It's important that the function that calls this locks because getting the transforms and using the data must be an atomic operation #if WITH_PHYSX PxScene* PScene = GetPhysXScene(SceneType); check(PScene); PxU32 OutErrorCode = 0; #if !WITH_APEX PScene->lockWrite(); PScene->fetchResults(true, &OutErrorCode); PScene->unlockWrite(); #else // #if !WITH_APEX // The APEX scene calls the fetchResults function for the PhysX scene, so we only call ApexScene->fetchResults(). NxApexScene* ApexScene = GetApexScene(SceneType); check(ApexScene); ApexScene->fetchResults(true, &OutErrorCode); #endif // #if !WITH_APEX UpdateActiveTransforms(SceneType); if (OutErrorCode != 0) { UE_LOG(LogPhysics, Log, TEXT("PHYSX FETCHRESULTS ERROR: %d"), OutErrorCode); } #endif // WITH_PHYSX PhysicsSubsceneCompletion[SceneType] = NULL; bPhysXSceneExecuting[SceneType] = false; }
void Engine::update( double step ) { for ( SceneMap::iterator itr=_sceneMap.begin(); itr!=_sceneMap.end(); ++itr ) { PxScene* scene = itr->second; scene->simulate( step ); while( !scene->fetchResults() ) { /* do nothing but wait */ } } }
void FPhysScene::ProcessPhysScene(uint32 SceneType) { SCOPE_CYCLE_COUNTER(STAT_TotalPhysicsTime); SCOPE_CYCLE_COUNTER(STAT_PhysicsFetchDynamicsTime); check(SceneType < NumPhysScenes); if( bPhysXSceneExecuting[SceneType] == 0 ) { // Not executing this scene, must call TickPhysScene before calling this function again. UE_LOG(LogPhysics, Log, TEXT("WaitPhysScene`: Not executing this scene (%d) - aborting."), SceneType); return; } PhysicsSubsceneCompletion[SceneType] = NULL; if (FrameLagAsync()) { checkAtCompileTime(PST_MAX == 2, Assumtiopns_about_physics_scenes); // Here we assume the PST_Sync is the master and never fame lagged if (SceneType == PST_Sync) { // the one frame lagged one should be done by now. check(!FrameLaggedPhysicsSubsceneCompletion[PST_Async].GetReference() || FrameLaggedPhysicsSubsceneCompletion[PST_Async]->IsComplete()); } else { FrameLaggedPhysicsSubsceneCompletion[PST_Async] = NULL; } } #if WITH_PHYSX PxScene* PScene = GetPhysXScene(SceneType); check(PScene); PxU32 OutErrorCode = 0; #if !WITH_APEX PScene->lockWrite(); PScene->fetchResults( true, &OutErrorCode ); PScene->unlockWrite(); #else // #if !WITH_APEX // The APEX scene calls the fetchResults function for the PhysX scene, so we only call ApexScene->fetchResults(). NxApexScene* ApexScene = GetApexScene(SceneType); check(ApexScene); ApexScene->fetchResults( true, &OutErrorCode ); #endif // #if !WITH_APEX if(OutErrorCode != 0) { UE_LOG(LogPhysics, Log, TEXT("PHYSX FETCHRESULTS ERROR: %d"), OutErrorCode); } #endif // WITH_PHYSX // Reset execution flag bPhysXSceneExecuting[SceneType] = false; }
void PhysXBetweenStepsTask::run() { PX_ASSERT(mSubStepSize > 0.0f); PX_ASSERT(mNumSubSteps > 0); #if PX_PHYSICS_VERSION_MAJOR == 3 PxScene* scene = mScene.getPhysXScene(); if (scene != NULL) { while (mSubStepNumber < mNumSubSteps) { PX_PROFILE_ZONE("ApexSceneManualSubstep", GetInternalApexSDK()->getContextId()); // fetch the first substep uint32_t errorState = 0; { SCOPED_PHYSX_LOCK_WRITE(&mScene); scene->fetchResults(true, &errorState); } PX_ASSERT(errorState == 0); for (uint32_t i = 0; i < mScene.mModuleScenes.size(); i++) { PX_PROFILE_ZONE("ModuleSceneManualSubstep", GetInternalApexSDK()->getContextId()); mScene.mModuleScenes[i]->interStep(mSubStepNumber, mNumSubSteps); } // run the next substep { SCOPED_PHYSX_LOCK_WRITE(&mScene); scene->simulate(mSubStepSize); } mSubStepNumber++; } } #endif mLast->removeReference(); // decrement artificially high ref count that prevented checkresults from being executed }
void StepPhysX() { gScene->simulate(gTimeStep); gScene->fetchResults(true); }