protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        // Realloc();
        if (formations.Length == 0)
        {
            return(inputDeps);
        }

        //NativeArrayExtensions.ResizeNativeArray(ref raycastHits, math.max(raycastHits.Length,minions.Length));
        //NativeArrayExtensions.ResizeNativeArray(ref raycastCommands, math.max(raycastCommands.Length, minions.Length));

        var copyNavigationJob = new CopyNavigationPositionToFormation
        {
            formations     = formations.data,
            agents         = formations.agents,
            navigators     = formations.navigators,
            navigationData = formations.navigationData,
            dt             = Time.deltaTime
        };

        var updateFormationsJob = new UpdateFormations
        {
            closestFormations      = formations.closestFormations,
            formationNavigators    = formations.navigators,
            formationHighLevelPath = formations.highLevelPaths,
            formations             = formations.data,
        };

        var closestSearchJob = new SearchClosestFormations
        {
            formations        = formations.data,
            closestFormations = formations.closestFormations,
            formationEntities = formations.entities
        };

        // ==== Schedule Formation jobs ======
        var copyJobFence       = copyNavigationJob.Schedule(formations.Length, SimulationState.SmallBatchSize, inputDeps);
        var closestSearchFence = closestSearchJob.Schedule(formations.Length, SimulationState.HugeBatchSize, copyJobFence);

        var updateFormationsFence = updateFormationsJob.Schedule(formations.Length, SimulationState.SmallBatchSize,
                                                                 closestSearchFence);

        // Pass two, rearrangeing the minion indices
        // TODO Split this system into systems that make sense

        //AddDependency(rearrangeFence);

        // calculate formation movement
        // advance formations
        // calculate minion position and populate the array
        return(updateFormationsFence);
    }
예제 #2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        // Realloc();
        if (formations.Length == 0)
        {
            return(inputDeps);
        }

        //NativeArrayExtensions.ResizeNativeArray(ref raycastHits, math.max(raycastHits.Length,minions.Length));
        //NativeArrayExtensions.ResizeNativeArray(ref raycastCommands, math.max(raycastCommands.Length, minions.Length));

        var copyNavigationJob = new CopyNavigationPositionToFormation
        {
            formations     = formations.data,
            agents         = formations.agents,
            navigators     = formations.navigators,
            navigationData = formations.navigationData,
            dt             = Time.deltaTime
        };
        var copyNavigationJobHandle = copyNavigationJob.Schedule(formations.Length, SimulationState.SmallBatchSize, inputDeps);

        var copyFormations    = new NativeArray <FormationData>(formations.data.Length, Allocator.TempJob);
        var copyFormationsJob = new CopyComponentData <FormationData>
        {
            Source  = formations.data,
            Results = copyFormations
        };
        var copyFormationJobHandle = copyFormationsJob.Schedule(formations.data.Length, SimulationState.HugeBatchSize, copyNavigationJobHandle);

        var copyFormationEntities    = new NativeArray <Entity>(formations.entities.Length, Allocator.TempJob);
        var copyFormationEntitiesJob = new CopyEntities
        {
            Source  = formations.entities,
            Results = copyFormationEntities
        };
        var copyFormationEntitiesJobHandle = copyFormationEntitiesJob.Schedule(formations.entities.Length, SimulationState.HugeBatchSize, copyNavigationJobHandle);
        var copyBarrier = JobHandle.CombineDependencies(copyFormationJobHandle, copyFormationEntitiesJobHandle);

        var closestSearchJob = new SearchClosestFormations
        {
            formations        = copyFormations,
            closestFormations = formations.closestFormations,
            formationEntities = copyFormationEntities
        };
        var closestSearchJobHandle = closestSearchJob.Schedule(formations.Length, SimulationState.HugeBatchSize, copyBarrier);

        var updateFormationsJob = new UpdateFormations
        {
            closestFormations      = formations.closestFormations,
            formationNavigators    = formations.navigators,
            formationHighLevelPath = formations.highLevelPaths,
            formations             = formations.data,
        };
        var updateFormationsJobHandle = updateFormationsJob.Schedule(formations.Length, SimulationState.SmallBatchSize, closestSearchJobHandle);

        // Pass two, rearrangeing the minion indices
        // TODO Split this system into systems that make sense

        // calculate formation movement
        // advance formations
        // calculate minion position and populate the array

        return(updateFormationsJobHandle);
    }