コード例 #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            // Get the things we need to destroy
            NativeQueue <Entity> destroyQueue = new NativeQueue <Entity>(Allocator.TempJob);

            var collectLifeTimeJob = new CollectExceededLifetimeJob
            {
                EntQueue = destroyQueue.AsParallelWriter()
            }.Schedule(this, inputDeps);

            //collectLifeTimeJob.Complete();

            var collectDistanceJob = new CollectExceededDistanceJob
            {
                EntQueue    = destroyQueue.AsParallelWriter(),
                MaxDistance = maxDistance
            }.Schedule(this, inputDeps);

            //collectDistanceJob.Complete();

            var multiHitCheckJob = new CollectExceededHitJob
            {
                EntQueue = destroyQueue.AsParallelWriter()
            }.Schedule(this, inputDeps);

            //multiHitCheckJob.Complete();

            var collectors = JobHandle.CombineDependencies(collectLifeTimeJob, collectDistanceJob, multiHitCheckJob);

            NativeArray <Entity> entitiesToDestroy = new NativeArray <Entity>(destroyQueue.Count, Allocator.TempJob);
            var fillJob = new FillDestroyArrayJob
            {
                Entities = entitiesToDestroy,
                EntQueue = destroyQueue
            }.Schedule(JobHandle.CombineDependencies(collectors, inputDeps));

            // Make sure our array fill job is done
            //fillJob.Complete();

            if (fillJob.IsCompleted)
            {
                // Destroy all entities in the array
                if (entitiesToDestroy.Length > 0)
                {
                    EntityManager.DestroyEntity(entitiesToDestroy);
                }

                // Dispose of the NativeContainers
                //destroyQueue.Dispose();
                entitiesToDestroy.Dispose();

                return(inputDeps);
            }

            return(fillJob);
        }
コード例 #2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var queue  = new NativeQueue <int2>(Allocator.TempJob);
        var writer = queue.AsParallelWriter();

        var config = GetSingleton <Config>();
        var job    = new NavMeshJob
        {
            config       = config,
            physicsWorld = physicsWorldSystem.PhysicsWorld,
            queue        = writer
        };

        var unionJob = new UnionJob
        {
            queue = queue
        };

        var physicHandle = JobHandle.CombineDependencies(physicsWorldSystem.FinalJobHandle, inputDeps);
        var handle       = job.Schedule(config.cellWidth * config.cellHeight, 64, physicHandle);
        var resultHandle = unionJob.Schedule(this, handle);

        queue.Dispose();

        //resultHandle.Complete();
        return(resultHandle);
    }
コード例 #3
0
        public static JobHandle GetUniqueKeysDependsOn <Tkey, Tval>(
            this NativeMultiHashMap <Tkey, Tval> map,
            out NativeQueue <Tkey> buffer,
            out NativeList <Tkey> uniqueKeys,
            Allocator allocator,
            JobHandle inputDeps
            )
            where Tkey : struct, IEquatable <Tkey>, IComparable <Tkey>
            where Tval : struct
        {
            buffer     = new NativeQueue <Tkey>(allocator);
            uniqueKeys = new NativeList <Tkey>(allocator);

            var deps = new Jobs.MultiHashToKeysQueueJob <Tkey, Tval>()
            {
                keys = buffer.AsParallelWriter()
            }.Schedule(map, 1, inputDeps);
            var resHandle = new Jobs.QueueToUniqueListValuesJob <Tkey>()
            {
                vals       = buffer,
                uniqueVals = uniqueKeys
            }.Schedule(deps);

            return(resHandle);
        }
コード例 #4
0
        public JobHandle GenerateContacts(BurstSolverImpl solver, float deltaTime)
        {
            var generateParticleContactsJob = new ParticleGrid.GenerateParticleParticleContactsJob
            {
                grid       = grid,
                gridLevels = grid.populatedLevels.GetKeyArray(Allocator.TempJob),

                positions     = solver.positions,
                orientations  = solver.orientations,
                restPositions = solver.restPositions,
                velocities    = solver.velocities,
                invMasses     = solver.invMasses,
                radii         = solver.principalRadii,
                fluidRadii    = solver.smoothingRadii,
                phases        = solver.phases,

                particleMaterialIndices = solver.abstraction.collisionMaterials.AsNativeArray <int>(),
                collisionMaterials      = ObiColliderWorld.GetInstance().collisionMaterials.AsNativeArray <BurstCollisionMaterial>(),

                contactsQueue          = particleContactQueue.AsParallelWriter(),
                fluidInteractionsQueue = fluidInteractionQueue.AsParallelWriter(),
                dt = deltaTime
            };

            return(generateParticleContactsJob.Schedule(grid.CellCount, 2));
        }
