コード例 #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var job = new DisconnectJob {
                commandBuffer = m_Barrier.CreateCommandBuffer()
            };
            var handle = job.ScheduleSingle(this, inputDeps);

            m_Barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
コード例 #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
#if UNITY_EDITOR || DEVELOPMENT_BUILD
            m_GhostStatsCollectionSystem.AddDiscardedPackets(m_NetStats[0]);
            m_NetStats[0] = 0;
#endif
            if (!HasSingleton <NetworkProtocolVersion>())
            {
                var entity      = EntityManager.CreateEntity();
                var rpcVersion  = World.GetExistingSystem <RpcSystem>().CalculateVersionHash();
                var gameVersion = HasSingleton <GameProtocolVersion>() ? GetSingleton <GameProtocolVersion>().Version : 0;
                EntityManager.AddComponentData(entity, new NetworkProtocolVersion
                {
                    NetCodeVersion       = NetworkProtocolVersion.k_NetCodeVersion,
                    GameVersion          = gameVersion,
                    RpcCollectionVersion = rpcVersion
                });
            }
            var concurrentFreeQueue = freeNetworkIds.AsParallelWriter();
            inputDeps = m_Driver.ScheduleUpdate(inputDeps);
            if (m_DriverListening)
            {
                // Schedule accept job
                var acceptJob = new ConnectionAcceptJob();
                acceptJob.driver         = m_Driver;
                acceptJob.commandBuffer  = m_Barrier.CreateCommandBuffer();
                acceptJob.numNetworkId   = numNetworkIds;
                acceptJob.freeNetworkIds = freeNetworkIds;
                acceptJob.rpcQueue       = rpcQueue;
                acceptJob.tickRate       = default(ClientServerTickRate);
                if (HasSingleton <ClientServerTickRate>())
                {
                    acceptJob.tickRate = GetSingleton <ClientServerTickRate>();
                }
                acceptJob.tickRate.ResolveDefaults();
                acceptJob.protocolVersion = GetSingleton <NetworkProtocolVersion>();
                inputDeps = acceptJob.Schedule(inputDeps);
            }
            else
            {
                freeNetworkIds.Clear();
            }

            var completeJob = new CompleteConnectionJob
            {
                commandBuffer   = m_Barrier.CreateCommandBuffer().ToConcurrent(),
                protocolVersion = GetSingleton <NetworkProtocolVersion>()
            };
            inputDeps = completeJob.Schedule(this, inputDeps);

            inputDeps = JobHandle.CombineDependencies(inputDeps, LastDriverWriter);
            var disconnectJob = new DisconnectJob
            {
                commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent(),
                driver        = m_Driver
            };
            inputDeps = disconnectJob.ScheduleSingle(this, inputDeps);

            // Schedule parallel update job
            var recvJob = new ConnectionReceiveJob();
            recvJob.commandBuffer  = m_Barrier.CreateCommandBuffer().ToConcurrent();
            recvJob.driver         = m_ConcurrentDriver;
            recvJob.freeNetworkIds = concurrentFreeQueue;
            recvJob.networkId      = GetComponentDataFromEntity <NetworkIdComponent>();
            recvJob.rpcBuffer      = GetBufferFromEntity <IncomingRpcDataStreamBufferComponent>();
            recvJob.cmdBuffer      = GetBufferFromEntity <IncomingCommandDataStreamBufferComponent>();
            recvJob.snapshotBuffer = GetBufferFromEntity <IncomingSnapshotDataStreamBufferComponent>();
            recvJob.localTime      = NetworkTimeSystem.TimestampMS;
#if UNITY_EDITOR || DEVELOPMENT_BUILD
            recvJob.netStats = m_NetStats;
#endif
            // FIXME: because it uses buffer from entity
            LastDriverWriter = recvJob.ScheduleSingle(this, inputDeps);
            m_Barrier.AddJobHandleForProducer(LastDriverWriter);
            return(LastDriverWriter);
        }