| | | 1 | | //======================================================================= |
| | | 2 | | // GravitasReplayHashService.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using Chronicler; |
| | | 9 | | using FixedMathSharp.Chronicler; |
| | | 10 | | |
| | | 11 | | namespace Gravitas; |
| | | 12 | | |
| | | 13 | | internal static class GravitasReplayHashService |
| | | 14 | | { |
| | | 15 | | public static ChronicleHash Compute( |
| | | 16 | | GravitasWorldContext context, |
| | | 17 | | GravitasReplayHashMode mode) |
| | | 18 | | { |
| | 993 | 19 | | var writer = new ChronicleHashWriter(); |
| | 993 | 20 | | writer.WriteSection("gravitas.replay", 1); |
| | 993 | 21 | | writer.WriteEnum(mode); |
| | 993 | 22 | | writer.WriteEnum(context.Settings.RuntimeMode); |
| | 993 | 23 | | writer.WriteInt32(context.FrameRate); |
| | 993 | 24 | | writer.WriteFixed64(context.DeltaTime); |
| | 993 | 25 | | writer.WriteFixed64(context.InvDeltaTime); |
| | 993 | 26 | | writer.WriteInt32(context.FrameCount); |
| | 993 | 27 | | writer.WriteFixed64(context.TotalTime); |
| | 993 | 28 | | writer.WriteInt32(context.LateSimulateToken); |
| | | 29 | | |
| | 993 | 30 | | PhysicsRuntimeMode runtimeMode = context.Settings.RuntimeMode; |
| | 993 | 31 | | if (runtimeMode.Runs3D()) |
| | 713 | 32 | | context.Physics.PrepareReplayColliders(); |
| | 993 | 33 | | if (runtimeMode.Runs2D()) |
| | 454 | 34 | | context.Physics2D.PrepareReplayColliders(); |
| | | 35 | | |
| | 993 | 36 | | context.Settings.ContributeReplayHash(ref writer); |
| | 993 | 37 | | context.Environment.ContributeReplayHash(ref writer); |
| | 993 | 38 | | context.Constraints3D.ContributeReplayHash(ref writer, mode); |
| | 993 | 39 | | context.Constraints2D.ContributeReplayHash(ref writer, mode); |
| | | 40 | | |
| | 993 | 41 | | if (runtimeMode.Runs3D()) |
| | 713 | 42 | | context.Physics.ContributeReplayHash(ref writer, mode); |
| | 993 | 43 | | if (runtimeMode.Runs2D()) |
| | 454 | 44 | | context.Physics2D.ContributeReplayHash(ref writer, mode); |
| | 993 | 45 | | if (runtimeMode.RunsMixedContacts()) |
| | 174 | 46 | | context.MixedCollisions.ContributeReplayHash(ref writer, mode); |
| | | 47 | | |
| | 993 | 48 | | return writer.ToHash(); |
| | | 49 | | } |
| | | 50 | | } |