コード例 #5
0
        protected override void OnCreate()
        {
            m_NewGhosts        = new NativeList <T>(16, Allocator.Persistent);
            m_NewGhostIds      = new NativeList <int>(16, Allocator.Persistent);
            m_InitialArchetype = EntityManager.CreateArchetype(ComponentType.ReadWrite <T>(),
                                                               ComponentType.ReadWrite <GhostComponent>());

            m_GhostUpdateSystemGroup = World.GetOrCreateSystem <GhostUpdateSystemGroup>();
            m_GhostMap           = m_GhostUpdateSystemGroup.GhostEntityMap;
            m_ConcurrentGhostMap = m_GhostMap.AsParallelWriter();
            m_DestroyGroup       = GetEntityQuery(ComponentType.ReadOnly <T>(),
                                                  ComponentType.Exclude <GhostComponent>(),
                                                  ComponentType.Exclude <PredictedGhostSpawnRequestComponent>());
            m_SpawnRequestGroup = GetEntityQuery(ComponentType.ReadOnly <T>(),
                                                 ComponentType.ReadOnly <PredictedGhostSpawnRequestComponent>());
            m_PlayerGroup = GetEntityQuery(ComponentType.ReadOnly <NetworkStreamConnection>(),
                                           ComponentType.ReadOnly <NetworkIdComponent>(), ComponentType.Exclude <NetworkStreamDisconnected>());

            m_InvalidGhosts                 = new NativeList <Entity>(1024, Allocator.Persistent);
            m_DelayedSpawnQueue             = new NativeQueue <DelayedSpawnGhost>(Allocator.Persistent);
            m_CurrentDelayedSpawnList       = new NativeList <DelayedSpawnGhost>(1024, Allocator.Persistent);
            m_ConcurrentDelayedSpawnQueue   = m_DelayedSpawnQueue.AsParallelWriter();
            m_PredictedSpawnQueue           = new NativeQueue <DelayedSpawnGhost>(Allocator.Persistent);
            m_CurrentPredictedSpawnList     = new NativeList <DelayedSpawnGhost>(1024, Allocator.Persistent);
            m_ConcurrentPredictedSpawnQueue = m_PredictedSpawnQueue.AsParallelWriter();
            m_Barrier = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();

            m_PredictSpawnGhosts        = new NativeList <PredictSpawnGhost>(16, Allocator.Persistent);
            m_PredictionSpawnCleanupMap = new NativeHashMap <int, int>(16, Allocator.Persistent);

            m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>();
        }
コード例 #6
0
 public void Initialize()
 {
     m_LocalEndPoint    = new NativeArray <NetworkEndPoint>(1, Allocator.Persistent);
     m_LocalEndPoint[0] = IPCManager.Instance.CreateEndPoint();
     m_IPCQueue         = new NativeQueue <IPCManager.IPCQueuedMessage>(Allocator.Persistent);
     m_IPCQueueParallel = m_IPCQueue.AsParallelWriter();
 }
コード例 #7
0
        protected override void OnCreate()
        {
            var shader = Shader.Find("LineRenderer");

            if (shader == null)
            {
                Debug.Log("Wrong shader");
                m_Material = null;
                return;
            }

            m_Material      = new Material(shader);
            m_ComputeBuffer = new ComputeBuffer(MaxLines, UnsafeUtility.SizeOf <Line>());
            m_CommandBuffer = new CommandBuffer();

            m_LineList            = new NativeList <Line>(MaxLines, Allocator.Persistent);
            m_LineQueue           = new NativeQueue <Line>(Allocator.Persistent);
            m_ConcurrentLineQueue = m_LineQueue.AsParallelWriter();

            // Fake singleton entity
            m_SingletonEntity = EntityManager.CreateEntity();
            EntityManager.AddComponentData(m_SingletonEntity, new LineRendererComponentData());

            m_Material.SetBuffer("lines", m_ComputeBuffer);
            m_Material.renderQueue = (int)RenderQueue.Transparent;

            m_RenderOffset = new NativeArray <float2>(2, Allocator.Persistent);

            m_LevelGroup = GetEntityQuery(ComponentType.ReadWrite <LevelComponent>());
            m_LineGroup  = GetEntityQuery(ComponentType.ReadWrite <LineRendererComponentData>());
        }
