MultithreadedTest.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 { return false; }
  18. private:
  19. // Execute a lambda either on this thread or in a separate job
  20. void Execute(default_random_engine &ioRandom, const char *inName, function<void()> inFunction);
  21. // Thread main function that spawns boxes
  22. void BoxSpawner();
  23. // Thread main function that spawns ragdolls
  24. void RagdollSpawner();
  25. // Thread main function that casts rays
  26. void CasterMain();
  27. thread mBoxSpawnerThread;
  28. thread mRagdollSpawnerThread;
  29. thread mCasterThread;
  30. atomic<bool> mIsQuitting = false;
  31. };