StateRecorder.h 1.3 KB

1234567891011121314151617181920212223242526272829303132
  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/Core/StreamIn.h>
  6. #include <Jolt/Core/StreamOut.h>
  7. JPH_NAMESPACE_BEGIN
  8. /// Class that records the state of a physics system. Can be used to check if the simulation is deterministic by putting the recorder in validation mode.
  9. /// Can be used to restore the state to an earlier point in time.
  10. class StateRecorder : public StreamIn, public StreamOut
  11. {
  12. public:
  13. /// Constructor
  14. StateRecorder() = default;
  15. StateRecorder(const StateRecorder &inRHS) : mIsValidating(inRHS.mIsValidating) { }
  16. /// Sets the stream in validation mode. In this case the physics system ensures that before it calls ReadBytes that it will
  17. /// ensure that those bytes contain the current state. This makes it possible to step and save the state, restore to the previous
  18. /// step and step again and when the recorded state is not the same it can restore the expected state and any byte that changes
  19. /// due to a ReadBytes function can be caught to find out which part of the simulation is not deterministic
  20. void SetValidating(bool inValidating) { mIsValidating = inValidating; }
  21. bool IsValidating() const { return mIsValidating; }
  22. private:
  23. bool mIsValidating = false;
  24. };
  25. JPH_NAMESPACE_END