PhysXBenchmarksCommon.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifdef HAVE_BENCHMARK
  9. #include <Benchmarks/PhysXBenchmarksCommon.h>
  10. #include <PhysXTestUtil.h>
  11. #include <PhysXTestCommon.h>
  12. #include <Scene/PhysXScene.h>
  13. namespace PhysX::Benchmarks
  14. {
  15. void PhysXBenchmarkEnvironment::SetUpBenchmark()
  16. {
  17. PhysX::Environment::SetupInternal();
  18. }
  19. void PhysXBenchmarkEnvironment::TearDownBenchmark()
  20. {
  21. PhysX::Environment::TeardownInternal();
  22. }
  23. AzPhysics::SceneHandle PhysXBaseBenchmarkFixture::GetDefaultSceneHandle() const
  24. {
  25. return m_testSceneHandle;
  26. }
  27. void PhysXBaseBenchmarkFixture::UpdateSimulation(unsigned int numFrames, float timeStep /*= DefaultTimeStep*/)
  28. {
  29. if (auto* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get())
  30. {
  31. for (AZ::u32 i = 0; i < numFrames; i++)
  32. {
  33. physicsSystem->Simulate(timeStep);
  34. }
  35. }
  36. }
  37. void PhysXBaseBenchmarkFixture::StepScene1Tick(float timeStep /*= DefaultTimeStep*/)
  38. {
  39. m_defaultScene->StartSimulation(timeStep);
  40. m_defaultScene->FinishSimulation();
  41. static_cast<PhysX::PhysXScene*>(m_defaultScene)->FlushTransformSync();
  42. }
  43. void PhysXBaseBenchmarkFixture::SetUpInternal()
  44. {
  45. m_testSceneHandle = CreateDefaultTestScene(); //create the default scene
  46. if (auto* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get())
  47. {
  48. m_defaultScene = physicsSystem->GetScene(m_testSceneHandle);
  49. }
  50. Physics::DefaultWorldBus::Handler::BusConnect();
  51. }
  52. void PhysXBaseBenchmarkFixture::TearDownInternal()
  53. {
  54. Physics::DefaultWorldBus::Handler::BusDisconnect();
  55. //Clean up the test scene
  56. m_defaultScene = nullptr;
  57. if (auto* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get())
  58. {
  59. physicsSystem->RemoveScene(m_testSceneHandle);
  60. }
  61. m_testSceneHandle = AzPhysics::InvalidSceneHandle;
  62. TestUtils::ResetPhysXSystem();
  63. }
  64. AzPhysics::SceneHandle PhysXBaseBenchmarkFixture::CreateDefaultTestScene()
  65. {
  66. if (auto* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get())
  67. {
  68. AzPhysics::SceneConfiguration sceneConfiguration = GetDefaultSceneConfiguration();
  69. sceneConfiguration.m_sceneName = "BenchmarkWorld";
  70. AzPhysics::SceneHandle sceneHandle = physicsSystem->AddScene(sceneConfiguration);
  71. return sceneHandle;
  72. }
  73. return AzPhysics::InvalidSceneHandle;
  74. }
  75. } //namespace PhysX::Benchmarks
  76. #endif //HAVE_BENCHMARK