Exemplo n.º 1
0
        void Generate(Entity mapEntity, float2 resize)
        {
            var mapData = EntityManager.GetComponentData <MapData>(mapEntity);

            var commandBuffer = _barrierSystem.CreateCommandBuffer();

            int monsterCount = _monstersQuery.CalculateEntityCount();

            Job.WithCode(() =>
            {
                var genData          = GenerateMap.Default;
                genData.monsterCount = monsterCount;
                commandBuffer.AddComponent(mapEntity, genData);

                mapData.width  += (int)resize.x;
                mapData.height += (int)resize.y;

                mapData.width  = math.max(15, mapData.width);
                mapData.height = math.max(15, mapData.height);

                commandBuffer.SetComponent(mapEntity, mapData);
            }).Schedule();

            _barrierSystem.AddJobHandleForProducer(Dependency);
        }
    protected override JobHandle OnUpdate(JobHandle inputDep)
    {
        if (!m_DriverSystem.ClientDriver.IsCreated)
        {
            return(inputDep);
        }
        PingClientUIBehaviour.UpdateStats(m_pingStats[0], m_pingStats[1]);
        if (PingClientUIBehaviour.ServerEndPoint.IsValid && m_ConnectionGroup.IsEmptyIgnoreFilter)
        {
            var conJob = new ConnectJob
            {
                driver        = m_DriverSystem.ClientDriver,
                serverEP      = PingClientUIBehaviour.ServerEndPoint,
                commandBuffer = m_Barrier.CreateCommandBuffer()
            };
            inputDep = conJob.Schedule(inputDep);
            m_Barrier.AddJobHandleForProducer(inputDep);
            return(inputDep);
        }
        var pingJob = new PingJob
        {
            driver        = m_DriverSystem.ClientDriver,
            serverEP      = PingClientUIBehaviour.ServerEndPoint,
            pendingPings  = m_pendingPings,
            pingStats     = m_pingStats,
            fixedTime     = Time.fixedTime,
            commandBuffer = m_Barrier.CreateCommandBuffer()
        };
        var handle = pingJob.ScheduleSingle(this, inputDep);

        m_Barrier.AddJobHandleForProducer(handle);
        return(handle);
    }
Exemplo n.º 3
0
        protected override JobHandle OnUpdate(JobHandle inputDependency)
        {
            MarkPrivate();
            inputDependency = PrepareOwnerData(inputDependency, out var ownerPosContainers);
            inputDependency = ConsiderOwner(inputDependency, ownerPosContainers);

            m_beginEcbSystem.AddJobHandleForProducer(inputDependency);
            m_beginEcbSystem.AddJobHandleForProducer(inputDependency);
            return(inputDependency);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            // Deserialize the command type from the reader stream
            // Execute the RPC
            inputDeps = JobHandle.CombineDependencies(inputDeps, m_ReceiveSystem.LastDriverWriter);
            var execJob = new RpcExecJob
            {
                commandBuffer    = m_Barrier.CreateCommandBuffer().ToConcurrent(),
                entityType       = GetArchetypeChunkEntityType(),
                connectionType   = GetArchetypeChunkComponentType <NetworkStreamConnection>(),
                inBufferType     = GetArchetypeChunkBufferType <IncomingRpcDataStreamBufferComponent>(),
                outBufferType    = GetArchetypeChunkBufferType <OutgoingRpcDataStreamBufferComponent>(),
                execute          = m_RpcData,
                hashToIndex      = m_RpcTypeHashToIndex,
                driver           = m_ReceiveSystem.ConcurrentDriver,
                reliablePipeline = m_ReceiveSystem.ReliablePipeline,
                protocolVersion  = GetSingleton <NetworkProtocolVersion>()
            };
            var handle = execJob.Schedule(m_RpcBufferGroup, inputDeps);

            m_Barrier.AddJobHandleForProducer(handle);
            handle = m_ReceiveSystem.Driver.ScheduleFlushSend(handle);
            m_ReceiveSystem.LastDriverWriter = handle;
            return(handle);
        }
