Example #1
0
    public void removeColumnsAbove(int x, int y, int z)
    {
        DiscreteDomainRangeList <LightColumn> licoms = this[x, z];

        licoms.RemoveStartAbove(y);
        this[x, z] = licoms;
    }
Example #2
0
    public void addColumnAt(LightColumn newlcolm, int x, int z)
    {
        DiscreteDomainRangeList <LightColumn> lcolms = this[x, z];

        lcolms.Add(newlcolm);
        this[x, z] = lcolms;
    }
Example #3
0
    public void clearColumnsAt(int x, int z)
    {
        DiscreteDomainRangeList <LightColumn> lcolms = this[x, z];

        lcolms.Clear();
        this[x, z] = lcolms;
    }
Example #4
0
    public List <LightColumn> lightColumnsAdjacentToAndFlushWithSimpleRangeAndPoint(SimpleRange colmRange, PTwo coord)
    {
//		PTwo coord = colm.coord;
        List <LightColumn> result = new List <LightColumn>();

        foreach (PTwo surroundingCo in DirectionUtil.SurroundingPTwoCoordsFromPTwo(coord))
        {
            DiscreteDomainRangeList <LightColumn> adjRangeList = this.lightColumnListAtOrNull(surroundingCo.s, surroundingCo.t);
            if (adjRangeList == null)
            {
                continue;
            }
            for (int i = 0; i < adjRangeList.Count; ++i)
            {
                LightColumn adjLightColumn = adjRangeList[i];

                OverlapState overlap = colmRange.overlapStateWith(adjLightColumn.range);
                if (OverLapUtil.OverlapExists(overlap))
                {
                    result.Add(adjLightColumn);
                }
            }
        }
        return(result);
    }
Example #5
0
    private List <LightColumn> columnsThatColumnJustConnectedWith(LightColumn colAtY, int y)
    {
        List <LightColumn> result = new List <LightColumn>();

        bool colExtentMinusOneEqualY = colAtY.extent() - 1 == y;
        bool colStartEqualY          = colAtY.startP == y;

        foreach (PTwo co in DirectionUtil.SurroundingPTwoCoordsFromPTwo(colAtY.coord))
        {
            DiscreteDomainRangeList <LightColumn> licols = m_lightColumnMap[co];
            LightColumn justConnected = null;
            if (colExtentMinusOneEqualY)
            {
                justConnected = licols.rangeWithStartEqual(y);
            }
            else if (colStartEqualY)
            {
                justConnected = licols.rangeWithExtentMinusOneEqual(y);
            }
            else
            {
                justConnected = licols.rangeWithStartAndExtentMinusOneEqual(y);
            }

            if (justConnected != null)
            {
                result.Add(justConnected);
            }
        }
        return(result);
    }
Example #6
0
    public void addReplaceColumn(LightColumn col)
    {
        DiscreteDomainRangeList <LightColumn> cols = this[col.coord];

        cols.RemoveWithRangeEqualTo(col.range);

        cols.Add(col);
        this[col.coord] = cols;
    }
Example #7
0
    //COPY PASTE OF ABOVE FUNC.!
    private void updateSurfaceHeightsInDirection(Quad area, Direction dir)
    {
//		return;

        PTwo nudge      = DirectionUtil.NudgeCoordForDirectionPTwo(dir);
        Axis axis       = DirectionUtil.AxisForDirection(dir);
        PTwo startPoint = area.origin;

        if (DirectionUtil.IsPosDirection(dir))
        {
            if (axis == Axis.X)
            {
                startPoint.t += area.dimensions.t;
            }
            else
            {
                startPoint.s += area.dimensions.s;
            }
        }
        PTwo iterNudge   = PTwo.Abs(nudge).flipSAndT();
        int  length      = axis == Axis.X ? area.dimensions.t : area.dimensions.s;
        PTwo cursorPoint = startPoint;

        List <LightColumn> needUpdateColumns = new List <LightColumn>();

        for (int i = 0; i < length; ++i)
        {
//			DiscreteDomainRangeList<LightColumn> licols = m_lightColumnMap[cursorPoint + nudge];
//			if (licols == null)
//				continue;
            DiscreteDomainRangeList <LightColumn> insideCols = m_lightColumnMap[cursorPoint];
            if (insideCols == null)
            {
                continue;
            }

            int surfaceHeightJustBeyondBorder = this.m_noisePatch.highestPointAtPatchRelativeCoord(cursorPoint + nudge);

            for (int j = 0; j < insideCols.Count; ++j)
            {
                LightColumn insideCol = insideCols[j];
                if (insideCol.heightIsBelowExtent(surfaceHeightJustBeyondBorder))
                {
                    addToSurfaceExposedColumnIfNotContains(insideCol);
                    needUpdateColumns.Add(insideCol);
                }
            }

            cursorPoint += iterNudge;
        }

        foreach (LightColumn col in needUpdateColumns)
        {
            updateColumnAt(col, col.coord, null, PatchQuad);
        }
    }
