protected override void OnUpdate()
    {
        EntityQuery entityQuery = GetEntityQuery(typeof(Translation), typeof(Rotation), typeof(NonUniformScale), typeof(Planetoid));

        quadrantMultiHashMap.Clear();

        if (quadrantMultiHashMap.Capacity < entityQuery.CalculateLength())
        {
            quadrantMultiHashMap.Capacity = entityQuery.CalculateLength();
        }

        SetQuadrantDataJob setQuadrantDataJob = new SetQuadrantDataJob
        {
            quadrantMultiHashMap = quadrantMultiHashMap.ToConcurrent()
        };

        //JobHandle jobHandle = setQuadrantDataJob.Schedule(this);
        JobHandle jobHandle = JobForEachExtensions.Schedule(setQuadrantDataJob, entityQuery); //extension for jobs using parallel for

        jobHandle.Complete();

        DebugDrawQuadrant(CodeMonkey.Utils.UtilsClass.GetMouseWorldPosition());
    }
Beispiel #2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //Timer specific
        var startTimerJob = new StartTimerJob();
        var handle        = startTimerJob.Schedule(inputDeps);
        //Timer specific

        EntityQuery query = GetEntityQuery(typeof(Translation), typeof(Velocity));

        quadrantMultiHashMap.Clear();
        if (query.CalculateEntityCount() > quadrantMultiHashMap.Capacity)
        {
            quadrantMultiHashMap.Capacity = query.CalculateEntityCount();
        }

        ArchetypeChunkComponentType <Translation> translationChunk = GetArchetypeChunkComponentType <Translation>(true);
        ArchetypeChunkComponentType <Velocity>    velocityChunk    = GetArchetypeChunkComponentType <Velocity>(true);

        //Update quadrants data
        SetQuadrantDataJob setQuadrantData = new SetQuadrantDataJob()
        {
            translationType = translationChunk,
            velocityType    = velocityChunk,
            quadrantHashMap = quadrantMultiHashMap.AsParallelWriter()
        };

        var handle2 = setQuadrantData.Schedule(query, handle);

        //Timer specific
        var endTimerJob = new EndTimerJob();

        timerRecoder.RegisterTimeInMS(time);
        //Timer specific

        return(endTimerJob.Schedule(handle2));
    }