Example #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
#if UNITY_EDITOR || DEVELOPMENT_BUILD
            if (m_StatsCollection.CurrentNameOwner != this)
            {
                m_StatsCollection.SetGhostNames(this, serializers.CreateSerializerNameList());
            }
            m_StatsCollection.AddSnapshotStats(m_NetStats);
#endif
            var commandBuffer = m_Barrier.CreateCommandBuffer();
            if (playerGroup.IsEmptyIgnoreFilter)
            {
                m_GhostDespawnSystem.LastQueueWriter.Complete();
                m_GhostDespawnSystem.InterpolatedDespawnQueue.Clear();
                m_GhostDespawnSystem.PredictedDespawnQueue.Clear();
                var clearMapJob = new ClearMapJob
                {
                    ghostMap = m_ghostEntityMap
                };
                var clearHandle = clearMapJob.Schedule(inputDeps);
                m_GhostUpdateSystemGroup.LastGhostMapWriter = clearHandle;
                var clearJob = new ClearGhostsJob
                {
                    commandBuffer = commandBuffer.ToConcurrent()
                };
                inputDeps = clearJob.Schedule(this, inputDeps);
                m_Barrier.AddJobHandleForProducer(inputDeps);
                return(JobHandle.CombineDependencies(inputDeps, clearHandle));
            }

            serializers.BeginDeserialize(this);
            JobHandle playerHandle;
            var       readJob = new ReadStreamJob
            {
                players               = playerGroup.ToEntityArrayAsync(Allocator.TempJob, out playerHandle),
                snapshotFromEntity    = GetBufferFromEntity <IncomingSnapshotDataStreamBufferComponent>(),
                snapshotAckFromEntity = GetComponentDataFromEntity <NetworkSnapshotAckComponent>(),
                ghostEntityMap        = m_ghostEntityMap,
                compressionModel      = m_CompressionModel,
                serializers           = serializers,
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                netStats = m_NetStats,
#endif
                interpolatedDespawnQueue = m_GhostDespawnSystem.InterpolatedDespawnQueue,
                predictedDespawnQueue    = m_GhostDespawnSystem.PredictedDespawnQueue,
                predictedFromEntity      = GetComponentDataFromEntity <PredictedGhostComponent>(true),
                isThinClient             = HasSingleton <ThinClientComponent>()
            };
            inputDeps = readJob.Schedule(JobHandle.CombineDependencies(inputDeps, playerHandle,
                                                                       m_GhostDespawnSystem.LastQueueWriter));
            m_GhostDespawnSystem.LastQueueWriter = inputDeps;

            m_Barrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Example #2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
        m_StatsCollection.AddSnapshotReceiveStats(m_NetStats);
#endif
        var commandBuffer = m_Barrier.CreateCommandBuffer();
        if (playerGroup.IsEmptyIgnoreFilter)
        {
            m_DelayedDespawnQueue.Clear();
            var clearMapJob = new ClearMapJob
            {
                ghostMap = m_ghostEntityMap
            };
            var clearHandle = clearMapJob.Schedule(inputDeps);
            var clearJob    = new ClearGhostsJob
            {
                commandBuffer = commandBuffer.ToConcurrent()
            };
            inputDeps = clearJob.Schedule(this, inputDeps);
            m_Barrier.AddJobHandleForProducer(inputDeps);
            return(JobHandle.CombineDependencies(inputDeps, clearHandle));
        }

        serializers.BeginDeserialize(this);
        JobHandle playerHandle;
        var       readJob = new ReadStreamJob
        {
            commandBuffer         = commandBuffer,
            players               = playerGroup.ToEntityArray(Allocator.TempJob, out playerHandle),
            snapshotFromEntity    = GetBufferFromEntity <IncomingSnapshotDataStreamBufferComponent>(),
            snapshotAckFromEntity = GetComponentDataFromEntity <NetworkSnapshotAckComponent>(),
            ghostEntityMap        = m_ghostEntityMap,
            compressionModel      = m_CompressionModel,
            serializers           = serializers,
            #if ENABLE_UNITY_COLLECTIONS_CHECKS
            netStats = m_NetStats,
            #endif
            replicatedEntityType = ComponentType.ReadWrite <ReplicatedEntityComponent>(),
            delayedDespawnQueue  = m_DelayedDespawnQueue,
            targetTick           = m_TimeSystem.interpolateTargetTick,
            predictedFromEntity  = GetComponentDataFromEntity <PredictedEntityComponent>(true)
        };
        inputDeps = readJob.Schedule(JobHandle.CombineDependencies(inputDeps, playerHandle));

        m_Barrier.AddJobHandleForProducer(inputDeps);
        return(inputDeps);
    }