Example #8
0
    public int countAt(int x, int z)
    {
        DiscreteDomainRangeList <LightColumn> cols = this.lightColumnListAtOrNull(x, z);

        if (cols == null)
        {
            return(0);
        }

        return(cols.Count);
    }
Example #9
0
    public LightColumn columnContaining(int x, int y, int z)
    {
        DiscreteDomainRangeList <LightColumn> cols = this.lightColumnListAtOrNull(x, z);

        if (cols == null)
        {
            return(null);
        }

        return(cols.rangeContaining(y));
    }
Example #10
0
    private void updateRangeListAtXZ(List <Range1D> heightRanges, Coord pRelCoord, bool solidBlockRemoved, SurroundingSurfaceValues ssvs)
    {
        DiscreteDomainRangeList <LightColumn> liCols = m_lightColumnMap[pRelCoord.x, pRelCoord.z];

        if (!solidBlockRemoved && heightRanges.Count <= 1)        // equal zero would be down right silly.
        {
            return;
        }
        // y above highest extent?
        int highestDiscontinuity = liCols.highestExtent();

        int lowestSurroundingLevel = ssvs.lowestValue();

        //CASE WHERE A BLOCK IS ADDED TO THE TOP OF OR OVER TOP OF THE SURFACE
        if (pRelCoord.y > highestDiscontinuity && !solidBlockRemoved)
        {
            // Y MUST BE THE TOP BLOCK?
            int hRangeCount = heightRanges.Count;

            SimpleRange between = discontinuityBetween(heightRanges[hRangeCount - 2], heightRanges[hRangeCount - 1]);
            if (!between.isErsatzNull())
            {
                AssertUtil.Assert(pRelCoord.y == between.extentMinusOne(), "confused. y is " + pRelCoord.y + " between range is " + between.toString());
                int         lightValue = pRelCoord.y >= lowestSurroundingLevel? (int)Window.LIGHT_LEVEL_MAX_BYTE : 0;
                LightColumn licol      = new LightColumn(PTwo.PTwoXZFromCoord(pRelCoord), (byte)lightValue, between);
                liCols.Add(licol);
                return;                 // licol;
            }
            throw new Exception("don't want to be here. we think a block couldn't be placed vertically in between at this point");
        }

        //TODO handle case where y is above surface, solid block removed
        // need to destroy some discon ranges (not incorporate y).
        Range1D highest = heightRanges[heightRanges.Count - 1];

        if (pRelCoord.y > highest.extent())
        {
            liCols.RemoveStartAbove(highest.extent());
        }
        else
        {
            LightColumn newCol = liCols.Incorporate(pRelCoord.y, solidBlockRemoved);
            if (newCol != null)
            {
                newCol.coord = new PTwo(pRelCoord.x, pRelCoord.z);
            }
//			throw new Exception("lots of exceptions. we failed to incorp a solid block added.");
        }
        b.bug("we incorporated a pRelCOord: " + pRelCoord.toString() + "solid removed was: " + solidBlockRemoved);

        m_lightColumnMap[pRelCoord.x, pRelCoord.z] = liCols;
    }
Example #11
0
    private List <LightColumn> columnsAdjacentTo(Coord pco)
    {
        List <LightColumn> result = new List <LightColumn>();

        foreach (Direction dir in DirectionUtil.TheDirectionsXZ())
        {
            Coord adjCo = pco + DirectionUtil.NudgeCoordForDirection(dir);
            DiscreteDomainRangeList <LightColumn> adjLicols = m_lightColumnMap[pco.x, pco.z];
            LightColumn lico = adjLicols.rangeContaining(pco.y);
            if (lico != null)
            {
                result.Add(lico);
            }
        }
        return(result);
    }
Example #12
0
    private void updateQuadBorderInDirection(Quad area, Direction dir)
    {
        PTwo nudge      = DirectionUtil.NudgeCoordForDirectionPTwo(dir);
        Axis axis       = DirectionUtil.AxisForDirection(dir);
        PTwo startPoint = area.origin;

        if (DirectionUtil.IsPosDirection(dir))
        {
            if (axis == Axis.X)
            {
                startPoint.t += area.dimensions.t;
            }
            else
            {
                startPoint.s += area.dimensions.s;
            }
        }
        PTwo iterNudge   = PTwo.Abs(nudge).flipSAndT();
        int  length      = axis == Axis.X ? area.dimensions.t : area.dimensions.s;
        PTwo cursorPoint = startPoint;

        for (int i = 0; i < length; ++i)
        {
            DiscreteDomainRangeList <LightColumn> licols = m_lightColumnMap[cursorPoint + nudge];
            if (licols == null)
            {
                continue;
            }
            DiscreteDomainRangeList <LightColumn> insideCols = m_lightColumnMap[cursorPoint];
            if (insideCols == null)
            {
                continue;
            }

            for (int j = 0; j < licols.Count; ++j)
            {
                LightColumn outsideCol = licols[j];
                for (int k = 0; k < insideCols.Count; ++k)
                {
                    LightColumn insideCol = insideCols[k];
                    updateColumnAt(insideCol, insideCol.coord, outsideCol, area);
                }
            }

            cursorPoint += iterNudge;
        }
    }
