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); } }
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)); }
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); }
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)); } }