public override void Dispose() { foreach (LandCase2D[,] landObject2DsArray in this.landObjects2DLayers) { for (int i = 0; i < landObject2DsArray.GetLength(0); i++) { for (int j = 0; j < landObject2DsArray.GetLength(1); j++) { LandCase2D landObjectsList = landObject2DsArray[i, j]; if (landObjectsList != null) { landObjectsList.Dispose(); } } } } this.landObjects2DLayers.Clear(); }
public override void DrawIn(RenderWindow window, ref FloatRect boundsView) { LandCase2D[,] layer2D = this.landObjects2DLayers.FirstOrDefault(); if (layer2D == null) { return; } for (int i = 0; i < layer2D.GetLength(0); i++) { for (int j = 0; j < layer2D.GetLength(1); j++) { FloatRect bounds = new FloatRect(this.Position.X + j * MainWindow.MODEL_TO_VIEW, this.Position.Y + i * MainWindow.MODEL_TO_VIEW, MainWindow.MODEL_TO_VIEW, MainWindow.MODEL_TO_VIEW); /*if (bounds.Left < boundsView.Left + boundsView.Width * && bounds.Left + bounds.Width > boundsView.Left * && bounds.Top < boundsView.Top + boundsView.Height * && bounds.Top + bounds.Height > boundsView.Top) * {*/ if (bounds.Intersects(boundsView)) { bool firstCaseDrawn = false; foreach (LandCase2D[,] landObject2DsArray in this.landObjects2DLayers) { LandCase2D landObjectsList = landObject2DsArray[i, j]; if (landObjectsList != null) { landObjectsList.DrawIn(window, ref boundsView); firstCaseDrawn = landObjectsList.IsValid; } } } } } }
public int UpdateCurrentAltitude(LandWorld2D landWorld2D, ILandChunk landChunk, int newAltitude) { int trueCurrentAltitude = Math.Max(Math.Min(newAltitude, landChunk.AltitudeMax), landChunk.AltitudeMin); int altitudeMin = Math.Max(landChunk.AltitudeMin, trueCurrentAltitude - LandWorld2D.LOADED_ALTITUDE_RANGE); int altitudeMax = Math.Min(landChunk.AltitudeMax, trueCurrentAltitude + LandWorld2D.LOADED_ALTITUDE_RANGE); int AltitudesMinToRemove = Math.Min(this.altitudeMax + 1, altitudeMin) - this.altitudeMin; if (this.landObjects2DLayers.Count > 0) { for (int i = 0; i < AltitudesMinToRemove; i++) { this.landObjects2DLayers.RemoveAt(0); //Console.WriteLine("Remove altitude : " + (this.altitudeMin + i)); } int AltitudesMaxToRemove = this.altitudeMax - Math.Max(this.altitudeMin - 1, altitudeMax); for (int i = 0; i < AltitudesMaxToRemove; i++) { this.landObjects2DLayers.RemoveAt(this.landObjects2DLayers.Count - 1); //Console.WriteLine("Remove altitude : " + (this.altitudeMax - i)); } int supLimit = Math.Min(this.altitudeMin, altitudeMax + 1); int AltitudesMinToAdd = supLimit - altitudeMin; for (int i = 0; i < AltitudesMinToAdd; i++) { LandCase2D[,] landObject2Ds = new LandCase2D[landChunk.Area.Height, landChunk.Area.Width]; this.CreateAltitude2D(landWorld2D, landChunk, supLimit - i - 1, ref landObject2Ds); this.landObjects2DLayers.Insert(0, landObject2Ds); //Console.WriteLine("Add altitude : " + (supLimit - i - 1)); } } int infLimit = Math.Max(this.altitudeMax, altitudeMin - 1); int AltitudesMaxToAdd = altitudeMax - infLimit; for (int i = 0; i < AltitudesMaxToAdd; i++) { LandCase2D[,] landObject2Ds = new LandCase2D[landChunk.Area.Height, landChunk.Area.Width]; this.CreateAltitude2D(landWorld2D, landChunk, infLimit + i + 1, ref landObject2Ds); this.landObjects2DLayers.Add(landObject2Ds); //Console.WriteLine("Add altitude : " + (infLimit + i + 1)); } this.altitudeMin = altitudeMin; this.altitudeMax = altitudeMax; int z = 0; foreach (LandCase2D[,] landCases in this.landObjects2DLayers) { for (int i = 0; i < landChunk.Area.Height; i++) { for (int j = 0; j < landChunk.Area.Width; j++) { if (landCases[i, j] != null) { landCases[i, j].SetLandCaseRatio((this.altitudeMin + z) - trueCurrentAltitude, LandWorld2D.LOADED_ALTITUDE_RANGE); } } } z++; } return(trueCurrentAltitude); }