예제 #1
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);
    }
예제 #2
0
 private void addToSurfaceExposedColumnIfNotContains(LightColumn col)
 {
     if (!surfaceExposedColumns.Contains(col))
     {
         surfaceExposedColumns.Add(col);
     }
 }
예제 #3
0
//	private static bool getAlreadyDone(bool[,] colDoneCheckList, PTwo co)
//	{
//		AssertUtil.Assert(! (co.area() >= colDoneCheckList.GetLength(0) * colDoneCheckList.GetLength(1)), "problems with col done checklist out of bounds:" +
//		    "" + co.toString() + " check list length: " + colDoneCheckList.Length);
//
//		return colDoneCheckList[co.s, co.t];
//	}
//
//	private static void setTrueAlreadyDone(ref bool[,] colDoneCheckList, PTwo co)
//	{
//		AssertUtil.Assert(! (co.area() >= colDoneCheckList.GetLength(0) * colDoneCheckList.GetLength(1)), "problems with col done checklist out of bounds:" +
//		    "" + co.toString() + " check list length: " + colDoneCheckList.Length);
//
//		colDoneCheckList[co.s, co.t] = true;
//	}

    #region debug

    void addColumnIfNoiseCoordOO(LightColumn lcol)
    {
        if (NoiseCoord.Equal(this.m_noisePatch.coord, new NoiseCoord(0, 0)))
        {
            ChunkManager.debugLinesAssistant.addColumn(lcol.toColumnDebug(), this.debugTimeDrewDebugColm++, m_noisePatch.coord);
        }
    }
예제 #4
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);
    }
예제 #5
0
    public void addColumnAt(LightColumn newlcolm, int x, int z)
    {
        DiscreteDomainRangeList <LightColumn> lcolms = this[x, z];

        lcolms.Add(newlcolm);
        this[x, z] = lcolms;
    }
예제 #6
0
    private LightColumn lightestNeightbor(SimpleRange colRange, PTwo co)
    {
        LightColumn lightest = null;

        List <LightColumn> neighbors = m_lightColumnMap.lightColumnsAdjacentToAndFlushWithSimpleRangeAndPoint(colRange, co);

        if (neighbors.Count == 0)
        {
            return(null);
        }

        lightest = neighbors[0];

        //CONSIDER: could be a little faster if we iterated over directions ourselves here...
        for (int i = 1; i < neighbors.Count; ++i)
        {
            LightColumn neicol = neighbors[i];
            if (neicol.lightLevel > lightest.lightLevel)
            {
                lightest = neicol;
            }
        }

        return(lightest);
    }
예제 #7
0
 private void addDebugColumnIfNoiseCoZIsNeg(LightColumn col, int handyI)
 {
     if (this.m_noisePatch.coord.z < 0)
     {
         int handyInt = handyI;
         ChunkManager.debugLinesAssistant.addColumn(col.toColumnDebug(), handyInt, this.m_noisePatch.coord);
     }
 }
예제 #8
0
    private bool columnContains(LightColumn lcol, int y)
    {
        if (lcol == null)
        {
            return(false);
        }

        return(lcol.contains(y));
    }
예제 #9
0
    public void addReplaceColumn(LightColumn col)
    {
        DiscreteDomainRangeList <LightColumn> cols = this[col.coord];

        cols.RemoveWithRangeEqualTo(col.range);

        cols.Add(col);
        this[col.coord] = cols;
    }
예제 #10
0
    private void updateColumnAt(LightColumn lightcol, PTwo coord, LightColumn influencerColumn, Quad withinBounds)
    {
        if (!withinBounds.contains(coord))
        {
            return;
        }

        bool tookInfluence = false;

        if (influencerColumn == null)
        {
//			addColumnIfNoiseCoordOO(lightcol); //DBG
            lightcol.setLightLevelToMax();
            tookInfluence = true;
        }
        else
        {
            tookInfluence = lightcol.takeInfluenceFromColumn(influencerColumn);
//			if (tookInfluence) //DEBUG!!!
//			{
//				this.addDebugColumnIfNoiseCoZIsNeg(lightcol, 4);
//				this.addDebugColumnIfNoiseCoZIsNeg(influencerColumn, 1);
//			}
        }
        if (!tookInfluence)
        {
            return;
        }

        List <LightColumn> adjacentNeighbors = m_lightColumnMap.lightColumnsAdjacentToAndFlushWith(lightcol);

        if (adjacentNeighbors == null)
        {
            return;
        }

        for (int i = 0; i < adjacentNeighbors.Count; ++i)
        {
            LightColumn adjNeighbor = adjacentNeighbors[i];
            //TEST WANT
            updateColumnAt(adjNeighbor, adjNeighbor.coord, lightcol, withinBounds);
        }

        // touch any connected columns below this light col
        // then check this column done on check list
//		foreach(LightColumn belowCol in m_lightColumnMap[coord].toList() )
//		{
//			if (belowCol.Equals(lightcol))
//				continue;
//			foreach(LightColumn adjCol in adjacentNeighbors) {
//				belowCol.takeInfluenceFromColumn(adjCol);
//				if (belowCol.lightLevel >= lightcol.lightLevel - Window.UNIT_FALL_OFF_BYTE * 2)
//					break;
//			}
//		}
//		columnDoneCheckList[coord.s,coord.t] = true;
    }
