PhysicsScene.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Core/Reference.h>
  5. #include <Physics/Body/BodyCreationSettings.h>
  6. namespace JPH {
  7. class PhysicsSystem;
  8. /// Contains the creation settings of a set of bodies
  9. class PhysicsScene : public RefTarget<PhysicsScene>
  10. {
  11. public:
  12. JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(PhysicsScene)
  13. /// Add a body to the scene
  14. void AddBody(const BodyCreationSettings &inBody);
  15. /// Get amount of bodies in this scene
  16. size_t GetNumBodies() const { return mBodies.size(); }
  17. /// Access to the body settings for this scene
  18. const vector<BodyCreationSettings> & GetBodies() const { return mBodies; }
  19. vector<BodyCreationSettings> & GetBodies() { return mBodies; }
  20. /// Instantiate all bodies
  21. void CreateBodies(PhysicsSystem *inSystem) const;
  22. /// Go through all body creation settings and fix shapes that are scaled incorrectly (note this will change the scene a bit).
  23. /// @return False when not all scales could be fixed.
  24. bool FixInvalidScales();
  25. /// Saves the state of this object in binary form to inStream.
  26. /// @param inStream The stream to save the state to
  27. /// @param inSaveShapes If the shapes should be saved as well (these could be shared between physics scenes, in which case the calling application may want to write custom code to restore them)
  28. /// @param inSaveGroupFilter If the group filter should be saved as well (these could be shared)
  29. void SaveBinaryState(StreamOut &inStream, bool inSaveShapes, bool inSaveGroupFilter) const;
  30. using PhysicsSceneResult = Result<Ref<PhysicsScene>>;
  31. /// Restore a saved scene from inStream
  32. static PhysicsSceneResult sRestoreFromBinaryState(StreamIn &inStream);
  33. private:
  34. /// The bodies that are part of this scene
  35. vector<BodyCreationSettings> mBodies;
  36. };
  37. } // JPH