Example #13
0
    private void updateColumnsSolidAddedBelowSurface(List <Range1D> heightRanges, Coord pRelCoord,
                                                     SurroundingSurfaceValues ssvs, bool shouldPropagateLight)
    {
        b.bug("adding below surface");
        int x = pRelCoord.x, y = pRelCoord.y, z = pRelCoord.z;
        DiscreteDomainRangeList <LightColumn> licols = m_lightColumnMap[x, z];

        LightColumn prevColContainingY = licols.rangeContaining(y);

        AssertUtil.Assert(prevColContainingY != null, "confusing. how did we add a block not in the area of a light colm under the surface?");

        List <LightColumn> columnsJustDisconnected = this.columnsThatColumnJustConnectedWith(prevColContainingY, y);

        LightColumn aboveSplit = licols.Incorporate(y, false);

        if (aboveSplit != null)
        {
            aboveSplit.coord = new PTwo(x, z);
        }

        LightColumn newBelow = licols.rangeContaining(y - 1);
        LightColumn newAbove = licols.rangeContaining(y + 1);

        if (newBelow == null && newAbove == null)        // COLUMNS WERE CUT OFF?
        {
            b.bug("got both y above and below null");
            // general reboot
            resetAndUpdateColumnsWithin(LightDomainAround(PTwo.PTwoXZFromCoord(pRelCoord)));
            return;
        }

        updateColumnOrLightestNeighbor(newBelow);

        updateColumnOrLightestNeighbor(newAbove);



        foreach (LightColumn colm in columnsJustDisconnected)
        {
            updateColumnOrLightestNeighbor(colm);
        }
    }
Example #14
0
 public DiscreteDomainRangeList <LightColumn> this[int x, int z]
 {
     get{
         //check out of bounds and ask a singleton that will make for the ranges
         if (!NoisePatchDims.isIndexSafe(new PTwo(x, z)))
         {
             return(ChunkManager.lightColumnWorldMap.lightColumnsAtWoco(x, z, this.noiseCoord));
         }
         DiscreteDomainRangeList <LightColumn> lcolms = m_lightColumns[x * NoisePatch.patchDimensions.x + z];
         if (lcolms == null)
         {
             lcolms = new DiscreteDomainRangeList <LightColumn>();
             m_lightColumns[x * NoisePatch.patchDimensions.x + z] = lcolms;
         }
         return(lcolms);
     }
     set {
         m_lightColumns[x * NoisePatch.patchDimensions.x + z] = value;
     }
 }
Example #15
0
 // this func. represnts our muddled strategy unfortuntly.
 private void checkSurfaceStatusAt(int newHeight, int xx, int zz, ref ChangeOfLightStatus lightChangeStatus, ref List <LightColumn> needUpdateCols)
 {
     foreach (PTwo neighborPoint in DirectionUtil.SurroundingPTwoCoordsFromPTwo(new PTwo(xx, zz)))
     {
         //inefficient?
         DiscreteDomainRangeList <LightColumn> lilcoms = m_lightColumnMap[neighborPoint];
         b.bug("checking surface...");
         if (lilcoms == null)
         {
             continue;
         }
         b.bug("not ull");
         for (int i = 0; i < lilcoms.Count; ++i)
         {
             LightColumn lilc            = lilcoms[i];
             bool        wasAboveSurface = surfaceExposedColumns.Contains(lilc);
             if (lilc.range.extent() > newHeight)
             {
                 b.bug("extent was greater than new height");
                 if (!wasAboveSurface)
                 {
                     b.bug("added a column now surf exposed");
                     lightChangeStatus = ChangeOfLightStatus.LIGHTENED;
                     surfaceExposedColumns.Add(lilc);
                     needUpdateCols.Add(lilc);
                 }
             }
             else
             {
                 b.bug("below surface new height is: " + newHeight + "lilc range extent is: " + lilc.range.extent());
                 if (wasAboveSurface)
                 {
                     lightChangeStatus = ChangeOfLightStatus.DARKENED;
                     needUpdateCols.Add(lilc);
                     surfaceExposedColumns.Remove(lilc);
                 }
             }
         }
     }
 }
