MultithreadedTest.h 1.3 KB

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