예제 #1
0
        public NodeLocation(ChunkKey chunk, NodeKey key)
        {
            myChunk = chunk;
            myNode  = key;

            updateInternalValues();
        }
예제 #2
0
        public void tick()
        {
            while (myShouldQuit == false)
            {
                UInt64 key;
                while (myRequestedLocations.Count > 0)
                {
                    lock (myRequestedLocations)
                    {
                        key = myRequestedLocations.Dequeue();
                    }

                    Chunk c = buildChunk(key);
                    myGeneratedChunks.Enqueue(c);
                }

                //forcing a rebuild of a known chunk
                while (myForcedRebuild.Count > 0)
                {
                    UInt64 kkey;
                    myForcedRebuild.TryTake(out kkey);
                    ChunkKey ck = new ChunkKey(kkey);
                    Chunk    c  = buildChunk(kkey);
                    c.changeNumber++; //since this is a new one
                    myGeneratedChunks.Enqueue(c);
                }

                Thread.Sleep(10);
            }
        }
예제 #3
0
 public Region(TerrainGenerator generator, UInt64 id)
 {
     myOrigin    = ChunkKey.createWorldLocationFromKey(id);
     myGenerator = generator;
     myId        = id;
     Info.print("Creating region {0}", id);
 }
예제 #4
0
        public NodeLocation(UInt32 x, UInt32 y, UInt32 z, int depth)
        {
            nx = x;
            ny = y;
            nz = z;

            UInt32 lx, ly, lz;
            UInt64 cx, cy, cz;

            //get the bottom 10 bits for the local node location (within a chunk)
            lx = nx & 0x3ff;
            ly = ny & 0x3ff;
            lz = nz & 0x3ff;

            myNode = NodeKey.combineCode(lx, ly, lz, depth);

            //this is the chunk biased number
            //get the top 21 bits
            cx = (nx >> 10) & 0x1fffff;
            cy = (ny >> 10) & 0x1fffff;
            cz = (nz >> 10) & 0x1fffff;
            UInt64 chunkKey = (cx << 42) + (cy << 21) + cz;

            myChunk = new ChunkKey(chunkKey);
        }
예제 #5
0
        public void buildRequestedChunkList()
        {
            myRequestedChunks.Clear();

            //determine all the chunks that should be in memory
            for (int x = -loadedSize; x <= loadedSize; x++)
            {
                for (int y = -2; y < elevation; y++)
                {
                    for (int z = -loadedSize; z <= loadedSize; z++)
                    {
                        Vector3i temp = interestChunk;
                        temp.X += x;
                        temp.Y  = y;
                        temp.Z += z;
                        UInt64 key = ChunkKey.createKey(temp);
                        myRequestedChunks.Add(key);
                    }
                }
            }

            UInt64 interestKey = ChunkKey.createKey(interestChunk);

            myRequestedChunks.Sort((x, y) => (x - interestKey).CompareTo(y - interestKey));
        }
예제 #6
0
        public void regenCurrentChunk()
        {
            ChunkKey ck = new ChunkKey(myPager.interestPoint);

            myChunks.Remove(ck.myKey);
            myTerrainSource.forceRebuild(ck.myKey);
        }
예제 #7
0
        public UInt64 regionId(Vector3 pos)
        {
            Vector3 ret = new Vector3();

            ret.X = (float)Math.Floor(pos.X / WorldParameters.theWorldSize);
            ret.Y = 0;// (float)Math.Floor(pos.Y / WorldParameters.theWorldSize);
            ret.Z = (float)Math.Floor(pos.Z / WorldParameters.theWorldSize);

            return(ChunkKey.createKeyFromWorldLocation(ret));
        }
예제 #8
0
        public Chunk findChunk(ChunkKey chunkKey)
        {
            Chunk chunk = null;

            if (myChunks.TryGetValue(chunkKey.myKey, out chunk) == true)
            {
                //Warn.print("Cannot find chunk");
            }

            return(chunk);
        }
예제 #9
0
        public Node findNode(Vector3 worldLocation)
        {
            UInt64 key = ChunkKey.createKeyFromWorldLocation(worldLocation);
            Chunk  chunk;

            if (myChunks.TryGetValue(key, out chunk) == false)
            {
                return(null);
            }

            return(chunk.findNodeContaining(worldLocation));
        }
예제 #10
0
        public static Chunk chunkIntersecting(World world, Vector3 point)
        {
            UInt64 key   = ChunkKey.createKeyFromWorldLocation(point);
            Chunk  chunk = null;

            if (world.chunks.TryGetValue(key, out chunk) == true)
            {
                return(chunk);
            }

            return(null);
        }