Example #3
0
        protected override void OnUpdate()
        {
#if UNITY_EDITOR || DEVELOPMENT_BUILD
            if (m_NetStats.IsCreated && m_NetStats.Length != m_GhostCollectionSystem.m_GhostTypeCollection.Length * 3 + 3 + 1)
            {
                m_NetStats.Dispose();
            }
            if (!m_NetStats.IsCreated)
            {
                m_NetStats = new NativeArray <uint>(m_GhostCollectionSystem.m_GhostTypeCollection.Length * 3 + 3 + 1, Allocator.Persistent);
            }
            m_StatsCollection.AddSnapshotStats(m_NetStats);
#endif
            var commandBuffer = m_Barrier.CreateCommandBuffer();
            if (playerGroup.IsEmptyIgnoreFilter)
            {
                m_GhostCompletionCount[0] = m_GhostCompletionCount[1] = 0;
                // If there were no ghosts spawned at runtime we don't need to cleanup
                if (ghostCleanupGroup.IsEmptyIgnoreFilter)
                {
                    return;
                }
                m_GhostDespawnSystem.LastQueueWriter.Complete();
                m_GhostDespawnSystem.InterpolatedDespawnQueue.Clear();
                m_GhostDespawnSystem.PredictedDespawnQueue.Clear();
                var clearMapJob = new ClearMapJob
                {
                    ghostMap        = m_ghostEntityMap,
                    spawnedGhostMap = m_spawnedGhostEntityMap
                };
                var clearHandle = clearMapJob.Schedule(Dependency);
                LastGhostMapWriter = clearHandle;
                var clearJob = new ClearGhostsJob
                {
                    entitiesType  = GetEntityTypeHandle(),
                    commandBuffer = commandBuffer.AsParallelWriter()
                };
                Dependency = clearJob.Schedule(clearJobGroup, Dependency);
                m_Barrier.AddJobHandleForProducer(Dependency);
                Dependency = JobHandle.CombineDependencies(Dependency, clearHandle);
                return;
            }

            // Don't start ghost snapshot processing until we're in game, but allow the cleanup code above to run
            if (!HasSingleton <NetworkStreamInGame>())
            {
                //I need to reset the received version if the player is not in game.
                m_ReceivedGhostVersion[0] = 0;
                return;
            }

            JobHandle playerHandle;
            var       readJob = new ReadStreamJob
            {
                GhostComponentCollection = m_GhostCollectionSystem.m_GhostComponentCollection,
                GhostTypeCollection      = m_GhostCollectionSystem.m_GhostTypeCollection,
                GhostComponentIndex      = m_GhostCollectionSystem.m_GhostComponentIndex,
                players = playerGroup.ToEntityArrayAsync(Allocator.TempJob,
                                                         out playerHandle),
                snapshotFromEntity           = GetBufferFromEntity <IncomingSnapshotDataStreamBufferComponent>(),
                snapshotDataBufferFromEntity = GetBufferFromEntity <SnapshotDataBuffer>(),
                ghostSpawnBufferFromEntity   = GetBufferFromEntity <GhostSpawnBuffer>(),
                snapshotDataFromEntity       = GetComponentDataFromEntity <SnapshotData>(),
                snapshotAckFromEntity        = GetComponentDataFromEntity <NetworkSnapshotAckComponent>(),
                ghostEntityMap       = m_ghostEntityMap,
                receivedGhostVersion = m_ReceivedGhostVersion,
                compressionModel     = m_CompressionModel,
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                netStats = m_NetStats,
#endif
                interpolatedDespawnQueue = m_GhostDespawnSystem.InterpolatedDespawnQueue,
                predictedDespawnQueue    = m_GhostDespawnSystem.PredictedDespawnQueue,
                predictedFromEntity      = GetComponentDataFromEntity <PredictedGhostComponent>(true),
                ghostFromEntity          = GetComponentDataFromEntity <GhostComponent>(true),
                isThinClient             = HasSingleton <ThinClientComponent>(),
                commandBuffer            = commandBuffer,
                ghostSpawnEntity         = GetSingletonEntity <GhostSpawnQueueComponent>(),
                ghostVersion             = m_GhostCollectionSystem.GhostTypeCollectionHash,
                GhostCompletionCount     = m_GhostCompletionCount
            };
            Dependency = readJob.Schedule(JobHandle.CombineDependencies(Dependency, playerHandle,
                                                                        m_GhostDespawnSystem.LastQueueWriter));
            m_GhostDespawnSystem.LastQueueWriter = Dependency;

            m_Barrier.AddJobHandleForProducer(Dependency);
        }