示例#1
0
        /*unsafe bool CalculateHeightmapCoverage(int x1, int z1, int xCount, int zCount, int elemsLeft, int* skip, BlockRaw* mapPtr) {
         *      int prevRunCount = 0;
         *      for (int y = height - 1; y >= 0; y--) {
         *              if (elemsLeft <= 0) return true;
         *              int mapIndex = x1 + width * (z1 + y * length);
         *              int heightmapIndex = x1 + z1 * width;
         *
         *              for (int z = 0; z < zCount; z++) {
         *                      int baseIndex = mapIndex;
         *                      int index = z * xCount;
         *                      for (int x = 0; x < xCount;) {
         *                              int curRunCount = skip[index];
         *                              x += curRunCount; mapIndex += curRunCount; index += curRunCount;
         *
         *                              if (x < xCount && BlockInfo.BlocksLight[mapPtr[mapIndex]]) {
         *                                      int lightOffset = (BlockInfo.LightOffset[mapPtr[mapIndex]] >> Side.Top) & 1;
         *                                      heightmap[heightmapIndex + x] = (short)(y - lightOffset);
         *                                      elemsLeft--;
         *                                      skip[index] = 0;
         *                                      int offset = prevRunCount + curRunCount;
         *                                      int newRunCount = skip[index - offset] + 1;
         *
         *                                      // consider case 1 0 1 0, where we are at 0
         *                                      // we need to make this 3 0 0 0 and advance by 1
         *                                      int oldRunCount = (x - offset + newRunCount) < xCount ? skip[index - offset + newRunCount] : 0;
         *                                      if (oldRunCount != 0) {
         *                                              skip[index - offset + newRunCount] = 0;
         *                                              newRunCount += oldRunCount;
         *                                      }
         *                                      skip[index - offset] = newRunCount;
         *                                      x += oldRunCount; index += oldRunCount; mapIndex += oldRunCount;
         *                                      prevRunCount = newRunCount;
         *                              } else {
         *                                      prevRunCount = 0;
         *                              }
         *                              x++; mapIndex++; index++;
         *                      }
         *                      prevRunCount = 0;
         *                      heightmapIndex += width;
         *                      mapIndex = baseIndex + width; // advance one Z
         *              }
         *      }
         *      return false;
         * }*/

        unsafe bool CalculateHeightmapCoverage_2(int x1, int z1, int xCount, int zCount, int elemsLeft, int *skip)
        {
            int prevRunCount = 0;

            for (int y = height - 1; y >= 0; y--)
            {
                if (elemsLeft <= 0)
                {
                    return(true);
                }
                int mapIndex       = x1 + width * (z1 + y * length);
                int heightmapIndex = x1 + z1 * width;

                for (int z = 0; z < zCount; z++)
                {
                    int baseIndex = mapIndex;
                    int index     = z * xCount;
                    for (int x = 0; x < xCount;)
                    {
                        int curRunCount = skip[index];
                        x += curRunCount; mapIndex += curRunCount; index += curRunCount;

                        int x2 = mapIndex % width;
                        int y2 = mapIndex / oneY;                         // posIndex / (width * length)
                        int z2 = (mapIndex / width) % length;

                        if (x < xCount && BlockInfo.BlocksLight[ChunkHandler.GetBlock(x2, y2, z2)])
                        {
                            int lightOffset = (BlockInfo.LightOffset[ChunkHandler.GetBlock(x2, y2, z2)] >> Side.Top) & 1;
                            heightmap[heightmapIndex + x] = (short)(y - lightOffset);
                            elemsLeft--;
                            skip[index] = 0;
                            int offset      = prevRunCount + curRunCount;
                            int newRunCount = skip[index - offset] + 1;

                            // consider case 1 0 1 0, where we are at 0
                            // we need to make this 3 0 0 0 and advance by 1
                            int oldRunCount = (x - offset + newRunCount) < xCount ? skip[index - offset + newRunCount] : 0;
                            if (oldRunCount != 0)
                            {
                                skip[index - offset + newRunCount] = 0;
                                newRunCount += oldRunCount;
                            }
                            skip[index - offset] = newRunCount;
                            x           += oldRunCount; index += oldRunCount; mapIndex += oldRunCount;
                            prevRunCount = newRunCount;
                        }
                        else
                        {
                            prevRunCount = 0;
                        }
                        x++; mapIndex++; index++;
                    }
                    prevRunCount    = 0;
                    heightmapIndex += width;
                    mapIndex        = baseIndex + width;              // advance one Z
                }
            }
            return(false);
        }
