示例#1
0
        public void RemoveEntity(IEntity entity)
        {
            this.entitiesArea.Remove(entity);

            ILandChunk lEntityChunk = this.entitiesToChunks[entity];

            lEntityChunk.EntitiesInChunk.Remove(entity);
            this.entitiesToChunks.Remove(entity);

            if (this.entitiesToBooking.ContainsKey(entity))
            {
                BookingEntity bookingEntity = this.entitiesToBooking[entity];
                if (this.entitiesToChunks[bookingEntity] != lEntityChunk)
                {
                    this.RemoveEntity(this.entitiesToBooking[entity]);
                }
            }

            if (entity is BookingEntity)
            {
                BookingEntity bookingEntity = entity as BookingEntity;
                this.entitiesToBooking.Remove(bookingEntity.Owner);
            }

            this.NotifyEntityRemoved(lEntityChunk, entity);

            entity.Dispose();
        }
示例#2
0
        public void UpdateLogic(LandWorld world, Time deltaTime)
        {
            foreach (PlayerEntity playerEntity in this.playerEntitiesUpdated)
            {
                world.OnFocusAreaChanged(playerEntity.TruePosition, this.worldResolution);
            }

            foreach (KeyValuePair <PlayerEntity, bool> playerEntityEntry in this.playerEntityToAdded)
            {
                if (playerEntityEntry.Value == false)
                {
                    ILandChunk landChunk = world.GetLandChunkAt(playerEntityEntry.Key.Position.X, playerEntityEntry.Key.Position.Y);

                    if (landChunk != null)
                    {
                        // Update player altitude
                        int altitude = world.GetAltitudeAt(playerEntityEntry.Key.Position.X, playerEntityEntry.Key.Position.Y);
                        playerEntityEntry.Key.SetPosition(playerEntityEntry.Key.Position.X, playerEntityEntry.Key.Position.Y, altitude);

                        world.EntityManager.AddEntity(playerEntityEntry.Key, landChunk);
                    }
                }
            }

            this.playerEntitiesUpdated.Clear();
        }
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"];

            ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"];

            bool[,] subArea = new bool[3, 3];

            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    this.GetComputedLandType(altitudeLandLayerGenerator, area, i, j, out LandType landType, out LandType secondType, out LandTransition landTransition);

                    int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i);

                    int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i);

                    GroundLandObject groundLandObject = new GroundLandObject(area.Left + j, area.Top + i, altitude, landType);

                    GroundLandObject secondGroundLandObject = new GroundLandObject(area.Left + j, area.Top + i, altitude, secondType);
                    secondGroundLandObject.SetTransition(landTransition);

                    AssignGround(landChunk, i, j, altitude, altitudeOffset, groundLandObject, secondGroundLandObject);

                    this.powerArea[i + 2, j + 2] = (int)this.GetLandTypeFromPower(altitude);
                }
            }

            landChunk.AddTypeInChunk(typeof(GroundLandObject));

            return(seed);
        }
示例#4
0
 public void NotifyEntityRemoved(ILandChunk landChunk, IEntity entity)
 {
     if (this.EntityRemoved != null)
     {
         this.EntityRemoved(landChunk, entity);
     }
 }
示例#5
0
文件: LandWorld.cs 项目: Deneyr/PokeU
        public ILandChunk GetLandChunkAt(int x, int y)
        {
            ILandChunk result = null;

            int offsetX = x - this.currentChunksArea.Left;
            int offsetY = y - this.currentChunksArea.Top;

            if (offsetX >= 0 && offsetY >= 0)
            {
                int chunkX = offsetX / CHUNK_SIZE;
                int chunkY = offsetY / CHUNK_SIZE;

                if (chunkY < this.landChunkArea.Count &&
                    chunkX < this.landChunkArea[0].Count)
                {
                    offsetX %= CHUNK_SIZE;
                    offsetY %= CHUNK_SIZE;

                    LandChunkContainer container = this.landChunkArea[chunkY][chunkX];

                    if (container.LandChunk != null)
                    {
                        result = container.LandChunk;
                    }
                }
            }
            return(result);
        }
