Ejemplo n.º 1
0
 public void UpdateBorder(uint[] ids)
 {
     // Generate Border Data
     gpuUtils.UpdateData[] update = new gpuUtils.UpdateData[ids.Length];
     for (int i = 0; i < ids.Length; i++)
     {
         var hex = gridUtils.GetHexByID(ids[i]);
         update[i] = hex.GetUpdateGPUData(true);
     }
     ComputeUpdateBorder(update);
 }
Ejemplo n.º 2
0
    public gpuUtils.UpdateData GetUpdateGPUData(bool isBorderData)
    {
        gpuUtils.UpdateData data = new gpuUtils.UpdateData {
            idStatusTerrain = new Vector3(ID, Utils.BoolToFloat(Active), Type.ID)
        };

        var n = GetNeighbourGPUData(isBorderData);

        data.neighbours  = new Vector3(n[0], n[1], n[2]);
        data.neighbours2 = new Vector3(n[3], n[4], n[5]);
        return(data);
    }
Ejemplo n.º 3
0
        private void SetBuffer()
        {
            // set data
            gpuUtils.UpdateData[] updatedata = new gpuUtils.UpdateData[gridUtils.HexagonCount];
            for (int i = 1; i < gridUtils.HexagonCount; i++)
            {
                updatedata[i] = gridUtils.GetHexByID((uint)i).GetUpdateGPUData(false);
            }

            _bufUpdate.SetCounterValue((uint)gridUtils.HexagonCount);
            _bufUpdate.SetData(updatedata);

            _waterResCompute.SetBuffer(_verticeskernel, "_WaterfallVertices", _bufWaterfallVertices);
            _waterResCompute.SetBuffer(_indiceskernel, "_WaterfallIndices", _bufWaterfallIndices);
            _waterResCompute.SetBuffer(_indiceskernel, "UpdateWaterIds", _bufUpdate);
        }
Ejemplo n.º 4
0
    // called on user input changing hexagons
    public void UpdateHexagons(Hexagon[] hex, uint[] active, uint[] terrain)
    {
        uint[][] neighbours        = new uint[hex.Length][];
        gpuUtils.UpdateData[] data = new gpuUtils.UpdateData[hex.Length];

        List <uint> updateNeighbours = new List <uint>();

        for (int i = 0; i < hex.Length; i++)
        {
            // set new active
            if (active[i] == 0 && ActiveHexagons.Contains(hex[i].ID))
            {
                hex[i].Active = false;
                ActiveHexagons.Remove(hex[i].ID);
            }
            else if (active[i] == 1 && !ActiveHexagons.Contains(hex[i].ID))
            {
                hex[i].Active = true;
                ActiveHexagons.Add(hex[i].ID);
            }

            // set new type
            hex[i].Type = _mapConfig.GetTerrainTypeByID((int)terrain[i]);
            hex[i].UpdateNeighbours();

            // update neighbours
            neighbours[i] = hex[i].GetNeighbourGPUData(false);

            // get data points
            updateNeighbours.AddRange(hex[i].GetNeighbours());
            data[i] = hex[i].GetUpdateGPUData(false);

            //Debug.Log( $"Adding update for id {hex[i].ID}  setting type to: {data[i].idStatusTerrain}" );
        }


        // UPDATE NEIGHBOUR TERRAIN
        gpuUtils.UpdateData[] neighbourUpdateData = new gpuUtils.UpdateData[updateNeighbours.Count];
        for (int i = 0; i < updateNeighbours.Count; i++)
        {
            neighbourUpdateData[i] = gridUtils.GetHexByID(updateNeighbours[i]).GetUpdateGPUData(false);
        }

        // generate IDS
        uint[] ids = new uint[hex.Length];
        for (int i = 0; i < hex.Length; i++)
        {
            ids[i] = hex[i].ID;
        }

        // Update Selected Hexagons
        _terrainResource.UpdateHexagons(data);
        _terrainResource.UpdateBorder(ids);
        _terrainResource.UpdateTesselation(ids);           //TODO: Only call this on type changed for type changed ID's

        // Update Selected Neighbourhood
        _terrainResource.UpdateHexagons(neighbourUpdateData);
        _terrainResource.UpdateBorder(updateNeighbours.ToArray());

        UpdateGridResources(UpdateType.Terrain, data);
        UpdateGridResources(UpdateType.Border, neighbourUpdateData);
    }