Пример #1
0
            public void Execute(Entity entity, int index, [ReadOnly] ref SendRpcCommandRequestComponent dest,
                                [ReadOnly] ref TActionRequest action)
            {
                commandBuffer.DestroyEntity(index, entity);
                if (connections.Length > 0)
                {
                    if (dest.TargetConnection != Entity.Null)
                    {
                        if (!rpcFromEntity.Exists(dest.TargetConnection))
                        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                            throw new InvalidOperationException("Cannot send RPC with no remote connection.");
#else
                            return;
#endif
                        }
                        var buffer = rpcFromEntity[dest.TargetConnection];
                        rpcQueue.Schedule(buffer, action);
                    }
                    else
                    {
                        for (var i = 0; i < connections.Length; ++i)
                        {
                            var buffer = rpcFromEntity[connections[i]];
                            rpcQueue.Schedule(buffer, action);
                        }
                    }
                }
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                else
                {
                    throw new InvalidOperationException("Cannot send RPC with no remote connection.");
                }
#endif
            }
Пример #2
0
            public void Execute(Entity entity, int index, [ReadOnly] ref SendRpcCommandRequestComponent dest,
                                [ReadOnly] ref TActionRequest action)
            {
                if (dest.TargetConnection != Entity.Null)
                {
                    var buffer = rpcFromEntity[dest.TargetConnection];
                    rpcQueue.Schedule(buffer, action);
                }
                else
                {
                    for (var i = 0; i < connections.Length; ++i)
                    {
                        var buffer = rpcFromEntity[connections[i]];
                        rpcQueue.Schedule(buffer, action);
                    }
                }

                commandBuffer.DestroyEntity(index, entity);
            }
Пример #3
0
            public void Execute()
            {
                NetworkConnection con;

                while ((con = driver.Accept()) != default(NetworkConnection))
                {
                    // New connection can never have any events, if this one does - just close it
                    DataStreamReader reader;
                    if (con.PopEvent(driver, out reader) != NetworkEvent.Type.Empty)
                    {
                        con.Disconnect(driver);
                        continue;
                    }

                    // create an entity for the new connection
                    var ent = commandBuffer.CreateEntity();
                    commandBuffer.AddComponent(ent, new NetworkStreamConnection {
                        Value = con
                    });
                    commandBuffer.AddComponent(ent, new NetworkSnapshotAckComponent());
                    commandBuffer.AddComponent(ent, new CommandTargetComponent());
                    commandBuffer.AddBuffer <IncomingRpcDataStreamBufferComponent>(ent);
                    var rpcBuffer = commandBuffer.AddBuffer <OutgoingRpcDataStreamBufferComponent>(ent);
                    commandBuffer.AddBuffer <IncomingCommandDataStreamBufferComponent>(ent);
                    commandBuffer.AddBuffer <IncomingSnapshotDataStreamBufferComponent>(ent);

                    RpcSystem.SendProtocolVersion(rpcBuffer, protocolVersion);

                    // Send RPC - assign network id
                    int nid;
                    if (!freeNetworkIds.TryDequeue(out nid))
                    {
                        // Avoid using 0
                        nid             = numNetworkId[0] + 1;
                        numNetworkId[0] = nid;
                    }

                    commandBuffer.AddComponent(ent, new NetworkIdComponent {
                        Value = nid
                    });
                    rpcQueue.Schedule(rpcBuffer, new RpcSetNetworkId
                    {
                        nid         = nid,
                        netTickRate = tickRate.NetworkTickRate,
                        simMaxSteps = tickRate.MaxSimulationStepsPerFrame,
                        simTickRate = tickRate.SimulationTickRate
                    });
                }
            }