示例#6
0
 public void NotifyEntityChunkChanged(ILandChunk landChunkFrom, ILandChunk landChunkTo, IEntity entity)
 {
     if (this.EntityChunkChanged != null)
     {
         this.EntityChunkChanged(landChunkFrom, landChunkTo, entity);
     }
 }
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            ALandLayerGenerator groundLandLayerGenerator = worldGenerator.Generators["defaultGround"];

            ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"];

            ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"];

            ALandLayerGenerator elementLandLayerGenerator = worldGenerator.Generators["element"];

            bool isThereSandElement = false;

            Random random = new Random(seed);

            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i);

                    int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i);

                    int elementIndex = random.Next(0, 8);

                    int power = this.GetElementPower(elementLandLayerGenerator.GetComputedPowerAt(j, i));

                    LandType landType = (LandType)groundLandLayerGenerator.GetComputedPowerAt(j, i);

                    if (landType == LandType.SAND)
                    {
                        if (power >= 8 && random.Next(0, 3) > 0 && altitudeOffset == 0)
                        {
                            float trueAltitude = altitudeLandLayerGenerator.GetPowerAt(new SFML.System.Vector2f(area.Left + j, area.Top + i));

                            if ((elementIndex == 1 || elementIndex == 3) &&
                                trueAltitude > 0.6 && random.Next(0, 4) > 0)
                            {
                                elementIndex -= 1;
                            }

                            GroundElementLandObject groundElement = new GroundElementLandObject(area.Left + j, area.Top + i, altitude, landType, elementIndex);

                            LandCase landCase = landChunk.GetLandCase(i, j, altitude);

                            landCase.LandOverGround = groundElement;

                            isThereSandElement = true;
                        }
                    }
                }
            }

            if (isThereSandElement)
            {
                landChunk.AddTypeInChunk(typeof(GroundElementLandObject));
            }

            return(random.Next());
        }
示例#8
0
 public void OnEntityRemovedToManager(ILandChunk landChunk, IEntity entity)
 {
     if (entity is PlayerEntity &&
         this.playerEntityToAdded.ContainsKey(entity as PlayerEntity))
     {
         this.playerEntityToAdded[entity as PlayerEntity] = false;
     }
 }
示例#9
0
        private void OnChunkAdded(ILandChunk obj)
        {
            this.chunkResourcesLoader.LoadChunkResources(obj);

            IObject2DFactory landChunk2DFactory = LandWorld2D.MappingObjectModelView[obj.GetType()];

            this.landChunksDictionary.Add(obj, landChunk2DFactory.CreateObject2D(this, obj) as LandChunk2D);
        }
示例#10
0
        private void OnChunkRemoved(ILandChunk obj)
        {
            this.chunkResourcesLoader.UnloadChunkResources(obj);

            this.landChunksDictionary[obj].Dispose();

            this.landChunksDictionary.Remove(obj);
        }