예제 #11
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);
        }
    }
예제 #12
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;
    }
예제 #13
0
 private void clearSurfaceExposedListAt(int x, int z)
 {
     //TODO make faster collection? another lightColumnMap maybe?
     for (int i = 0; i < surfaceExposedColumns.Count; ++i)
     {
         LightColumn col = surfaceExposedColumns[i];
         if (col.coord.s == x && col.coord.t == z)
         {
             surfaceExposedColumns.RemoveAt(i);
             --i;
         }
     }
 }
예제 #14
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));
    }
예제 #15
0
    public float lightValueAtPatchRelativeCoord(Coord relCo)
    {
        LightColumn lilc = m_lightColumnMap.columnContaining(relCo);

        if (lilc == null)
        {
            return(0f);            // Window.LIGHT_LEVEL_MAX; //TEST// 0f;
        }
//		addColumnIfNoiseCoordOO(lilc); //DBG

//		if (lilc.lightLevel > 17f)
//			this.addDebugColumnIfNoiseCoZIsNeg(lilc, (int)(lilc.lightLevel / 3f));

        return((float)lilc.lightLevel);         //WANT
    }
예제 #16
0
    public void replaceColumnsWithHeightRanges(List <Range1D> heightRanges, int x, int z, SurroundingSurfaceValues ssvs)
    {
        int countAt = m_lightColumnMap.countAt(x, z);

        if (countAt > 0)
        {
            //clobber columns here.
            m_lightColumnMap.clearColumnsAt(x, z);
            clearSurfaceExposedListAt(x, z);
        }

        //add new discons
        int lowestSurroundingSurfaceHeight = ssvs.lowestValue();

        ssvs.debugAssertLowestNonNegFound();         //DBG

//		AssertUtil.Assert(lowestSurroundingSurfaceHeight > 0, "weird. lowest sur value is: " + lowestSurroundingSurfaceHeight);

//		AssertUtil.Assert(NoiseCoord.Equal(this.debugOrigNoiseCoord, m_noisePatch.coord ), "not equal? nco "
//			+ m_noisePatch.coord.toString() + " and orig??" + debugOrigNoiseCoord.toString()); //fails

        List <SimpleRange> discons = discontinuitiesFromHeightRanges(heightRanges);

        int light = 0;

        LightColumn col = null;
        bool        exposedLightColumn = false;
        int         countDisCon        = discons.Count; //DBG

        foreach (SimpleRange discon in discons)
        {
            exposedLightColumn = discon.extent() > lowestSurroundingSurfaceHeight;
            light = 0;             // discon.extent() > lowestSurroundingSurfaceHeight ? (int) Window.LIGHT_LEVEL_MAX_BYTE : 0;
            col   = new LightColumn(new PTwo(x, z), (byte)light, discon);
            if (exposedLightColumn)
            {
                //DBG
//				if (countDisCon > 1) {
//					bugIf0Neg1( " discon extent: " + discon.extent() + " lowest Sur Height: " + lowestSurroundingSurfaceHeight + " x: " + x + " z: " + z);
//				}

                surfaceExposedColumns.Add(col);

//				this.addDebugColumnIfNoiseCoZIsNeg(col, 4);
            }
            m_lightColumnMap.addColumnAt(col, x, z);
        }
    }
        private LightSetup GetLightSetup(ILightSetupPlugin plugin)
        {
            LightSetup lightSetup = new LightSetup();

            if (plugin.Lights != null && plugin.Lights.Any())
            {
                //convert back to 2d array for setup
                lightSetup.LightRows = new List <LightRow>();

                lightSetup.NumberOfRows    = plugin.Lights.Max(l => l.Top);
                lightSetup.NumberOfColumns = plugin.Lights.Max(l => l.Left);

                for (int row = 0; row <= lightSetup.NumberOfRows; row++)
                {
                    LightRow lightRow = new LightRow();
                    lightRow.RowIndex     = row;
                    lightRow.LightColumns = new List <LightColumn>();
                    for (int column = 0; column <= lightSetup.NumberOfColumns; column++)
                    {
                        LightColumn lightColumn = new LightColumn();
                        lightColumn.ColumnIndex = column;
                        if (column == 0 || column == lightSetup.NumberOfColumns ||
                            row == 0 || row == lightSetup.NumberOfRows)
                        {
                            Light light = (from l in plugin.Lights
                                           where l.Top == row &&
                                           l.Left == column
                                           select l).FirstOrDefault();
                            if (light != null)
                            {
                                lightColumn.Id    = light.Id.ToString();
                                lightColumn.Index = light.Index.ToString();

                                lightColumn.Enabled = !string.IsNullOrEmpty(lightColumn.Id);
                            }
                        }
                        else
                        {
                            lightColumn.Enabled = false;
                        }

                        lightRow.LightColumns.Add(lightColumn);
                    }
                    lightSetup.LightRows.Add(lightRow);
                }
            }
            return(lightSetup);
        }
