Exemplo n.º 1
0
        protected override bool isValidAndReady(Adjustment adjustment, Chunk chunk)
        {
            switch (adjustment.type)
            {
            /// for dirty chunks we can just go for it
            case FocusAdjustmentType.Dirty:
                return(true);

            case FocusAdjustmentType.InFocus:
                /// we can only mesh a newly in focus chunk if it's at the loaded resolution.
                if (chunk.currentResolution == Chunk.Resolution.Loaded)
                {
                    bool necessaryNeighborsAreLoaded = true;
                    bool necessaryNeighborsAreEmpty  = chunk.isEmpty;
                    bool blockingNeighborsAreSolid   = chunk.isSolid;
                    MarchingTetsMeshGenerator.ForEachRequiredNeighbor(adjustment.chunkID, lens.level, (neighborID, neighborChunk) => {
                        bool neighborIsWithinLevelBounds = neighborID.isWithin(Coordinate.Zero, lens.level.chunkBounds);
                        // check if they're loaded. out of bounds chunks will never be loaded and can be skipped
                        if (neighborIsWithinLevelBounds && neighborChunk.currentResolution < Chunk.Resolution.Loaded)
                        {
                            necessaryNeighborsAreLoaded = false;
                            return(false);
                        }

                        // out of bounds chunks will never be loaded and will always be empty, we only need to check in bounds chunks for empty
                        if (neighborIsWithinLevelBounds && !neighborChunk.isEmpty)
                        {
                            necessaryNeighborsAreEmpty = false;
                        }

                        // only in bounds chunks can be solid, so if it's out of bounds or not solid, we mark it so.
                        if (!neighborIsWithinLevelBounds || !neighborChunk.isSolid)
                        {
                            blockingNeighborsAreSolid = false;
                        }

                        return(true);
                    });

                    if (!necessaryNeighborsAreLoaded)
                    {
#if DEBUG
                        chunk.recordEvent($"Chunk is not ready for MeshGenerationAperture job, Necessary neighbors not loaded yet.");
#endif
                        return(false);
                    }

                    /// we don't need to load the mesh if it and it's neighbors are all solid or empty
                    if (blockingNeighborsAreSolid || necessaryNeighborsAreEmpty)
                    {
                        /// set mesh as empty
                        if (chunk.adjustmentLockType == (Chunk.Resolution.Meshed, FocusAdjustmentType.InFocus))
                        {
#if DEBUG
                            chunk.recordEvent($"Chunk can skip MeshGenerationAperture queue, {(blockingNeighborsAreSolid ? "solid chunk is hidden" : "required neighbors are all empty")}. Setting empty mesh");
#endif
                            chunk.setMesh(default);
                            return(false);
                        }