Ejemplo n.º 1
0
    public void editLightWithAdjacentNonTerminatingSurfaceHeightAtPatchRelativeZ(int surfaceHeight, int patchRelZ)
    {
        if (!this.spanContainsZ(patchRelZ))
        {
            return;
        }

        int  heightAt      = this.lightLevelTrapezoid.heightAt(patchRelZ).extent();
        byte lightAtBefore = this.lightLevelAt(patchRelZ);

        if (surfaceHeight < heightAt)
        {
            this.addLightLevelsWithAdjacentSurfaceHeightSpanOffset(surfaceHeight, patchRelZ - this.spanStart);
        }
        else
        {
            this.lightLevelTrapezoid.removeLightLevelsBySubtractingAdjacentSurface(patchRelZ);
        }

        //INFLUENCE...
        int deltaLight = (int)(lightAtBefore - this.lightLevelAt(patchRelZ));

        if (Mathf.Abs(deltaLight) > (int)UNIT_FALL_OFF_BYTE)
        {
            SimpleRange influenceRange = SimpleRange.SimpleRangeWithStartAndExtent(patchRelZ - INFLUENCE_RADIUS, patchRelZ + INFLUENCE_RADIUS);
            influenceRange = SimpleRange.IntersectingRange(influenceRange, new SimpleRange(0, NoisePatch.patchDimensions.z));             //wimp out (need other noisepatch windows too)
            influenceNeighborsInDirectionWithinZRange(Direction.xpos, influenceRange, INFLUENCE_RADIUS, deltaLight > 0);
            influenceNeighborsInDirectionWithinZRange(Direction.xneg, influenceRange, INFLUENCE_RADIUS, deltaLight > 0);
        }
    }
Ejemplo n.º 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));
    }
Ejemplo n.º 3
0
    private void extendCurtainToIncludeWocoZ(int woco_z, bool extendInZPosForMiddle, Range1D adjacentSurfaceContinuityZPosNeg, Range1D airRange, bool setTerminalStatus)
    {
        // greater than end
        if (woco_z >= this.worldEndZ)
        {
            ZCurtainUnit lastcu = sections[sections.Count - 1];
            lastcu.zRange = lastcu.zRange.extendRangeToInclude(woco_z);
            sections[sections.Count - 1] = lastcu;
            if (setTerminalStatus)
            {
                setDiscontinuityEndWithSurfaceRange(adjacentSurfaceContinuityZPosNeg, airRange);
            }
            return;
        }

        if (woco_z <= this.worldStartZ)
        {
            ZCurtainUnit firstcu = sections[0];
            firstcu.zRange = firstcu.zRange.extendRangeToInclude(woco_z);
            sections[0]    = firstcu;
            if (setTerminalStatus)
            {
                setDiscontinuityStartWithSurfaceRange(adjacentSurfaceContinuityZPosNeg, airRange);
            }
            return;
        }

        if (sections.Count == 1)
        {
            ZCurtainUnit zcu = sections[0];
            if (zcu.zRange.contains(woco_z))
            {
                return;
            }
        }

        if (sections.Count < 2)
        {
            return;
        }         // can't be anthing more to do!

        // Between ranges
        // now we need bool extend in z pos

        SimpleRange  zRange;
        SimpleRange  nextZRange;
        bool         combineWithNext = false;
        int          i = 0;
        ZCurtainUnit zcurtain_unit;
        ZCurtainUnit nextZCurtain_unit;

        for (; i < sections.Count - 1; ++i)
        {
            zcurtain_unit     = sections[i];
            nextZCurtain_unit = sections[i + 1];

            zRange     = zcurtain_unit.zRange;
            nextZRange = nextZCurtain_unit.zRange;

            if (zRange.contains(woco_z))
            {
                return;
            }

            if (zRange.extent() <= woco_z && nextZRange.start > woco_z)
            {
                if (extendInZPosForMiddle)
                {
                    zRange = SimpleRange.SimpleRangeWithStartAndExtent(zRange.start, woco_z + 1);
                }
                else
                {
                    nextZRange = SimpleRange.SimpleRangeWithStartAndExtent(woco_z, nextZRange.extent());
                }

                //connected up now?
                if (zRange.extent() == nextZRange.start)
                {
                    zRange.range           += nextZRange.range;
                    zcurtain_unit.endIsOpen = nextZCurtain_unit.endIsOpen;
                    sections.RemoveAt(i + 1);                     // remove next
                }
                else
                {
                    nextZCurtain_unit.zRange = nextZRange;
                    sections[i + 1]          = nextZCurtain_unit;
                }

                zcurtain_unit.zRange = zRange;
                sections[i]          = zcurtain_unit;
                break;
            }
        }
    }