Example #1
0
 public static Func <ReplicatedObject, ObjectMessageSender> CreateFactory(
     IMessageSender sender,
     TransportGroupRouter groupRouter,
     TransportGroupId group,
     IBasicObjectPool <MulticastNetworkMessage> networkMessages)
 {
     return(@object => new ObjectMessageSender(sender, groupRouter, group, networkMessages, @object));
 }
Example #2
0
 public ObjectMessageSender(IMessageSender sender,
                            TransportGroupRouter groupRouter,
                            TransportGroupId group,
                            IBasicObjectPool <MulticastNetworkMessage> networkMessages,
                            ReplicatedObject o)
 {
     _sender          = sender;
     _object          = o;
     _groupRouter     = groupRouter;
     _group           = group;
     _networkMessages = networkMessages;
 }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
 public TransportRouterConfig(TransportGroupId defaultGroup, params KeyValuePair <TransportGroupId, TransportGroupConfig>[] groups)
 {
     DefaultGroup = defaultGroup;
     Groups       = ArrayDictionary.FromValues(groups);
 }
Example #6
0
 public TransportRouterConfig(IDictionary <TransportGroupId, TransportGroupConfig> groups, TransportGroupId defaultGroup)
 {
     Groups       = groups;
     DefaultGroup = defaultGroup;
 }
Example #7
0
 public ConnectionGroup(TransportGroupId groupId, int maxConnections)
 {
     GroupId        = groupId;
     MaxConnections = maxConnections;
     _connections   = new List <ConnectionId>(maxConnections);
 }
Example #8
0
 public bool Equals(TransportGroupId other)
 {
     return(Value == other.Value);
 }
Example #9
0
 public IList <ConnectionId> GetActiveConnections(TransportGroupId groupId)
 {
     return(_groups[groupId].ActiveConnections);
 }
Example #10
0
 public IConnectionGroup GetConnectionGroup(TransportGroupId group)
 {
     return(_groups[group]);
 }
Example #11
0
 public void SetDataHandler(TransportGroupId group, ITransportDataHandler handler)
 {
     _dataHandlers[group] = handler;
 }
Example #12
0
        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));
        }
Example #13
0
 public void SetConnectionHandler(TransportGroupId group, ITransportConnectionHandler handler)
 {
     _connectionHandlers[group] = handler;
 }