コード例 #1
0
        protected override void OnCreateManager()
        {
            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.ToConcurrent();

            // 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>());
        }
コード例 #2
0
        protected override void OnCreateManager()
        {
            base.OnCreateManager();

            //Create our queues to hold entities to spawn bolt from
            enemyBoltSpawnQueue  = new NativeQueue <Entity>(Allocator.Persistent);
            allyBoltSpawnQueue   = new NativeQueue <Entity>(Allocator.Persistent);
            playerBoltSpawnQueue = new NativeQueue <Entity>(Allocator.Persistent);

            enemyBoltSpawnList  = new NativeList <Entity>(100000, Allocator.Persistent);
            allyBoltSpawnList   = new NativeList <Entity>(100000, Allocator.Persistent);
            playerBoltSpawnList = new NativeList <Entity>(100000, Allocator.Persistent);

            //Create the entitie that holds our queue, one way of making them accessible to other systems
            BoltSpawnerEntityData data = new BoltSpawnerEntityData();

            data.enemyBoltSpawnQueueConcurrent  = enemyBoltSpawnQueue.ToConcurrent();
            data.allyBoltSpawnQueueConcurrent   = allyBoltSpawnQueue.ToConcurrent();
            data.playerBoltSpawnQueueConcurrent = playerBoltSpawnQueue.ToConcurrent();

            dataEntity = EntityManager.CreateEntity();
            EntityManager.AddComponentData(dataEntity, data);

            //Create entities that we will use as "prefab" for our bolts
            //Add the Prefab IComponentData to make sure those entities are not picked up by systems
            prefabEnemyBolt = EntityManager.Instantiate(MonoBehaviourECSBridge.Instance.enemyBolt);
            EntityManager.AddComponentData <Prefab>(prefabEnemyBolt, new Prefab());

            prefabAllyBolt = EntityManager.Instantiate(MonoBehaviourECSBridge.Instance.allyBolt);
            EntityManager.AddComponentData <Prefab>(prefabAllyBolt, new Prefab());

            prefabPlayerBolt = EntityManager.Instantiate(MonoBehaviourECSBridge.Instance.playerBolt);
            EntityManager.AddComponentData <Prefab>(prefabPlayerBolt, new Prefab());
        }
コード例 #3
0
    protected override void OnUpdate()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            NativeQueue <Entity> collidedEntities = new NativeQueue <Entity>(Allocator.TempJob);
            var checkIntersectionJob = new CheckRaySpheresIntersection()
            {
                collided = collidedEntities.ToConcurrent(),
                ray      = mouseRay
            };

            checkIntersectionJob.Schedule(this).Complete();


            while (collidedEntities.Count > 0)
            {
                //Get first point
                if (collidedEntities.Count == 1)
                {
                    SceneController.Instance.PointClickedEntity(collidedEntities.Dequeue());
                }
                else
                {
                    //Debug.Log("Intersected entity: " + collidedEntities.Dequeue());
                    collidedEntities.Dequeue();
                }
            }

            collidedEntities.Dispose();
        }
    }
コード例 #4
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_ConcurrentIPCQueue = m_IPCQueue.ToConcurrent();
 }
コード例 #5
0
 protected override JobHandle OnUpdate(JobHandle inputDependencies)
 {
     timeout -= Time.deltaTime;
     if (timeout < 0)
     {
         if (!settings)
         {
             CreateTexts();
         }
         timeout += settings.tickTime;
         var job = new AsteroidSystemJob()
         {
             changes  = changes.ToConcurrent(),
             launches = launches.ToConcurrent(),
             minShip  = settings.minShipStock,
             shipCost = settings.shipCost
         };
         int2 todo;
         while (changes.TryDequeue(out todo))
         {
             texts[todo.x].text = cache[todo.y + 1];
         }
         int l;
         while (launches.TryDequeue(out l))
         {
             SpawnShip(l);
         }
         return(job.Schedule(this, inputDependencies));
     }
     else
     {
         return(inputDependencies);
     }
 }