예제 #11
0
        public Chunk findOrCreateChunk(ChunkKey chunkKey)
        {
            Chunk chunk = findChunk(chunkKey);

            if (chunk == null)
            {
                chunk = new Chunk(chunkKey.myLocation);
                addChunk(chunk);
                myTerrainSource.chunkCache.updateChunk(chunk);
            }

            return(chunk);
        }
예제 #12
0
        public NodeLocation(Vector3 worldLoc, int depth)
        {
            myChunk = new ChunkKey(worldLoc);
            Vector3 local = worldLoc - myChunk.myLocation;
            UInt32  lx, ly, lz;

            lx = (UInt32)(local.X * WorldParameters.theLeafRatio);
            ly = (UInt32)(local.Y * WorldParameters.theLeafRatio);
            lz = (UInt32)(local.Z * WorldParameters.theLeafRatio);

            myNode = NodeKey.combineCode(lx, ly, lz, depth);

            updateInternalValues();
        }
예제 #13
0
        public void setInterest(Vector3 loc)
        {
            interestPoint = loc;

            Vector3i location = ChunkKey.createIdFromWorldLocation(loc);

            if (location == interestChunk)
            {
                return;
            }

            interestChunk = location;

            buildRequestedChunkList();
            requestMissingChunks();
            purgeExcessChunks();
        }
예제 #14
0
        public Chunk buildChunk(UInt64 key)
        {
            Vector3 pos = ChunkKey.createWorldLocationFromKey(key);
            UInt64  id  = regionId(pos);

//          Region region;
//          if (myRegionGenerators.TryGetValue(id, out region) == false)
//          {
//             region = new Region(this, myTerrainModules, id);
//             region.world = myWorld;
//             myRegionGenerators.Add(id, region);
//          }
//
//          Chunk chunk = region.buildChunk(key);
//         return chunk;
            return(null);
        }
예제 #15
0
        public Chunk buildChunk(UInt64 key)
        {
            Vector3 pos = ChunkKey.createWorldLocationFromKey(key);
            UInt64  id  = regionId(pos);
            Region  region;

            if (myRegionGenerators.TryGetValue(id, out region) == false)
            {
                region = new Region(this, id);
                region.init(myTerrainConfig["terrain"]);
                region.world = myWorld;
                myRegionGenerators.Add(id, region);
            }

            Chunk chunk = region.buildChunk(key);

            return(chunk);
        }
예제 #16
0
 public Chunk(Vector3 location)
 {
     myLocation = location;
     myChunkKey = new ChunkKey(myLocation);
     reset();
 }
예제 #17
0
        public Chunk buildChunk(UInt64 key)
        {
            Vector3 position = ChunkKey.createWorldLocationFromKey(key);

            UInt32 air = 0;

            UInt32[] mats = new UInt32[12]
            {
                Hash.hash("snow"),           //Ice 0
                Hash.hash("gravel"),         //Tundra 1
                Hash.hash("sand"),           //Desert 2
                Hash.hash("grass"),          //Grassland 3
                Hash.hash("dirt"),           //Savanna 4
                Hash.hash("log_spruce"),     //TemperateSeasonalForest 5
                Hash.hash("log_oak"),        //TropicalSeasonalForest 6
                Hash.hash("marble"),         //Taiga 7
                Hash.hash("finished_oak"),   //TemperateRainforest 8
                Hash.hash("finished_birch"), //TropicalRainforest 9
                Hash.hash("sandstone"),      //ShallowOcean 10
                Hash.hash("bedrock")         //DeepOcean 11
            };

            UInt32 water = Hash.hash("water");

            //how big a chunk are we taking
            int   count    = WorldParameters.theNodeCount;
            float stepSize = WorldParameters.theChunkSize / count; //with a count of 32 and the default cube of 102.4m this is a stepsize of 3.2m
            bool  hasSolid = false;
            bool  hasAir   = false;

            float px = position.X / WorldParameters.theWorldSize;
            float pz = position.Z / WorldParameters.theWorldSize;

            float  elevation  = mySampler.get(px, pz, 0) * WorldParameters.theMaxElevation;
            float  biomeFloat = mySampler.get(px, pz, 3);
            UInt32 biome      = BitConverter.ToUInt32(BitConverter.GetBytes(biomeFloat), 0);

            biome = biome & 0xf;


            //generate point cloud
            UInt32[, ,] pc = new UInt32[count, count, count];
            for (int x = 0; x < count; x++)
            {
                for (int z = 0; z < count; z++)
                {
                    for (int y = 0; y < count; y++)
                    {
                        double ny = position.Y + (y * stepSize);

                        if (ny < elevation) //underground
                        {
                            hasSolid    = true;
                            pc[x, y, z] = mats[biome];
                        }
                        else
                        {
                            if (ny < (waterLevel * WorldParameters.theMaxElevation))
                            {
                                pc[x, y, z] = water;
                                hasSolid    = true;
                            }
                            else
                            {
                                pc[x, y, z] = air;
                                hasAir      = true;
                            }
                        }
                    }
                }
            }

            Chunk chunk = new Chunk(position);

            chunk.world = world;
            if (hasSolid == false && hasAir == true)
            {
                chunk.myRoot.materialId = air;
            }
            else
            {
                chunk.fromPointCloud(pc);
            }

            Info.print("Built chunk {0}", chunk.chunkKey.myKey);
            return(chunk);
        }