コード例 #8
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        float  deltaTime = Time.DeltaTime;
        float3 moveDir   = new float3(-1f, 0f, 0f);
        float  moveSpeed = 4f;

        NativeQueue <PipePassedEvent> .ParallelWriter eventQueueParallel = eventQueue.AsParallelWriter();

        JobHandle jobHandle = Entities.ForEach((int entityInQueryIndex, ref Translation translation, ref Pipe pipe) => {
            float xBefore      = translation.Value.x;
            translation.Value += moveDir * moveSpeed * deltaTime;
            float xAfter       = translation.Value.x;

            if (pipe.isBottom && xBefore > 0 && xAfter <= 0)
            {
                // Passed the Player
                eventQueueParallel.Enqueue(new PipePassedEvent {
                });
            }
        }).Schedule(inputDeps);

        jobHandle.Complete();

        while (eventQueue.TryDequeue(out PipePassedEvent pipePassedEvent))
        {
            OnPipePassed?.Invoke(this, EventArgs.Empty);
        }

        return(jobHandle);
    }
コード例 #9
0
        protected override JobHandle OnUpdate(JobHandle inputDep)
        {
            int spawnCount = 0;
            int cnt;

            while (spawnCountQueue.TryDequeue(out cnt))
            {
                spawnCount += cnt;
            }
            SetSingleton(new ParticleSpawnCountComponent {
                spawnCount = spawnCount
            });
            var commandBuffer = barrier.CreateCommandBuffer().ToConcurrent();
            var spawnJob      = new ParticleSpawnJob();

            spawnJob.spawnCountQueue = spawnCountQueue.AsParallelWriter();
            spawnJob.commandBuffer   = commandBuffer;
            spawnJob.deltaTime       = Time.DeltaTime;
            spawnJob.m_ColorSizeParticleArchetype = m_ColorSizeParticleArchetype;
            spawnJob.m_ColorParticleArchetype     = m_ColorParticleArchetype;
            spawnJob.m_SizeParticleArchetype      = m_SizeParticleArchetype;
            spawnJob.m_ParticleArchetype          = m_ParticleArchetype;
            inputDep = spawnJob.Schedule(this, inputDep);

            barrier.AddJobHandleForProducer(inputDep);
            return(inputDep);
        }
        protected override void OnUpdate()
        {
            if (!m_TickThisFrame)
            {
                return;
            }

            var ecb = m_EndSimulationEcbSystem.CreateCommandBuffer().AsParallelWriter();

            ScheduledTicks.Clear();
            var tickEvents = ScheduledTicks.AsParallelWriter();

            Entities
            .ForEach((int entityInQueryIndex, Entity entity, ref TurnDurationComponent durationComponent, ref DurationStateComponent state) =>
            {
                if (durationComponent.Tick())
                {
                    tickEvents.Enqueue(entity);
                    state.MarkTick();
                }
                else
                {
                    state.State &= ~(EDurationState.TICKED_THIS_FRAME);
                }

                if (durationComponent.IsExpired())
                {
                    ecb.DestroyEntity(entityInQueryIndex, entity);
                    state.MarkExpired();
                }
            })
            .WithBurst()
            .ScheduleParallel();
        }