Example #16
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
                }
            }
        }
    }
Example #17
0
    public List <LightColumn> lightColumnsAdjacentToAndAtleastPartiallyAbove(Coord coord)
    {
        List <LightColumn> result = new List <LightColumn>();

        foreach (PTwo surroundingCo in DirectionUtil.SurroundingPTwoCoordsFromPTwo(PTwo.PTwoXZFromCoord(coord)))
        {
            DiscreteDomainRangeList <LightColumn> adjRangeList = this.lightColumnListAtOrNull(surroundingCo.s, surroundingCo.t);
            if (adjRangeList == null)
            {
                continue;
            }
            for (int i = 0; i < adjRangeList.Count; ++i)
            {
                LightColumn adjLightColumn = adjRangeList[i];
                if (adjLightColumn.extent() > coord.y)
                {
                    b.bug("actually added one");
                    result.Add(adjLightColumn);
                }
            }
        }
        return(result);
    }
Example #18
0
    private void updateWindowsWithHeightRangesSolidRemoved(List <Range1D> heightRanges, Coord pRelCoord,
                                                           SurroundingSurfaceValues ssvs, bool shouldPropagateLight)
    {
        int x = pRelCoord.x, y = pRelCoord.y, z = pRelCoord.z;
        DiscreteDomainRangeList <LightColumn> liCols = m_lightColumnMap[x, z];

        LightColumn colJustBelowYBeforeUpdate        = liCols.rangeContaining(y - 1);  //null if there wasn't

        Range1D highest = heightRanges[heightRanges.Count - 1];
        int     newSurfaceHeightExtentAtXZ           = highest.extent();

        if (colJustBelowYBeforeUpdate != null)
        {
            colJustBelowYBeforeUpdate = colJustBelowYBeforeUpdate.Copy();             // safe keeping
        }

        updateRangeListAtXZ(heightRanges, pRelCoord, true, ssvs);

        //case where y represents a removed top block
        // where either air or solid was underneath the
        // former top block
        if (newSurfaceHeightExtentAtXZ <= y)
        {
            //no column here anymore
            //surface was revealed.
            //add any adjacent blocks to exposed list
            // if they weren't on the list before
            // add them to need update list
            // our work is done...return (put the above in a function)

            b.bug("got new surf less than y");
            Coord surfaceTopCoord = pRelCoord;
            if (newSurfaceHeightExtentAtXZ < y)
            {
                b.bug("is fully less than");
                surfaceTopCoord.y = newSurfaceHeightExtentAtXZ;
            }

            foreach (LightColumn col in  m_lightColumnMap.lightColumnsAdjacentToAndAtleastPartiallyAbove(surfaceTopCoord))
            {
                b.bug("updating ");
                addToSurfaceExposedColumnIfNotContains(col);
                col.lightLevel = Window.LIGHT_LEVEL_MAX_BYTE;
                updateColumnAt(col, col.coord, null, LightDomainAround(col.coord));
            }

            m_lightColumnMap[x, z] = liCols;

            return;
        }

        //REMAINING CASES: Y REMOVED FROM BELOW SURFACE

        int lowestSurroundingSurface = ssvs.lowestValue();

        LightColumn colAtY = liCols.rangeContaining(y);

        AssertUtil.Assert(colAtY != null, "(remove block. didn't get a col at y in lc calc) y was: " + y);


        if (y > lowestSurroundingSurface)               //just update it. anything new will update. anything not new won't.
        {
            //one way or another a newly exposed column here
            addToSurfaceExposedColumnIfNotContains(colAtY);
            updateColumnAt(colAtY, colAtY.coord, null, LightDomainAround(x, z));
            return;
        }

        //REMAINING CASES: Y WAS BELOW THE SURFACE AND NOT EXPOSED BY ADJACENT SURFACE.
        List <LightColumn> justConnectedWithColumns = columnsThatColumnJustConnectedWith(colAtY, y);

        if (justConnectedWithColumns.Count == 0)
        {
            return;
        }

        LightColumn lightest = colAtY;

        bool atYIsLightest = true;

        foreach (LightColumn justConnectedCol in justConnectedWithColumns)
        {
            if (justConnectedCol.lightLevel > lightest.lightLevel)
            {
                lightest      = justConnectedCol;
                atYIsLightest = false;
            }
        }

        if (atYIsLightest)
        {
            foreach (LightColumn adjCol in justConnectedWithColumns)
            {
                updateColumnAt(adjCol, adjCol.coord, colAtY, LightDomainAround(adjCol.coord));
            }
        }
        else
        {
            updateColumnAt(colAtY, colAtY.coord, lightest, LightDomainAround(colAtY.coord));
        }
    }