public bool Remove(int k) { V v; if (hashtable.TryGetValue(k, out v)) { hashtable.Remove(k); list.Remove(v); return(true); } return(false); }
UnityNetDriverConnection GetConnection(IntHashtable <UnityNetDriverConnection> connections, int id) { UnityNetDriverConnection conn; connections.TryGetValue(id.GetHashCode(), out conn); return(conn); }
public ObjectRPCTable GetRPCTable(SerializableObject obj) { ObjectRPCTable table; if (!rpcTables.TryGetValue(obj.classID, out table)) { table = new ObjectRPCTable(obj.serverType, obj.clientType); rpcTables[obj.classID] = table; } table.Validate(obj); return table; }
public SerializableObject AddReference(ISerializableObjectFieldSerializer serializer, int id, int fieldIndex) { var obj = channel.AddObjectReferenceToSerialize(this, id); if ((obj != null) || !isLoading) { return obj; } int idHash = id.GetHashCode(); if (objectReferencedFieldStates == null) { objectReferencedFieldStates = new IntHashtable<IntHashtableList<ReplicatedObjectFieldState>>(); } IntHashtableList<ReplicatedObjectFieldState> fields; if (!objectReferencedFieldStates.TryGetValue(idHash, out fields)) { fields = new IntHashtableList<ReplicatedObjectFieldState>(); objectReferencedFieldStates[idHash] = fields; } if (!fields.Contains(curFieldState.fieldSpec.fieldID)) { fields.Add(curFieldState.fieldSpec.fieldID, curFieldState); } curFieldState.AddReference(id, fieldIndex); return null; }
void InternalHandleReplicatedObjectData(NetMsgs.ReplicatedObjectData objectData) { #if PROFILING try { Perf.Begin("ActorReplicationChannel.InternalHandleReplicatedObjectData"); #endif CHECK_FLD(objectData.archive); var netID = objectData.archive.ReadUShort(); CHECK_FLD(objectData.archive); var obj = _connection.world.GetObjectByNetID(netID); var create = objectData.archive.ReadUnsignedBits(1) != 0; var relevant = objectData.archive.ReadUnsignedBits(1) != 0; var tearOff = objectData.archive.ReadUnsignedBits(1) != 0; CHECK_FLD(objectData.archive); ObjectReplicator replicator; if (obj == null) { if (!create) { throw new ActorReplicationException("Actor replication error (no actor with id " + netID + " and create flag not set)!"); } var netIDOuter = objectData.archive.ReadUShort(); var outerObj = _connection.world.GetObjectByNetID(netIDOuter); var classID = objectData.archive.ReadInt(); CHECK_FLD(objectData.archive); obj = _connection.world.InternalCreateReplicatedObject(classID, netID); replicator = new ObjectReplicator(this, obj, _connection.world.InternalGetReplicatedFields(obj), false); obj.internal_SetReplicator(connection, replicator); obj.PreConstruct(outerObj); obj.PreNetConstruct(); } else { if (create) { throw new ActorReplicationException("Actor replication error (actor with id " + netID + " create flag not set)!"); } replicator = obj.internal_GetReplicator(connection); } var actor = obj as Actor; bool wasRelevant = true; if (actor != null) { wasRelevant = actor.isNetRelevant; actor.internal_NetRelevant = relevant; } obj.PreNetReceive(); isSending = false; replicator.DeltaSerialize(0f, objectData.archive, false); obj.SerializeCustomData(objectData.archive); CHECK_FLD(objectData.archive); obj.PostNetReceive(); if (create) { obj.Construct(); obj.PostNetConstruct(); obj.PostConstruct(); } replicator.OnRep(); obj.PostOnRepFields(); if (create && (actor != null) && !_connection.world.isTraveling) { actor.OnLevelStart(); } IntHashtableList<ObjectReplicator> repls; if (pendingRefs.TryGetValue(obj.netIDHashCode, out repls)) { for (int i = 0; i < repls.Values.Count; ++i) { repls.Values[i].ResolveReference(obj, netID); } for (int i = 0; i < repls.Values.Count; ++i) { repls.Values[i].OnRep(); } repls.Clear(); } if ((actor != null) && (wasRelevant != relevant)) { actor.OnNetRelevancyChanged(); } if ((actor != null) && tearOff) { obj.internal_SetReplicator(connection, null); actor.NetTearOff(); } #if PROFILING } finally { Perf.End(); } #endif }