コード例 #11
0
    protected override void OnUpdate()
    {
        //Create parallel writer
        NativeQueue <StateInfo> .ParallelWriter events = stateEvents.AsParallelWriter();

        float dt = Time.DeltaTime;

        JobHandle job = Entities.ForEach((Entity e, ref PhysicsVelocity velocity, in DirectionData direction, in SpeedData speed, in StateComponent state) =>
        {
            velocity.Linear = 0;

            if (state.CurrentState != State.Dying)
            {
                velocity.Linear.xz = direction.Value * speed.Value * dt;
                // velocity.Linear.y = -9.18f;
                velocity.Angular.xz = 0;
            }

            //If inputs to move, change state

            if (!direction.Value.Equals(float2.zero))
            {
                events.Enqueue(new StateInfo
                {
                    Entity       = e,
                    Action       = StateInfo.ActionType.TryChange,
                    DesiredState = State.Running
                });
            }
        }).ScheduleParallel(Dependency);
コード例 #12
0
        protected override void OnCreate()
        {
            m_NewGhosts          = new NativeList <T>(16, Allocator.Persistent);
            m_NewGhostIds        = new NativeList <int>(16, Allocator.Persistent);
            m_Archetype          = GetGhostArchetype();
            m_PredictedArchetype = GetPredictedGhostArchetype();
            m_InitialArchetype   = EntityManager.CreateArchetype(ComponentType.ReadWrite <T>(), ComponentType.ReadWrite <ReplicatedEntityComponent>());

            m_GhostMap           = World.GetOrCreateSystem <GhostReceiveSystemGroup>().GhostEntityMap;
            m_ConcurrentGhostMap = m_GhostMap.AsParallelWriter();
            m_SpawnRequestGroup  = GetEntityQuery(ComponentType.ReadOnly <T>(),
                                                  ComponentType.ReadOnly <PredictedSpawnRequestComponent>());

            m_InvalidGhosts                 = new NativeList <Entity>(1024, Allocator.Persistent);
            m_DelayedSpawnQueue             = new NativeQueue <DelayedSpawnGhost>(Allocator.Persistent);
            m_CurrentDelayedSpawnList       = new NativeList <DelayedSpawnGhost>(1024, Allocator.Persistent);
            m_ConcurrentDelayedSpawnQueue   = m_DelayedSpawnQueue.AsParallelWriter();
            m_PredictedSpawnQueue           = new NativeQueue <DelayedSpawnGhost>(Allocator.Persistent);
            m_CurrentPredictedSpawnList     = new NativeList <DelayedSpawnGhost>(1024, Allocator.Persistent);
            m_ConcurrentPredictedSpawnQueue = m_PredictedSpawnQueue.AsParallelWriter();
            m_Barrier = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();

            m_PredictSpawnGhosts        = new NativeList <PredictSpawnGhost>(16, Allocator.Persistent);
            m_PredictionSpawnCleanupMap = new NativeHashMap <int, int>(16, Allocator.Persistent);

            m_TimeSystem = World.GetOrCreateSystem <NetworkTimeSystem>();
        }
コード例 #13
0
    void Start()
    {
        m_ParticleSystem = GetComponent <ParticleSystem>();

        var main             = m_ParticleSystem.main;
        var collision        = m_ParticleSystem.collision;
        int maxParticleCount = main.maxParticles;

        m_SortKeys   = new NativeArray <SortKey>(maxParticleCount, Allocator.Persistent);
        m_Collisions = new NativeQueue <Collision>(Allocator.Persistent);

        m_CacheJob = new CacheJob
        {
            sortKeys = m_SortKeys,
        };

        m_SortJob = new SortJob
        {
            sortKeys = m_SortKeys
        };

        m_CollisionJob = new CollisionJob
        {
            sortKeys    = m_SortKeys,
            collisions  = m_Collisions.AsParallelWriter(),
            bounce      = collision.bounceMultiplier,
            radiusScale = collision.radiusScale,
            maxDiameter = main.startSize.constantMax * collision.radiusScale // TODO - handle different size curve modes and size over life if needed
        };

        m_ApplyCollisionsJob = new ApplyCollisionsJob
        {
            collisions = m_Collisions
        };
    }
コード例 #14
0
    protected override void OnCreate()
    {
        base.OnCreate();

        _messageQueue = new NativeQueue <AudioMessage>(Allocator.Persistent);
        messageIn     = _messageQueue.AsParallelWriter();
    }
コード例 #15
0
        public void UpdateWorld()
        {
            var identifyMoving = new IdentifyMovingColliders
            {
                movingColliders = movingColliders.AsParallelWriter(),
                colliders       = ObiColliderWorld.GetInstance().colliderShapes.AsNativeArray <BurstColliderShape>(cellSpans.count),
                bounds          = ObiColliderWorld.GetInstance().colliderAabbs.AsNativeArray <BurstAabb>(cellSpans.count),
                cellIndices     = cellSpans.AsNativeArray <BurstCellSpan>(),
                colliderCount   = colliderCount
            };
            JobHandle movingHandle = identifyMoving.Schedule(cellSpans.count, 128);

            var updateMoving = new UpdateMovingColliders
            {
                movingColliders = movingColliders,
                grid            = grid,
                colliderCount   = colliderCount
            };

            updateMoving.Schedule(movingHandle).Complete();

            // remove tail from the current spans array:
            if (colliderCount < cellSpans.count)
            {
                cellSpans.count -= cellSpans.count - colliderCount;
            }
        }
    protected override void OnUpdate()
    {
        GridData data  = GridData.GetInstance();
        int      index = System.Math.Abs(rand.NextInt()) % randomValues.Length;

        // chunk vars
        var translationType = GetComponentTypeHandle <Translation>(true);
        var movementType    = GetComponentTypeHandle <MovementComponent>();
        var entityInfoType  = GetComponentTypeHandle <EntityInfo>();
        var entities        = GetEntityTypeHandle();

        // job
        var job = new FarmerTaskSystemJob();

        job.gridHashMap           = data.gridStatus;
        job.randArray             = randomValues;
        job.nextIndex             = index;
        job.gridSize              = data.width;
        job.radiusForSearch       = data.width / 4;
        job.removals              = hashRemovalsFarmer.AsParallelWriter();
        job.IsPlantType           = GetComponentDataFromEntity <PlantComponent>(true);
        job.plantGrowthMax        = PlantSystem.MAX_GROWTH;
        job.addRemoveTags         = addRemoveTags.AsParallelWriter();
        job.setInfo               = componentSetInfo.AsParallelWriter();
        job.TranslationTypeHandle = translationType;
        job.MovementTypeHandle    = movementType;
        job.EntityInfoHandle      = entityInfoType;
        job.EntityType            = entities;

        this.Dependency = job.ScheduleParallel(m_Group, this.Dependency);
    }
コード例 #17
0
ファイル: KillerSystem.cs プロジェクト: REDNIGHT/SpaceWar-ECS
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //
            inputDeps = new KillerCountJob
            {
                actorDeathByKillerCount = playerScoreServerSystem.scoreCount,
            }
            .Schedule(this, inputDeps);


            outs.Clear();
            ins.Clear();
            inputDeps = new KillInfoSerializeJob
            {
                outs = outs.AsParallelWriter(),
            }
            .Schedule(this, inputDeps);

            inputDeps = outs.ToListJob(ref ins, inputDeps);

            inputDeps = new SyncKillInfoJob
            {
                ins = ins.AsDeferredJobArray(),
            }
            .Schedule(this, inputDeps);

            return(inputDeps);
        }
