From 630f15ad8b64b10815af207f3e9b4a63cc88a274 Mon Sep 17 00:00:00 2001 From: SokyranTheDragon Date: Mon, 6 May 2024 17:58:32 +0200 Subject: [PATCH] Sync ActivityGizmo/CompActivity, don't sync HarbingerTree.UpdateRoots Syncing of `HarbingerTree.UpdateRoots` was removed, as the method would naturally be queued up during simulation (SpawnSetup) and called in as a long event, causing the call to be synced. If dev mode syncing was disabled it would end up never being called. Synced following fields: - `ActivityGizmo.targetValuePct` - `CompActivity.suppressIfAbove` - `CompActivity.suppressionEnabled` This required creating a sync worker for `ActivityGizmo`. The syncing here is pretty similar to syncing of `GeneGizmo_Resource`, `Gene_Resource`, and `Gene_Hemogen`. It would potentially be possible to make a more universal approach, but I could not think of one myself. `SyncGeneGizmoResource` and `SyncActivityGizmoTarget` sync the same field (`Gizmo_Slider.targetValuePct`), but we can't register sync field targeting `Gizmo_Slider` as that type is not syncable. --- Source/Client/Syncing/Dict/SyncDictDlc.cs | 17 +++++++++++++++++ Source/Client/Syncing/Game/SyncFields.cs | 16 ++++++++++++++++ Source/Client/Syncing/Game/SyncMethods.cs | 1 - 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Source/Client/Syncing/Dict/SyncDictDlc.cs b/Source/Client/Syncing/Dict/SyncDictDlc.cs index 53fbb638..bc66ee44 100644 --- a/Source/Client/Syncing/Dict/SyncDictDlc.cs +++ b/Source/Client/Syncing/Dict/SyncDictDlc.cs @@ -285,6 +285,23 @@ public static class SyncDictDlc } }, #endregion + + #region Anomaly + + { + (ByteWriter data, ActivityGizmo gizmo) => WriteSync(data, gizmo.Comp), + (ByteReader data) => + { + var comp = ReadSync(data); + + // The gizmo may not yet be initialized for the comp. + comp.gizmo ??= new ActivityGizmo(comp.parent); + + return (ActivityGizmo)comp.gizmo; + } + } + + #endregion }; } } diff --git a/Source/Client/Syncing/Game/SyncFields.cs b/Source/Client/Syncing/Game/SyncFields.cs index 728a2f8d..7ad0c136 100644 --- a/Source/Client/Syncing/Game/SyncFields.cs +++ b/Source/Client/Syncing/Game/SyncFields.cs @@ -87,6 +87,10 @@ public static class SyncFields public static ISyncField SyncEntityContainmentMode; public static ISyncField SyncExtractBioferrite; + public static ISyncField SyncActivityGizmoTarget; + public static ISyncField SyncActivityCompTarget; + public static ISyncField SyncActivityCompSuppression; + public static void Init() { SyncMedCare = Sync.Field(typeof(Pawn), nameof(Pawn.playerSettings), nameof(Pawn_PlayerSettings.medCare)); @@ -218,6 +222,10 @@ public static void Init() SyncStudiableCompEnabled = Sync.Field(typeof(CompStudiable), nameof(CompStudiable.studyEnabled)); SyncEntityContainmentMode = Sync.Field(typeof(CompHoldingPlatformTarget), nameof(CompHoldingPlatformTarget.containmentMode)); SyncExtractBioferrite = Sync.Field(typeof(CompHoldingPlatformTarget), nameof(CompHoldingPlatformTarget.extractBioferrite)); + + SyncActivityGizmoTarget = Sync.Field(typeof(ActivityGizmo), nameof(ActivityGizmo.targetValuePct)).SetBufferChanges(); + SyncActivityCompTarget = Sync.Field(typeof(CompActivity), nameof(CompActivity.suppressIfAbove)).SetBufferChanges(); + SyncActivityCompSuppression = Sync.Field(typeof(CompActivity), nameof(CompActivity.suppressionEnabled)); } [MpPrefix(typeof(StorytellerUI), nameof(StorytellerUI.DrawStorytellerSelectionInterface))] @@ -534,6 +542,14 @@ static void SyncGeneResourceChange(Gizmo_Slider __instance) if (geneGizmo.gene is Gene_Hemogen) SyncGeneHemogenAllowed.Watch(geneGizmo.gene); } + else if (__instance is ActivityGizmo activityGizmo) + { + SyncActivityGizmoTarget.Watch(activityGizmo); + + var comp = activityGizmo.Comp; + SyncActivityCompTarget.Watch(comp); + SyncActivityCompSuppression.Watch(comp); + } } [MpPrefix(typeof(ITab_ContentsGenepackHolder), nameof(ITab_ContentsGenepackHolder.DoItemsLists))] diff --git a/Source/Client/Syncing/Game/SyncMethods.cs b/Source/Client/Syncing/Game/SyncMethods.cs index fd654c36..42e42532 100644 --- a/Source/Client/Syncing/Game/SyncMethods.cs +++ b/Source/Client/Syncing/Game/SyncMethods.cs @@ -386,7 +386,6 @@ public static void Init() SyncMethod.Register(typeof(HarbingerTree), nameof(HarbingerTree.CreateCorpseStockpile)).SetContext(SyncContext.MapSelected); SyncMethod.Register(typeof(HarbingerTree), nameof(HarbingerTree.AddNutrition)).SetDebugOnly(); SyncMethod.Register(typeof(HarbingerTree), nameof(HarbingerTree.SpawnNewTree)).SetDebugOnly(); - SyncMethod.Register(typeof(HarbingerTree), nameof(HarbingerTree.UpdateRoots)).SetDebugOnly(); SyncMethod.LocalFunc(typeof(HarbingerTree), nameof(HarbingerTree.GetGizmos), "DelayedSplatter").SetDebugOnly(); // Set blood splatters delay // Pawn creep joiner tracker