public static Func <ReplicatedObject, ObjectMessageSender> CreateFactory( IMessageSender sender, TransportGroupRouter groupRouter, TransportGroupId group, IBasicObjectPool <MulticastNetworkMessage> networkMessages) { return(@object => new ObjectMessageSender(sender, groupRouter, group, networkMessages, @object)); }
public ObjectMessageSender(IMessageSender sender, TransportGroupRouter groupRouter, TransportGroupId group, IBasicObjectPool <MulticastNetworkMessage> networkMessages, ReplicatedObject o) { _sender = sender; _object = o; _groupRouter = groupRouter; _group = group; _networkMessages = networkMessages; }
public bool AssignToGroup(TransportGroupId newGroup, ConnectionId connectionId) { //Debug.Log("assigning " + connectionId + " to " + newGroup); for (int i = 0; i < _groups.Count; i++) { var group = _groups[i]; _connections[group].Remove(connectionId); } var groupConfig = _config.Groups[newGroup]; var activeConnections = _connections[newGroup]; if (activeConnections.Count < groupConfig.MaxConnections) { activeConnections.Add(connectionId); return(true); } Debug.LogWarning("No more room in " + newGroup); return(false); }
public bool AssignToGroup(TransportGroupId newGroupId, ConnectionId connectionId) { //Debug.Log("assigning " + connectionId + " to " + newGroup); var newGroup = _groups[newGroupId]; if (newGroup.ActiveConnections.Count < newGroup.MaxConnections) { var existingGroupId = GetAssignedGroupId(connectionId); if (existingGroupId.HasValue) { var existingGroup = _groups[existingGroupId.Value]; existingGroup.RemoveConnection(connectionId); } newGroup.AddConnection(connectionId); return(true); } Debug.LogWarning("No more room in " + newGroup); return(false); }
public TransportRouterConfig(TransportGroupId defaultGroup, params KeyValuePair <TransportGroupId, TransportGroupConfig>[] groups) { DefaultGroup = defaultGroup; Groups = ArrayDictionary.FromValues(groups); }
public TransportRouterConfig(IDictionary <TransportGroupId, TransportGroupConfig> groups, TransportGroupId defaultGroup) { Groups = groups; DefaultGroup = defaultGroup; }
public ConnectionGroup(TransportGroupId groupId, int maxConnections) { GroupId = groupId; MaxConnections = maxConnections; _connections = new List <ConnectionId>(maxConnections); }
public bool Equals(TransportGroupId other) { return(Value == other.Value); }
public IList <ConnectionId> GetActiveConnections(TransportGroupId groupId) { return(_groups[groupId].ActiveConnections); }
public IConnectionGroup GetConnectionGroup(TransportGroupId group) { return(_groups[group]); }
public void SetDataHandler(TransportGroupId group, ITransportDataHandler handler) { _dataHandlers[group] = handler; }
public static NetworkSystems Create( IConnectionTransporter transporter, IConnectionlessTransporter connectionlessTransporter, TransportRouterConfig groupRouterConfig, TransportGroupId objectGroupId, IReadOnlyDictionary <ObjectType, Func <GameObject> > replicatedObjectPools, IMessageSender messageSender, IConnectionManager connectionManager, ILatencyInfo latencyInfo, DependencyContainer globalDependencies) { var connectionlessMessageSender = new ConnectionlessMessageSender(connectionlessTransporter); var messagePools = MessageTypes.CreateMessagePool(MessageTypes.NetworkMessageTypes); var objectMessagePools = MessageTypes.CreateMessagePool(MessageTypes.ObjectMessageTypes); var objectMessageParser = new ObjectMessageParser(MessageTypes.ObjectMessageTypes); var dependencies = globalDependencies.Copy(); dependencies.AddDependency("latencyInfo", latencyInfo); foreach (var pool in messagePools.Pools) { dependencies.AddDependency(pool.ToString(), pool); } foreach (var pool in objectMessagePools.Pools) { dependencies.AddDependency(pool.ToString(), pool); } var groupRouter = new TransportGroupRouter(transporter, groupRouterConfig); Func <GameObject, ObjectMessageRouter> objectMessageDispatcherFactory = gameObject => new ObjectMessageRouter(MessageTypes.ObjectMessageTypes, gameObject); var networkMessagePool = new BasicObjectPool <ReplicatedObjectStore.ObjectMessageSender.MulticastNetworkMessage>( pool => new ReplicatedObjectStore.ObjectMessageSender.MulticastNetworkMessage(pool, MessageTypes.NetworkMessageTypes[typeof(BasicMessage.ToObject)])); var objectMessageSenderFactory = ReplicatedObjectStore.ObjectMessageSender.CreateFactory( messageSender, groupRouter, objectGroupId, networkMessagePool); var replicationDecorator = ReplicatedObjectStore.GameObjectReplicationDecorator(objectMessageDispatcherFactory, objectMessageSenderFactory, dependencies, MessageTypes.ObjectMessageTypes); int replicatedObjectCapacity = 256; var replicatedObjectStore = new ReplicatedObjectStore(replicatedObjectPools, replicationDecorator, replicatedObjectCapacity); var replicator = new Replicator(replicatedObjectStore, groupRouter.GetConnectionGroup(objectGroupId), new NetworkReplicator(messageSender, messagePools), objectMessageParser); var defaultMessageRouter = new MessageRouter(MessageTypes.NetworkMessageTypes, latencyInfo); groupRouter.SetDataHandler(groupRouterConfig.DefaultGroup, defaultMessageRouter); return(new NetworkSystems( messageSender, connectionlessMessageSender, messagePools, connectionManager, groupRouter, defaultMessageRouter, replicatedObjectStore, MessageTypes.NetworkMessageTypes, MessageTypes.ObjectMessageTypes, replicator, objectMessageParser)); }
public void SetConnectionHandler(TransportGroupId group, ITransportConnectionHandler handler) { _connectionHandlers[group] = handler; }