示例#11
0
文件: LandWorld.cs 项目: Deneyr/PokeU
        private void PrepareChunksUpdated(List <LandChunkContainer> chunksRemoved, List <LandChunkContainer> chunksAdded)
        {
            foreach (LandChunkContainer container in chunksRemoved)
            {
                this.landChunksToRemove.Add(container.Area);

                /*if (container.LandChunk != null
                 *  && this.currentLoadedLandChunks.ContainsKey(container.Area)
                 *  && this.landChunksCache.Contains(container.LandChunk) == false)
                 * {
                 *  this.landChunksToRemove.Add(container.Area);
                 * }
                 * else if(this.landChunkLoader.IsLandChunkLoading(container.Area) || this.pendingLandChunksImported.ContainsKey(container.Area) == false)
                 * {
                 *  this.landChunksToRemove.Add(container.Area);
                 * }*/
            }

            List <LandChunkContainer> subChunksAddedList = new List <LandChunkContainer>();

            foreach (LandChunkContainer container in chunksAdded)
            {
                this.mainMutex.WaitOne();

                // Order is important
                if (this.landChunkLoader.IsLandChunkLoading(container.Area) == false &&
                    this.pendingLandChunksImported.ContainsKey(container.Area) == false)
                {
                    this.mainMutex.ReleaseMutex();

                    if (this.currentLoadedLandChunks.ContainsKey(container.Area))
                    {
                        LandChunkContainer landChunkContainer = this.currentLoadedLandChunks[container.Area];
                        ILandChunk         landChunkCache     = this.landChunksCache.FirstOrDefault(pElem => pElem.Area == container.Area);
                        if (landChunkCache != null)
                        {
                            this.landChunksCache.Remove(landChunkCache);

                            container.LandChunk          = landChunkContainer.LandChunk;
                            landChunkContainer.LandChunk = null;
                            this.currentLoadedLandChunks[container.Area] = container;
                        }
                    }
                    else
                    {
                        subChunksAddedList.Add(container);
                    }
                }
                else
                {
                    this.mainMutex.ReleaseMutex();
                }

                this.landChunksToRemove.Remove(container.Area);
            }

            this.landChunkLoader.RequestChunk(subChunksAddedList);
        }
示例#12
0
文件: LandWorld.cs 项目: Deneyr/PokeU
 private void NotifyChunkRemoved(ILandChunk landChunkRemoved)
 {
     if (this.ChunkRemoved != null)
     {
         Console.WriteLine("chunk removed" + landChunkRemoved.Area.Left + " : " + landChunkRemoved.Area.Top + " - " + remainingChunks.Count);
         remainingChunks.Remove(landChunkRemoved);
         this.ChunkRemoved(landChunkRemoved);
     }
 }
示例#13
0
        public void AddEntity(IEntity entity, ILandChunk landChunk)
        {
            this.entitiesArea.Add(entity);
            this.entitiesToChunks.Add(entity, landChunk);

            landChunk.EntitiesInChunk.Add(entity);

            this.NotifyEntityAdded(landChunk, entity);
        }
示例#14
0
        public void OnChunkAdded(ILandChunk landChunk)
        {
            foreach (IEntity entity in landChunk.EntitiesInChunk)
            {
                this.entitiesArea.Add(entity);
                this.entitiesToChunks.Add(entity, landChunk);

                this.NotifyEntityAdded(landChunk, entity);
            }
        }
示例#15
0
        public void OnEntityAdded(ILandChunk landChunk, IEntity entity)
        {
            IObject2DFactory entityFactory = LandWorld2D.MappingObjectModelView[entity.GetType()];

            if (this.landWorld2D.TryGetTarget(out LandWorld2D world2D))
            {
                world2D.ResourcesLoader.LoadEntitiesResources(entity);

                this.entitiesToEntities2D.Add(entity, entityFactory.CreateObject2D(world2D, entity) as AEntity2D);
            }
        }
示例#16
0
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    landChunk.SetAltitudeAt(i, j, this.GetComputedPowerAt(j, i));
                }
            }

            return(seed);
        }
示例#17
0
        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);
        }
示例#18
0
文件: LandWorld.cs 项目: Deneyr/PokeU
        public int GetAltitudeAt(int x, int y)
        {
            int result = 0;

            ILandChunk landChunk = this.GetLandChunkAt(x, y);

            if (landChunk != null)
            {
                result = landChunk.GetAltitudeAt(y - landChunk.Area.Top, x - landChunk.Area.Left);
            }

            return(result);
        }
