public LandChunk2D(LandWorld2D landWorld2D, ILandChunk landChunk) { this.altitudeMin = int.MaxValue; this.altitudeMax = int.MinValue; this.Width = landChunk.Area.Width; this.Height = landChunk.Area.Height; this.landObjects2DLayers = new List <LandCase2D[, ]>(); this.UpdateCurrentAltitude(landWorld2D, landChunk, landWorld2D.CurrentAltitude); //for(int z = 0; z < this.altitudeMax - this.altitudeMin + 1; z++) //{ // List<IObject2D> listobject2Ds = new List<IObject2D>(); // LandCase[,] landCases = landChunk.GetLandObjectsAtAltitude(this.altitudeMin + z); // LandCase2D[,] landObject2Ds = new LandCase2D[landChunk.Area.Height, landChunk.Area.Width]; // for (int i = 0; i < landChunk.Area.Height; i++) // { // for (int j = 0; j < landChunk.Area.Width; j++) // { // if (landCases[i, j] != null) // { // landObject2Ds[i, j] = LandWorld2D.MappingObjectModelView[typeof(LandCase)].CreateObject2D(landWorld2D, landCases[i, j]) as LandCase2D; // if (z + this.altitudeMin < this.altitudeMax) // { // landObject2Ds[i, j].UpdateOverLandCase(landChunk.GetLandObjectsAtAltitude(this.altitudeMin + z + 1)[i, j]); // } // if (z > 0) // { // landObject2Ds[i, j].UpdateUnderLandCase(landChunk.GetLandObjectsAtAltitude(this.altitudeMin + z - 1)[i, j]); // } // landObject2Ds[i, j].SetLandCaseRatio(this.altitudeMin + z, LandWorld2D.LOADED_ALTITUDE_RANGE); // } // else // { // landObject2Ds[i, j] = null; // } // } // } // this.landObjects2DLayers.Add(landObject2Ds); //} this.Position = new Vector2f(landChunk.Area.Left, landChunk.Area.Top); }
private void CreateAltitude2D(LandWorld2D landWorld2D, ILandChunk landChunk, int altitude, ref LandCase2D[,] landObject2Ds) { List <IObject2D> listobject2Ds = new List <IObject2D>(); LandCase[,] landCases = landChunk.GetLandObjectsAtAltitude(altitude); LandCase[,] landCasesUp = null; LandCase[,] landCasesDown = null; if (altitude < landChunk.AltitudeMax) { landCasesUp = landChunk.GetLandObjectsAtAltitude(altitude + 1); } if (altitude > landChunk.AltitudeMin) { landCasesDown = landChunk.GetLandObjectsAtAltitude(altitude - 1); } 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].IsOnlyWater == false || landCasesUp == null || landCasesUp[i, j] == null || landCasesUp[i, j].LandWater == null)) { landObject2Ds[i, j] = LandWorld2D.MappingObjectModelView[typeof(LandCase)].CreateObject2D(landWorld2D, landCases[i, j]) as LandCase2D; if (landCasesUp != null) { landObject2Ds[i, j].UpdateOverLandCase(landCasesUp[i, j]); } if (landCasesDown != null) { landObject2Ds[i, j].UpdateUnderLandCase(landCasesDown[i, j]); } } else { landObject2Ds[i, j] = null; } } } }
public LandCase2D(LandWorld2D landWorld2D, LandCase landCase) { this.landGroundOverWallList = new List <ILandObject2D>(); this.landWater = null; this.landOverWall = null; this.landWall = null; this.landOverGround = null; this.landGroundList = new List <ILandObject2D>(); this.underLandCaseData = new LandCaseData(false, false); this.overLandCaseData = new LandCaseData(false, false); foreach (ILandObject landGroundObject in landCase.LandGroundList) { ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landGroundObject.GetType()].CreateObject2D(landWorld2D, landGroundObject) as ILandObject2D; this.landGroundList.Add(landObject2D); } if (landCase.LandOverGround != null) { ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landCase.LandOverGround.GetType()].CreateObject2D(landWorld2D, landCase.LandOverGround) as ILandObject2D; this.landOverGround = landObject2D; } if (landCase.LandWall != null) { foreach (ILandObject landGroundOverWallObject in landCase.LandGroundOverWallList) { ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landGroundOverWallObject.GetType()].CreateObject2D(landWorld2D, landGroundOverWallObject) as ILandObject2D; this.landGroundOverWallList.Add(landObject2D); } } if (landCase.LandWater != null) { ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landCase.LandWater.GetType()].CreateObject2D(landWorld2D, landCase.LandWater) as ILandObject2D; this.landWater = landObject2D; } if (landCase.LandWall != null) { ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landCase.LandWall.GetType()].CreateObject2D(landWorld2D, landCase.LandWall) as ILandObject2D; this.landWall = landObject2D; } if (landCase.LandWall != null) { if (landCase.LandOverWall != null) { ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landCase.LandOverWall.GetType()].CreateObject2D(landWorld2D, landCase.LandOverWall) as ILandObject2D; this.landOverWall = landObject2D; } } }
public override IObject2D CreateObject2D(LandWorld2D landWorld2D, IObject obj) { LandCase landCase = obj as LandCase; return(new LandCase2D(landWorld2D, landCase)); }
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); }
public abstract IObject2D CreateObject2D(LandWorld2D landWorld2D, IObject obj);
public override IObject2D CreateObject2D(LandWorld2D landWorld2D, IObject obj) { ILandChunk landChunk = obj as ILandChunk; return(new LandChunk2D(landWorld2D, landChunk)); }