Skip to content

Commit

Permalink
4.4.6
Browse files Browse the repository at this point in the history
- Improved performance marginally for clients using prediction.
- Fixed SyncDictionary.DirtyAll not working.
- Fixed NetworkTransform.SetSychronizedProperties updating only observers when called by the server (#774).
- Changed NetworkTransform removed server ability to SetSynchronizedProperties if client authoritative with owner.
- Fixed ChildTransformTickSmoother ignoring owner smoothed properties (#770, #771).
- Fixed SceneManager sometimes not automatically setting the proper active scene (#765).
- Fixed Resettable/RingBuffer enumerator not working.
- Fixed clientHost sometimes incorrectly losing render visibility of objects. (#772).
  • Loading branch information
FirstGearGames committed Sep 20, 2024
1 parent 8e4f8b3 commit 411ad2d
Show file tree
Hide file tree
Showing 48 changed files with 1,495 additions and 971 deletions.
112 changes: 63 additions & 49 deletions Assets/FishNet/CodeGenerating/Helpers/GeneralHelper.cs

Large diffs are not rendered by default.

18 changes: 6 additions & 12 deletions Assets/FishNet/CodeGenerating/Helpers/NetworkBehaviourHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal class NetworkBehaviourHelper : CodegenBase
public MethodReference Replicate_NonAuthoritative_MethodRef;
public MethodReference Replicate_Authortative_MethodRef;
public MethodReference Reconcile_Client_MethodRef;
public MethodReference Reconcile_Client_Local_MethodRef;
public MethodReference Replicate_Replay_MethodRef;
public MethodReference Reconcile_Reader_MethodRef;
public MethodReference RegisterReplicateRpc_MethodRef;
Expand All @@ -44,7 +45,6 @@ internal class NetworkBehaviourHelper : CodegenBase
public MethodReference SendServerRpc_MethodRef;
public MethodReference SendObserversRpc_MethodRef;
public MethodReference SendTargetRpc_MethodRef;
public MethodReference DirtySyncType_MethodRef;
public MethodReference RegisterServerRpc_MethodRef;
public MethodReference RegisterObserversRpc_MethodRef;
public MethodReference RegisterTargetRpc_MethodRef;
Expand Down Expand Up @@ -117,11 +117,11 @@ public override bool ImportReferences()
Reconcile_Server_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_Client))
Reconcile_Client_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_Client_Local))
Reconcile_Client_Local_MethodRef = base.ImportReference(mi);
//Misc.
else if (mi.Name == nameof(NetworkBehaviour.OwnerMatches))
OwnerMatches_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.DirtySyncType))
DirtySyncType_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.NetworkInitializeIfDisabled))
NetworkInitializeIfDisabled_MethodRef = base.ImportReference(mi);
//Prediction
Expand Down Expand Up @@ -178,7 +178,6 @@ internal MethodDefinition GetAwakeMethodDefinition(TypeDefinition typeDef)
return typeDef.GetMethod(AWAKE_METHOD_NAME);
}


/// <summary>
/// Creates a replicate delegate.
/// </summary>
Expand All @@ -205,8 +204,6 @@ internal void CreateReplicateDelegate(MethodDefinition originalMethodDef, Method
processor.InsertLast(insts);
}



