예제 #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;
            }
        }