예제 #18
0
        public List <Chunk> findNeighbors(Chunk chunk, ChunkKey.Neighbor neighbors)
        {
            List <Chunk> ret = new List <Chunk>();
            ChunkKey     k   = chunk.chunkKey;

            if ((neighbors & ChunkKey.Neighbor.LEFT) == ChunkKey.Neighbor.LEFT)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.LEFT)));
            }
            if ((neighbors & ChunkKey.Neighbor.RIGHT) == ChunkKey.Neighbor.RIGHT)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.RIGHT)));
            }
            if ((neighbors & ChunkKey.Neighbor.BOTTOM) == ChunkKey.Neighbor.BOTTOM)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.BOTTOM)));
            }
            if ((neighbors & ChunkKey.Neighbor.TOP) == ChunkKey.Neighbor.TOP)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.TOP)));
            }
            if ((neighbors & ChunkKey.Neighbor.FRONT) == ChunkKey.Neighbor.FRONT)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.FRONT)));
            }
            if ((neighbors & ChunkKey.Neighbor.BACK) == ChunkKey.Neighbor.BACK)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.BACK)));
            }
            if ((neighbors & ChunkKey.Neighbor.LBF) == ChunkKey.Neighbor.LBF)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.LBF)));
            }
            if ((neighbors & ChunkKey.Neighbor.LB) == ChunkKey.Neighbor.LB)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.LB)));
            }
            if ((neighbors & ChunkKey.Neighbor.LBB) == ChunkKey.Neighbor.LBB)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.LBB)));
            }
            if ((neighbors & ChunkKey.Neighbor.BF) == ChunkKey.Neighbor.BF)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.BF)));
            }
            if ((neighbors & ChunkKey.Neighbor.BB) == ChunkKey.Neighbor.BB)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.BB)));
            }
            if ((neighbors & ChunkKey.Neighbor.RBF) == ChunkKey.Neighbor.RBF)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.RBF)));
            }
            if ((neighbors & ChunkKey.Neighbor.RB) == ChunkKey.Neighbor.RB)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.RB)));
            }
            if ((neighbors & ChunkKey.Neighbor.RBB) == ChunkKey.Neighbor.RBB)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.RBB)));
            }
            if ((neighbors & ChunkKey.Neighbor.LF) == ChunkKey.Neighbor.LF)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.LF)));
            }
            if ((neighbors & ChunkKey.Neighbor.BL) == ChunkKey.Neighbor.BL)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.BL)));
            }
            if ((neighbors & ChunkKey.Neighbor.RF) == ChunkKey.Neighbor.RF)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.RF)));
            }
            if ((neighbors & ChunkKey.Neighbor.BR) == ChunkKey.Neighbor.BR)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.BR)));
            }
            if ((neighbors & ChunkKey.Neighbor.LTF) == ChunkKey.Neighbor.LTF)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.LTF)));
            }
            if ((neighbors & ChunkKey.Neighbor.LT) == ChunkKey.Neighbor.LT)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.LT)));
            }
            if ((neighbors & ChunkKey.Neighbor.LTB) == ChunkKey.Neighbor.LTB)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.LTB)));
            }
            if ((neighbors & ChunkKey.Neighbor.TF) == ChunkKey.Neighbor.TF)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.TF)));
            }
            if ((neighbors & ChunkKey.Neighbor.TB) == ChunkKey.Neighbor.TB)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.TB)));
            }
            if ((neighbors & ChunkKey.Neighbor.RTF) == ChunkKey.Neighbor.RTF)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.RTF)));
            }
            if ((neighbors & ChunkKey.Neighbor.RT) == ChunkKey.Neighbor.RT)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.RT)));
            }
            if ((neighbors & ChunkKey.Neighbor.RTB) == ChunkKey.Neighbor.RTB)
            {
                ret.Add(findChunk(k.neighbor(ChunkKey.Neighbor.RTB)));
            }
            return(ret);
        }