Skip to content

Commit

Permalink
Sync ActivityGizmo/CompActivity, don't sync HarbingerTree.UpdateRoots
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SokyranTheDragon committed May 6, 2024
1 parent 3e3bfb0 commit 630f15a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Source/Client/Syncing/Dict/SyncDictDlc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,23 @@ public static class SyncDictDlc
}
},
#endregion

#region Anomaly

{
(ByteWriter data, ActivityGizmo gizmo) => WriteSync(data, gizmo.Comp),
(ByteReader data) =>
{
var comp = ReadSync<CompActivity>(data);

// The gizmo may not yet be initialized for the comp.
comp.gizmo ??= new ActivityGizmo(comp.parent);

return (ActivityGizmo)comp.gizmo;
}
}

#endregion
};
}
}
16 changes: 16 additions & 0 deletions Source/Client/Syncing/Game/SyncFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));

Check failure on line 224 in Source/Client/Syncing/Game/SyncFields.cs

View workflow job for this annotation

GitHub Actions / Builds

'CompHoldingPlatformTarget' does not contain a definition for 'extractBioferrite'

Check failure on line 224 in Source/Client/Syncing/Game/SyncFields.cs

View workflow job for this annotation

GitHub Actions / Builds

'CompHoldingPlatformTarget' does not contain a definition for '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))]
Expand Down Expand Up @@ -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))]
Expand Down
1 change: 0 additions & 1 deletion Source/Client/Syncing/Game/SyncMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 630f15a

Please sign in to comment.