protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (minionSystem == null)
        {
            return(inputDeps);
        }

        if (arrows.Length == 0)
        {
            return(inputDeps);
        }
        if (minions.Length == 0)
        {
            return(inputDeps);
        }

        // Update seems to be called after Play mode has been exited

        // ============ REALLOC ===============
        // todo fix nativearray
        NativeArrayExtensions.ResizeNativeArray(ref raycastHits, math.max(raycastHits.Length, arrows.Length));
        NativeArrayExtensions.ResizeNativeArray(ref raycastCommands, math.max(raycastCommands.Length, arrows.Length));

        // ============ JOB CREATION ===============

        var arrowJob = new ProgressArrowJob
        {
            raycastCommands = raycastCommands,
            arrows          = arrows.data,
            arrowEntities   = arrows.entities,
            dt = Time.deltaTime,
            allMinionTransforms     = minions.transforms,
            buckets                 = minionSystem.CollisionBuckets,
            minionConstData         = minions.constData,
            AttackCommands          = CommandSystem.AttackCommandsConcurrent,
            minionEntities          = minions.entities,
            queueForKillingEntities = lifecycleManager.queueForKillingEntities
        };

        var stopArrowJob = new StopArrowsJob
        {
            raycastHits        = raycastHits,
            arrows             = arrows.data,
            arrowEntities      = arrows.entities,
            stoppedArrowsQueue = lifecycleManager.deathQueue
        };

        var arrowJobFence = arrowJob.Schedule(arrows.Length, SimulationState.SmallBatchSize, JobHandle.CombineDependencies(inputDeps, CommandSystem.AttackCommandsFence));

        arrowJobFence.Complete();
        var raycastJobFence   = RaycastCommand.ScheduleBatch(raycastCommands, raycastHits, SimulationState.SmallBatchSize, arrowJobFence);
        var stopArrowJobFence = stopArrowJob.Schedule(arrows.Length, SimulationState.SmallBatchSize, raycastJobFence);

        CommandSystem.AttackCommandsConcurrentFence = JobHandle.CombineDependencies(stopArrowJobFence, CommandSystem.AttackCommandsConcurrentFence);
        // Complete arrow movement
        return(stopArrowJobFence);
    }
예제 #2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (flyingUnits.Length == 0)
        {
            return(inputDeps);
        }

        // ============ REALLOC ===============

        // todo fix nativearray
        NativeArrayExtensions.ResizeNativeArray(ref raycastHits, math.max(raycastHits.Length, flyingUnits.Length));
        NativeArrayExtensions.ResizeNativeArray(ref raycastCommands, math.max(raycastCommands.Length, flyingUnits.Length));

        // ============ JOB CREATION ===============
        var prepareRaycastsJob = new PrepareRaycasts
        {
            transforms      = flyingUnits.transforms,
            raycastCommands = raycastCommands
        };

        var flightJob = new MinionFlightJob
        {
            raycastHits      = raycastHits,
            minionData       = flyingUnits.data,
            flyingUnits      = flyingUnits.transforms,
            rigidbodies      = flyingUnits.rigidbodies,
            textureAnimators = flyingUnits.animationData,
            dt = Time.deltaTime,
        };

        // ==================== JOB SCHEDULING ==============
        var prepareRaycastFence = prepareRaycastsJob.Schedule(flyingUnits.Length, SimulationState.SmallBatchSize, inputDeps);

        prepareRaycastFence.Complete();         // TODO fix me
        var raycastJobFence = RaycastCommand.ScheduleBatch(raycastCommands, raycastHits, SimulationState.SmallBatchSize, prepareRaycastFence);
        var flightJobFence  = flightJob.Schedule(flyingUnits.Length, SimulationState.SmallBatchSize, raycastJobFence);

        return(flightJobFence);
    }