コード例 #6
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            NativeQueue <Entity> clickedButtons = new NativeQueue <Entity>(Allocator.TempJob);

            {
                ProcessClicks clicksJob = new ProcessClicks
                {
                    EntityType       = GetArchetypeChunkEntityType(),
                    BufferType       = GetArchetypeChunkBufferType <PointerInputBuffer>(),
                    EventType        = GetArchetypeChunkComponentType <PointerEvent>(),
                    ButtonTargetType = GetComponentDataFromEntity <Button>(),
                    ClickedButtons   = clickedButtons.ToConcurrent()
                };
                inputDeps = clicksJob.Schedule(m_EventGroup, inputDeps);
                inputDeps.Complete();

                while (clickedButtons.TryDequeue(out Entity entity))
                {
                    EntityManager.AddComponent(entity, typeof(ButtonClickedEvent));
                }
            }
            clickedButtons.Dispose();

            return(inputDeps);
        }
コード例 #7
0
    public void ConcurrentEnqueue_Wrap()
    {
        var queue  = new NativeQueue <int> (Allocator.Temp);
        var cQueue = queue.ToConcurrent();

        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();
    }
コード例 #8
0
        protected override IDictionary <string, object> GetProps(ref JobHandle inputDeps)
        {
            var counters = new NativeQueue <CounterComponent>(Allocator.TempJob);

            var job = new CounterJob()
            {
                Increment = onPlusClicked.Invoked,
                Decrement = onMinusClicked.Invoked,
                Counters  = counters.ToConcurrent()
            };

            inputDeps = job.Schedule(this, inputDeps);

            inputDeps.Complete();

            var counter = counters.Dequeue();

            counters.Dispose();

            onPlusClicked.Reset();
            onMinusClicked.Reset();

            return(new Dictionary <string, object>()
            {
                { "count", counter.Count },
                { "onPlusClicked", onPlusClicked.Action },
                { "onMinusClicked", onMinusClicked.Action }
            });
        }
コード例 #9
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var commandBufferSystem = World.GetExistingManager <BeginSimulationEntityCommandBufferSystem>();

            inputDeps = new ProcessJob
            {
                AddTargetInRangeQueue    = m_AddTargetInRangeQueue.ToConcurrent(),
                RemoveTargetInRangeQueue = m_RemoveTargetInRangeQueue.ToConcurrent(),
                TranslationFromEntity    = GetComponentDataFromEntity <Translation>(true),
                TargetInRangeFromEntity  = GetComponentDataFromEntity <TargetInRange>(true),
                DeltaTime = UnityEngine.Time.deltaTime
            }.Schedule(this, inputDeps);

            var addTargetInRangeDeps = new AddTargetInRangeJob
            {
                AddTargetInRangeQueue = m_AddTargetInRangeQueue,
                CommandBuffer         = commandBufferSystem.CreateCommandBuffer()
            }.Schedule(inputDeps);

            var removeTargetInRangeDeps = new RemoveTargetInRangeJob
            {
                RemoveTargetInRangeQueue = m_RemoveTargetInRangeQueue,
                CommandBuffer            = commandBufferSystem.CreateCommandBuffer()
            }.Schedule(inputDeps);

            inputDeps = JobHandle.CombineDependencies(addTargetInRangeDeps, removeTargetInRangeDeps);

            commandBufferSystem.AddJobHandleForProducer(inputDeps);

            return(inputDeps);
        }
コード例 #10
0
    protected override void OnCreateManager()
    {
        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.ToConcurrent();
        m_DestroyGroup       = GetEntityQuery(ComponentType.ReadOnly <T>(),
                                              ComponentType.Exclude <ReplicatedEntityComponent>(), ComponentType.Exclude <PredictedSpawnRequestComponent>());
        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.ToConcurrent();
        m_PredictedSpawnQueue           = new NativeQueue <DelayedSpawnGhost>(Allocator.Persistent);
        m_CurrentPredictedSpawnList     = new NativeList <DelayedSpawnGhost>(1024, Allocator.Persistent);
        m_ConcurrentPredictedSpawnQueue = m_PredictedSpawnQueue.ToConcurrent();
        m_Barrier = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();

        m_PredictSpawnGhosts        = new NativeList <PredictSpawnGhost>(16, Allocator.Persistent);
        m_PredictionSpawnCleanupMap = new NativeHashMap <int, int>(16, Allocator.Persistent);
    }