コード例 #18
0
    protected override void OnUpdate()
    {
        EntityCommandBuffer.ParallelWriter commandBuffer = commandBufferSystem.CreateCommandBuffer().AsParallelWriter(); // create a command buffer
        EntityQuery nameQuery = GetEntityQuery(nameQueryDesc);                                                           // query the entities

        //Add label job

        NativeQueue <NameToRemoveEvent> .ParallelWriter eventQueueParallel = eventQueue.AsParallelWriter();

        RemoveNameToVoiceControllerJob removeNameJob = new RemoveNameToVoiceControllerJob {
            commandBuffer      = commandBuffer,
            entityType         = GetEntityTypeHandle(),
            nameType           = GetComponentTypeHandle <PoliceUnitName>(true),
            eventQueueParallel = eventQueueParallel
        };
        JobHandle removeNameJobHandle = removeNameJob.Schedule(nameQuery, this.Dependency); //schedule the job

        commandBufferSystem.AddJobHandleForProducer(removeNameJobHandle);                   // make sure the components get added/removed for the job

        removeNameJobHandle.Complete();

        while (eventQueue.TryDequeue(out NameToRemoveEvent nameEvent))
        {
            OnPoliceUnitDeletedWithName?.Invoke(this, new OnPoliceUnitDeletedWithNameArgs {
                PoliceUnitName = nameEvent.Name.ToString()
            });
        }
    }