/// <summary>
/// Creates a RPC delegate for rpcType.
/// </summary>
Expand Down Expand Up @@ -277,9 +274,7 @@ internal Instruction CreateLocalClientIsOwnerCheck(MethodDefinition methodDef, L
if (loggingType != LoggingType.Off)
{
string disableLoggingText = (notifyMessageCanBeDisabled) ? DISABLE_LOGGING_TEXT : string.Empty;
string msg = (retIfOwner) ?
$"Cannot complete action because you are the owner of this object. {disableLoggingText}." :
$"Cannot complete action because you are not the owner of this object. {disableLoggingText}.";
string msg = (retIfOwner) ? $"Cannot complete action because you are the owner of this object. {disableLoggingText}." : $"Cannot complete action because you are not the owner of this object. {disableLoggingText}.";

instructions.AddRange(base.GetClass<GeneralHelper>().LogMessage(methodDef, msg, loggingType));
}
Expand Down Expand Up @@ -387,8 +382,8 @@ internal void CreateIsClientCheck(MethodDefinition methodDef, LoggingType loggin
internal void CreateIsServerCheck(MethodDefinition methodDef, LoggingType loggingType, bool useStatic, bool insertFirst, bool checkIsNetworked)
{
/* This is placed after the if check.
* Should the if check pass then code
* jumps to this instruction. */
* Should the if check pass then code
* jumps to this instruction. */
ILProcessor processor = methodDef.Body.GetILProcessor();
Instruction endIf = processor.Create(OpCodes.Nop);

Expand Down Expand Up @@ -445,7 +440,6 @@ private List<Instruction> CreateIsNetworkedCheck(MethodDefinition methodDef, Ins
return insts;
}


/// <summary>
/// Creates a return using the ReturnType for methodDef.
/// </summary>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ MonoBehaviour:
<ComponentIndex>k__BackingField: 0
<PredictedSpawn>k__BackingField: {fileID: 0}
<PredictedOwner>k__BackingField: {fileID: 0}
_networkBehaviours:
- {fileID: 0}
- {fileID: -5271135124957689192}
<SerializedRootNetworkBehaviour>k__BackingField: {fileID: 0}
<SerializedNestedNetworkObjects>k__BackingField: []
NetworkBehaviours: []
<InitializedParentNetworkBehaviour>k__BackingField: {fileID: 0}
<InitializedNestedNetworkObjects>k__BackingField: []
_isNetworked: 1
_isSpawnable: 1
_isGlobal: 0
Expand All @@ -75,14 +73,14 @@ MonoBehaviour:
_spectatorInterpolation: 2
_enableTeleport: 0
_teleportThreshold: 1
<PrefabId>k__BackingField: 26
<PrefabId>k__BackingField: 65535
<SpawnableCollectionId>k__BackingField: 0
<AssetPathHash>k__BackingField: 14364260540862342890
<SceneId>k__BackingField: 0
SerializedTransformProperties:
Position: {x: 0, y: 0, z: 0}
Rotation: {x: 0, y: 0, z: 0, w: 1}
LocalScale: {x: 1, y: 1, z: 1}
Rotation: {x: 0, y: 0, z: 0, w: 0}
LocalScale: {x: 0, y: 0, z: 0}
--- !u!114 &6667641716399555817
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -116,9 +114,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 1
_componentIndexCache: 255
_addedNetworkObject: {fileID: 4512293259955182956}
_networkObjectCache: {fileID: 4512293259955182956}
_networkObjectCache: {fileID: 0}
_componentConfiguration: 0
_synchronizeParent: 0
_packing:
Expand Down
76 changes: 33 additions & 43 deletions Assets/FishNet/Demos/ColliderRollback/Prefabs/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 2, z: -2}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
Expand All @@ -47,50 +48,40 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 26b716c41e9b56b4baafaf13a523ba2e, type: 3}
m_Name:
m_EditorClassIdentifier:
NetworkObserver: {fileID: 0}
<PrefabId>k__BackingField: 27
<SpawnableCollectionId>k__BackingField: 0
_scenePathHash: 0
<SceneId>k__BackingField: 0
<AssetPathHash>k__BackingField: 7473726319608011331
AdaptiveInterpolationValue: 4
<IsNested>k__BackingField: 0
<ComponentIndex>k__BackingField: 0
<PredictedSpawn>k__BackingField: {fileID: 0}
<PredictedOwner>k__BackingField: {fileID: 0}
NetworkBehaviours: []
<InitializedParentNetworkBehaviour>k__BackingField: {fileID: 0}
<InitializedNestedNetworkObjects>k__BackingField: []
_isNetworked: 1
_isSpawnable: 1
_isGlobal: 0
_initializeOrder: 0
_defaultDespawnType: 0
NetworkObserver: {fileID: 0}
_enablePrediction: 0
_predictionType: 0
_graphicalObject: {fileID: 0}
_detachGraphicalObject: 0
_enableStateForwarding: 1
_networkTransform: {fileID: 0}
_ownerInterpolation: 1
_ownerSmoothedProperties: 255
_adaptiveInterpolation: 3
_spectatorSmoothedProperties: 255
_spectatorInterpolation: 2
_enableTeleport: 0
_ownerTeleportThreshold: 1
_spectatorAdaptiveInterpolation: 1
_spectatorInterpolation: 1
_adaptiveSmoothingType: 0
_customSmoothingData:
InterpolationPercent: 1
CollisionInterpolationPercent: 0.1
InterpolationDecreaseStep: 1
InterpolationIncreaseStep: 3
_preconfiguredSmoothingDataPreview:
InterpolationPercent: 0.5
CollisionInterpolationPercent: 0.05
InterpolationDecreaseStep: 1
InterpolationIncreaseStep: 2
<ComponentIndex>k__BackingField: 0
<PredictedSpawn>k__BackingField: {fileID: 0}
_networkBehaviours:
- {fileID: 2759061792589502182}
- {fileID: 1348621277}
- {fileID: 1348621278}
<ParentNetworkObject>k__BackingField: {fileID: 0}
<ChildNetworkObjects>k__BackingField: []
_teleportThreshold: 1
<PrefabId>k__BackingField: 65535
<SpawnableCollectionId>k__BackingField: 0
<AssetPathHash>k__BackingField: 7473726319608011331
<SceneId>k__BackingField: 0
SerializedTransformProperties:
Position: {x: 0, y: 0, z: 0}
Rotation: {x: 0, y: 0, z: 0, w: 0}
LocalScale: {x: 0, y: 0, z: 0}
_isNetworked: 1
_isGlobal: 0
_initializeOrder: 0
_defaultDespawnType: 0
--- !u!114 &2759061792589502182
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -103,15 +94,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9d3558aad46c24549bea48d0e3938264, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 0
_componentIndexCache: 255
_addedNetworkObject: {fileID: 8475222101369129519}
_networkObjectCache: {fileID: 8475222101369129519}
_networkObjectCache: {fileID: 0}
_hitboxLayer:
serializedVersion: 2
m_Bits: 32
_audio: {fileID: 8300000, guid: 0330762d2b3c8d641bfe11ad89b7e196, type: 3}
_muzzleFlashPrefab: {fileID: 39148481766341303, guid: 4385a793e032d634bb912f84a23d6db1,
type: 3}
m_Bits: 0
_audio: {fileID: 0}
_muzzleFlashPrefab: {fileID: 0}
--- !u!114 &1348621277
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -124,9 +114,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e6d656f377f37164d8d7431aa4e43cdb, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 1
_componentIndexCache: 255
_addedNetworkObject: {fileID: 8475222101369129519}
_networkObjectCache: {fileID: 8475222101369129519}
_networkObjectCache: {fileID: 0}
--- !u!114 &1348621278
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -139,9 +129,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c718ab30626bbd648952910f74780a06, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 2
_componentIndexCache: 255
_addedNetworkObject: {fileID: 8475222101369129519}
_networkObjectCache: {fileID: 8475222101369129519}
_networkObjectCache: {fileID: 0}
_moveRate: 3
--- !u!143 &5081159371976248031
CharacterController:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace FishNet.Example.ComponentStateSync
{


/// <summary>
/// It's very important to exclude this from codegen.
/// However, whichever value you are synchronizing must not be excluded. This is why the value is outside the StructySync class.
Expand All @@ -29,10 +27,12 @@ public bool Enabled
/// Component to state sync.
/// </summary>
public T Component { get; private set; }

/// <summary>
/// Delegate signature for when the component changes.
/// </summary>
public delegate void StateChanged(T component, bool prevState, bool nextState, bool asServer);

/// <summary>
/// Called when the component state changes.
/// </summary>
Expand Down Expand Up @@ -99,6 +99,7 @@ private void AddOperation(T component, bool prev, bool next)
bool asServer = true;
OnChange?.Invoke(component, prev, next, asServer);
}

/// <summary>
/// Writes all changed values.
/// </summary>
Expand Down Expand Up @@ -128,21 +129,20 @@ internal protected override void WriteFull(PooledWriter writer)
[APIExclude]
internal protected override void Read(PooledReader reader, bool asServer)
{
bool nextValue = reader.ReadBoolean();
if (base.NetworkManager == null)
return;

base.SetReadArguments(reader, asServer, out bool newChangeId, out bool _, out bool canModifyValues);

bool prevValue = GetState();
bool nextValue = reader.ReadBoolean();

/* When !asServer don't make changes if server is running.
* This is because changes would have already been made on
* the server side and doing so again would result in duplicates
* and potentially overwrite data not yet sent. */
bool asClientAndHost = (!asServer && base.NetworkManager.IsServerStarted);
if (!asClientAndHost)
* This is because changes would have already been made on
* the server side and doing so again would result in duplicates
* and potentially overwrite data not yet sent. */
if (canModifyValues)
Component.enabled = nextValue;

OnChange?.Invoke(Component, prevValue, nextValue, asServer);
if (newChangeId)
OnChange?.Invoke(Component, prevValue, nextValue, asServer);
}

/// <summary>
Expand All @@ -151,4 +151,4 @@ internal protected override void Read(PooledReader reader, bool asServer)
/// <returns></returns>
public object GetSerializedType() => null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ChangeData(CustomOperation operation, Structy data)
Data = data;
}
}

