示例#1
0
        public static void SaveChunks(List <GameObject> _pool, string _worldName, WorldSeed _seed)
        {
            _WSeed.amplitude = _seed.amplitude;
            _WSeed.frequency = _seed.frequency;
            _WSeed.octave    = _seed.octave;
            _WSeed.reigons   = _seed.reigons.ToArray();
            _WSeed.items     = _seed.randomLoot.ToArray();
            WorldGenSettings wgs = new WorldGenSettings(_worldName, _WSeed, Global.maxChunkSize);

            IOChunks.SaveWorldGenSettings(wgs);
            foreach (GameObject chunk in _pool)
            {
                chunk.GetComponent <MeshBuilder>().SaveChunk();
            }
        }
示例#2
0
 public static void SetChunks(int count, WorldSeed seed)
 {
     chunks = new List <Chunk>();
     Global.chunks.Clear();
     for (int x = -count; x < count; x++)
     {
         for (int z = -count; z < count; z++)
         {
             Chunk newChunk = new Chunk(RandomizeChunk(seed, x, z));
             newChunk.x = x;
             newChunk.z = z;
             chunks.Add(newChunk);
             //chunks[x, z].blocks = RandomizeChunk(seed);
         }
     }
 }
示例#3
0
 //public static Block[,] SetSurroundingBlocks(Block[,] blocks, int x, int z, int left, int right, int front, int back) {
 //    Block[,] bl = blocks;
 //    if(x + 1 < Global.maxChunkSize && bl[x + 1, z].isFloor) {
 //        int[] sub = bl[x + 1, z].subMesh;
 //        bl[x + 1, z].subMesh = CubeMaterial(sub[0], sub[1], left, sub[3], sub[4], sub[5]);
 //    }
 //    if(x - 1 >= 0 && bl[x - 1, z].isFloor) {
 //        int[] sub = bl[x - 1, z].subMesh;
 //        bl[x - 1, z].subMesh = CubeMaterial(sub[0], sub[1], sub[2], right, sub[4], sub[5]);
 //    }
 //    if(z + 1 < Global.maxChunkSize && bl[x, z + 1].isFloor) {
 //        int[] sub = bl[x, z + 1].subMesh;
 //        bl[x, z + 1].subMesh = CubeMaterial(sub[0], sub[1], sub[2], sub[3], front, sub[5]);
 //    }
 //    if(z - 1 >= 0 && bl[x, z - 1].isFloor) {
 //        int[] sub = bl[x, z - 1].subMesh;
 //        bl[x, z - 1].subMesh = CubeMaterial(sub[0], sub[1], sub[2], sub[3], sub[4], back);
 //    }
 //    return bl;
 //}
 public static Block[,] RandomizeChunk(WorldSeed seed, int offSetX, int offSetZ)
 {
     Block[,] blocks = new Block[maxChunkSize, maxChunkSize];
     //First pass
     for (int z = 0; z < maxChunkSize; z++)
     {
         for (int x = 0; x < maxChunkSize; x++)
         {
             float perlin = Mathf.PerlinNoise(x + offSetX * seed.frequency, z + offSetZ * seed.frequency) * seed.amplitude + seed.octave;
             blocks[x, z]         = new Block(x, 0, z, 0, 1, 2, 3, 4, 5);
             blocks[x, z].isFloor = perlin > seed.reigons[0].level ? true : false;
         }
     }
     blocks = SecondPass(seed, blocks);
     return(blocks);
 }
示例#4
0
 public static Block[,] SecondPass(WorldSeed seed, Block[,] blocks)
 {
     Block[,] bl = blocks;
     //Second pass
     for (int z = 0; z < maxChunkSize; z++)
     {
         for (int x = 0; x < maxChunkSize; x++)
         {
             if (!bl[x, z].isFloor)
             {
                 int[] s = seed.reigons[0].subMeshes;
                 // bl = SetSurroundingBlocks(bl, x, z, s[2], s[3], s[4], s[5]);
             }
         }
     }
     return(bl);
 }
示例#5
0
        void OnNewWorldRequest(Point worldPos, WorldSerialized ser, int generation)
        {
            if (worlds.ContainsKey(worldPos))
            {
                Log.Dump(worldPos, "world alrady present");
                return;
            }

            if (!validatorPool.Any())
            {
                throw new Exception("no validators!");
            }

            ManualLock <Point> lck = new ManualLock <Point>(worldLocks, worldPos);

            if (!lck.Locked)
            {
                Log.Dump(worldPos, "can't work, locked");
                return;
            }

            string hostName = "host world " + worldPos;

            if (generation != 0)
            {
                hostName = hostName + " (" + generation + ")";
            }
            OverlayEndpoint validatorHost = new OverlayEndpoint(validatorPool.Random(n => r.Next(n)), new OverlayHostName(hostName));

            WorldInitializer init;
            WorldInfo        newWorld;
            bool             hasSpawn = false;

            if (ser == null)
            {
                WorldSeed seed = new WorldSeed(r.Next(), RandomColor(worldPos));

                if (serverSpawnDensity == 0)
                {
                    if (worldPos == Point.Zero)
                    {
                        hasSpawn = true;
                    }
                }
                else if ((worldPos.x % serverSpawnDensity == 0) && (worldPos.y % serverSpawnDensity == 0))
                {
                    hasSpawn = true;
                }

                newWorld = new WorldInfo(worldPos, validatorHost, generation, hasSpawn);
                init     = new WorldInitializer(newWorld, seed);
            }
            else
            {
                hasSpawn = ser.spawnPos.HasValue;
                newWorld = new WorldInfo(worldPos, validatorHost, generation, hasSpawn);
                init     = new WorldInitializer(newWorld, ser);
            }


            OverlayEndpoint validatorClient = new OverlayEndpoint(validatorHost.addr, Client.hostName);

            RemoteAction
            .Send(Host, validatorClient, ProcessClientDisconnect, MessageType.WORLD_VALIDATOR_ASSIGN, init)
            .Respond(remoteActions, lck, (res, stm) =>
            {
                if (res != Response.SUCCESS)
                {
                    throw new Exception(Log.StDump("unexpected", res));
                }

                //if (hasSpawn == true)
                //    spawnWorlds.Add(worldPos);

                worlds.Add(newWorld.position, newWorld);

                //Log.LogWriteLine("New world " + worldPos + " validated by " + validatorHost.addr);

                foreach (Point p in Point.SymmetricRange(Point.One))
                {
                    if (p == Point.Zero)
                    {
                        continue;
                    }

                    Point neighborPos = p + newWorld.position;

                    if (!worlds.ContainsKey(neighborPos))
                    {
                        continue;
                    }

                    WorldInfo neighborWorld = worlds[neighborPos];

                    MessageWorld(neighborWorld, MessageType.NEW_NEIGHBOR, newWorld);
                    MessageWorld(newWorld, MessageType.NEW_NEIGHBOR, neighborWorld);
                }
            });
        }