示例#1
0
    public static List <PTwo> PointsInsideBorderOfQuad(Quad area, int inset)
    {
        List <PTwo> result = new List <PTwo>();
        SimpleRange sRange = area.sSimpleRange();
        SimpleRange tRange = area.tSimpleRange();

        if (inset > sRange.range / 2 || inset > tRange.range / 2)
        {
            return(result);
        }

        int outerNudge = inset + 1;

        int start         = sRange.start + inset;
        int otherDim      = tRange.start + inset;
        int otherDimOuter = tRange.extent() - outerNudge;

        for (int i = start; i < sRange.extent() - outerNudge; ++i)
        {
            result.Add(new PTwo(i, otherDim));
            result.Add(new PTwo(i, otherDimOuter));
        }

        start         = tRange.start + inset + 1;
        otherDim      = sRange.start + inset;
        otherDimOuter = sRange.extent() - outerNudge;

        for (int i = start; i < tRange.extent() - outerNudge - 1; ++i)
        {
            result.Add(new PTwo(otherDim, i));
            result.Add(new PTwo(otherDimOuter, i));
        }

        return(result);
    }
示例#2
0
    public SimpleRange considerLightValuesFromOther(LightLevelTrapezoid other, bool subtract, SimpleRange withinRange, float influenceFactor)
    {
        int minInfluenceIndex = 258;
        int maxInfluenceIndex = 0;

        if (!SimpleRange.RangesIntersect(trapezoid.span, withinRange))
        {
            return(new SimpleRange(0, 0));
        }

        byte influenceFromOther = (byte)(Window.LIGHT_LEVEL_MAX * influenceFactor - Window.UNIT_FALL_OFF_BYTE);

        withinRange = SimpleRange.IntersectingRange(withinRange, new SimpleRange(0, NoisePatch.patchDimensions.z));         // safer...
        if (withinRange.isErsatzNull())
        {
            return(new SimpleRange(0, 0));
        }

        for (int i = withinRange.start; i < withinRange.extent(); ++i)
        {
            byte myCurrentLightLevel = zLightLevels[i];
            byte othersLightLevel    = other.zLightLevels[i];

//			if (myCurrentLightLevel == Window.LIGHT_LEVEL_MAX_BYTE)
//				continue;

            byte influenceAmount = 0;

            if (myCurrentLightLevel <= influenceFromOther)
            {
//				if (subtract) {
//				} else {
                influenceAmount = (byte)(other.zLightLevels[i] - Window.UNIT_FALL_OFF_BYTE);
//				}
            }
            else
            {
                //cheap0
                influenceAmount = (byte)(myCurrentLightLevel + (influenceFromOther / 2f * (subtract? -1 : 1)));
            }
            zLightLevels[i] = (byte)Mathf.Clamp(influenceAmount, 0, (int)Window.LIGHT_LEVEL_MAX_BYTE);

            minInfluenceIndex = Mathf.Min(minInfluenceIndex, i);
            maxInfluenceIndex = Mathf.Max(maxInfluenceIndex, i + 1);
        }

        if (maxInfluenceIndex == 0)
        {
            return(new SimpleRange(0, 0));
        }

        return(SimpleRange.SimpleRangeWithStartAndExtent(minInfluenceIndex, maxInfluenceIndex));
    }
示例#3
0
 private static bool RangeAboveSurface(SimpleRange range, SurroundingSurfaceValues ssvs)
 {
     foreach (Direction dir in DirectionUtil.TheDirectionsXZ())
     {
         int height = ssvs.valueForDirection(dir);
         if (height < range.extent())
         {
             return(true);
         }
     }
     return(false);
 }
