コード例 #1
0
        void AddSortedCellArrays()
        {
            float startCellGrouping = GetOrGenerateCellGrouping(startCell.index);

            DynamicBuffer <CellSystem.SectorCell>   sectorCells   = commandBuffer.AddBuffer <CellSystem.SectorCell>(sectorEntity);
            DynamicBuffer <CellSystem.AdjacentCell> adjacentCells = commandBuffer.AddBuffer <CellSystem.AdjacentCell>(sectorEntity);

            for (int i = 0; i < cellMatrix.Length; i++)
            {
                if (!cellMatrix.ItemIsSet(i))
                {
                    continue;
                }

                WorleyNoise.CellData cellData = cellMatrix.GetItem(i).data;

                if (cellData.value == 0)
                {
                    continue;
                }

                if (GetOrGenerateCellGrouping(cellData.index) != startCellGrouping)
                {
                    adjacentCells.Add(new CellSystem.AdjacentCell {
                        index = cellData.index
                    });
                }
                else
                {
                    sectorCells.Add(new CellSystem.SectorCell {
                        index = cellData.index
                    });
                }
            }
        }
コード例 #2
0
        public void Returns_values_greater_than_zero()
        {
            WorleyNoise.CellData  cell  = testUtil.RandomCellData(cellWorley);
            WorleyNoise.PointData point = testUtil.RandomPointData(cellWorley);

            float sumOfAllValuesPoint = 0;
            float sumOfAllValuesCell  = 0;

            sumOfAllValuesCell += cell.index.x;
            sumOfAllValuesCell += cell.index.y;
            sumOfAllValuesCell += cell.position.x;
            sumOfAllValuesCell += cell.position.z;
            sumOfAllValuesCell += cell.value;

            sumOfAllValuesPoint += point.distance2Edge;
            sumOfAllValuesPoint += point.distance;

            sumOfAllValuesPoint += point.currentCellValue;
            sumOfAllValuesPoint += point.adjacentCellValue;

            sumOfAllValuesPoint += point.currentCellPosition.x;
            sumOfAllValuesPoint += point.currentCellPosition.z;
            sumOfAllValuesPoint += point.adjacentCellPosition.x;
            sumOfAllValuesPoint += point.adjacentCellPosition.z;

            sumOfAllValuesPoint += point.currentCellIndex.x;
            sumOfAllValuesPoint += point.currentCellIndex.y;
            sumOfAllValuesPoint += point.adjacentCellIndex.x;
            sumOfAllValuesPoint += point.adjacentCellIndex.y;

            Assert.NotZero(sumOfAllValuesPoint, "Point");
            Assert.NotZero(sumOfAllValuesCell, "Cell");
        }
コード例 #3
0
        public void GetWorleyDistanceNotNines()
        {
            WorleyNoise.CellData adjacentPlaceholder;
            float dist2Edge;

            WorleyNoise.CellData cell = GetWorleyDataHelper(out adjacentPlaceholder, out dist2Edge, false, true);

            bool somethingWasGenerated = cell.value != 0;
            bool distanceNotNines      = dist2Edge != 999999;

            Assert.IsTrue(somethingWasGenerated && distanceNotNines);
        }
コード例 #4
0
        public void AdjacentCellIsDifferent()
        {
            WorleyNoise.CellData adjacent;
            float dist2EdgePlaceholder;

            WorleyNoise.CellData cell = GetWorleyDataHelper(out adjacent, out dist2EdgePlaceholder, true, false);

            bool notZero   = adjacent.value != 0;
            bool different = !adjacent.index.Equals(cell.index);

            Assert.IsTrue(notZero && different, "adjacent is zero: " + notZero);
        }
