Test.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Physics/PhysicsSystem.h>
  5. #include <Renderer/Renderer.h>
  6. #include <Input/Keyboard.h>
  7. #include <Skeleton/SkeletonPose.h>
  8. #include <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. // Initialize the test
  30. virtual void Initialize() { }
  31. // Number used to scale the terrain and camera movement to the scene
  32. virtual float GetWorldScale() const { return 1.0f; }
  33. // If this test implements a contact listener, it should be returned here
  34. virtual ContactListener *GetContactListener() { return nullptr; }
  35. class PreUpdateParams
  36. {
  37. public:
  38. float mDeltaTime;
  39. Keyboard * mKeyboard;
  40. CameraState mCameraState;
  41. #ifdef JPH_DEBUG_RENDERER
  42. const SkeletonPose::DrawSettings * mPoseDrawSettings;
  43. #endif // JPH_DEBUG_RENDERER
  44. };
  45. // Update the test, called before the physics update
  46. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) { }
  47. // Update the test, called after the physics update
  48. virtual void PostPhysicsUpdate(float inDeltaTime) { }
  49. // Override to specify the initial camera state (local to GetCameraPivot)
  50. virtual void GetInitialCamera(CameraState &ioState) const { }
  51. // Override to specify a camera pivot point and orientation (world space)
  52. virtual Mat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) const { return Mat44::sIdentity(); }
  53. // Optional settings menu
  54. virtual bool HasSettingsMenu() const { return false; }
  55. virtual void CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) { }
  56. // Force the application to restart the test
  57. virtual void RestartTest() { mNeedsRestart = true; }
  58. virtual bool NeedsRestart() const { return mNeedsRestart; }
  59. // If this test is supposed to be deterministic
  60. virtual bool IsDeterministic() const { return true; }
  61. // Saving / restoring state for replay
  62. virtual void SaveState(StateRecorder &inStream) const { }
  63. virtual void RestoreState(StateRecorder &inStream) { }
  64. protected:
  65. // Utility function to create a static floor body
  66. Body & CreateFloor();
  67. // Utiltity function to create a floor consisting of very large triangles
  68. Body & CreateLargeTriangleFloor();
  69. // Create an uneven terrain floor body
  70. Body & CreateMeshTerrain();
  71. Body & CreateHeightFieldTerrain();
  72. JobSystem * mJobSystem = nullptr;
  73. PhysicsSystem * mPhysicsSystem = nullptr;
  74. BodyInterface * mBodyInterface = nullptr;
  75. DebugRenderer * mDebugRenderer = nullptr;
  76. private:
  77. bool mNeedsRestart = false;
  78. };