private IEnumerable faceSetsAtAcrossIndexFlushWithRange(int acrossI, Range1D range, Direction dir) { int currentFSI = -1; for (int j = range.start; j < range.extent(); ++j) { if (j < 0) { continue; } if (j > faceSetTableHalfDims.t) { break; } AlignedCoord curAlco = new AlignedCoord(acrossI, j); int fsindex = indexOfFaceSetAtCoord(curAlco, dir); if (fsindex >= 0 && fsindex != currentFSI) { currentFSI = fsindex; yield return(fsindex); } } }
private void addMeshDataForExposedRanges(List <Range1D> exposedRanges, Direction camFacingDir, ref int starting_tri_i, int xx, int zz) { ChunkIndex targetBlockIndex; foreach (Range1D rng in exposedRanges) { int blockY = rng.start; // while(blockY < rng.extent()) { targetBlockIndex = new ChunkIndex(xx, blockY, zz); if (blockY == Range1D.theErsatzNullRange().start) { throw new Exception("this range was ersatz nullish " + rng.toString()); } Block b = m_noisePatch.blockAtChunkCoordOffset(chunkCoord, new Coord(xx, blockY, zz)); // addYFaceAtChunkIndex(targetBlockIndex, b.type, camFacingDir, starting_tri_i); // old way with the while loop (now each range is one quad) addYFaceAtChunkIndex(targetBlockIndex, b.type, camFacingDir, starting_tri_i, rng.range); starting_tri_i += 4; // blockY++; // } } }
// TODO: really make an index lookup table class private void setIndicesOfFaceSetsAtRangeToIndex(Range1D range, int acrossI, Direction dir, int indexToSetTo) { for (int i = range.start; i < range.extent(); ++i) { setIndexOfFaceSetAtCoord(indexToSetTo, new AlignedCoord(acrossI, i), dir); } }
private void addDiscontinuityWith(Range1D aboveRange, Range1D belowRange, int xx, int zz, SurroundingSurfaceValues ssvs, bool wantToEditPossibly, bool doLightUpDate) { int gap = aboveRange.start - belowRange.extent(); if (gap > 0) { addDiscontinuityAt(new SimpleRange(belowRange.extent(), gap), xx, zz, ssvs, wantToEditPossibly, doLightUpDate); } }
public bool addNewZCurtainSectionAt(PTwo xzco, Range1D continuityRangeAtZPlusOrMinusOne, Range1D airRange) { if (doAddNewZCurtainSectionAt(xzco, continuityRangeAtZPlusOrMinusOne, airRange)) { bounds = bounds.expandedToContainPoint(xzco); return(true); } return(false); }
public FaceInfo(Coord _coord, Range1D _range, Direction _dir, ILightDataProvider _lightDataProvider) { coord = _coord; lightLevel = 0; // _range.top_light_level; direction = _dir; blockType = _range.blockType; // arg.. duplications... range = _range; lightDataProvider = _lightDataProvider; }
public static Range1D[] splitRangeIntoTopAndRemainder(Range1D splitMe, BlockType remainderType) { Range1D[] result = new Range1D[2]; Range1D top = new Range1D(splitMe.extentMinusOne(), 1, remainderType); //, splitMe.top_light_level, splitMe.top_light_level); splitMe.range--; result[0] = top; result[1] = splitMe; return(result); }
public DiscontinuityCurtain(PTwo xzStartCoord, Range1D continuityRangeAtZMinusOne, Range1D airRange) { bounds = Quad.UnitQuadWithPoint(xzStartCoord); ZCurtain inital_zc = new ZCurtain(xzStartCoord.t); inital_zc.setDiscontinuityStartWithSurfaceRange(continuityRangeAtZMinusOne, airRange); z_curtains.Add(inital_zc); }
public Range1D subRangeBelow(int level) { if (level <= this.start) { return(Range1D.theErsatzNullRange()); } int min = Mathf.Min(this.extent(), level); return(new Range1D(this.start, min - this.start, this.blockType)); //, this.top_light_level, this.bottom_light_level); }
public Range1D setRangeStartTo(int level) { int newRange = this.extent() - level - 1; if (newRange <= 0) { return(Range1D.theErsatzNullRange()); } return(new Range1D(level + 1, newRange, this.blockType)); //, this.top_light_level, this.bottom_light_level); }
public static Range1D Union(Range1D raa, Range1D rbb) { int unionExtent = raa.extent() > rbb.extent() ? raa.extent() : rbb.extent(); int unionStart = raa.start < rbb.start ? raa.start : rbb.start; if (unionStart >= unionExtent) { return(Range1D.theErsatzNullRange()); } return(new Range1D(unionStart, unionExtent - unionStart, raa.blockType)); }
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; }
public static Range1D IntersectingRange(Range1D raa, Range1D rbb) { int interExtent = raa.extent() < rbb.extent() ? raa.extent() : rbb.extent(); int interStart = raa.start > rbb.start ? raa.start : rbb.start; if (interStart >= interExtent) { return(Range1D.theErsatzNullRange()); } return(new Range1D(interStart, interExtent - interStart, raa.blockType)); // int extentDif = raa.e }
private static SimpleRange discontinuityBetween(Range1D belowRange, Range1D aboveRange) { int gap = aboveRange.start - belowRange.extent(); if (gap > 0) { return(new SimpleRange(belowRange.extent(), gap)); } // throw new Exception("good to know if this happens. discon between got a null range. no gap?"); return(SimpleRange.theErsatzNullRange()); }
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)); }
public Range1D subRangeAbove(int level) { if (level < this.start) { return(this); } int newRange = this.extentMinusOne() - level; if (newRange <= 0) { return(Range1D.theErsatzNullRange()); } return(new Range1D(level + 1, newRange, this.blockType)); //, this.top_light_level, this.bottom_light_level); }
private void updateWindowsWithHeightRangesSolidAdded(List <Range1D> heightRanges, Coord pRelCoord, SurroundingSurfaceValues ssvs, bool shouldPropagateLight) { Range1D highest = heightRanges[heightRanges.Count - 1]; int newSurfaceHeightAtXZ = highest.extent(); bool yIsNewHighestSurface = pRelCoord.y == newSurfaceHeightAtXZ - 1; b.bug("y is " + pRelCoord.y + " new surf height minus one: " + (newSurfaceHeightAtXZ - 1)); // WAS A FORMERLY SURFACE EXPOSED SURFACE COLUMN JUST COVERED? if (yIsNewHighestSurface) { updateColumnsWithHigherHighestSurface(heightRanges, pRelCoord, ssvs, shouldPropagateLight); return; } updateColumnsSolidAddedBelowSurface(heightRanges, pRelCoord, ssvs, shouldPropagateLight); }
//TODO: test this func. public static Quad Intersection(Quad ii, Quad kk) { Range1D ii_s = new Range1D(ii.origin.s, ii.dimensions.s); Range1D ii_t = new Range1D(ii.origin.t, ii.dimensions.t); Range1D kk_s = new Range1D(kk.origin.s, kk.dimensions.s); Range1D kk_t = new Range1D(kk.origin.t, kk.dimensions.t); ii_s = Range1D.IntersectingRange(ii_s, kk_s); kk_t = Range1D.IntersectingRange(ii_t, kk_t); if (ii_s.isErsatzNull() || kk_t.isErsatzNull()) { return(Quad.theErsatzNullQuad()); } return(new Quad(new PTwo(ii_s.start, kk_t.start), new PTwo(ii_s.range, kk_t.range))); }
static Range1D StrToRange(string s) { string[] segs = s.Split(new string[] { "," }, System.StringSplitOptions.RemoveEmptyEntries); Range1D r = new Range1D(); if (segs.Length == 1) { float f = System.Convert.ToSingle(segs[0].Trim()); r.SetMinMax(f, f); } else if (segs.Length > 1) { r.SetMinMax(System.Convert.ToSingle(segs[0].Trim()), System.Convert.ToSingle(segs[1].Trim())); } else { throw new System.Exception("Invalid range string"); } return(r); }
//TODO: need extra parameters for the air and surface at z plus 1! private void extendWithXZCoord(PTwo xzco, Range1D continuityRangeAtZPlusOrMinusOne, Range1D airRange, bool setTerminatingDisConStatus) { Range1D x_domain = bounds.sRange(); if (x_domain.contains(xzco.s)) { PTwo relCo = xzco - bounds.origin; ZCurtain zcur = z_curtains[relCo.s]; if (setTerminatingDisConStatus) { zcur.extendCurtainToIncludeWocoZ(xzco.t, continuityRangeAtZPlusOrMinusOne, airRange); } else { zcur.extendCurtainToIncludeNonTerminationWocoZ(xzco.t); } z_curtains[relCo.s] = zcur; bounds = bounds.expandedToContainPoint(xzco); } }
private static bool aSolidRangeIsFlushWithRangeAtIndex(List <Range1D> heights, int currentIndex, bool wantAboveRange) { int nudgeIndex = wantAboveRange ? 1 : -1; Range1D currentRange = heights[currentIndex]; if (wantAboveRange) { if (currentIndex == heights.Count - 1) { return(false); } Range1D nextRangeAbove = heights[currentIndex + 1]; if (currentRange.extent() == nextRangeAbove.start) { if (!Block.BlockTypeIsATranslucentType(nextRangeAbove.blockType)) { return(true); } } } else { if (currentIndex == 0) { return(false); } Range1D prevRangeBelow = heights[currentIndex - 1]; if (currentRange.start == prevRangeBelow.extent()) { if (!Block.BlockTypeIsATranslucentType(prevRangeBelow.blockType)) { return(true); } } } return(false); }
private void addToFaceSetsAt(int nextToRangeIndex, FaceInfo finfo) { Range1D addRange = finfo.range; Direction dir = finfo.direction; AssertUtil.Assert(nextToRangeIndex < this.faceSetTableHalfDims.s - 1, "need next to range to be in our table minus one column"); foreach (int faceSetIndex in faceSetsAtAcrossIndexFlushWithRange(nextToRangeIndex, addRange, dir)) { FaceSet nextToFS = faceSets[faceSetIndex]; if (nextToFS.canIncorporatePartOrAllOfRange(addRange, nextToRangeIndex + 1)) { Range1D usedRange = nextToFS.addRangeAtAcrossReturnAddedRange(addRange, nextToRangeIndex + 1); AssertUtil.Assert(usedRange.range > 0, "confusing used range was zero or less? (in face agg add fs w range)"); setIndicesOfFaceSetsAtRangeToIndex(usedRange, nextToRangeIndex + 1, dir, faceSetIndex + FaceAggregator.FACETABLE_LOOKUP_SHIFT); Range1D unusedRangeBelow = addRange.subRangeBelowRange(usedRange); if (!unusedRangeBelow.isErsatzNull()) { // addNewFaceSetsWith(nextToRangeIndex + 1, addRange, dir); addNewFaceSetsWith(nextToRangeIndex + 1, finfo); } Range1D unusedAbove = addRange.subRangeAboveRange(usedRange); if (!unusedAbove.isErsatzNull()) { finfo.range = unusedAbove; // addToFaceSetsAt(nextToRangeIndex, unusedAbove, dir); addToFaceSetsAt(nextToRangeIndex, finfo); } return; } } addNewFaceSetsWith(nextToRangeIndex + 1, finfo); }
private bool doAddNewZCurtainSectionAt(PTwo xzco, Range1D continuityRangeAtZPlusOrMinusOne, Range1D airRange) { if (!thereIsAdjacencyOnOneSideOrTheOther(xzco)) { return(false); } Range1D x_domain = bounds.sRange(); if (x_domain.contains(xzco.s)) { PTwo relCo = bounds.origin - xzco; ZCurtain zcur = z_curtains[relCo.s]; zcur.addNewCurtainUnitWithZNegStartAt(xzco.t); zcur.setDiscontinuityStartWithSurfaceRange(continuityRangeAtZPlusOrMinusOne, airRange); z_curtains[relCo.s] = zcur; return(true); } if (x_domain.start - 1 == xzco.s) { ZCurtain zc = new ZCurtain(xzco.t); zc.setDiscontinuityStartWithSurfaceRange(continuityRangeAtZPlusOrMinusOne, airRange); z_curtains.Insert(0, zc); return(true); } else if (x_domain.extent() == xzco.s) { ZCurtain zc = new ZCurtain(xzco.t); zc.setDiscontinuityStartWithSurfaceRange(continuityRangeAtZPlusOrMinusOne, airRange); z_curtains.Add(zc); return(true); } return(false); }
public OverlapState overlapWithRange(Range1D other) { if (this.start == other.extent()) { return(OverlapState.FlushWithStart); } if (this.start > other.extent()) { return(OverlapState.BeforeStart); } if (this.extent() == other.start) { return(OverlapState.FlushWithExtent); } if (RangesIntersect(this, other)) { if (this.contains(other)) { return(OverlapState.IContainIt); } if (other.contains(this)) { return(OverlapState.ItContainsMe); } if (other.start < this.start) { return(OverlapState.OverlappingOverStart); } return(OverlapState.OverlappingOverEnd); } return(OverlapState.BeyondExtent); }
public Plinth(PTwo _patchRelOrigin, int y_height, float seed) // : base(_patchRelativePlot) { Coord dims = new Coord(5, 5, 6); // fake Quad _prplot = new Quad(_patchRelOrigin, PTwo.PTwoXZFromCoord(dims)); // setupSBB(_prplot, y_height); setupSB(_prplot, y_height); int i = 0; int j = 0; for (; i < this.plot.dimensions.s; ++i) { for (j = 0; j < this.plot.dimensions.t; ++j) { List <Range1D> rangs = new List <Range1D>(); // if (i == plot.dimensions.s /2 && j == plot.dimensions.t/2) if (i == 0 || i == plot.dimensions.s - 1 || j == 0 || j == plot.dimensions.t - 1) { Range1D column = new Range1D(0, dims.y, BlockType.Stucco); rangs.Add(column); ranges[i, j] = rangs; // TODO: convert to range table } else { Range1D floor = new Range1D(0, 1, BlockType.Sand); // Range1D mezzo = new Range1D(dims.y/2, 1, BlockType.Sand); Range1D ceil = new Range1D(dims.y - 1, 1, BlockType.Stucco); rangs.Add(floor); // rangs.Add(mezzo); rangs.Add(ceil); ranges[i, j] = rangs; } } } }
// public ZDiscontinuityPointCoverageStatus zCoverageStatusForPointIncludeXAdjaceny(PTwo woco_pointxz) // { // XDiscontinuityPointCoverageStatus xcoverage = this.xCoverageStatusForPoint(woco_pointxz); // // if (xcoverage <= XDiscontinuityPointCoverageStatus.BeyondBoundsXPos) //beyond bounds pos or neg // return false; // // if (xcoverage == XDiscontinuityPointCoverageStatus.XAdjacentToLowerLimit) { // woco_pointxz.s++; // } else if (xcoverage == XDiscontinuityPointCoverageStatus.XAdjacentToUpperLimit) { // woco_pointxz.s--; // } // // ZDiscontinuityPointCoverageStatus zcoverage = this.zCoverageStatusForPoint(woco_pointxz); // // if (zcoverage <= ZDiscontinuityPointCoverageStatus.BeyondBoundsZPos) { // // } // } public XDiscontinuityPointCoverageStatus xCoverageStatusForPoint(PTwo woco_pointxz) { Range1D srange = bounds.sRange(); if (woco_pointxz.s > srange.extentMinusOne()) { if (srange.extent() == woco_pointxz.s) { return(XDiscontinuityPointCoverageStatus.XAdjacentToUpperLimit); } return(XDiscontinuityPointCoverageStatus.BeyondBoundsXPos); } if (woco_pointxz.s < srange.start) { if (srange.start - 1 == woco_pointxz.s) { return(XDiscontinuityPointCoverageStatus.XAdjacentToLowerLimit); } return(XDiscontinuityPointCoverageStatus.BeyondBoundsXNeg); } return(XDiscontinuityPointCoverageStatus.WithinXDomain); }
private void setDiscontinuityWithSurfaceRange(Range1D lastContinuityBeforeRange, Range1D airRange_, bool wantStart) { if (sections.Count < 1) { return; } SimpleRange surfRange = new SimpleRange(lastContinuityBeforeRange.start, lastContinuityBeforeRange.range); SimpleRange airRange = new SimpleRange(airRange_.start, airRange_.range); ZCurtainUnit zcu; if (wantStart) { zcu = sections[0]; } else { zcu = sections[sections.Count - 1]; } // whether zcu.startIsOpen = SimpleRange.SimpleRangeCoversRange(surfRange, airRange); }
private void addNewFaceSetsWith(int acrossI, FaceInfo finfo) { Range1D addRange = finfo.range; Direction dir = finfo.direction; AlignedCoord startAlco = new AlignedCoord(acrossI, addRange.start); int fsIndex = indexOfFaceSetAtCoord(startAlco, dir); if (!indexRepresentsAnOccupiedCoord(fsIndex)) { newFaceSetAtCoord(startAlco, addRange.blockType, dir, 0, finfo.lightDataProvider); } // newFaceSetAtCoord(startAlco, addRange.blockType, dir, addRange.bottom_light_level, finfo.lightDataProvider); FaceSet justAddedFS = faceSetAt(startAlco, dir); Range1D usedRange = justAddedFS.addRangeAtAcrossReturnAddedRange(addRange, acrossI); int nowOccupiedFS = unshiftedIndexOfFaceSetAtCoord(startAlco, dir); AssertUtil.Assert(nowOccupiedFS > -1, "wha negative occupied coord? " + nowOccupiedFS); setIndicesOfFaceSetsAtRangeToIndex(usedRange, acrossI, dir, nowOccupiedFS); AssertUtil.Assert(addRange.subRangeBelowRange(usedRange).isErsatzNull(), "we thought there would be no range below. whoops"); Range1D unusedRangeAbove = addRange.subRangeAboveRange(usedRange); if (!unusedRangeAbove.isErsatzNull()) { if (unusedRangeAbove.range > 0) { finfo.range = unusedRangeAbove; addNewFaceSetsWith(acrossI, finfo); } } }
public static Strip theErsatzNullStrip() { return(new Strip(Range1D.theErsatzNullRange(), IndexSet.theErsatzNullIndexSet())); }
public static bool StripNotNull(Strip ss) { return(!Range1D.Equal(ss.range, Range1D.theErsatzNullRange())); }