bool BuildChunk(int x1, int y1, int z1, ref bool allAir)
        {
            light = game.Lighting;
            PreStretchTiles(x1, y1, z1);
            BlockID *chunkPtr  = stackalloc BlockID[extChunkSize3]; chunk = chunkPtr;
            byte *   countsPtr = stackalloc byte[chunkSize3 * Side.Sides]; counts = countsPtr;
            int *    bitsPtr   = stackalloc int[extChunkSize3]; bitFlags = bitsPtr;

            MemUtils.memset((IntPtr)chunkPtr, 0, 0, extChunkSize3 * sizeof(BlockID));
            if (ReadChunkData(x1, y1, z1, ref allAir))
            {
                return(false);
            }
            MemUtils.memset((IntPtr)countsPtr, 1, 0, chunkSize3 * Side.Sides);

            chunkEndX = Math.Min(x1 + chunkSize, width);
            chunkEndZ = Math.Min(z1 + chunkSize, length);
            Stretch(x1, y1, z1);
            PostStretchTiles(x1, y1, z1);

            int xMax = Math.Min(width, x1 + chunkSize);
            int yMax = Math.Min(height, y1 + chunkSize);
            int zMax = Math.Min(length, z1 + chunkSize);

            for (int y = y1, yy = 0; y < yMax; y++, yy++)
            {
                for (int z = z1, zz = 0; z < zMax; z++, zz++)
                {
                    int chunkIndex = (yy + 1) * extChunkSize2 + (zz + 1) * extChunkSize + (0 + 1);
                    for (int x = x1, xx = 0; x < xMax; x++, xx++)
                    {
                        curBlock = chunk[chunkIndex];
                        if (info.Draw[curBlock] != DrawType.Gas)
                        {
                            int index = ((yy << 8) | (zz << 4) | xx) * Side.Sides;
                            X      = x; Y = y; Z = z;
                            cIndex = chunkIndex;
                            RenderTile(index);
                        }
                        chunkIndex++;
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
        bool BuildChunk(int x1, int y1, int z1, ref bool allAir)
        {
            light = game.Lighting;
            PreStretchTiles(x1, y1, z1);
            BlockID *chunkPtr  = stackalloc BlockID[extChunkSize3]; chunk = chunkPtr;
            byte *   countsPtr = stackalloc byte[chunkSize3 * Side.Sides]; counts = countsPtr;
            int *    bitsPtr   = stackalloc int[extChunkSize3]; bitFlags = bitsPtr;

            MemUtils.memset((IntPtr)chunkPtr, 0, 0, extChunkSize3 * sizeof(BlockID));

            bool allSolid = false;

            fixed(BlockRaw *mapPtr = map.blocks)
            {
                                #if !ONLY_8BIT
                if (BlockInfo.MaxUsed >= 256)
                {
                    ReadChunkData_16Bit(x1, y1, z1, mapPtr, ref allAir, ref allSolid);
                }
                else
                {
                    ReadChunkData_8Bit(x1, y1, z1, mapPtr, ref allAir, ref allSolid);
                }
                                #else
                ReadChunkData_8Bit(x1, y1, z1, mapPtr, ref allAir, ref allSolid);
                                #endif

                if (x1 == 0 || y1 == 0 || z1 == 0 || x1 + chunkSize >= width ||
                    y1 + chunkSize >= height || z1 + chunkSize >= length)
                {
                    allSolid = false;
                }

                if (allAir || allSolid)
                {
                    return(false);
                }
                light.LightHint(x1 - 1, z1 - 1, mapPtr);
            }

            MemUtils.memset((IntPtr)countsPtr, 1, 0, chunkSize3 * Side.Sides);
            int xMax = Math.Min(width, x1 + chunkSize);
            int yMax = Math.Min(height, y1 + chunkSize);
            int zMax = Math.Min(length, z1 + chunkSize);

            chunkEndX = xMax; chunkEndZ = zMax;
            Stretch(x1, y1, z1);
            PostStretchTiles(x1, y1, z1);

            for (int y = y1, yy = 0; y < yMax; y++, yy++)
            {
                for (int z = z1, zz = 0; z < zMax; z++, zz++)
                {
                    int chunkIndex = (yy + 1) * extChunkSize2 + (zz + 1) * extChunkSize + (0 + 1);
                    for (int x = x1, xx = 0; x < xMax; x++, xx++)
                    {
                        curBlock = chunk[chunkIndex];
                        if (BlockInfo.Draw[curBlock] != DrawType.Gas)
                        {
                            int index = ((yy << 8) | (zz << 4) | xx) * Side.Sides;
                            X      = x; Y = y; Z = z;
                            cIndex = chunkIndex;
                            RenderTile(index);
                        }
                        chunkIndex++;
                    }
                }
            }
            return(true);
        }