2
0

Test.h 3.7 KB

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