コード例 #19
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //
            destroyActorOutsA.Clear();
            destroyActorOutsB.Clear();
            destroyActors.Clear();


            inputDeps = new GetDestroyActorJobA
            {
                destroyActorOuts = destroyActorOutsA.AsParallelWriter(),
            }
            .Schedule(this, inputDeps);

            inputDeps = new GetDestroyActorJobB
            {
                destroyActorOuts = destroyActorOutsB.AsParallelWriter(),
            }
            .Schedule(this, inputDeps);

            inputDeps = NativeQueueEx.ToListJob(destroyActorOutsA, destroyActorOutsB, ref destroyActors, inputDeps);

            inputDeps = new DestroyVisibleDistanceJob
            {
                destroyActors = destroyActors.AsDeferredJobArray(),
            }
            .Schedule(this, inputDeps);


            return(inputDeps);
        }
コード例 #20
0
ファイル: WeaponSystem.cs プロジェクト: ckendal3/WDIB-Combat
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            NativeQueue <ProjectileQueueData> queueData = new NativeQueue <ProjectileQueueData>(Allocator.TempJob);

            // set weapon states
            JobHandle processWeaponJob = new ProcessWeaponState()
            {
                inputs      = InputQuery.ToComponentDataArray <InputState>(Allocator.TempJob),
                inputsOwner = InputQuery.ToComponentDataArray <OwnerID>(Allocator.TempJob)
            }.Schedule(this, inputDeps);

            // create projectile data for weapons
            JobHandle shootJob = new ShootWeaponJob()
            {
                queueData = queueData.AsParallelWriter()
            }.Schedule(this, processWeaponJob);

            shootJob.Complete();

            // Spawn all of projectiles from the weapons
            for (int i = 0; i < queueData.Count; i++)
            {
                ProjectileQueueData data = queueData.Dequeue();

                ProjectileFactory.CreateProjectiles(WeaponParameters.Instance.GetWeaponDataByID(data.WeaponID).projectileId, data.SpawnPos, data.SpawnRot, data.Owner);
            }

            queueData.Dispose();

            return(shootJob);
        }
コード例 #21
0
        protected override void OnUpdate()
        {
            NativeQueue <PipePassedEvent> .ParallelWriter parallelWriter = eventQuery.AsParallelWriter();
            NavAgentSystem navAgentSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <NavAgentSystem>();

            Entities.WithBurst().WithAll <NavAgentComponent>().ForEach((Entity e, ref AgentPathInfoComponent agentPathInfoComponentr, ref NavAgentComponent navAgent) =>
            {
                if (!agentPathInfoComponentr.goes && navAgent.status == AgentStatus.Idle)
                {
                    navAgent.status = AgentStatus.PathQueued;
                    agentPathInfoComponentr.goes = !agentPathInfoComponentr.goes;
                    Vector3 destination          = agentPathInfoComponentr.goes ? agentPathInfoComponentr.endPos : agentPathInfoComponentr.startPos;

                    parallelWriter.Enqueue(new PipePassedEvent {
                        destination = destination,
                        Entity      = e,
                        navAgent    = navAgent,
                    });
                }
            }).Schedule();

            while (eventQuery.TryDequeue(out PipePassedEvent pipePassedEvent))
            {
                navAgentSystem.SetDestination(pipePassedEvent.Entity, pipePassedEvent.navAgent, pipePassedEvent.destination);
            }
        }