Exemplo n.º 6
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_LevelGroup.IsEmptyIgnoreFilter)
            {
                var settings = GetSingleton <ServerSettings>();
                var level    = EntityManager.CreateEntity();
                EntityManager.AddComponentData(level, new LevelComponent
                {
                    width          = settings.levelWidth,
                    height         = settings.levelHeight,
                    playerForce    = settings.playerForce,
                    bulletVelocity = settings.bulletVelocity
                });
                return(inputDeps);
            }
            JobHandle levelDep;
            var       job = new RequestLoadJob
            {
                commandBuffer = m_Barrier.CreateCommandBuffer(),
                level         = m_LevelGroup.ToComponentDataArray <LevelComponent>(Allocator.TempJob, out levelDep)
            };
            var handle = job.ScheduleSingle(this, JobHandle.CombineDependencies(inputDeps, levelDep));

            m_Barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
Exemplo n.º 7
0
    protected override void OnUpdate()
    {
        var commandBuffer = m_Barrier.CreateCommandBuffer();

        var serverData   = GetSingleton <GameSettingsComponent>();
        var gameNameData = GetSingleton <ServerDataComponent>();

        Entities
        .WithNone <SentClientGameRpcTag>()
        .ForEach((Entity entity, in NetworkIdComponent netId) =>
        {
            commandBuffer.AddComponent(entity, new SentClientGameRpcTag());
            var req = commandBuffer.CreateEntity();
            commandBuffer.AddComponent(req, new SendClientGameRpc
            {
                levelWidth     = serverData.levelWidth,
                levelHeight    = serverData.levelHeight,
                levelDepth     = serverData.levelDepth,
                playerForce    = serverData.playerForce,
                bulletVelocity = serverData.bulletVelocity,
                gameName       = gameNameData.GameName
            });

            commandBuffer.AddComponent(req, new SendRpcCommandRequestComponent {
                TargetConnection = entity
            });
        }).Schedule();

        m_Barrier.AddJobHandleForProducer(Dependency);
    }
