StateRecorder.h 1.3 KB

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