コード例 #22
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            outAs.Clear();
            outBs.Clear();
            ins.Clear();

            var inputDepsA = new WeaponOnMessageJobA
            {
                outs = outAs.AsParallelWriter(),
            }
            .Schedule(this, inputDeps);

            var inputDepsB = new WeaponOnMessageJobB
            {
                outs = outBs.AsParallelWriter(),
            }
            .Schedule(this, inputDeps);

            inputDeps = NativeQueueEx.ToListJob(outAs, outBs, ref ins, JobHandle.CombineDependencies(inputDepsA, inputDepsB));

            inputDeps = new SyncWeaponInstalledStateJob
            {
                ins = ins.AsDeferredJobArray(),
            }
            .Schedule(this, inputDeps);
            return(inputDeps);
        }
    protected override void OnCreate()
    {
        commandQueue         = new NativeQueue <Command>(Allocator.Persistent);
        commandQueueFrontEnd = commandQueue.AsParallelWriter();

        weaponPrefabs = new NativeList <Entity>(Allocator.Persistent);
    }
        protected override void OnUpdate()
        {
            var ecb = m_EndSimulationEcbSystem.CreateCommandBuffer().AsParallelWriter();

            ScheduledTicks.Clear();
            var ScheduledTicksWriter = ScheduledTicks.AsParallelWriter();
            var dt = Time.DeltaTime;

            Entities
            .ForEach((int entityInQueryIndex, Entity entity, ref TimeDurationComponent durationComponent, ref DurationStateComponent state) =>
            {
                if (durationComponent.Tick(dt))
                {
                    ScheduledTicksWriter.Enqueue(entity);
                    state.MarkTick();
                }
                else
                {
                    state.State &= ~(EDurationState.TICKED_THIS_FRAME);
                }

                if (durationComponent.IsExpired())
                {
                    ecb.DestroyEntity(entityInQueryIndex, entity);
                    state.MarkExpired();
                }
            })
            .WithBurst()
            .ScheduleParallel();
        }