Exemplo n.º 8
0
    protected override void OnUpdate()
    {
        var playerEntity            = GetSingletonEntity <NetworkIdComponent>();
        var commandTargetFromEntity = GetComponentDataFromEntity <CommandTargetComponent>();

        var commandBuffer = m_Barrier.CreateCommandBuffer().AsParallelWriter();

        Entities
        .WithNone <GhostShipState>()
        .WithAll <ShipTagComponentData, PredictedGhostComponent>()
        .ForEach((Entity entity) => {
            var state          = commandTargetFromEntity[playerEntity];
            state.targetEntity = entity;
            commandTargetFromEntity[playerEntity] = state;
            commandBuffer.AddComponent(0, entity, new GhostShipState());
        }).Schedule();

        Entities.WithNone <SnapshotData>()
        .WithAll <GhostShipState>()
        .WithNativeDisableParallelForRestriction(commandTargetFromEntity)
        .ForEach((Entity ent, int entityInQueryIndex) => {
            var commandTarget = commandTargetFromEntity[playerEntity];

            if (ent == commandTarget.targetEntity)
            {
                commandTarget.targetEntity            = Entity.Null;
                commandTargetFromEntity[playerEntity] = commandTarget;
            }
            commandBuffer.RemoveComponent <GhostShipState>(entityInQueryIndex, ent);
        }).ScheduleParallel();
        m_Barrier.AddJobHandleForProducer(Dependency);
    }
    protected override void OnUpdate()
    {
        var entityType = GetEntityTypeHandle();

        var playerEntity            = GetSingletonEntity <NetworkIdComponent>();
        var commandTargetFromEntity = GetComponentDataFromEntity <CommandTargetComponent>();

        var commandBuffer = m_Barrier.CreateCommandBuffer().AsParallelWriter();

        Entities.WithNone <GhostShipState>().WithAll <ShipTagComponentData, PredictedGhostComponent>().ForEach((Entity entity) => {
            var state          = commandTargetFromEntity[playerEntity];
            state.targetEntity = entity;
            commandTargetFromEntity[playerEntity] = state;
            commandBuffer.AddComponent(0, entity, new GhostShipState());
        }).Schedule();

        var destroyJob = new DestroyJob
        {
            commandBuffer           = commandBuffer,
            entityType              = entityType,
            playerEntity            = playerEntity,
            commandTargetFromEntity = GetComponentDataFromEntity <CommandTargetComponent>()
        };
        var inputDeps = destroyJob.Schedule(m_DestroyGroup, Dependency);

        m_Barrier.AddJobHandleForProducer(inputDeps);
        Dependency = inputDeps;
    }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var inputDeps1 = new AddSystemStateJob
            {
                Ecb        = m_EntityCommandBuffer.CreateCommandBuffer().ToConcurrent(),
                EntityType = GetArchetypeChunkEntityType(),
                Targets    = GetArchetypeChunkComponentType <AbilityOwnerComponent>()
            }.Schedule(m_AddSystemState, inputDeps);

            var inputDeps2 = new CleanupEntityJob
            {
                Ecb        = m_EntityCommandBuffer.CreateCommandBuffer().ToConcurrent(),
                EntityType = GetArchetypeChunkEntityType(),
            }.Schedule(m_RemoveSystemState, inputDeps);

            inputDeps = JobHandle.CombineDependencies(inputDeps, inputDeps1, inputDeps2);

            inputDeps = new RemoveElementFromDynamicBuffer
            {
                bufferFromEntity = GetBufferFromEntity <GrantedAbilityBufferElement>(),
                entities         = m_RemoveSystemState.ToEntityArray(Allocator.TempJob),
                targetComponents = m_RemoveSystemState.ToComponentDataArray <GrantedAbilitySystemStateComponent>(Allocator.TempJob)
            }.Schedule(inputDeps);

            inputDeps = new AddElementToDynamicBuffer
            {
                bufferFromEntity = GetBufferFromEntity <GrantedAbilityBufferElement>(),
                entities         = m_AddSystemState.ToEntityArray(Allocator.TempJob),
                targetComponents = m_AddSystemState.ToComponentDataArray <AbilityOwnerComponent>(Allocator.TempJob)
            }.Schedule(inputDeps);


            m_EntityCommandBuffer.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
 private void Start()
 {
     if (spawnAtEcs)
     {
         commandBufferSystem = World.DefaultGameObjectInjectionWorld
                               .GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
         var entityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ecsPrefab,
                                                                                   new GameObjectConversionSettings(World.DefaultGameObjectInjectionWorld,
                                                                                                                    GameObjectConversionUtility.ConversionFlags.SceneViewLiveLink, new BlobAssetStore()));
         var jobHandle = new MyEcsSpawnJob()
         {
             CommandBuffer = commandBufferSystem.CreateCommandBuffer(),
             NumberOfCubes = numberOfCubes,
             EcsPrefab     = entityPrefab,
             MyRandom      = new Random((uint)UnityEngine.Random.Range(1, 100000))
         }.Schedule();
         commandBufferSystem.AddJobHandleForProducer(jobHandle);
     }
     else
     {
         for (var i = 0; i < numberOfCubes; i++)
         {
             Instantiate(monoPrefab).transform.position = new Vector3(UnityEngine.Random.Range(-100, 100f), 0, 0);
         }
     }
 }
Exemplo n.º 12
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var entityType = GetArchetypeChunkEntityType();

        JobHandle playerHandle;
        var       playerEntity = playerGroup.ToEntityArray(Allocator.TempJob, out playerHandle);

        var updateJob = new UpdateJob
        {
            snapshotFromEntity = GetBufferFromEntity <ShipSnapshotData>(),
            targetTick         = NetworkTimeSystem.interpolateTargetTick
        };

        inputDeps = updateJob.Schedule(this, inputDeps);
        var destroyJob = new DestroyJob
        {
            commandBuffer         = m_Barrier.CreateCommandBuffer().ToConcurrent(),
            entityType            = entityType,
            playerEntity          = playerEntity,
            playerStateFromEntity = GetComponentDataFromEntity <PlayerStateComponentData>()
        };

        inputDeps = destroyJob.Schedule(destroyGroup, JobHandle.CombineDependencies(inputDeps, playerHandle));
        m_Barrier.AddJobHandleForProducer(inputDeps);
        return(inputDeps);
    }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (_options == null)
            {
                _options = GameObject.Find("Options").GetComponent <Options>();
            }

            inputDeps = JobHandle.CombineDependencies(inputDeps, _terrain.UpdateCacheJob);
            var       blockHitCounts = new NativeArray <int>(_options.terrainSizeX * _options.terrainSizeZ, Allocator.TempJob);
            JobHandle outputJob      = new UpdateCannonballJob
            {
                PlayerCenterPosition = _playerPosCache.PlayerPosition + new float3(0, PLAYER_RADIUS, 0),
                ElapsedTime          = Time.time,
                TerrainSize          = new int2(_options.terrainSizeX, _options.terrainSizeZ),
                EnableInvincibility  = _options.invincibility,
                BlockHeights         = _terrain.CachedBlockHeights,
                BlockEntities        = _terrain.BlockEntities,
                BlockHitCounts       = blockHitCounts,
                BoxHeightDamage      = _options.boxHeightDamage,
                CommandBuffer        = _barrier.CreateCommandBuffer().ToConcurrent(),
            }.Schedule(_cannonballQuery, inputDeps);

            _barrier.AddJobHandleForProducer(outputJob);
            return(outputJob);
        }
