Example #1
0
 private void alertNeighbors(NeighborChunks neighborChunks)
 {
     foreach (var neiPos in new CubeNeighbors6 {
         center = neighborChunks.center
     }.GetNeighbors)
     {
         if (lookup.ContainsKey(neiPos))
         {
             lookup[neiPos].Add(neighborChunks.chunk);
             neighborChunks.Add(lookup[neiPos].chunk);
         }
     }
 }
Example #2
0
        public void Add(Chunk c)
        {
            if (lookup.Keys.Contains(c.ChunkPos))
            {
                //TODO: destroy/clean-up current chunk at chunkPos
            }

            NeighborChunks nc = new NeighborChunks(c);

            nc.OnAddedNeighbor = HandleNewNeighbors;
            if (!lookup.ContainsKey(c.ChunkPos))
            {
                lookup.Add(c.ChunkPos, nc);
            }
            else
            {
                lookup[c.ChunkPos] = nc;
            }

            alertNeighbors(lookup[c.ChunkPos]);
        }
Example #3
0
        public Chunk(Vector3 position, WorldGenerator worldGenerator, Dictionary <Vector3, Chunk> region)
        {
            Position = position;

            Neighbors = new NeighborChunks();

            this.region         = region;
            this.worldGenerator = worldGenerator;

            //Only about ~5% of all blocks are visible
            int total = (int)(0.05 * SIZE * SIZE * HEIGHT);

            blocks = new ushort?[HEIGHT][][];
            for (int y = 0; y < HEIGHT; y++)
            {
                blocks[y] = new ushort?[SIZE][];

                for (int x = 0; x < SIZE; x++)
                {
                    blocks[y][x] = new ushort?[SIZE];
                }
            }

            BiomeData = new byte[SIZE][];
            for (int x = 0; x < BiomeData.Length; x++)
            {
                BiomeData[x] = new byte[SIZE];
            }

            Active = new List <BlockIndex>(total);

            //Initialize mesh
            VertexList            = new List <VertexPositionTextureLight>(6 * total);
            TransparentVertexList = new List <VertexPositionTextureLight>(3 * total);

            //Initialize light
            lightQueue = new Queue <LightNode>(100);
            lightList  = new List <LightNode>(100);

            nodes       = new LightNode[6];
            lightValues = new byte[6];

            lightSourceValues = Assets.LightValues;

            isTransparent = Assets.TransparentBlocks;
            isLightSource = Assets.LightSources;

            chunksToUpdate = new HashSet <Chunk>(5);

            lightMap = new byte[HEIGHT][][];
            for (int y = 0; y < HEIGHT; y++)
            {
                lightMap[y] = new byte[SIZE][];

                for (int x = 0; x < SIZE; x++)
                {
                    lightMap[y][x] = new byte[SIZE];
                }
            }

            lightSources = new List <BlockIndex>(100);

            Initialize();
            InitializeLight();
            CalculateMesh();
        }