/// <summary>
/// Types of changes. This is related to ChangedData
/// where you can specify what has changed.
Expand All @@ -67,6 +68,7 @@ public enum CustomOperation : byte
/// <param name="oldItem"></param>
/// <param name="newItem"></param>
public delegate void CustomChanged(CustomOperation op, Structy oldItem, Structy newItem, bool asServer);

/// <summary>
/// Called when the Structy changes.
/// </summary>
Expand Down Expand Up @@ -121,10 +123,10 @@ private void AddOperation(CustomOperation operation, Structy prev, Structy next)
}

/* Set as changed even if cannot dirty.
* Dirty is only set when there are observers,
* but even if there are not observers
* values must be marked as changed so when
* there are observers, new values are sent. */
* Dirty is only set when there are observers,
* but even if there are not observers
* values must be marked as changed so when
* there are observers, new values are sent. */
_valuesChanged = true;
base.Dirty();

Expand Down Expand Up @@ -190,11 +192,7 @@ internal protected override void WriteFull(PooledWriter writer)
[APIExclude]
internal protected override void Read(PooledReader reader, bool asServer)
{
/* When !asServer don't make changes if server is running.
* This is because changes would have already been made on
* the server side and doing so again would result in duplicates
* and potentially overwrite data not yet sent. */
bool asClientAndHost = (!asServer && base.NetworkManager.IsServerStarted);
base.SetReadArguments(reader, asServer, out bool newChangeId, out bool _, out bool canModifyValues);

int changes = reader.ReadInt32();
for (int i = 0; i < changes; i++)
Expand All @@ -213,12 +211,12 @@ internal protected override void Read(PooledReader reader, bool asServer)
else if (operation == CustomOperation.Age)
next.Age = reader.ReadUInt16();

OnChange?.Invoke(operation, prev, next, asServer);

if (!asClientAndHost)
if (canModifyValues)
Value = next;

if (newChangeId)
OnChange?.Invoke(operation, prev, next, asServer);
}

}

/// <summary>
Expand Down Expand Up @@ -254,4 +252,4 @@ internal protected override void ResetState(bool asServer)
/// <returns></returns>
public object GetSerializedType() => typeof(Structy);
}
}
}
Loading

0 comments on commit 411ad2d

Please sign in to comment.