Exemplo n.º 1
0
        bool ReadChunkData(int x1, int y1, int z1, ref bool outAllAir)           // only assign this variable once
        {
            bool allAir = true, allSolid = true;

            fixed(BlockID *mapPtr = map.blocks)
            {
                for (int yy = -1; yy < 17; yy++)
                {
                    int y = yy + y1;
                    if (y < 0)
                    {
                        continue;
                    }
                    if (y >= height)
                    {
                        break;
                    }
                    for (int zz = -1; zz < 17; zz++)
                    {
                        int z = zz + z1;
                        if (z < 0)
                        {
                            continue;
                        }
                        if (z >= length)
                        {
                            break;
                        }

                        int index      = (y * length + z) * width + (x1 - 1 - 1);
                        int chunkIndex = (yy + 1) * extChunkSize2 + (zz + 1) * extChunkSize + (-1 + 1) - 1;

                        for (int xx = -1; xx < 17; xx++)
                        {
                            int x = xx + x1;
                            index++;
                            chunkIndex++;
                            if (x < 0)
                            {
                                continue;
                            }
                            if (x >= width)
                            {
                                break;
                            }
                            BlockID rawBlock = mapPtr[index];

                            allAir            = allAir && info.Draw[rawBlock] == DrawType.Gas;
                            allSolid          = allSolid && info.FullOpaque[rawBlock];
                            chunk[chunkIndex] = rawBlock;
                        }
                    }
                }
                outAllAir = allAir;

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

                if (allAir || allSolid)
                {
                    return(true);
                }
                light.LightHint(x1 - 1, z1 - 1, mapPtr);
                return(false);
            }
        }
Exemplo 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);
        }