示例#2
0
        int CalcHeightAt(int x, int maxY, int z, int index)
        {
            int mapIndex = (maxY * length + z) * width + x;

            //BlockRaw[] blocks = game.World.blocks1;

            for (int y = maxY; y >= 0; y--)
            {
                //BlockID block = blocks[mapIndex];
                BlockID block = ChunkHandler.GetBlock(x, y, z);
                if (BlockInfo.BlocksLight[block])
                {
                    int offset = (BlockInfo.LightOffset[block] >> Side.Top) & 1;
                    heightmap[index] = (short)(y - offset);
                    return(y - offset);
                }
                mapIndex -= oneY;
            }
            heightmap[index] = -10;
            return(-10);
        }
示例#3
0
        void ResetNeighourChunk(int cx, int cy, int cz, BlockID block,
                                int y, int index, int nY)
        {
            World world = game.World;
            int   minY  = cy << 4;

            int x = index % width;
            int z = (index / width) % length;

            // Update if any blocks in the chunk are affected by light change
            for (; y >= minY; y--)
            {
                BlockID other    = ChunkHandler.GetBlock(x, y, z);
                bool    affected = y == nY?Needs(block, other) : BlockInfo.Draw[other] != DrawType.Gas;

                if (affected)
                {
                    renderer.RefreshChunk(cx, cy, cz); return;
                }
                index -= world.Width * world.Length;
            }
        }
        /// <summary> Updates the underlying block array, and dimensions of this map. </summary>
        public void SetNewMap(BlockRaw[] blocks, int width, int height, int length)
        {
            Width  = width;  MaxX = width - 1;
            Height = height; MaxY = height - 1;
            Length = length; MaxZ = length - 1;

            if (ChunkHandler == null)
            {
                game.LocalPlayer.Position = new Vector3((width / 2), 128, (width / 2));
                ChunkHandler = new ChunkHandler(Width, game);
                ChunkHandler.GenInitialChunks(seed, width);
            }
            else
            {
                game.LocalPlayer.Position = new Vector3((width / 2), 128, (width / 2));
                ChunkHandler.GenInitialChunks(seed, width);
            }

            //blocks1 = blocks;
            if (blocks.Length == 0)
            {
                blocks1 = null;
            }
            //blocks2 = blocks1;
            //HasBlocks = blocks1 != null;
            HasBlocks = (ChunkHandler != null && ChunkHandler.ChunkArray != null);

            //if (blocks.Length != (width * height * length))
            //	throw new InvalidOperationException("Blocks array length does not match volume of map.");

            if (Env.EdgeHeight == -1)
            {
                Env.EdgeHeight = height / 2;
            }
            if (Env.CloudHeight == -1)
            {
                Env.CloudHeight = height + 2;
            }
        }
示例#5
0
        public ChunkGenerator(ChunkHandler ChunkHandler)
        {
            rnd       = new JavaRandom();
            rnd2      = new JavaRandom();
            this.Seed = rnd.GetSeed();
            //chunkXMul = rnd.nextLong();
            //chunkZMul = rnd.nextLong();

            n1 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            n2 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            n3 = new OctaveNoise(6, rnd);

            n4 = new OctaveNoise(8, rnd);

            n5 = new OctaveNoise(8, rnd);
            n6 = new OctaveNoise(8, rnd);

            n7 = new OctaveNoise(8, rnd);

            this.ChunkHandler = ChunkHandler;
        }