コード例 #11
0
        /// <summary>
        /// Process all queued events.
        /// </summary>
        public void ProcessEvents()
        {
            // Early bail to avoid setting up job stuff unnecessarily
            if (_queuedEvents.Length == 0)
            {
                return;
            }

            NativeQueue <UnityEvent <T_Event> > eventsToProcessQueue =
                new NativeQueue <UnityEvent <T_Event> >(Allocator.TempJob);

            BuildEventQueueJob job = new BuildEventQueueJob();

            job.queuedEvents    = _queuedEvents;
            job.subscribers     = _subscribers;
            job.eventsToProcess = eventsToProcessQueue.ToConcurrent();

            job.Schedule(_queuedEvents.Length, _batchCount).Complete();

            while (eventsToProcessQueue.TryDequeue(out UnityEvent <T_Event> ev))
            {
                try
                {
                    _subscriberCallbacks[ev.subscriberIndex](ev.ev);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            eventsToProcessQueue.Dispose();
            _queuedEvents.Clear();
        }
コード例 #12
0
    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.ToConcurrent();
        enqueueJob.result = writeStatus;

        enqueueJob.Schedule(queueSize, 1).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");
        }

        queue.Dispose();
        writeStatus.Dispose();
    }
コード例 #13
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.ToConcurrent();
            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);
        }
コード例 #14
0
        protected override void OnUpdate()
        {
            if (m_Group.CalculateLength() > 0)
            {
                EntityManager.RemoveComponent(m_Group, ComponentType.ReadWrite <DamagedDispatched>());
            }

            new ProcessDamagedJob
            {
                DamagedQueue = m_DamagedQueue.ToConcurrent()
            }.Schedule(this).Complete();

            while (m_DamagedQueue.TryDequeue(out var component))
            {
                if (!(EntityManager.Exists(component.This) && EntityManager.Exists(component.Other)))
                {
                    continue;
                }

                var damaged = PostUpdateCommands.CreateEntity(m_Archetype);
                PostUpdateCommands.SetComponent(damaged, component);

                PostUpdateCommands.AddComponent(component.This, new DamagedDispatched());
            }
        }
コード例 #15
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_Ships.Length == 0)
            {
                return(inputDeps);
            }

            var handle = new CalculatePositionsJob
            {
                Ships            = m_Ships.Data,
                Planets          = m_Planets.Data,
                TargetPlanet     = GetComponentDataFromEntity <PlanetData>(),
                DeltaTime        = Time.deltaTime,
                Entities         = m_Ships.Entities,
                Positions        = m_Ships.Positions,
                Rotations        = m_Ships.Rotations,
                ShipArrivedQueue = m_ShipArrivedQueue.ToConcurrent()
            }.Schedule(m_Ships.Length, 32, inputDeps);

            handle = new ShipArrivedTagJob
            {
                EntityCommandBuffer = m_EndFrameBarrier.CreateCommandBuffer(),
                ShipArrivedQueue    = m_ShipArrivedQueue
            }.Schedule(handle);

            return(handle);
        }
コード例 #16
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            _queue.Clear();
            var ha = new ChunkJob {
                cq = _queue.ToConcurrent()
            }.Schedule(query, inputDeps);

            _waitHandle = ha;
            return(_waitHandle);
        }