示例#19
0
文件: LandWorld.cs 项目: Deneyr/PokeU
        public LandCase GetLandCaseAt(int x, int y, int z)
        {
            LandCase result = null;

            ILandChunk landChunk = this.GetLandChunkAt(x, y);

            if (landChunk != null)
            {
                result = landChunk.GetLandCase(y - landChunk.Area.Top, x - landChunk.Area.Left, z);
            }

            return(result);
        }
示例#20
0
        public void LoadChunkResources(ILandChunk landChunk)
        {
            IntRect altitudeRect = new IntRect(landChunk.Area.Left, landChunk.Area.Top, 0, 0);

            if (this.loadedChunks.Contains(altitudeRect))
            {
                throw new Exception("Try to load an already loaded chunk");
            }

            if (chunksInCache.Contains(altitudeRect))
            {
                chunksInCache.Remove(altitudeRect);
            }
            else
            {
                HashSet <string> resourcesPath = new HashSet <string>();

                HashSet <Type> landObjectTypes = landChunk.TypesInChunk;

                foreach (Type type in landObjectTypes)
                {
                    IEnumerable <string> resources = LandWorld2D.MappingObjectModelView[type].Resources.Keys;

                    foreach (string path in resources)
                    {
                        resourcesPath.Add(path);
                    }
                }

                HashSet <string> realResourcesToLoad = new HashSet <string>();
                foreach (string path in resourcesPath)
                {
                    if (this.pathToChunksDictionary.ContainsKey(path) == false)
                    {
                        this.pathToChunksDictionary.Add(path, new HashSet <IntRect>());

                        realResourcesToLoad.Add(path);
                    }

                    this.pathToChunksDictionary[path].Add(altitudeRect);
                }

                this.chunksToPathsDictionary.Add(altitudeRect, resourcesPath);

                if (realResourcesToLoad.Any())
                {
                    LandWorld2D.TextureManager.LoadTextures(realResourcesToLoad);
                }
            }
            loadedChunks.Add(altitudeRect);
        }
示例#21
0
        public void OnEntityRemoved(ILandChunk landChunk, IEntity entity)
        {
            if (this.entitiesToEntities2D.ContainsKey(entity))
            {
                if (this.landWorld2D.TryGetTarget(out LandWorld2D world2D))
                {
                    world2D.ResourcesLoader.UnloadEntitiesResources(entity);
                }

                this.entitiesToEntities2D[entity].Dispose();

                this.entitiesToEntities2D.Remove(entity);
            }
        }
示例#22
0
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            ALandLayerGenerator grassLandLayerGenerator = worldGenerator.Generators["grass"];

            ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"];

            ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"];

            ALandLayerGenerator elementLandLayerGenerator = worldGenerator.Generators["element"];

            bool isThereGrassElement = false;

            Random random = new Random(seed);

            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i);

                    int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i);

                    int elementIndex = random.Next(0, 12);

                    int power = this.GetElementPower(elementLandLayerGenerator.GetComputedPowerAt(j, i));

                    GrassType grassType = (GrassType)grassLandLayerGenerator.GetComputedPowerAt(j, i);

                    if (power >= 2 && random.Next(0, 3) > 0 && altitudeOffset == 0 && grassType != GrassType.NONE)
                    {
                        GrassElementLandObject grassElement = new GrassElementLandObject(area.Left + j, area.Top + i, altitude, grassType, elementIndex);

                        LandCase landCase = landChunk.GetLandCase(i, j, altitude);

                        landCase.LandOverGround = grassElement;

                        isThereGrassElement = true;
                    }
                }
            }

            if (isThereGrassElement)
            {
                landChunk.AddTypeInChunk(typeof(GrassElementLandObject));
            }

            return(random.Next());
        }
示例#23
0
        public void OnChunkRemoved(ILandChunk landChunk)
        {
            foreach (IEntity entity in landChunk.EntitiesInChunk)
            {
                this.entitiesArea.Remove(entity);

                this.entitiesToChunks.Remove(entity);

                if (this.entitiesToBooking.ContainsKey(entity))
                {
                    this.RemoveEntity(entity);
                }

                this.NotifyEntityRemoved(landChunk, entity);
            }
        }
