예제 #1
0
    public float[] GenerateHeightMap()
    {
        if (!SurfaceGenerated)
        {
            Vector2Int bottomLeft = new Vector2(Location.x * ChunkSizeX, Location.z * ChunkSizeZ);
            Vector2Int topRight   = new Vector2(Location.x * ChunkSizeX + ChunkSizeX, Location.z * ChunkSizeZ + ChunkSizeZ);
            Result.SurfaceData = Sampler.SetSurfaceData(bottomLeft, topRight);
            SurfaceGenerated   = true;

            Result.Min = (int)Sampler.GetMin();
            Result.Max = (int)Sampler.GetMax();

            return(Result.SurfaceData);
        }
        return(Result.SurfaceData);
    }
예제 #2
0
        public void GenerateHeightMap()
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();

            if (!SurfaceGenerated)
            {
                UnityGameServer.Logger.Log("Heightmap Generting...");
                builder.GenerateHeightMap();
                SurfaceGenerated = true;
            }

            watch.Stop();
            UnityGameServer.Logger.Log("Min: {0}, Max: {1}", Sampler.GetMin(), Sampler.GetMax());
            UnityGameServer.Logger.Log("Heightmap Gen: " + watch.Elapsed);
        }
예제 #3
0
    public ColumnResult Generate(int Y_Min, int Y_Max, int xStart, int zStart)
    {
        Result.Min = int.MaxValue;
        Result.Max = int.MinValue;

        Stopwatch watch_overall = new Stopwatch();

        watch_overall.Start();

        if (GPU_Accelorated_Noise)
        {
            UnityGameServer.Logger.Log("Using GPU sampler.");
            ((GPU_TerrainSampler)Sampler).ComputeNoiseGrid(Y_Min, Y_Max, xStart, zStart);
        }

        int globalLocY = 0;
        int globalLocZ = 0;
        int globalLocX = 0;
        int x, y, z = 0;

        for (globalLocY = Y_Min, y = Y_Min; y < Y_Max; globalLocY++, y++)
        {
            Result.Max = Mathf.Max(y, Result.Max);
            Result.Min = Mathf.Min(y, Result.Min);

            for (globalLocZ = zStart, z = 0; z < ChunkSizeZ; globalLocZ++, z++)
            {
                for (globalLocX = xStart, x = 0; x < ChunkSizeX; globalLocX++, x++)
                {
                    if (deactivated)
                    {
                        UnityGameServer.Logger.Log("DEACTIVATED!!!");
                        break;
                    }



                    Vector3     worldPos  = new Vector3(x * xSideLength, y * ySideLength, z * zSideLength);
                    Vector3Int  globalPos = new Vector3Int(globalLocX * skipDist, globalLocY * skipDist, globalLocZ * skipDist);
                    Vector3Int  localPos  = new Vector3Int(x, y, z);
                    GridPoint[] grid      = new GridPoint[8];
                    for (int i = 0; i < grid.Length; i++)
                    {
                        grid[i] = GetGridPoint(worldPos + locOffset[i], localPos + directionOffsets[i], globalPos + globalOffsets[i]);
                    }
                    ProcessBlock(grid, 0);
                    //GeneratedBlocks++;
                }
            }
        }

        watch_overall.Stop();

        UnityGameServer.Logger.Log("GPU_ColumnBuilder Generate(): Overall: {0}", watch_overall.Elapsed);

        if (GPU_Accelorated_Noise)
        {
            ((GPU_TerrainSampler)Sampler).Dispose_ISO_Types();
        }

        UnityGameServer.Logger.Log("Min: {0}, Max: {1}", Sampler.GetMin(), Sampler.GetMax());
        UnityGameServer.Logger.Log("Res.Min: {0}, Res.Max: {1}", Result.Min, Result.Max);
        UnityGameServer.Logger.Log("Y_Min: {0}, Y_Max: {1}", Y_Min, Y_Max);

        return(Result);
    }