コード例 #17
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            JobHandle bulletHandle;
            JobHandle asteroidHandle;
            JobHandle levelHandle;
            JobHandle settingsHandle;

            var asteroidJob = new DestroyAsteroidJob
            {
                commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(),
                bulletChunks  = bulletGroup.CreateArchetypeChunkArray(Allocator.TempJob, out bulletHandle),
                bulletAgeType = GetArchetypeChunkComponentType <BulletAgeComponentData>(true),
                positionType  = GetArchetypeChunkComponentType <Translation>(true),
                sphereType    = GetArchetypeChunkComponentType <CollisionSphereComponentData>(true),
                entityType    = GetArchetypeChunkEntityType(),
                level         = m_LevelGroup.ToComponentDataArray <LevelComponent>(Allocator.TempJob, out levelHandle)
            };
            var shipJob = new DestroyShipJob
            {
                commandBuffer    = barrier.CreateCommandBuffer().ToConcurrent(),
                asteroidChunks   = asteroidGroup.CreateArchetypeChunkArray(Allocator.TempJob, out asteroidHandle),
                bulletChunks     = asteroidJob.bulletChunks,
                bulletAgeType    = asteroidJob.bulletAgeType,
                positionType     = asteroidJob.positionType,
                sphereType       = asteroidJob.sphereType,
                playerIdType     = GetArchetypeChunkComponentType <PlayerIdComponentData>(),
                entityType       = asteroidJob.entityType,
                serverSettings   = settingsGroup.ToComponentDataArray <ServerSettings>(Allocator.TempJob, out settingsHandle),
                playerClearQueue = playerClearQueue.ToConcurrent(),
                level            = asteroidJob.level
            };
            var asteroidDep = JobHandle.CombineDependencies(inputDeps, bulletHandle, levelHandle);
            var shipDep     = JobHandle.CombineDependencies(asteroidDep, asteroidHandle, settingsHandle);

            var h1 = asteroidJob.Schedule(asteroidGroup, asteroidDep);
            var h2 = shipJob.Schedule(shipGroup, shipDep);

            var handle = JobHandle.CombineDependencies(h1, h2);

            barrier.AddJobHandleForProducer(handle);

            var cleanupShipJob = new ClearShipPointerJob
            {
                playerClearQueue = playerClearQueue,
                playerState      = GetComponentDataFromEntity <PlayerStateComponentData>()
            };
            var cleanupChunkJob = new ChunkCleanupJob
            {
                bulletChunks   = shipJob.bulletChunks,
                asteroidChunks = shipJob.asteroidChunks,
                level          = shipJob.level
            };

            return(JobHandle.CombineDependencies(cleanupShipJob.Schedule(h2), cleanupChunkJob.Schedule(handle)));
        }
コード例 #18
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var removeList      = new NativeQueue <RemoveItem>(Allocator.TempJob);
            var timerRemoveList = new NativeQueue <WakeItem>(Allocator.TempJob);
            var job             = new WakeJob()
            {
                NodeSleepings = GetArchetypeChunkBufferType <NodeSleeping>(),
                RemoveList    = removeList.ToConcurrent(),
            };

            var jobTimer = new WakeWithTimerJob()
            {
                dt = Time.deltaTime,
                NodeTimeBufferType = GetArchetypeChunkBufferType <NodeTimer>(),
                ActionRunStateType = GetArchetypeChunkComponentType <ActionRunState>(),
                RemoveList         = timerRemoveList.ToConcurrent(),
            };

            var handle      = job.Schedule(m_Group, inputDeps);
            var handleTimer = jobTimer.Schedule(m_GroupTimer, inputDeps);

            handle.Complete();
            handleTimer.Complete();

            if (removeList.Count > 0)
            {
                var actionRunStates = GetComponentDataFromEntity <ActionRunState>();
                while (removeList.TryDequeue(out var item))
                {
                    var states    = actionRunStates[item.Entity];
                    var container = ActionStateMapToAsset.Instance.GetContainer(states.InstanceID);
                    container.SetNodeCycle(new ActionStateIndex()
                    {
                        ChunkIndex = states.ChunkIndex, NodeIndex = item.NodeIndex
                    }, NodeCycle.Waking);
                }
            }

            if (timerRemoveList.Count > 0)
            {
                while (timerRemoveList.TryDequeue(out var item))
                {
                    var container = ActionStateMapToAsset.Instance.GetContainer(item.InstanceID);
                    container.SetNodeCycle(new ActionStateIndex()
                    {
                        ChunkIndex = item.ChunkIndex, NodeIndex = item.NodeIndex
                    }, NodeCycle.Waking);
                }
            }

            removeList.Dispose();
            timerRemoveList.Dispose();
            return(inputDeps);
        }