示例#24
0
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"];

            bool[,] subArea = new bool[3, 3];

            this.powerArea = new int[area.Height + 4, area.Width + 4];

            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    int[,] subAreaInt = new int[3, 3];
                    int maxLocalAltitude = int.MinValue;

                    maxLocalAltitude = this.GetComputedMatrix(altitudeLandLayerGenerator, i, j, ref subAreaInt);

                    int diffAltitude = maxLocalAltitude - subAreaInt[1, 1];

                    this.powerArea[i + 2, j + 2] = diffAltitude;

                    for (int offset = 0; offset < diffAltitude; offset++)
                    {
                        this.GetComputedLandType(area, ref subAreaInt, maxLocalAltitude, out LandTransition landTransition);

                        if (landTransition != LandTransition.NONE)
                        {
                            AltitudeLandObject altitudeLandObject = new AltitudeLandObject(area.Left + j, area.Top + i, subAreaInt[1, 1], LandType.GRASS);

                            landChunk.InitializeLandCase(i, j, subAreaInt[1, 1]);
                            landChunk.GetLandCase(i, j, subAreaInt[1, 1]).LandWall = altitudeLandObject;

                            altitudeLandObject.SetLandTransition(landTransition);
                        }

                        subAreaInt[1, 1]++;
                    }
                }
            }

            landChunk.AddTypeInChunk(typeof(AltitudeLandObject));

            return(seed);
        }
示例#25
0
        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;
                    }
                }
            }
        }
示例#26
0
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"];

            bool isThereWater = false;

            this.ConstructAltitudeArea(worldGenerator, area);

            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    int altitude = this.powerArea[i + 1, j + 1];

                    int[,] subAreaInt = new int[3, 3];
                    int maxLocalAltitude = int.MinValue;

                    maxLocalAltitude = this.GetComputedMatrix(i, j, ref subAreaInt);

                    for (int z = altitude; z <= 0; z++)
                    {
                        this.GetComputedLandType(area, ref subAreaInt, maxLocalAltitude, out LandTransition landTransition);

                        WaterLandObject waterLandObject = new WaterLandObject(area.Left + j, area.Top + i, z);
                        waterLandObject.SetLandTransition(landTransition);

                        landChunk.InitializeLandCase(i, j, z);
                        landChunk.GetLandCase(i, j, z).LandWater = waterLandObject;
                        isThereWater = true;

                        subAreaInt[1, 1]++;
                    }
                }
            }

            if (isThereWater)
            {
                landChunk.AddTypeInChunk(typeof(WaterLandObject));
            }

            return(seed);
        }
示例#27
0
        public bool BookPositionForEntity(LandWorld world, IEntity entity, int x, int y, int z)
        {
            if (this.entitiesToBooking.ContainsKey(entity) == false)
            {
                ILandChunk landChunk = world.GetLandChunkAt(x, y);

                if (landChunk != null)
                {
                    BookingEntity bookingEntity = new BookingEntity(entity, x, y, z);

                    this.entitiesToBooking.Add(entity, bookingEntity);

                    this.AddEntity(entity, landChunk);

                    return(true);
                }
            }

            return(false);
        }
