Beispiel #1
0
 public void Execute()
 {
     if (PowderTypes.values[type].IsGenerator())
     {
         if (!isPainting)
         {
             for (var x = coord.x - PowderGame.brushSize; x <= coord.x + PowderGame.brushSize; ++x)
             {
                 if (!PowderSystemUtils.IsOccupied(ref hashMap, x, coord.y))
                 {
                     PowderGame.Spawn(ref cmdBuffer, x, coord.y, type);
                 }
             }
         }
     }
     else
     {
         var size = 0;
         for (var y = coord.y - PowderGame.brushSize; y <= coord.y + PowderGame.brushSize; ++y)
         {
             for (var x = coord.x - size; x <= coord.x + size; ++x)
             {
                 if (!PowderSystemUtils.IsOccupied(ref hashMap, x, y))
                 {
                     PowderGame.Spawn(ref cmdBuffer, x, y, type);
                 }
             }
             size += y < coord.y ? 1 : -1;
         }
     }
 }
Beispiel #2
0
    void ChangeElement(int index, int newType)
    {
        var p = powders[index];

        PowderSystemUtils.SchdeduleRemovePowder(ref toDeleteEntities, index);
        PowderGame.Spawn(ref cmdBuffer, p.coord.x, p.coord.y, newType);
    }
Beispiel #3
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        CheckDisposeTempData();

        // Compute index
        positionsMap        = new NativeHashMap <int, int>(m_PowderGroup.Length, Allocator.Temp);
        toDeleteEntities    = new NativeHashMap <int, int>(Mathf.Max(m_PowderGroup.Length / 10, 64), Allocator.Temp);
        m_TempDataAllocated = true;

        var computeHashJob = new HashCoordJob()
        {
            powders = m_PowderGroup.powders,
            hashMap = positionsMap
        };
        var previousJobHandle = computeHashJob.Schedule(m_PowderGroup.Length, 64, inputDeps);

        if ((Input.GetMouseButtonDown(0) || Input.GetMouseButton(0)) && PowderGame.IsInWorld(Input.mousePosition))
        {
            var coord    = PowderGame.ScreenToCoord(Input.mousePosition);
            var spawnJob = new SpawnJob()
            {
                hashMap    = positionsMap,
                coord      = coord,
                cmdBuffer  = m_Barrier.CreateCommandBuffer(),
                type       = PowderGame.currentPowder,
                isPainting = !Input.GetMouseButtonDown(0)
            };
            previousJobHandle = spawnJob.Schedule(previousJobHandle);
        }

        // Simulate
        if (PowderGame.simulate)
        {
            var simulateJob = new SimulateJob()
            {
                powders          = m_PowderGroup.powders,
                positions        = m_PowderGroup.positions,
                hashMap          = positionsMap,
                rand             = Rand.Create(),
                entities         = m_PowderGroup.entities,
                cmdBuffer        = m_Barrier.CreateCommandBuffer(),
                toDeleteEntities = toDeleteEntities
            };
            previousJobHandle = simulateJob.Schedule(m_PowderGroup.Length, 64, previousJobHandle);
        }

        var deleteEntitiesJob = new DeleteEntitiesJob()
        {
            entities         = m_PowderGroup.entities,
            cmdBuffer        = m_Barrier.CreateCommandBuffer(),
            toDeleteEntities = toDeleteEntities
        };

        previousJobHandle = deleteEntitiesJob.Schedule(m_PowderGroup.Length, 64, previousJobHandle);

        inputDeps = previousJobHandle;

        return(inputDeps);
    }
Beispiel #4
0
    public static int GetPowderIndex(ref NativeHashMap <int, int> hashMap, int x, int y)
    {
        int index;

        if (hashMap.TryGetValue(PowderGame.CoordKey(x, y), out index))
        {
            return(index);
        }
        return(-1);
    }
Beispiel #5
0
    public void Execute(int index)
    {
        var updatedPowder = Simulate(powders[index], index);

        if (!powders[index].Same(updatedPowder))
        {
            cmdBuffer.SetComponent(entities[index], updatedPowder);
            positions[index] = new Position2D()
            {
                Value = PowderGame.CoordToWorld(powders[index].coord)
            };
        }
    }
Beispiel #6
0
    void Generate(ref Powder p, ref Neighbors n)
    {
        var generatedType = PowderTypes.values[p.type].generatedElementType;

        if (PowderTypes.values[generatedType].state == PowderState.Liquid || PowderTypes.values[generatedType].state == PowderState.Powder)
        {
            if (n.TopEmpty())
            {
                var generatedPowder = PowderTypes.values[generatedType].creator(new Vector2Int(p.coord.x, p.coord.y - 1));
                PowderGame.Spawn(ref cmdBuffer, generatedPowder);
            }
        }
        else if (n.BottomEmpty())
        {
            var generatedPowder = PowderTypes.values[generatedType].creator(new Vector2Int(p.coord.x, p.coord.y + 1));
            PowderGame.Spawn(ref cmdBuffer, generatedPowder);
        }
    }
Beispiel #7
0
    public void Execute(int index)
    {
        var key = PowderGame.CoordKey(powders[index].coord);

        hashMap.TryAdd(key, index);
    }
Beispiel #8
0
 public void Reset()
 {
     PowderGame.Reset();
 }