コード例 #19
0
    protected override void OnUpdate()
    {
        NativeQueue <TileData> nativeQueue = new NativeQueue <TileData>(Allocator.TempJob);

        CopyTileJob copyTileJob = new CopyTileJob {
            nativeQueue = nativeQueue.ToConcurrent()
        };
        JobHandle jobHandle = copyTileJob.Schedule(this);

        jobHandle.Complete();

        NativeArray <TileData> nativeArray = new NativeArray <TileData>(nativeQueue.Count, Allocator.TempJob);

        NativeQueueToArrayJob nativeQueueToArrayJob = new NativeQueueToArrayJob {
            nativeQueue = nativeQueue,
            nativeArray = nativeArray,
        };

        jobHandle = nativeQueueToArrayJob.Schedule();
        jobHandle.Complete();

        nativeQueue.Dispose();

        var camera = Camera.main;

        //if (camera != null && Input.GetMouseButtonDown(0))
        {
            var mousePosition = Input.mousePosition;
            var cameraRay     = camera.ScreenPointToRay(mousePosition);

            Entities.WithAll <HexTileHightlightComponent>().ForEach((Entity entity) => {
                PostUpdateCommands.RemoveComponent <HexTileHightlightComponent>(entity);
            });
            var deltaTime = Time.deltaTime;
            if (UnityEngine.Physics.Raycast(cameraRay, out var closestHit, float.PositiveInfinity))
            {
                Vector3   mapPos = new Vector3(closestHit.point.x, 0, closestHit.point.z);
                CubeIndex index  = HexUtils.FromPosition(mapPos, Bootstrap.Defines.TileRadius);
                Debug.DrawLine(Vector3.zero, closestHit.point, Color.red, 2.5f);
                for (int i = 0; i < nativeArray.Length; i++)
                {
                    if (nativeArray[i].index.Equals(index))
                    {
                        PostUpdateCommands.AddComponent(nativeArray[i].entity, new HexTileHightlightComponent());
                        break;
                    }
                }
            }
        }

        nativeArray.Dispose();
    }
コード例 #20
0
        protected override void OnUpdate()
        {
            if (Time.time > _nextUpdate)
            {
                AwaitingNavmeshText.text = $"Awaiting Path: {navQuery.PendingCount} people";
                CachedPathText.text      = $"Cached Paths: {navQuery.CachedCount}";
                _nextUpdate = Time.time + 0.5f;
            }
            var inputDeps = new DetectIdleAgentJob {
                data = data, needsPath = needsPath.ToConcurrent()
            }.Schedule(data.Length, 64);

            inputDeps = new SetNextPathJob {
                data = data, needsPath = needsPath
            }.Schedule(inputDeps);
            inputDeps.Complete();
        }
コード例 #21
0
    protected override void OnCreateManager()
    {
        m_NewGhosts        = new NativeList <T>(16, Allocator.Persistent);
        m_NewGhostIds      = new NativeList <int>(16, Allocator.Persistent);
        m_Archetype        = GetGhostArchetype();
        m_InitialArchetype = EntityManager.CreateArchetype(ComponentType.ReadWrite <T>(), ComponentType.ReadWrite <ReplicatedEntity>());

        m_GhostMap           = World.GetOrCreateManager <GhostReceiveSystem>().GhostEntityMap;
        m_ConcurrentGhostMap = m_GhostMap.ToConcurrent();
        m_DestroyGroup       = GetComponentGroup(ComponentType.ReadOnly <T>(),
                                                 ComponentType.Exclude <ReplicatedEntity>());

        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.ToConcurrent();
    }
