Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed verb syncing to work closer like IThingHolder #412

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 13 additions & 36 deletions Source/Client/Syncing/Dict/SyncDictRimWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,46 +295,15 @@ public static class SyncDictRimWorld
(SyncWorker sync, ref Verb verb) => {
if (sync.isWriting) {

if (verb.DirectOwner is Pawn pawn) {
sync.Write(VerbOwnerType.Pawn);
sync.Write(pawn);
}
else if (verb.DirectOwner is Ability ability) {
sync.Write(VerbOwnerType.Ability);
sync.Write(ability);
}
else if (verb.DirectOwner is ThingComp thingComp) {
sync.Write(VerbOwnerType.ThingComp);
sync.Write(thingComp);
}
else {
Log.Error($"Multiplayer :: SyncDictionary.Verb: Unknown DirectOwner {verb.loadID} {verb.DirectOwner}");
sync.Write(VerbOwnerType.None);
return;
}

sync.Write(verb.loadID);
sync.Write(verb.DirectOwner);
// No reason to sync loadID if the owner is null
if (verb.DirectOwner != null)
sync.Write(verb.loadID);
}
else {

var ownerType = sync.Read<VerbOwnerType>();
if (ownerType == VerbOwnerType.None) {
return;
}

IVerbOwner verbOwner = null;
if (ownerType == VerbOwnerType.Pawn) {
verbOwner = sync.Read<Pawn>();
}
else if (ownerType == VerbOwnerType.Ability) {
verbOwner = sync.Read<Ability>();
}
else if (ownerType == VerbOwnerType.ThingComp) {
verbOwner = sync.Read<ThingComp>() as IVerbOwner;
}

var verbOwner = sync.Read<IVerbOwner>();
if (verbOwner == null) {
Log.Error($"Multiplayer :: SyncDictionary.Verb: Unknown VerbOwnerType {ownerType}");
return;
}

Expand All @@ -348,6 +317,14 @@ public static class SyncDictRimWorld
}
}, true // implicit
},
{
(ByteWriter data, IVerbOwner obj) => {
WriteWithImpl<IVerbOwner>(data, obj, supportedVerbOwnerTypes);
},
(ByteReader data) => {
return ReadWithImpl<IVerbOwner>(data, supportedVerbOwnerTypes);
}, true // Implicit
},
#endregion

#region AI
Expand Down
12 changes: 7 additions & 5 deletions Source/Client/Syncing/Game/RwImplSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ public static class RwImplSerialization
typeof(WorldObjectComp)
};

internal static Type[] supportedVerbOwnerTypes =
{
typeof(Thing),
typeof(Ability),
typeof(ThingComp),
};

// ReSharper disable once InconsistentNaming
internal enum ISelectableImpl : byte
{
None, Thing, Zone, WorldObject
}

internal enum VerbOwnerType : byte
{
None, Pawn, Ability, ThingComp
}

public static void Init()
{
storageParents = TypeUtil.AllImplementationsOrdered(typeof(IStoreSettingsParent));
Expand Down
Loading