Exemplo n.º 14
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        JobHandle queryJob;
        var       connection   = m_ConnectionQuery.ToEntityArray(Allocator.TempJob, out queryJob);
        var       sendSetupJob = new SendPlayerSetupJob {
            CommandBuffer    = m_CommandBuffer.CreateCommandBuffer(),
            RpcQueue         = m_RpcSettingsQueue,
            ConnectionEntity = connection,
            RpcBuffer        = GetBufferFromEntity <OutgoingRpcDataStreamBufferComponent>()
        };
        var jobHandle = sendSetupJob.ScheduleSingle(this, JobHandle.CombineDependencies(inputDeps, queryJob));

        var remoteCommandJob = new SendRemoteCommandJob()
        {
            CommandBuffer    = m_CommandBuffer.CreateCommandBuffer(),
            RpcQueue         = m_RpcRemoteCmdQueue,
            ConnectionEntity = connection,
            RpcBuffer        = GetBufferFromEntity <OutgoingRpcDataStreamBufferComponent>()
        };

        jobHandle = remoteCommandJob.ScheduleSingle(this, jobHandle);

        m_CommandBuffer.AddJobHandleForProducer(jobHandle);
        return(jobHandle);
    }
Exemplo n.º 15
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var projectileTranslations = m_projectilesQuery.ToComponentDataArray <Translation>(Allocator.TempJob);
        var projectileCollisions   = m_projectilesQuery.ToComponentDataArray <CollisionSize>(Allocator.TempJob);
        var projectiles            = m_projectilesQuery.ToEntityArray(Allocator.TempJob);

        poolLocations.Clear();
        EntityManager.GetAllUniqueSharedComponentData <ProjectilePoolLocation>(poolLocations);

        if (projectileCollisions.Length > 0 && poolLocations.Count > 1)
        {
            var job = new ProjectileCollisionJob
            {
                ProjectileTranslations = projectileTranslations,
                ProjectileCollisions   = projectileCollisions,
                Projectiles            = projectiles,
                ECB          = m_beginSimEcbSystem.CreateCommandBuffer().ToConcurrent(),
                PoolLocation = poolLocations[1].Value
            };

            inputDeps = job.Schedule(this, inputDeps);
            m_projectilesQuery.AddDependency(inputDeps);
            m_beginSimEcbSystem.AddJobHandleForProducer(inputDeps);
        }
        else
        {
            projectileTranslations.Dispose();
            projectileCollisions.Dispose();
            projectiles.Dispose();
        }

        return(inputDeps);
    }