コード例 #22
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (!AttackCommands.IsCreated)
        {
            AttackCommands           = new NativeQueue <AttackCommand>(Allocator.Persistent);
            AttackCommandsConcurrent = AttackCommands.ToConcurrent();
        }

        AttackCommandsConcurrentFence.Complete();

        var attackCommandsJob = new AttackCommandsJob {
            minions = minions, attackCommands = AttackCommands
        };

        AttackCommandsFence = attackCommandsJob.Schedule(inputDeps);

        return(AttackCommandsFence);
    }
コード例 #23
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var commandBufferSystem = World.GetExistingManager <BeginSimulationEntityCommandBufferSystem>();

            inputDeps = new ProcessJob
            {
                RemoveQueue = m_RemoveQueue.ToConcurrent()
            }.Schedule(this, inputDeps);

            inputDeps = new RemoveJob
            {
                RemoveQueue   = m_RemoveQueue,
                CommandBuffer = commandBufferSystem.CreateCommandBuffer()
            }.Schedule(inputDeps);

            commandBufferSystem.AddJobHandleForProducer(inputDeps);

            return(inputDeps);
        }
コード例 #24
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var concurrentFreeQueue = freeNetworkIds.ToConcurrent();

        inputDeps = m_Driver.ScheduleUpdate(inputDeps);
        if (m_DriverListening)
        {
            // Schedule accept job
            var acceptJob = new ConnectionAcceptJob();
            acceptJob.driver        = m_Driver;
            acceptJob.commandBuffer = m_Barrier.CreateCommandBuffer();
            inputDeps = acceptJob.Schedule(inputDeps);

            // Schedule job to assign network ids to new connections
            var assignJob = new AssignNetworkIdJob();
            assignJob.commandBuffer  = m_Barrier.CreateCommandBuffer();
            assignJob.numNetworkId   = numNetworkIds;
            assignJob.freeNetworkIds = freeNetworkIds;
            assignJob.rpcQueue       = rpcQueue;
            assignJob.rpcBuffer      = GetBufferFromEntity <OutgoingRpcDataStreamBufferComponent>();
            inputDeps = assignJob.ScheduleSingle(this, inputDeps);
        }
        else
        {
            freeNetworkIds.Clear();
        }
        // 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;
        // FIXME: because it uses buffer from entity
        var handle = recvJob.ScheduleSingle(this, inputDeps);

        m_Barrier.AddJobHandleForProducer(handle);
        return(handle);
    }
コード例 #25
0
    void OnEnable()
    {
        velocity = new NativeArray <float>(targets.Length, Allocator.Persistent);
        commands = new NativeArray <RaycastCommand>(targets.Length, Allocator.Persistent);
        results  = new NativeArray <RaycastHit>(targets.Length, Allocator.Persistent);
        hitQueue = new NativeQueue <int>(Allocator.Persistent);

        transform.DetachChildren();

        for (int i = 0; i < targets.Length; i++)
        {
            velocity[i] = -1;
        }
        transformArray = new TransformAccessArray(targets);

        hitCheckJob = new IsHitGroundJob()
        {
            raycastResults = results,
            result         = hitQueue.ToConcurrent()
        };
    }
コード例 #26
0
        protected override void OnCreateManager()
        {
            base.OnCreateManager();

            uiEntityDataGroup = GetComponentGroup(typeof(UIData));

            //Allocate our queues
            entityOutOfBoundQueue = new NativeQueue <Entity>(Allocator.Persistent);
            entityCollisionQueue  = new NativeQueue <Entity>(Allocator.Persistent);

            //Create the entity that will contain our queues
            dataEntity = EntityManager.CreateEntity();

            //Create the compoenent data used to store our queues, other systems will look for that component data type
            DestroyEntityData data = new DestroyEntityData();

            data.entityOutOfBoundQueueConcurrent = entityOutOfBoundQueue.ToConcurrent();
            data.entityCollisionQueueConcurrent  = entityCollisionQueue.ToConcurrent();

            //Add that struct to the entity
            EntityManager.AddComponentData(dataEntity, data);
        }
