예제 #1
0
 /// <summary>
 /// Clears a single voxel
 /// </summary>
 /// <param name="voxelIndex">Index of voxel in the chunk</param>
 /// <param name="light">Light intensity left at the empty position</param>
 public void ClearVoxel(int voxelIndex, byte light)
 {
     if (lightSources != null)
     {
         int lightSourcesCount = lightSources.Count;
         for (int k = 0; k < lightSourcesCount; k++)
         {
             LightSource ls = lightSources [k];
             if (ls.voxelIndex == voxelIndex && ls.gameObject != null)
             {
                 DestroyImmediate(ls.gameObject);
                 break;
             }
         }
     }
     if (placeholders != null)
     {
         VoxelPlaceholder placeholder;
         if (placeholders.TryGetValue(voxelIndex, out placeholder))
         {
             if (placeholder != null && placeholder.voxelIndex == voxelIndex)
             {
                 DestroyImmediate(placeholder.gameObject);
                 placeholders.Remove(voxelIndex);
             }
         }
     }
     voxels [voxelIndex].Clear(light);
 }
        public bool TryGetValue(int x, int z, out HeightMapInfo[] heights, out int heightIndex)
        {
            int fx = x >> 7;
            int fz = z >> 7;

            heightIndex = ((z - (fz << 7)) << 7) + (x - (fx << 7));
            int key = ((fz + 1024) << 16) + (fx + 1024);

            if (key != lastKey || lastSector < 0)
            {
                int poolIndex;
                if (!sectorsDict.TryGetValue(key, out poolIndex) || key != sectorsPool[poolIndex].key)
                {
                    int leastUsed = int.MaxValue;
                    for (int k = 0; k < sectorsPool.Length; k++)
                    {
                        if (sectorsPool[k].uses < leastUsed)
                        {
                            leastUsed = sectorsPool[k].uses;
                            poolIndex = k;
                        }
                    }

                    // free entry from dictionary
                    HeightMapInfoPoolEntry sector = sectorsPool[poolIndex];
                    if (sector.key > 0)
                    {
                        sectorsDict.Remove(sector.key);
                    }

                    // set new key and add to dictionary
                    sector.key       = key;
                    sector.uses      = 0;
                    sectorsDict[key] = poolIndex;

                    // alloc buffer if it's the first time
                    if (sector.heights == null)
                    {
                        sector.heights = new HeightMapInfo[16384];
                    }
                    else
                    {
                        for (int k = 0; k < sector.heights.Length; k++)
                        {
                            sector.heights[k].biome       = null;
                            sector.heights[k].moisture    = 0;
                            sector.heights[k].groundLevel = 0;
                        }
                    }
                }
                lastKey    = key;
                lastSector = poolIndex;
            }

            HeightMapInfoPoolEntry theSector = sectorsPool[lastSector];

            theSector.uses++;
            heights = theSector.heights;
            return(heights[heightIndex].groundLevel != 0);
        }
예제 #3
0
        public bool TryGetValue(int x, int z, out HeightMapInfo[] heights, out int heightIndex)
        {
            int fx = x >> 8;
            int fz = z >> 8;

            heightIndex = ((z - (fz << 8)) << 8) + (x - (fx << 8));
            uint key = (uint)(((fz + 1024) << 16) + (fx + 1024));

            if (key == lastKey && lastSector != null)
            {
                heights = lastSector;
            }
            else if (!heightSectors.TryGetValue(key, out heights))
            {
                heights = new HeightMapInfo[65536];
                heightSectors.Add(key, heights);
            }
            lastSector = heights;
            lastKey    = key;
            return(heights [heightIndex].groundLevel != 0);
        }