// SPDX-FileCopyrightText: 2021 Jorrit Rouwe // SPDX-License-Identifier: MIT #include #include #include #include #include #include #include JPH_IMPLEMENT_RTTI_VIRTUAL(LoadSaveBinaryTest) { JPH_ADD_BASE_CLASS(LoadSaveBinaryTest, Test) } void LoadSaveBinaryTest::Initialize() { // Create scene Ref 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 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); }