Exemplo n.º 16
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_Prefab == Entity.Null)
            {
                var prefabs       = GetSingleton <GhostPrefabCollectionComponent>();
                var serverPrefabs = EntityManager.GetBuffer <GhostPrefabBuffer>(prefabs.serverPrefabs);
                m_Prefab = serverPrefabs[AsteroidsGhostSerializerCollection.FindGhostType <ShipSnapshotData>()].Value;
                m_Radius = EntityManager.GetComponentData <CollisionSphereComponent>(m_Prefab).radius;
            }

            JobHandle levelHandle;
            var       spawnJob = new SpawnJob
            {
                commandBuffer           = barrier.CreateCommandBuffer(),
                playerStateFromEntity   = GetComponentDataFromEntity <PlayerStateComponentData>(),
                commandTargetFromEntity = GetComponentDataFromEntity <CommandTargetComponent>(),
                networkIdFromEntity     = GetComponentDataFromEntity <NetworkIdComponent>(),
                shipPrefab = m_Prefab,
                shipRadius = m_Radius,
                level      = m_LevelGroup.ToComponentDataArray <LevelComponent>(Allocator.TempJob, out levelHandle),
                rand       = new Unity.Mathematics.Random((uint)Stopwatch.GetTimestamp())
            };
            var handle = spawnJob.ScheduleSingle(this, JobHandle.CombineDependencies(inputDeps, levelHandle));

            barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
Exemplo n.º 17
0
    protected override void OnUpdate()
    {
        var ecb     = BeginSimulationEntityCommandBufferSystem.CreateCommandBuffer();
        var prefabs = GetSingleton <EntityPrefabs>();

        Entities
        .WithName("Spawn_Balls")
        .ForEach((ref BallSpawner spawner, in LocalToWorld localToWorld) => {
            var r  = spawner.Random.NextFloat2Direction();
            var xz = float3(r.x, 0, r.y);
            var up = float3(0, 1, 0);

            spawner.TimeRemainder += spawner.SpawnsPerTick;
            while (spawner.TimeRemainder >= 1)
            {
                var ball = ecb.Instantiate(prefabs.Ball);

                ecb.SetComponent(ball, new Translation {
                    Value = localToWorld.Position
                });
                ecb.SetComponent(ball, new Rotation {
                    Value = Quaternion.LookRotation(xz, up)
                });
                spawner.TimeRemainder--;
            }
        })
        .WithBurst()
        .Schedule();
        BeginSimulationEntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
    }
Exemplo n.º 18
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var handle = inputDeps;

        if (PlayerPositionChanged())
        {
            var jobDespawn = new DeSpawnChunksAround
            {
                childBuffer    = GetBufferFromEntity <ChunkChildBlock>(true),
                commandBuffer  = ecbSystem.CreateCommandBuffer().ToConcurrent(),
                playerPosition = GetPlayerPosition()
            };
            handle = jobDespawn.Schedule(this, handle);

            var job = new SpawnChunksAround
            {
                commandBuffer  = ecbSystem.CreateCommandBuffer(),
                playerPosition = GetPlayerPosition()
            };
            handle = job.Schedule(handle);
            ecbSystem.AddJobHandleForProducer(handle);
        }

        return(handle);
    }
Exemplo n.º 19
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (Time.time - oldTime > updateTime)
        {
            oldTime = Time.time;

            var nativeArr = new NativeList <PlayerState>(100, Allocator.TempJob);

            var playerStateJob = new CreatePlayerStateJob()
            {
                arr = nativeArr
            }.ScheduleSingle(this, inputDeps);

            playerStateJob.Complete();

            var serializeJob = new SerializeStateJob()
            {
                CommandBuffer = m_EndFrameBarrier.CreateCommandBuffer(),
                players       = nativeArr
            }.Schedule(playerStateJob);

            m_EndFrameBarrier.AddJobHandleForProducer(serializeJob);

            serializeJob.Complete();

            nativeArr.Dispose();

            return(serializeJob);
        }
        return(inputDeps);
    }
Exemplo n.º 20
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var mouse = GetSingleton <SingletonMouseInput>();

        var jobHandle = inputDeps;

        if (mouse.LeftClickUp)
        {
            var selectionBoxJob = new SelectionBoxJob
            {
                currentMouseRayPosition = mouse.CurrentMouseRaycastPosition,
                initialMouseRayPosition = mouse.InitialMouseRaycastPosition,
                selected            = GetComponentDataFromEntity <TagSelected>(),
                entityCommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer(),
            };

            jobHandle = selectionBoxJob.ScheduleSingle(this, inputDeps);
        }
        else if (mouse.LeftClickDown)
        {
            var selectClickJob = new SelectClickJob
            {
                currentMouseRayPosition = mouse.CurrentMouseRaycastPosition,
                selected            = GetComponentDataFromEntity <TagSelected>(),
                entityCommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer(),
            };

            jobHandle = selectClickJob.Schedule(this, inputDeps);
        }

        m_EntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);

        return(jobHandle);
    }
