Esempio n. 1
0
        protected override JobHandle OnUpdate(JobHandle dependency)
        {
            var unitPositions     = m_UnitQuery.ToComponentDataArray <Translation>(Allocator.TempJob);
            var workerPositions   = m_WorkerQuery.ToComponentDataArray <Translation>(Allocator.TempJob);
            var selectedPositions = m_SelectedQuery.ToComponentDataArray <Translation>(Allocator.TempJob);

            Entity entity = m_MinimapQuery.GetSingletonEntity();
            DynamicBuffer <RenderTexture> buffer = EntityManager.GetBuffer <RenderTexture>(entity);

            NativeArray <float4> colorArray = new NativeArray <float4>(width * height, Allocator.TempJob);

            dependency = Job.WithCode(() => {
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        colorArray[x + (y * width)] = new float4(143.0f / 255.0f, 113.0f / 255.0f, 92.0f / 255.0f, 1.0f);
                    }
                }
            }).Schedule(dependency);

            dependency = Schedule(new float4(0, 0, 1, 1), unitPositions, colorArray, dependency);
            dependency = Schedule(new float4(1, 1, 0, 1), workerPositions, colorArray, dependency);
            dependency = Schedule(new float4(0, 1, 0, 1), selectedPositions, colorArray, dependency);

            NativeArray <int2> outVect = new NativeArray <int2>(4, Allocator.TempJob);

            outVect[0] = new int2(0, 0);
            outVect[1] = new int2(0, height - 1);
            outVect[2] = new int2(width - 1, height - 1);
            outVect[3] = new int2(width - 1, 0);

            MiniMapHelpers.ConstructCameraCoordonates(outVect, width, height);

            dependency = Job.WithCode(() => {
                for (int i = 0; i < 4; i++)
                {
                    int idx = (i + 1) % 4;
                    MiniMapHelpers.DrawLine(colorArray, width, height, outVect[i][0], outVect[i][1], outVect[idx][0], outVect[idx][1], new float4(1, 1, 1, 1));
                }
            }).Schedule(dependency);

            dependency.Complete();

            dependency = outVect.Dispose(dependency);

            buffer.CopyFrom(colorArray.Reinterpret <RenderTexture>());
            dependency = colorArray.Dispose(dependency);

            dependency = unitPositions.Dispose(dependency);
            dependency = workerPositions.Dispose(dependency);
            dependency = selectedPositions.Dispose(dependency);

            return(dependency);
        }
Esempio n. 2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            /* STEP 1 - Initialiser Dijkstra Grid */

            NativeArray <int> dijkstraGridBase = new NativeArray <int>(width * height, Allocator.TempJob);
            JobHandle         dependency       = Dijkstra.Construct(dijkstraGridBase, width, height, MAX_VALUE, _Obstacle, inputDeps);

            EntityCommandBuffer.Concurrent entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent();

            JobHandle jobHandle = Entities.ForEach((Entity entity, int entityInQueryIndex, DynamicBuffer <PathPosition> pathPositionBuffer, ref PathFollow pathFollow, in Translation translation, in MoveToComponent moveTo) =>
            {
                if (!pathFollow.move)
                {
                    pathFollow.move = true;

                    int2 position = MiniMapHelpers.ConvertWorldCoord(translation.Value, width, height);
                    int2 target   = MiniMapHelpers.ConvertWorldCoord(moveTo.endPosition, width, height);

                    /* STEP 2 - Explore all node to construct Dijkstra Grid */

                    NativeArray <int> dijkstraGrid = new NativeArray <int>(dijkstraGridBase.Length, Allocator.Temp);
                    dijkstraGrid.CopyFrom(dijkstraGridBase);

                    Dijkstra.Explore(dijkstraGrid, target, width, height);

                    /* STEP 3 - With Dijkstra Grid construct FlowField (array of dir vector) */

                    NativeArray <int2> flowfield = new NativeArray <int2>(width * height, Allocator.Temp);

                    Flowfield.Construct(flowfield, dijkstraGrid, position, target, width, height, MAX_VALUE);

                    pathPositionBuffer.CopyFrom(flowfield.Reinterpret <PathPosition>());

                    dijkstraGrid.Dispose();
                    flowfield.Dispose();

                    entityCommandBuffer.RemoveComponent <MoveToComponent>(entityInQueryIndex, entity);
                }
            }).Schedule(dependency);
Esempio n. 3
0
            public void Execute([ReadOnly] ref Translation translation)
            {
                int2 pos = MiniMapHelpers.ConvertWorldCoord(translation.Value, _width, _height);

                _dijkstraGrid[pos[0] + (pos[1] * _width)] = _max;
            }
Esempio n. 4
0
            public void Execute(int index)
            {
                int2 coords = MiniMapHelpers.ConvertWorldToTexture(m_positions[index].Value, width, height);

                m_results[coords[0] + (coords[1] * width)] = m_color;
            }