예제 #18
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);
    }
예제 #19
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;
        }
    }
예제 #20
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);
        }
    }
예제 #21
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);
                 }
             }
         }
     }
 }
예제 #22
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);
    }
예제 #23
0
    private void updateColumnOrLightestNeighbor(LightColumn col)
    {
        if (col != null)
        {
            LightColumn lightestN = lightestNeighbor(col);
            if (lightestN != null)
            {
                if (lightestN.lightLevel > col.lightLevel)
                {
                    updateColumnAt(col, col.coord, lightestN, LightDomainAround(col.coord));
                }
                else
                {
                    updateColumnAt(lightestN, lightestN.coord, col, LightDomainAround(lightestN.coord));
                }
            }
            else
            {
                col.lightLevel = 0;
            }

            m_lightColumnMap.addReplaceColumn(col);
        }
    }
예제 #24
0
 public List <LightColumn> lightColumnsAdjacentToAndFlushWith(LightColumn colm)
 {
     return(lightColumnsAdjacentToAndFlushWithSimpleRangeAndPoint(colm.range, colm.coord));
 }
        private PluginProperty[] GetPluginProperties(object plugin)
        {
            List <PluginProperty> pluginProperties = new List <PluginProperty>();

            if (plugin == null)
            {
                return(pluginProperties.ToArray());
            }

            Type pluginObjectType = plugin.GetType();

            foreach (System.Reflection.PropertyInfo objectProperty in pluginObjectType.GetProperties())
            {
                PluginProperty pluginProperty = new PluginProperty();
                bool           exclude        = false;
                bool           dataMember     = false;

                if (!objectProperty.CanWrite)
                {
                    continue;
                }

                pluginProperty.Name = objectProperty.Name;

                pluginProperty.Value = objectProperty.GetValue(plugin, null);

                Type propertyType = objectProperty.PropertyType;
                if (propertyType == typeof(string))
                {
                    pluginProperty.Type = "text";
                }
                else if (propertyType == typeof(int))
                {
                    pluginProperty.Type = "number";
                }
                else if (propertyType == typeof(bool))
                {
                    pluginProperty.Type = "boolean";
                }
                else if (propertyType == typeof(List <Core.Light>))
                {
                    pluginProperty.Type = "lights";

                    string[] colourClasses  = new string[] { "btn-primary", "btn-success", "btn-info", "btn-warning", "btn-danger" };
                    int      colourPosition = 0;

                    List <Core.Light> lights     = pluginProperty.Value as List <Core.Light>;
                    LightSetup        lightSetup = new LightSetup();

                    if (lights != null && lights.Any())
                    {
                        //convert back to 2d array for setup
                        lightSetup.LightRows = new List <LightRow>();

                        int numberOfRows    = lights.Max(l => l.Top);
                        int numberOfColumns = lights.Max(l => l.Left);

                        for (int row = 0; row <= numberOfRows; row++)
                        {
                            LightRow lightRow = new LightRow();
                            lightRow.RowIndex     = row;
                            lightRow.LightColumns = new List <LightColumn>();
                            for (int column = 0; column <= numberOfColumns; column++)
                            {
                                LightColumn lightColumn = new LightColumn();
                                lightColumn.ColumnIndex = column;
                                if (column == 0 || column == numberOfColumns ||
                                    row == 0 || row == numberOfRows)
                                {
                                    Light light = (from l in lights
                                                   where l.Top == row &&
                                                   l.Left == column
                                                   select l).FirstOrDefault();
                                    if (light != null)
                                    {
                                        lightColumn.Id    = light.Id.ToString();
                                        lightColumn.Index = light.Index.ToString();

                                        lightColumn.ColourClass = colourClasses[colourPosition++];

                                        lightColumn.Enabled = !string.IsNullOrEmpty(lightColumn.Id);

                                        if (lightColumn.Id == "1")
                                        {
                                            lightSetup.FirstColumnIndex = column;
                                            lightSetup.FirstRowIndex    = row;
                                        }
                                    }
                                    else
                                    {
                                        lightColumn.ColourClass = colourClasses[colourPosition++];
                                    }
                                }
                                else
                                {
                                    lightColumn.ColourClass = "disabled";
                                    lightColumn.Enabled     = false;
                                }
                                if (colourPosition >= colourClasses.Length)
                                {
                                    colourPosition = 0;
                                }
                                lightRow.LightColumns.Add(lightColumn);
                            }
                            lightSetup.LightRows.Add(lightRow);
                        }
                    }
                    pluginProperty.Value = lightSetup;
                }

                foreach (System.Attribute attr in objectProperty.GetCustomAttributes(true))
                {
                    if ((attr as DisplayAttribute) != null)
                    {
                        DisplayAttribute displayName = (DisplayAttribute)attr;
                        pluginProperty.DisplayName = displayName.Name;
                        pluginProperty.Description = displayName.Description;
                    }
                    else if ((attr as RangeAttribute) != null)
                    {
                        RangeAttribute range = (RangeAttribute)attr;
                        pluginProperty.MinValue = range.Minimum as int?;
                        pluginProperty.MaxValue = range.Maximum as int?;
                    }
                    else if ((attr as RequiredAttribute) != null)
                    {
                        RequiredAttribute required = (RequiredAttribute)attr;
                        pluginProperty.Required = required.AllowEmptyStrings;
                    }
                    else if ((attr as DataMemberAttribute) != null)
                    {
                        dataMember = true;
                    }
                    else if ((attr as KeyAttribute) != null)
                    {
                        exclude = true;
                        break;
                    }
                    else if ((attr as ConfigLookupAttribute) != null)
                    {
                        ConfigLookupAttribute lookup = (ConfigLookupAttribute)attr;
                        pluginProperty.Type = "lookup";

                        PropertyInfo optionsProperty = pluginObjectType.GetProperty(lookup.RetrieveValuesFrom);

                        IEnumerable <object> options       = optionsProperty.GetValue(plugin, null) as IEnumerable <object>;
                        List <SelectOption>  parsedOptions = new List <SelectOption>();
                        if (options.Any())
                        {
                            foreach (object option in options)
                            {
                                LookupItem       lookupItem       = option as LookupItem;
                                LookupItemString lookupItemString = option as LookupItemString;
                                SelectOption     pluginOption     = new SelectOption();

                                if (lookupItem != null)
                                {
                                    pluginOption.Id   = lookupItem.Id;
                                    pluginOption.Name = lookupItem.Name;
                                }
                                else if (lookupItemString != null)
                                {
                                    pluginOption.Id   = lookupItemString.Id;
                                    pluginOption.Name = lookupItemString.Name;
                                }
                                else
                                {
                                    pluginOption.Id   = option;
                                    pluginOption.Name = option.ToString();
                                }
                                parsedOptions.Add(pluginOption);
                            }
                        }
                        pluginProperty.Options = parsedOptions;
                    }
                }

                if (dataMember && !exclude)
                {
                    if (pluginProperty.Type == "lookup" && pluginProperty.Value != null)
                    {
                        var currentValue = (from o in pluginProperty.Options
                                            where o.Id.ToString() == pluginProperty.Value.ToString()
                                            select o).FirstOrDefault();
                        if (currentValue == null)
                        {
                            List <SelectOption> options = pluginProperty.Options as List <SelectOption>;
                            options.Add(new SelectOption()
                            {
                                Id   = pluginProperty.Value,
                                Name = "Invalid! " + pluginProperty.Value.ToString()
                            });
                            pluginProperty.Options = options;
                        }
                    }
                    pluginProperties.Add(pluginProperty);
                }
            }

            return(pluginProperties.ToArray());
        }
예제 #26
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));
        }
    }
예제 #27
0
 private LightColumn lightestNeighbor(LightColumn col)
 {
     return(lightestNeightbor(col.range, col.coord));
 }