LoadSnapshotTest.cpp 761 B

12345678910111213141516171819202122232425262728
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include <TestFramework.h>
  4. #include <Tests/Tools/LoadSnapshotTest.h>
  5. #include <Jolt/Physics/PhysicsScene.h>
  6. #include <Jolt/Core/StreamWrapper.h>
  7. #include <Utils/Log.h>
  8. JPH_IMPLEMENT_RTTI_VIRTUAL(LoadSnapshotTest)
  9. {
  10. JPH_ADD_BASE_CLASS(LoadSnapshotTest, Test)
  11. }
  12. void LoadSnapshotTest::Initialize()
  13. {
  14. ifstream stream("snapshot.bin", ifstream::in | ifstream::binary);
  15. if (!stream.is_open())
  16. FatalError("Unable to open 'snapshot.bin'");
  17. StreamInWrapper wrapper(stream);
  18. PhysicsScene::PhysicsSceneResult result = PhysicsScene::sRestoreFromBinaryState(wrapper);
  19. if (result.HasError())
  20. FatalError(result.GetError().c_str());
  21. result.Get()->CreateBodies(mPhysicsSystem);
  22. }