MultithreadedTest.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Tests/Test.h>
  6. // This test spawns boxes and ragdolls and performs ray cast tests from threads / jobs to see if the simulation is thread safe.
  7. class MultithreadedTest : public Test
  8. {
  9. public:
  10. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, MultithreadedTest)
  11. // Destructor
  12. virtual ~MultithreadedTest() override;
  13. // Number used to scale the terrain and camera movement to the scene
  14. virtual float GetWorldScale() const override { return 0.2f; }
  15. // Initialization
  16. virtual void Initialize() override;
  17. // Test will never be deterministic since various threads are trying to concurrently add / remove bodies
  18. virtual bool IsDeterministic() const override { return false; }
  19. private:
  20. // Execute a lambda either on this thread or in a separate job
  21. void Execute(default_random_engine &ioRandom, const char *inName, function<void()> inFunction);
  22. // Thread main function that spawns boxes
  23. void BoxSpawner();
  24. // Thread main function that spawns ragdolls
  25. void RagdollSpawner();
  26. // Thread main function that casts rays
  27. void CasterMain();
  28. thread mBoxSpawnerThread;
  29. thread mRagdollSpawnerThread;
  30. thread mCasterThread;
  31. atomic<bool> mIsQuitting = false;
  32. };