示例#28
0
        public void UnloadChunkResources(ILandChunk landChunk)
        {
            IntRect altitudeRect = new IntRect(landChunk.Area.Left, landChunk.Area.Top, 0, 0);

            if (this.loadedChunks.Contains(altitudeRect) == false)
            {
                throw new Exception("Try to unload a not loaded chunk");
            }

            this.chunksInCache.Add(altitudeRect);

            if (this.chunksInCache.Count > NB_MAX_CACHE_CHUNKS)
            {
                IntRect altitudeToRemove = this.chunksInCache.First();
                this.chunksInCache.RemoveAt(0);

                HashSet <string> pathsAltitudeToRemove = this.chunksToPathsDictionary[altitudeToRemove];
                HashSet <string> pathsToRemove         = new HashSet <string>();

                foreach (string path in pathsAltitudeToRemove)
                {
                    HashSet <IntRect> altitudes = this.pathToChunksDictionary[path];
                    altitudes.Remove(altitudeRect);

                    if (altitudes.Any() == false)
                    {
                        pathsToRemove.Add(path);
                        this.pathToChunksDictionary.Remove(path);
                    }
                }

                this.chunksToPathsDictionary.Remove(altitudeToRemove);

                if (pathsToRemove.Any())
                {
                    LandWorld2D.TextureManager.UnloadTextures(pathsToRemove);
                }
            }

            this.loadedChunks.Remove(altitudeRect);
        }
示例#29
0
        public bool MoveEntity(IEntity entity, int x, int y, int z)
        {
            if (this.entitiesToBooking.ContainsKey(entity))
            {
                BookingEntity bookingEntity = this.entitiesToBooking[entity];

                ILandChunk landChunkFrom = this.entitiesToChunks[entity];
                ILandChunk landChunkTo   = this.entitiesToChunks[bookingEntity];

                if (landChunkFrom == null || landChunkTo == null)
                {
                    throw new Exception("Error during entity moving, chunk from or to is null");
                }

                this.RemoveEntity(bookingEntity);
                if (landChunkFrom != landChunkTo)
                {
                    landChunkFrom.EntitiesInChunk.Remove(entity);
                    landChunkTo.EntitiesInChunk.Add(entity);

                    this.entitiesToChunks.Remove(entity);
                    this.entitiesToChunks.Add(entity, landChunkTo);

                    this.NotifyEntityChunkChanged(landChunkFrom, landChunkTo, entity);
                }

                entity.SetPosition(x, y, z);

                this.entitiesArea.Move(entity);

                this.NotifyEntityCaseChanged(entity);

                return(true);
            }

            return(false);
        }
示例#30
0
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"];

            ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"];

            bool[,] subArea = new bool[3, 3];

            bool isThereMountain = false;

            this.ConstructMountainArea(worldGenerator, area);

            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i);

                    int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i);

                    if ((altitude > 6 || (altitude == 6 && altitudeOffset > 0)) &&
                        altitude < 23)
                    {
                        LandCreationHelper.GetComputedLandType(this, area, i, j, out int mountainTypeInt, out int secondTypeInt, out LandTransition landTransition, out LandTransition secondLandTransition);
                        //this.GetComputedLandType(area, i, j, out MountainType mountainType, out MountainType secondType, out LandTransition landTransition, out LandTransition secondLandTransition);

                        MountainType mountainType = (MountainType)mountainTypeInt;
                        MountainType secondType   = (MountainType)secondTypeInt;

                        MountainLandObject groundLandObject       = null;
                        MountainLandObject secondGroundLandObject = null;

                        if (mountainType != MountainType.NONE)
                        {
                            groundLandObject = new MountainLandObject(area.Left + j, area.Top + i, altitude, mountainType);
                            groundLandObject.SetTransition(landTransition);

                            isThereMountain = true;
                        }

                        if (secondType != mountainType && secondType != MountainType.NONE)
                        {
                            secondGroundLandObject = new MountainLandObject(area.Left + j, area.Top + i, 0, secondType);
                            secondGroundLandObject.SetTransition(secondLandTransition);

                            isThereMountain = true;
                        }

                        bool onlyGround = altitude == 22 && altitudeOffset > 0;
                        AssignGround(landChunk, i, j, altitude, altitudeOffset, groundLandObject, secondGroundLandObject, onlyGround);
                    }
                }
            }

            if (isThereMountain)
            {
                landChunk.AddTypeInChunk(typeof(MountainLandObject));
            }

            return(seed);
        }