12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
- // SPDX-License-Identifier: MIT
- #include <TestFramework.h>
- #include <Tests/General/LoadSaveBinaryTest.h>
- #include <Tests/General/LoadSaveSceneTest.h>
- #include <Jolt/Physics/PhysicsScene.h>
- #include <Utils/Log.h>
- #include <Jolt/Core/StreamWrapper.h>
- #include <Layers.h>
- JPH_IMPLEMENT_RTTI_VIRTUAL(LoadSaveBinaryTest)
- {
- JPH_ADD_BASE_CLASS(LoadSaveBinaryTest, Test)
- }
- void LoadSaveBinaryTest::Initialize()
- {
- // Create scene
- Ref<PhysicsScene> scene = LoadSaveSceneTest::sCreateScene();
- {
- // Create a new scene by instantiating the scene in a physics system and then converting it back to a scene
- PhysicsSystem system;
- BPLayerInterfaceImpl layer_interface;
- system.Init(mPhysicsSystem->GetMaxBodies(), 0, 1024, 1024, layer_interface, BroadPhaseCanCollide, ObjectCanCollide);
- scene->CreateBodies(&system);
- Ref<PhysicsScene> scene_copy = new PhysicsScene();
- scene_copy->FromPhysicsSystem(&system);
- // Replace the original scene
- scene = scene_copy;
- }
- stringstream data;
- // Write scene
- {
- StreamOutWrapper stream_out(data);
- scene->SaveBinaryState(stream_out, true, true);
- }
- // Clear scene
- scene = nullptr;
- // Read scene back in
- {
- StreamInWrapper stream_in(data);
- PhysicsScene::PhysicsSceneResult result = PhysicsScene::sRestoreFromBinaryState(stream_in);
- if (result.HasError())
- FatalError(result.GetError().c_str());
- scene = result.Get();
- }
- // Instantiate scene
- scene->CreateBodies(mPhysicsSystem);
- }
|