コード例 #5
0
 bool AllAdjacentAreHigher(DynamicBuffer <CellSystem.AdjacentCell> adjacentCells, float heightGrouping)
 {
     for (int i = 0; i < adjacentCells.Length; i++)
     {
         WorleyNoise.CellData cell = cellSystem.GetCellData(adjacentCells[i].index);
         if (topologyUtil.CellHeightGroup(cell.index) <= heightGrouping)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #6
0
        public void GetWorleyNoiseNoAdjacent()
        {
            WorleyNoise.CellData adjacentPlaceholder;
            float dist2EdgePlaceholder;

            WorleyNoise.CellData cell = GetWorleyDataHelper(out adjacentPlaceholder, out dist2EdgePlaceholder, false, false);

            bool somethingWasGenerated = cell.value != 0;
            bool adjacentNotGenerated  = adjacentPlaceholder.value == 0;

            Assert.IsTrue(somethingWasGenerated && adjacentNotGenerated);
        }
コード例 #7
0
    void DrawChildCells(float2 frequency)
    {
        WorleyNoise childWorley = worley;

        childWorley.frequency = frequency;

        float3 meanPointWorld = parentCell.data.position + vectorUtil.MeanPoint(parentCell.vertices);

        WorleyNoise.CellData startChild = childWorley.GetCellData(meanPointWorld);

        var checkNext      = new NativeQueue <WorleyNoise.CellData>(Allocator.Temp);
        var alreadyChecked = new NativeList <int2>(Allocator.Temp);

        checkNext.Enqueue(startChild);
        alreadyChecked.Add(startChild.index);

        var children = new NativeList <WorleyNoise.CellProfile>(Allocator.Temp);

        while (checkNext.Count > 0)
        {
            WorleyNoise.CellData childData = checkNext.Dequeue();

            WorleyNoise.CellData dataFromParent = worley.GetCellData(childData.position);
            bool childIsInParent = dataFromParent.index.Equals(parentCell.data.index);

            if (!childIsInParent)
            {
                continue;
            }

            WorleyNoise.CellProfile childProfile = childWorley.GetCellProfile(childData);
            float3 positionInParent = childProfile.data.position - parentCell.data.position;
            positionInParent.y += baseHeight;

            leaves.Draw(childProfile, positionInParent);

            children.Add(childProfile);

            for (int i = 0; i < childProfile.vertices.Length; i++)
            {
                WorleyNoise.CellData adjacent = childProfile.adjacentCells[i].c0;
                if (!alreadyChecked.Contains(adjacent.index))
                {
                    checkNext.Enqueue(adjacent);
                    alreadyChecked.Add(adjacent.index);
                }
            }
        }

        checkNext.Dispose();
        alreadyChecked.Dispose();
    }
コード例 #8
0
        public void Cell_value_greater_than_zero_and_less_than_one()
        {
            for (int i = 0; i < 500; i++)
            {
                WorleyNoise.CellData  cell  = testUtil.RandomCellData(cellWorley);
                WorleyNoise.PointData point = testUtil.RandomPointData(cellWorley);

                Assert.Less(cell.value, 1, "Cell less than 1");
                Assert.Greater(cell.value, 0, "Cell greater than 0");
                Assert.Less(point.currentCellValue, 1, "Point less than 1");
                Assert.Greater(point.currentCellValue, 0, "Point greater than 0");
            }
        }
コード例 #9
0
ファイル: CellSystem.cs プロジェクト: danhale-git/factory-td
    void TryAddCell(int2 index)
    {
        if (!cellMatrix.ItemIsSet(index))
        {
            WorleyNoise.CellData cellData = worley.GetCellData(index);
            CellMatrixItem       cell     = new CellMatrixItem
                                            (
                cellData,
                topologyUtil.CellGrouping(index),
                topologyUtil.CellHeight(index)
                                            );

            cellMatrix.AddItem(cell, cellData.index);
        }
    }
コード例 #10
0
        WorleyNoise.CellData GetWorleyDataHelper(out WorleyNoise.CellData adjacentPlaceholder, out float dist2EdgePlaceholder, bool getAdjacent, bool getDistance)
        {
            WorleyNoise worley         = GetWorleyGenerator();
            float3      randomPosition = Random().NextFloat3();

            return(worley.GetWorleyData(
                       randomPosition.x,
                       randomPosition.y,
                       0.01f,
                       out adjacentPlaceholder,
                       out dist2EdgePlaceholder,
                       getAdjacent,
                       getDistance
                       ));
        }
コード例 #11
0
ファイル: CellSystem.cs プロジェクト: danhale-git/factory-td
    void ScheduleSectorJob(Entity cellEntity)
    {
        WorleyNoise.CellData startCell = entityManager.GetComponentData <WorleyNoise.CellData>(cellEntity);

        FloodFillSectorJob job = new FloodFillSectorJob {
            commandBuffer = jobManager.commandBuffer,
            startCell     = startCell,
            sectorEntity  = cellEntity,
            pointMatrix   = new Matrix <WorleyNoise.PointData>(10, Allocator.TempJob, startCell.position, job: true),
            cellMatrix    = new Matrix <CellMatrixItem>(1, Allocator.TempJob, new float3(startCell.index.x, 0, startCell.index.y), job: true),
            worley        = this.worley,
            topologyUtil  = new TopologyUtil().Construct()
        };

        jobManager.ScheduleNewJob(job);
    }
コード例 #12
0
    void ScheduleMeshDataJobs()
    {
        var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
        var chunks        = meshDataGroup.CreateArchetypeChunkArray(Allocator.TempJob);

        var entityType           = GetArchetypeChunkEntityType();
        var matrixType           = GetArchetypeChunkComponentType <CellSystem.MatrixComponent>(true);
        var sectorMasterCellType = GetArchetypeChunkComponentType <SectorSystem.MasterCell>(true);
        var worleyType           = GetArchetypeChunkBufferType <WorleyNoise.PointData>(true);

        for (int c = 0; c < chunks.Length; c++)
        {
            var chunk = chunks[c];

            var entities          = chunk.GetNativeArray(entityType);
            var matrices          = chunk.GetNativeArray(matrixType);
            var sectorMasterCells = chunk.GetNativeArray(sectorMasterCellType);
            var worleyArrays      = chunk.GetBufferAccessor(worleyType);

            for (int e = 0; e < entities.Length; e++)
            {
                CellSystem.MatrixComponent matrix     = matrices[e];
                WorleyNoise.CellData       masterCell = sectorMasterCells[e].Value;

                var worley = new NativeArray <WorleyNoise.PointData>(worleyArrays[e].AsNativeArray(), Allocator.Persistent);

                WaterMeshDataJob waterJob = new WaterMeshDataJob {
                    commandBuffer        = jobManager.commandBuffer,
                    waterEntityArchetype = waterArchetype,
                    matrix       = matrix,
                    masterCell   = masterCell,
                    worley       = worley,
                    topologyUtil = topologyUtil
                };

                jobManager.ScheduleNewJob(waterJob);

                commandBuffer.RemoveComponent <Tags.CreateWaterEntity>(entities[e]);
            }
        }

        commandBuffer.Playback(entityManager);
        commandBuffer.Dispose();
        chunks.Dispose();
    }
コード例 #13
0
        public void PointData_matches_CellData()
        {
            WorleyNoise.PointData randomPoint = testUtil.RandomPointData(cellWorley);
            WorleyNoise.CellData  cell        = cellWorley.GetCellData(randomPoint.currentCellIndex);

            Assert.IsTrue(
                randomPoint.currentCellPosition.Equals(cell.position),
                "Position\n" + "PointData: " + randomPoint.currentCellPosition + '\n' + "CellData: " + cell.position
                );
            Assert.IsTrue(
                randomPoint.currentCellIndex.Equals(cell.index),
                "Index\n" + "PointData: " + randomPoint.currentCellIndex + '\n' + "CellData: " + cell.index
                );
            Assert.IsTrue(
                randomPoint.currentCellValue.Equals(cell.value),
                "Value\n" + "PointData: " + randomPoint.currentCellValue + '\n' + "CellData: " + cell.value
                );
        }
コード例 #14
0
    void DebugWorley(int range)
    {
        for (int x = -range; x < range; x++)
        {
            for (int z = -range; z < range; z++)
            {
                /*float xf = 0.1f * ( (float)math.abs(x) / range );
                 * float zf = 0.1f * ( (float)math.abs(z) / range ); */

                float dist2Edge;
                WorleyNoise.CellData cell = worley.GetCellData(x, z, out dist2Edge);

                float colorFloat = cell.value;
                Color color      = new Color(colorFloat /* + dist2Edge */, colorFloat, colorFloat, 1);

                CreateCube(new float3(x, 0, z), color);
            }
        }
    }
コード例 #15
0
    protected override void OnUpdate()
    {
        var commandBuffer = new EntityCommandBuffer(Allocator.TempJob);
        var chunks        = sectorGroup.CreateArchetypeChunkArray(Allocator.TempJob);

        var entityType       = GetArchetypeChunkEntityType();
        var startCellType    = GetArchetypeChunkComponentType <WorleyNoise.CellData>(true);
        var pointArrayType   = GetArchetypeChunkBufferType <WorleyNoise.PointData>(true);
        var sectorCellType   = GetArchetypeChunkBufferType <CellSystem.SectorCell>(true);
        var adjacentCellType = GetArchetypeChunkBufferType <CellSystem.AdjacentCell>(true);

        for (int c = 0; c < chunks.Length; c++)
        {
            var chunk = chunks[c];

            var entities           = chunk.GetNativeArray(entityType);
            var startCells         = chunk.GetNativeArray(startCellType);
            var pointArrays        = chunk.GetBufferAccessor(pointArrayType);
            var sectorCellArrays   = chunk.GetBufferAccessor(sectorCellType);
            var adjacentCellArrays = chunk.GetBufferAccessor(adjacentCellType);

            for (int e = 0; e < entities.Length; e++)
            {
                Entity sectorEntity            = entities[e];
                WorleyNoise.CellData startCell = startCells[e];
                DynamicBuffer <WorleyNoise.PointData>   points        = pointArrays[e];
                DynamicBuffer <CellSystem.SectorCell>   sectorCells   = sectorCellArrays[e];
                DynamicBuffer <CellSystem.AdjacentCell> adjacentCells = adjacentCellArrays[e];

                WorleyNoise.CellData masterCell = cellSystem.GetCellData(sectorCells[0].index);

                float grouping = cellSystem.GetCellGrouping(startCell.index);
                bool  pathable = SectorIsPathable(points, grouping);
                int   height   = (int)cellSystem.GetCellHeight(masterCell.index);

                TypeComponent type = new TypeComponent();
                if (!pathable)
                {
                    if (AllAdjacentAreHigher(adjacentCells, topologyUtil.CellHeightGroup(masterCell.index)))
                    {
                        type.Value = SectorTypes.GULLY;
                    }
                    else
                    {
                        type.Value = SectorTypes.MOUNTAIN;
                    }
                }
                else if (topologyUtil.CellHeightGroup(masterCell.index) < 2 && sectorCells.Length > 2)
                {
                    type.Value = SectorTypes.LAKE;
                    commandBuffer.AddComponent <Tags.CreateWaterEntity>(sectorEntity, new Tags.CreateWaterEntity());
                }

                commandBuffer.AddComponent <TypeComponent>(sectorEntity, type);

                commandBuffer.RemoveComponent <WorleyNoise.CellData>(sectorEntity);
                commandBuffer.AddComponent <MasterCell>(sectorEntity, new MasterCell {
                    Value = masterCell
                });
            }
        }

        commandBuffer.Playback(entityManager);
        commandBuffer.Dispose();

        chunks.Dispose();
    }
コード例 #16
0
ファイル: CellSystem.cs プロジェクト: danhale-git/factory-td
 public CellMatrixItem(WorleyNoise.CellData data, float grouping, float height)
 {
     this.data     = data;
     this.grouping = grouping;
     this.height   = height;
 }
コード例 #17
0
    public WorleyNoise.CellProfile GetCellProfile(NativeArray <WorleyNoise.CellData> nineCells, WorleyNoise.CellData cell)
    {
        this.cellPosition = cell.position;

        this.triangles = bowyerWatson.Triangulate(nineCells);

        SortTrianglesClockwise();

        this.cellVertices    = new NativeList <float3>(Allocator.Temp);
        this.adjacentCells   = new NativeList <WorleyNoise.CellDataX2>(Allocator.Temp);
        this.vertexRotations = new NativeList <float>(Allocator.Temp);
        GetCellVerticesAndAdjacentCells();

        WorldToLocalVertexPositions();

        var cellProfile = new WorleyNoise.CellProfile();

        cellProfile.data            = cell;
        cellProfile.vertices        = new NineValues <float3>(cellVertices);
        cellProfile.adjacentCells   = new NineValues <WorleyNoise.CellDataX2>(adjacentCells);
        cellProfile.vertexRotations = new NineValues <float>(vertexRotations);

        triangles.Dispose();
        cellVertices.Dispose();
        adjacentCells.Dispose();

        return(cellProfile);
    }
コード例 #18
0
 public WorleyDatas(WorleyNoise.CellData cellFromIndex, WorleyNoise.CellData cellFromPosition)
 {
     this.cellFromIndex    = cellFromIndex;
     this.cellFromPosition = cellFromPosition;
 }