コード例 #27
0
        public void TestIssue101()
        {
            var hashMap = new NativeHashMap <ulong, byte>(100, Allocator.TempJob);
            var keys    = new NativeQueue <ulong>(Allocator.TempJob);

            try
            {
                var job = new Issue101Job()
                {
                    hashMap = hashMap.ToConcurrent(),
                    keys    = keys.ToConcurrent(),
                    Index   = 1,
                };

                job.Schedule(default(JobHandle)).Complete();
            }
            finally
            {
                keys.Dispose();
                hashMap.Dispose();
            }
        }
コード例 #28
0
ファイル: DisengageSystem.cs プロジェクト: gabrjt/ai-battle
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            EntityManager.RemoveComponent(m_DeadGroup, ComponentType.ReadWrite <Target>());

            var commandBufferSystem = World.GetExistingManager <BeginSimulationEntityCommandBufferSystem>();

            inputDeps = new ProcessJob
            {
                RemoveQueue           = m_RemoveQueue.ToConcurrent(),
                DeadFromEntity        = GetComponentDataFromEntity <Dead>(true),
                TranslationFromEntity = GetComponentDataFromEntity <Translation>(true)
            }.Schedule(this);

            inputDeps = new RemoveTargetJob
            {
                RemoveQueue   = m_RemoveQueue,
                CommandBuffer = commandBufferSystem.CreateCommandBuffer()
            }.Schedule(inputDeps);

            commandBufferSystem.AddJobHandleForProducer(inputDeps);

            return(inputDeps);
        }
コード例 #29
0
    public void Update()
    {
        UpdateParticleTimeJob nonPriorityUpdateJob = new UpdateParticleTimeJob
        {
            deltaTime         = Time.deltaTime,
            particleTimeList  = nonPriorityParticleTimeArray,
            deadParticleQueue = nonPriorityDeadParticleQueue.ToConcurrent(),
        };

        nonPriorityUpdateJobHandle = nonPriorityUpdateJob.Schedule(nonPriorityParticleTimeArray.Length, 10);

        UpdateParticleTimeJob priorityUpdateJob = new UpdateParticleTimeJob
        {
            deltaTime         = Time.deltaTime,
            particleTimeList  = priorityParticleTimeArray,
            deadParticleQueue = priorityDeadParticleQueue.ToConcurrent(),
        };

        priorityUpdateJobHandle = priorityUpdateJob.Schedule(priorityParticleTimeArray.Length, 10);

        //start executing the jobs now
        JobHandle.ScheduleBatchedJobs();
    }
コード例 #30
0
        private IEnumerator Operate()
        {
            var energyJob   = new EnergyConsumptionJob();
            var countingJob = new ChargingCounterJob();

            while (true)
            {
                if (Batteries.Count == 0)
                {
                    yield return(null);
                }

                for (var j = 0; j < Battery.AllData.Length; j++)
                {
                    var dE = Battery.AllData[j].DeltaEnergy;
                    if (SimManager.AllBatteries[Battery.AllData[j].UID].GetDrone(out var d))
                    {
                        d.UpdateEnergy(dE);
                    }
                }
                UpdateDroneInfo();
                energyJob.Energies      = Battery.AllData;
                energyJob.DronesToDrop  = _dronesToDrop.ToConcurrent();
                energyJob.DroneInfo     = _droneInfo;
                energyJob.DeltaTime     = _time.Timer();
                countingJob.HubData     = Hub.ChargingBatteryCounts;
                countingJob.BatteryData = Battery.AllData;
                _time.Now();

                _consumptionJobHandle = energyJob.Schedule(Battery.AllData.Length, 32);
                _chargeCountJobHandle =
                    countingJob.Schedule(Hub.ChargingBatteryCounts.Length, 1, _consumptionJobHandle);
                yield return(null);

                _chargeCountJobHandle.Complete();
            }
        }