Exemplo n.º 21
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);
    }
Exemplo n.º 22
0
    protected override JobHandle OnUpdate(JobHandle handle)
    {
        if (init && count > 0)
        {
            em.DestroyEntity(boubleQuery);
            count = 0;
            return(handle);
        }

        count = boubleQuery.CalculateEntityCount();
        var f = GetSingleton <SpawnerRndAreaComp>();

        if (sd.rangeMultChanged)
        {
            List <float> ranges = new List <float>();
            ranges.Add(sd.defaultGrav);
            for (int i = 1; i < 6; i++)
            {
                ranges.Add(ranges[i - 1] * sd.rangeMult);
            }
            f.smallRange  = ranges[1];
            f.mediumRange = ranges[2];
            f.largeRange  = ranges[3];
            f.hugeRange   = ranges[4];
            f.superRange  = ranges[5];
            ranges.Clear();
            sd.rangeMultChanged = false;
            SetSingleton <SpawnerRndAreaComp>(f);
        }

        createCount = sd.totalCount - count;

        for (int i = 0; i < createCount; i++)
        {
            rndDir     = _random.NextFloat2Direction();
            rndPos.x   = rndDir.x;
            rndPos.y   = 0;
            rndPos.z   = rndDir.y;
            rndPos    *= init ? _random.NextFloat(0, sd.cylinderRadius) : sd.cylinderRadius;
            rndPos.y   = _random.NextFloat(-sd.cylinderHeight, sd.cylinderHeight);
            posList[i] = rndPos;
        }

        handle = new Joby {
            ecb          = _ecbs.CreateCommandBuffer().ToConcurrent(),
            f            = f, sd = sd,
            prefabEntity = _prefabEntity,
            absorb       = sd.absorb,
            bounce       = sd.bounce,
            posList      = posList,
            bubFrac      = .5f / BoubleAuth._grad
        }.Schedule(createCount, 10, handle);

        _ecbs.AddJobHandleForProducer(handle);

        init = false;

        return(handle);
    }
Exemplo n.º 23
0
    protected override void OnUpdate()
    {
        var buffer = BeginSimulationEntityCommandBufferSystem.CreateCommandBuffer();

        OnUpdate(buffer);

        BeginSimulationEntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        inputDeps.Complete();

        JobHandle serverJobHandle;

        //Debug.Log("server system on update");
        if (!m_Driver.IsCreated)
        {
            ReliableUtility.Parameters reliabilityParams = new ReliableUtility.Parameters {
                WindowSize = 32
            };
            SimulatorUtility.Parameters simulatorParams = new SimulatorUtility.Parameters {
                MaxPacketSize = k_PacketSize, MaxPacketCount = 30, PacketDelayMs = 100
            };

            m_Driver = new UdpNetworkDriver(simulatorParams, reliabilityParams);
            NetworkEndPoint endpoint = NetworkEndPoint.AnyIpv4;
            endpoint.Port = 9000;
            if (m_Driver.Bind(endpoint) != 0)
            {
                Debug.Log("Failed to bind to port 9000");
            }
            else
            {
                m_Driver.Listen();
                Debug.Log("driver listening on port 9000");
            }

            currentId = new NativeList <int>(1, Allocator.Persistent);
            currentId.Add(0);
        }
        else
        {
            serverJobHandle = m_Driver.ScheduleUpdate(inputDeps);
            serverJobHandle = new ListenForConnectionsJob
            {
                commandBuffer = m_Barrier.CreateCommandBuffer(),
                driver        = m_Driver,
            }.Schedule(serverJobHandle);

            serverJobHandle.Complete();

            serverJobHandle = new UpdateServerJob
            {
                commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent(),
                driver        = m_Driver.ToConcurrent(),
                id            = currentId.AsDeferredJobArray()
            }.Schedule(this, serverJobHandle);

            m_Barrier.AddJobHandleForProducer(serverJobHandle);
            //Debug.Log("about to listen for connections");
            return(serverJobHandle);
        }

        return(inputDeps);
    }
