2
0

Test.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/Physics/PhysicsSystem.h>
  5. #include <Renderer/Renderer.h>
  6. #include <Input/Keyboard.h>
  7. #include <Jolt/Skeleton/SkeletonPose.h>
  8. #include <Jolt/Core/RTTI.h>
  9. class DebugUI;
  10. class UIElement;
  11. namespace JPH {
  12. class StateRecorder;
  13. class JobSystem;
  14. class ContactListener;
  15. class DebugRenderer;
  16. }
  17. class Test
  18. {
  19. public:
  20. JPH_DECLARE_RTTI_VIRTUAL_BASE(Test)
  21. // Destructor
  22. virtual ~Test() = default;
  23. // Set the physics system
  24. virtual void SetPhysicsSystem(PhysicsSystem *inPhysicsSystem) { mPhysicsSystem = inPhysicsSystem; mBodyInterface = &inPhysicsSystem->GetBodyInterface(); }
  25. // Set the job system
  26. void SetJobSystem(JobSystem *inJobSystem) { mJobSystem = inJobSystem; }
  27. // Set the debug renderer
  28. void SetDebugRenderer(DebugRenderer *inDebugRenderer) { mDebugRenderer = inDebugRenderer; }
  29. // Set the temp allocator
  30. void SetTempAllocator(TempAllocator *inTempAllocator) { mTempAllocator = inTempAllocator; }
  31. // Initialize the test
  32. virtual void Initialize() { }
  33. // Number used to scale the terrain and camera movement to the scene
  34. virtual float GetWorldScale() const { return 1.0f; }
  35. // If this test implements a contact listener, it should be returned here
  36. virtual ContactListener *GetContactListener() { return nullptr; }
  37. class PreUpdateParams
  38. {
  39. public:
  40. float mDeltaTime;
  41. Keyboard * mKeyboard;
  42. CameraState mCameraState;
  43. #ifdef JPH_DEBUG_RENDERER
  44. const SkeletonPose::DrawSettings * mPoseDrawSettings;
  45. #endif // JPH_DEBUG_RENDERER
  46. };
  47. // Update the test, called before the physics update
  48. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) { }
  49. // Update the test, called after the physics update
  50. virtual void PostPhysicsUpdate(float inDeltaTime) { }
  51. // Override to specify the initial camera state (local to GetCameraPivot)
  52. virtual void GetInitialCamera(CameraState &ioState) const { }
  53. // Override to specify a camera pivot point and orientation (world space)
  54. virtual Mat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) const { return Mat44::sIdentity(); }
  55. // Optional settings menu
  56. virtual bool HasSettingsMenu() const { return false; }
  57. virtual void CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) { }
  58. // Force the application to restart the test
  59. virtual void RestartTest() { mNeedsRestart = true; }
  60. virtual bool NeedsRestart() const { return mNeedsRestart; }
  61. // If this test is supposed to be deterministic
  62. virtual bool IsDeterministic() const { return true; }
  63. // Saving / restoring state for replay
  64. virtual void SaveState(StateRecorder &inStream) const { }
  65. virtual void RestoreState(StateRecorder &inStream) { }
  66. protected:
  67. // Utility function to create a static floor body
  68. Body & CreateFloor(float inSize = 200.0f);
  69. // Utiltity function to create a floor consisting of very large triangles
  70. Body & CreateLargeTriangleFloor();
  71. // Create an uneven terrain floor body
  72. Body & CreateMeshTerrain();
  73. Body & CreateHeightFieldTerrain();
  74. JobSystem * mJobSystem = nullptr;
  75. PhysicsSystem * mPhysicsSystem = nullptr;
  76. BodyInterface * mBodyInterface = nullptr;
  77. DebugRenderer * mDebugRenderer = nullptr;
  78. TempAllocator * mTempAllocator = nullptr;
  79. private:
  80. bool mNeedsRestart = false;
  81. };