コード例 #25
0
        protected override void OnUpdate()
        {
            // retrieve reference to static collider data
            var collEntity = _collDataEntityQuery.GetSingletonEntity();
            var collData   = EntityManager.GetComponentData <ColliderData>(collEntity);
            var random     = new global::Unity.Mathematics.Random((uint)Random.Range(1, 100000));

            var events = _eventQueue.AsParallelWriter();

            var hitTime  = _simulateCycleSystemGroup.HitTime;
            var timeMsec = _visualPinballSimulationSystemGroup.TimeMsec;
            var marker   = PerfMarker;

            Entities
            .WithName("StaticCollisionJob")
            .ForEach((Entity ballEntity, ref BallData ballData, ref CollisionEventData collEvent,
                      ref DynamicBuffer <BallInsideOfBufferElement> insideOfs) => {
                // find balls with hit objects and minimum time
                if (collEvent.ColliderId < 0 || collEvent.HitTime > hitTime)
                {
                    return;
                }

                marker.Begin();

                // retrieve static data
                ref var colliders = ref collData.Value.Value.Colliders;

                // pick collider that matched during narrowphase
                ref var coll = ref colliders[collEvent.ColliderId].Value;                 // object that ball hit in trials
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        GridData data = GridData.GetInstance();

        // chunk vars
        var translationType = GetComponentTypeHandle <Translation>(true);
        var entityInfoType  = GetComponentTypeHandle <EntityInfo>();
        var entities        = GetEntityTypeHandle();

        // job
        var job = new PerformTaskSystemJob();

        job.changes               = tillChanges.AsParallelWriter();
        job.grid                  = data.gridStatus.AsParallelWriter();
        job.plantsSold            = plantsSold;
        job.plantInfo             = GetComponentDataFromEntity <PlantComponent>(true);
        job.addRemoveTags         = addRemoveTags.AsParallelWriter();
        job.setInfo               = componentSetInfo.AsParallelWriter();
        job.plantGrowthMax        = PlantSystem.MAX_GROWTH;
        job.TranslationTypeHandle = translationType;
        job.EntityInfoHandle      = entityInfoType;
        job.EntityType            = entities;

        JobHandle jobHandle = job.ScheduleParallel(m_Group, inputDependencies);

        return(jobHandle);
    }
    public void Enqueue()
    {
        const int queueSize   = 100 * 1024;
        var       queue       = new NativeQueue <int>(Allocator.TempJob);
        var       writeStatus = new NativeArray <int>(queueSize, Allocator.TempJob);

        var enqueueJob = new ConcurrentEnqueue();

        enqueueJob.queue  = queue.AsParallelWriter();
        enqueueJob.result = writeStatus;

        var enqueue = enqueueJob.Schedule(queueSize, 1);

        enqueue.Complete();

        Assert.AreEqual(queueSize, queue.Count, "Job enqueued the wrong number of values");
        var allValues = new HashSet <int>();

        for (int i = 0; i < queueSize; ++i)
        {
            Assert.AreEqual(1, writeStatus[i], "Job failed to enqueue value");
            int enqueued = queue.Dequeue();
            Assert.IsTrue(enqueued >= 0 && enqueued < queueSize, "Job enqueued invalid value");
            Assert.IsTrue(allValues.Add(enqueued), "Job enqueued same value multiple times");
        }

        var disposeJob = queue.Dispose(enqueue);

        disposeJob.Complete();

        writeStatus.Dispose();
    }
コード例 #28
0
        protected override void OnUpdate()
        {
            if (Time.ElapsedTime > _nextUpdate)
            {
                AwaitingNavmeshText.text = $"Awaiting Path: {_navQuery.PendingCount} people";
                CachedPathText.text      = $"Cached Paths: {_navQuery.CachedCount}";
                _nextUpdate = (float)Time.ElapsedTime + 0.5f;
            }

            var entityCnt = _agentQuery.CalculateEntityCount();
            var entities  = _agentQuery.ToEntityArray(Allocator.TempJob);

            var inputDeps = new DetectIdleAgentJob
            {
                Entities  = entities,
                Agents    = GetComponentDataFromEntity <NavAgent>(),
                NeedsPath = _needsPath.AsParallelWriter()
            }.Schedule(entityCnt, 64);

            inputDeps = new SetNextPathJob
            {
                NeedsPath = _needsPath
            }.Schedule(inputDeps);
            inputDeps.Complete();
        }
コード例 #29
0
ファイル: NativeQueueTests.cs プロジェクト: d4got10/Boids2D
    public void ConcurrentEnqueue_Wrap()
    {
        var queue  = new NativeQueue <int> (Allocator.Temp);
        var cQueue = queue.AsParallelWriter();

        Assert.AreEqual(0, queue.Count);
        Assert.Throws <System.InvalidOperationException> (() => { queue.Dequeue(); });
        for (int i = 0; i < 256; ++i)
        {
            cQueue.Enqueue(i);
        }
        Assert.AreEqual(256, queue.Count);
        for (int i = 0; i < 128; ++i)
        {
            Assert.AreEqual(i, queue.Dequeue(), "Got the wrong value from the queue");
        }
        Assert.AreEqual(128, queue.Count);
        for (int i = 0; i < 128; ++i)
        {
            cQueue.Enqueue(i);
        }
        Assert.AreEqual(256, queue.Count);
        for (int i = 128; i < 256; ++i)
        {
            Assert.AreEqual(i, queue.Dequeue(), "Got the wrong value from the queue");
        }
        Assert.AreEqual(128, queue.Count);
        for (int i = 0; i < 128; ++i)
        {
            Assert.AreEqual(i, queue.Dequeue(), "Got the wrong value from the queue");
        }
        Assert.AreEqual(0, queue.Count);
        Assert.Throws <System.InvalidOperationException> (() => { queue.Dequeue(); });
        queue.Dispose();
    }
コード例 #30
0
    private static void TestNativeContainerConcurrent()
    {
        NativeArray <float> values = new NativeArray <float>(
            length: ARRAY_SIZE,
            allocator: Allocator.TempJob,
            options: NativeArrayOptions.UninitializedMemory);
        NativeQueue <float> result = new NativeQueue <float>(label: Allocator.Persistent);

        result.Enqueue(10);
        result.Enqueue(11);
        result.Enqueue(12);

        for (int i = 0; i < ARRAY_SIZE; i++)
        {
            values[i] = i;
        }

        FilterParallelForJob filterJob = new FilterParallelForJob();

        filterJob.compareType  = CompareType.MoreThan;
        filterJob.compareValue = 2;
        filterJob.src          = values;
        filterJob.results      = result.AsParallelWriter();

        JobHandle filterJobHandle = filterJob.Schedule(arrayLength: ARRAY_SIZE, innerloopBatchCount: 1);

        filterJobHandle.Complete();

        Print5FloatNativeQueue(result);

        values.Dispose();
        result.Dispose();
    }