Exemplo n.º 25
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var playerJob = new PlayerInputJob();

            playerJob.left            = 0;
            playerJob.right           = 0;
            playerJob.thrust          = 0;
            playerJob.shoot           = 0;
            playerJob.commandBuffer   = m_Barrier.CreateCommandBuffer().ToConcurrent();
            playerJob.inputFromEntity = GetBufferFromEntity <ShipCommandData>();
            playerJob.inputTargetTick = m_GhostPredict.PredictingTick;

            if (World.GetExistingSystem <ClientPresentationSystemGroup>().Enabled)
            {
                if (Input.GetKey("left"))
                {
                    playerJob.left = 1;
                }
                if (Input.GetKey("right"))
                {
                    playerJob.right = 1;
                }
                if (Input.GetKey("up"))
                {
                    playerJob.thrust = 1;
                }
                //if (InputSamplerSystem.spacePresses > 0)
                if (Input.GetKey("space"))
                {
                    playerJob.shoot = 1;
                }
            }
            else
            {
                // Spawn and generate some random inputs
                var state = (int)Time.ElapsedTime % 3;
                if (state == 0)
                {
                    playerJob.left = 1;
                }
                else
                {
                    playerJob.thrust = 1;
                }
                ++frameCount;
                if (frameCount % 100 == 0)
                {
                    playerJob.shoot = 1;
                    frameCount      = 0;
                }
            }

            var handle = playerJob.ScheduleSingle(this, inputDeps);

            m_Barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
Exemplo n.º 26
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var job = new AddJob();

            job.commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent();
            inputDeps         = job.Schedule(this, inputDeps);
            m_Barrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Exemplo n.º 27
0
    protected override void OnUpdate()
    {
        // Assign values to local variables captured in your job here, so that it has
        // everything it needs to do its work when it runs later.
        // For example,
        //     float deltaTime = Time.DeltaTime;

        // This declares a new kind of job, which is a unit of work to do.
        // The job is declared as an Entities.ForEach with the target components as parameters,
        // meaning it will process all entities in the world that have both
        // Translation and Rotation components. Change it to process the component
        // types you want.

        var commandBuffer = _commandBufferSystem.CreateCommandBuffer();

        var actualTime = Time.ElapsedTime;

        var attackPressed = Input.GetKey(KeyCode.Space);


        Entities.ForEach((ref Player player, in Translation playerPos) =>
        {
            // Implement the work to perform for each entity here.
            // You should only access data that is local or that is a
            // field on this job. Note that the 'rotation' parameter is
            // marked as 'in', which means it cannot be modified,
            // but allows this job to run in parallel with other jobs
            // that want to read Rotation component data.
            // For example,
            //     translation.Value += math.mul(rotation.Value, new float3(0, 0, 1)) * deltaTime;

            if (actualTime - player.LastAttackTime < player.AttackCoolDown)
            {
                return;
            }

            if (!attackPressed)
            {
                return;
            }

            player.LastAttackTime = actualTime;

            var bullet = commandBuffer.Instantiate(player.bullet);

            commandBuffer.SetComponent(bullet, new Translation {
                Value = playerPos.Value
            });
            commandBuffer.SetComponent(bullet, new DestroyAfterTime()
            {
                BirthTime = actualTime, CountDown = 2
            });
        }).Schedule();

        _commandBufferSystem.AddJobHandleForProducer(Dependency);
    }
Exemplo n.º 28
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);
        }
        protected override void OnUpdate()
        {
            var commandBuffer = m_Barrier.CreateCommandBuffer();

            Entities.WithAll <NetworkStreamDisconnected>().ForEach((Entity entity, in NetworkStreamConnection con) =>
            {
                commandBuffer.DestroyEntity(entity);
            }).Schedule();
            m_Barrier.AddJobHandleForProducer(Dependency);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var handle = new BlockTransformJob
            {
                CommandBuffer = _barrier.CreateCommandBuffer().ToConcurrent(),
            }.Schedule(this, inputDeps);

            _barrier.AddJobHandleForProducer(handle);
            return(handle);
        }