| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationAgentProfileRecord.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using Chronicler; |
| | | 10 | | using FixedMathSharp; |
| | | 11 | | using Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | namespace Trailblazer.Navigation; |
| | | 14 | | |
| | | 15 | | /// <summary>Records one exact immutable navigation-agent profile.</summary> |
| | | 16 | | internal sealed class NavigationAgentProfileRecord : IRecordable |
| | | 17 | | { |
| | 122 | 18 | | public NavigationAgentProfileRecord() |
| | | 19 | | { |
| | 122 | 20 | | } |
| | | 21 | | |
| | 154 | 22 | | public NavigationAgentProfileRecord(NavigationAgentProfile profile) => Capture(profile); |
| | | 23 | | |
| | | 24 | | public Fixed64 Radius; |
| | | 25 | | |
| | | 26 | | public Fixed64 Height; |
| | | 27 | | |
| | | 28 | | public Fixed64 RootToFootOffsetY; |
| | | 29 | | |
| | | 30 | | public Fixed64 MaxStepUp; |
| | | 31 | | |
| | | 32 | | public Fixed64 MaxDropDown; |
| | | 33 | | |
| | | 34 | | public Fixed64 ArrivalRadius; |
| | | 35 | | |
| | | 36 | | public TraversalMedia AllowedMedia; |
| | | 37 | | |
| | | 38 | | public TraversalCapability Capabilities; |
| | | 39 | | |
| | | 40 | | public void Capture(NavigationAgentProfile profile) |
| | | 41 | | { |
| | 139 | 42 | | Radius = profile.Shape.Radius; |
| | 139 | 43 | | Height = profile.Shape.Height; |
| | 139 | 44 | | RootToFootOffsetY = profile.Shape.RootToFootOffsetY; |
| | 139 | 45 | | MaxStepUp = profile.MaxStepUp; |
| | 139 | 46 | | MaxDropDown = profile.MaxDropDown; |
| | 139 | 47 | | ArrivalRadius = profile.ArrivalRadius; |
| | 139 | 48 | | AllowedMedia = profile.AllowedMedia; |
| | 139 | 49 | | Capabilities = profile.Capabilities; |
| | 139 | 50 | | } |
| | | 51 | | |
| | | 52 | | public bool TryCreate(out NavigationAgentProfile profile) |
| | | 53 | | { |
| | 78 | 54 | | profile = default; |
| | | 55 | | try |
| | | 56 | | { |
| | 78 | 57 | | profile = new NavigationAgentProfile( |
| | 78 | 58 | | new KinematicBodyShape(Radius, Height, RootToFootOffsetY), |
| | 78 | 59 | | MaxStepUp, |
| | 78 | 60 | | MaxDropDown, |
| | 78 | 61 | | ArrivalRadius, |
| | 78 | 62 | | AllowedMedia, |
| | 78 | 63 | | Capabilities); |
| | 74 | 64 | | return true; |
| | | 65 | | } |
| | 4 | 66 | | catch (ArgumentException) |
| | | 67 | | { |
| | 4 | 68 | | return false; |
| | | 69 | | } |
| | 78 | 70 | | } |
| | | 71 | | |
| | | 72 | | public void RecordData(IChronicler chronicler) |
| | | 73 | | { |
| | 197 | 74 | | RecordValues.Look(chronicler, ref Radius, "Radius", Fixed64.Zero); |
| | 197 | 75 | | RecordValues.Look(chronicler, ref Height, "Height", Fixed64.Zero); |
| | 197 | 76 | | RecordValues.Look(chronicler, ref RootToFootOffsetY, "RootToFootOffsetY", Fixed64.Zero); |
| | 197 | 77 | | RecordValues.Look(chronicler, ref MaxStepUp, "MaxStepUp", Fixed64.Zero); |
| | 197 | 78 | | RecordValues.Look(chronicler, ref MaxDropDown, "MaxDropDown", Fixed64.Zero); |
| | 197 | 79 | | RecordValues.Look(chronicler, ref ArrivalRadius, "ArrivalRadius", Fixed64.Zero); |
| | 197 | 80 | | RecordValues.Look(chronicler, ref AllowedMedia, "AllowedMedia", TraversalMedia.None); |
| | 197 | 81 | | RecordValues.Look(chronicler, ref Capabilities, "Capabilities", TraversalCapability.None); |
| | 197 | 82 | | } |
| | | 83 | | } |