示例#4
0
    private void updateColumnsWithHigherHighestSurface(List <Range1D> heightRanges, Coord pRelCoord, SurroundingSurfaceValues ssvs, bool shouldPropagateLight)
    {
        b.bug("update w higher highest surf");
        int         x = pRelCoord.x, y = pRelCoord.y, z = pRelCoord.z;
        SimpleRange justCoveredColumn        = new SimpleRange(y, 1);
        Range1D     highest                  = heightRanges[heightRanges.Count - 1];
        LightColumn newlico                  = null;
        int         lowestSurroundingSurface = ssvs.lowestValue();

        if (highest.range == 1)
        {
            AssertUtil.Assert(heightRanges.Count > 1, "what we just 'covered' bedrock?");
            Range1D secondHighest = heightRanges[heightRanges.Count - 2];
            justCoveredColumn = new SimpleRange(secondHighest.extent(), y + 1 - secondHighest.extent());              //(extent - start)

            //new column
            SimpleRange newColRange = justCoveredColumn;
            newColRange.range--;

            newlico = new LightColumn(PTwo.PTwoXZFromCoord(pRelCoord), 0, newColRange);
            m_lightColumnMap.addColumnAt(newlico, x, z);

            if (newColRange.extent() > lowestSurroundingSurface)
            {
                newlico.lightLevel = Window.LIGHT_LEVEL_MAX_BYTE;
                surfaceExposedColumns.Add(newlico);
            }
        }

        List <LightColumn> adjColsFlushToJustCovered = m_lightColumnMap.lightColumnsAdjacentToAndFlushWithSimpleRangeAndPoint(justCoveredColumn, new PTwo(x, z));

        foreach (LightColumn adjcol in adjColsFlushToJustCovered)
        {
            //adj cols could still be above
            if (adjcol.extent() <= y)
            {
                //get surrounding surface for these?
                SurroundingSurfaceValues assvs = m_noisePatch.surfaceValuesSurrounding(adjcol.coord);
                if (adjcol.extent() <= assvs.lowestValue())
                {
                    surfaceExposedColumns.Remove(adjcol);
                    adjcol.lightLevel = 0;
                    // put back?
                }
            }
        }

        resetAndUpdateColumnsWithin(LightDomainAround(x, z));
    }
示例#5
0
    public static List <NoiseCoord> NoiseCoordsWithingQuad(Quad area)
    {
        SimpleRange       sRange = area.sSimpleRange();
        SimpleRange       tRange = area.tSimpleRange();
        List <NoiseCoord> result = new List <NoiseCoord>();

        for (int i = sRange.start; i < sRange.extent(); ++i)
        {
            for (int j = tRange.start; j < tRange.extent(); ++j)
            {
                result.Add(new NoiseCoord(i, j));
            }
        }

        return(result);
    }
示例#6
0
//	public void addDiscontinuityRangeBeyondEndAtZExtent(SimpleRange newDisRange, int newZExtent)
    public void incorporateStartFlushWithExtentOther(LightLevelTrapezoid other)
    {
        AssertUtil.Assert(this.trapezoid.span.extent() == other.trapezoid.span.start,
                          "adding ranges from other but not getting other.start == this.extent: " +
                          "other start: " + other.trapezoid.span.start + "\nthis extent: " + this.trapezoid.span.extent());

        SimpleRange otherSpan  = other.trapezoid.span;
        int         newZExtent = otherSpan.extent();

        copyHeightAndLightFromOther(other);
//		this.zHeightRanges[newZExtent] = newDisRange;

        this.trapezoid.endRange   = other.trapezoid.endRange;       // CONSIDER: whether we need trapezoid end height dims at all at this point // SimpleRange.Average(this.trapezoid.endRange, newDisRange);
        this.trapezoid.span.range = newZExtent - this.trapezoid.span.start;

        assertSpanDebug("adding ranges from other");
    }
示例#7
0
    public int shortestDifferenceWith(int y, int z)
    {
        // slightly cheapo
        SimpleRange compareRange = this.lightLevelTrapezoid.heightAt(z);         // this.startRange;

//		if (z > this.spanStart + this.spanRange/2)
//			compareRange = this.endRange;

        if (compareRange.contains(y))
        {
            return(0);
        }

        if (y > compareRange.start)         // y is above entire range
        {
            return(compareRange.extent() - y);
        }

        return(compareRange.start - y);
    }
示例#8
0
    private void resetLightColumnsWithin(Quad area)
    {
        SimpleRange srange = area.sSimpleRange();
        SimpleRange trange = area.tSimpleRange();

        ChunkManager.debugLinesAssistant.clearColumns();         //DBG

        for (int i = srange.start; i < srange.extent(); ++i)
        {
            for (int j = trange.start; j < trange.extent(); ++j)
            {
                DiscreteDomainRangeList <LightColumn> lilcoms = m_lightColumnMap[i, j];
                if (lilcoms == null)
                {
                    continue;
                }
                for (int k = 0; k < lilcoms.Count; ++k)
                {
                    lilcoms[k].resetLightLevel();                     //WANT
                }
            }
        }
    }