예제 #4
0
        public void Generate()
        {
            if (empty)
            {
                return;
            }

            if (!Initialized)
            {
                return;
            }

            Stopwatch watch = new Stopwatch();

            watch.Start();

            //surfaceBlocksCount = 0;
            GeneratedBlocks = 0;

            int cx = Location.x;
            int cy = Location.y;
            int cz = Location.z;

            int xStart = cx * ChunkSizeX;
            int xEnd   = cx * ChunkSizeX + ChunkSizeX;

            int yStart = cy * ChunkSizeY;
            int yEnd   = cy * ChunkSizeY + ChunkSizeY;

            int zStart = cz * ChunkSizeZ;
            int zEnd   = cz * ChunkSizeZ + ChunkSizeZ;

            int globalLocX = 0;
            int globalLocY = 0;
            int globalLocZ = 0;

            int x = 0;
            int y = 0;
            int z = 0;

            int Y_Min = 0;
            int Y_Max = ChunkSizeY;

            int heightmapMin = VoxelConversions.WorldToVoxel(new Vector3(0, Math.Max(0, (float)Sampler.GetMin() - Depth), 0)).y;

            Logger.Log("heightmapMin: {0}", heightmapMin);

            int heightmapMin_local = VoxelConversions.GlobalToLocalChunkCoord(new Vector3Int(0, heightmapMin, 0)).y;

            Logger.Log("heightmapMin_local: {0}", heightmapMin_local);

            int heightmapMax = VoxelConversions.WorldToVoxel(new Vector3(0, Math.Min(SmoothVoxelSettings.MeterSizeY, (float)Sampler.GetMax()), 0)).y;

            Logger.Log("heightmapMax: {0}", heightmapMax);

            int heightmapMax_local = VoxelConversions.GlobalToLocalChunkCoord(new Vector3Int(0, heightmapMax, 0)).y;

            Logger.Log("heightmapMax_local: {0}", heightmapMax_local);

            Logger.Log("Generating with updated mode {0}: {1}", updateMode.ToString(), DebugTimer.Elapsed());

            if (updateMode == UpdateMode.EmptyToHeightmap)
            {
                return;
            }
            else if (updateMode == UpdateMode.EmptyToReduced || updateMode == UpdateMode.EmptyToFull ||
                     updateMode == UpdateMode.HeightmapToReduced || updateMode == UpdateMode.HeightmapToFull)
            {
                //Min = int.MaxValue;
                //Max = int.MinValue;
                switch (updateMode)
                {
                case UpdateMode.EmptyToReduced:
                case UpdateMode.HeightmapToReduced:
                    Y_Min   = heightmapMin_local;
                    yStart += Y_Min;
                    Y_Max   = heightmapMax_local;
                    break;

                case UpdateMode.EmptyToFull:
                case UpdateMode.HeightmapToFull:
                    Y_Max = heightmapMax_local;
                    break;
                }
            }
            else if (updateMode == UpdateMode.ReducedToFull)
            {
                Y_Max = heightmapMin_local;
                Logger.Log("ReducedToFull: " + heightmapMin_local);
            }

            //else if(updateMode == UpdateMode.)

            //if (LoadedFromDisk && !ReduceDepth && Max_Mode == LOD_Mode.Full)
            //    Y_Max = VoxelConversions.GlobalToLocalChunkCoord(VoxelConversions.WorldToVoxel(new Vector3(0, (float)Sampler.GetMin() - Depth, 0))).y;

            UnityGameServer.Logger.Log("Column: Y_Min: {0}, Y_Max: {1}", Y_Min, Y_Max);

            col_data.Allocate(ChunkSizeX, ChunkSizeY, ChunkSizeZ);
            builder.Generate(Y_Min, Y_Max, xStart, zStart);


            /*for (globalLocY = yStart, y = Y_Min; y < Y_Max; globalLocY++, y++)
             * {
             *
             *  Max = Mathf.Max(y, Max);
             *  Min = Mathf.Min(y, Min);
             *
             *  for (globalLocZ = zStart, z = 0; z < ChunkSizeZ; globalLocZ++, z++)
             *  {
             *      for (globalLocX = xStart, x = 0; x < ChunkSizeX; globalLocX++, x++)
             *      {
             *          if (deactivated)
             *          {
             *              break;
             *          }
             *
             *          Vector3 worldPos = new Vector3(x * xSideLength, y * ySideLength, z * zSideLength);
             *          Vector3Int globalPos = new Vector3Int(globalLocX * skipDist, globalLocY * skipDist, globalLocZ * skipDist);
             *          Vector3Int localPos = new Vector3Int(x, y, z);
             *          GridPoint[] grid = new GridPoint[8];
             *          for (int i = 0; i < grid.Length; i++)
             *              grid[i] = GetGridPoint(worldPos + locOffset[i], localPos + directionOffsets[i], globalPos + globalOffsets[i]);
             *          ProcessBlock(grid, 0);
             *          GeneratedBlocks++;
             *      }
             *  }
             * }*/

            watch.Stop();
            Logger.Log("Generated from {0} to {1}: " + DebugTimer.Elapsed(), Y_Min, Y_Max);
            Logger.Log("Generated surface blocks: {0}", col_data.surfaceBlocksCount);
        }