Ejemplo n.º 1
0
        public override IList <IEntity> Find(Vector3 position, int dimension)
        {
            var posX = position.X + xOffset;
            var posY = position.Y + yOffset;

            var xIndex = (int)Math.Floor(posX / areaSize);

            var yIndex = (int)Math.Floor(posY / areaSize);

            // x2 and y2 only required for complete exact range check

            /*var x2Index = (int) Math.Ceiling(posX / areaSize);
            *
            *  var y2Index = (int) Math.Ceiling(posY / areaSize);*/

            if (xIndex < 0 || yIndex < 0 || xIndex >= maxXAreaIndex || yIndex >= maxYAreaIndex)
            {
                return(null);
            }

            var areaEntities = entityAreas[xIndex][yIndex];

            sortedList.ClearSize();

            for (int j = 0, innerLength = areaEntities.Count; j < innerLength; j++)
            {
                var areaEntity           = areaEntities[j];
                var entityClientDistance = Vector3.DistanceSquared(areaEntity.Position, position);
                var entity = areaEntities[j];
                if (entityClientDistance <= entity.RangeSquared &&
                    CanSeeOtherDimension(dimension, entity.Dimension))
                {
                    areaEntity.LastStreamInRange = entityClientDistance;
                    if (((IPriorityEntity)entity).IsHighPriority)
                    {
                        sortedList.Add(0, areaEntity);
                    }
                    else
                    {
                        sortedList.Add(entityClientDistance, areaEntity);
                    }
                }
            }

            /*var i = limit;
             *
             * using (var enumerator = sortedList.GetEnumerator())
             * {
             *  while (i-- != 0 && enumerator.MoveNext())
             *  {
             *      yield return enumerator.Current.Value;
             *  }
             * }*/

            return(sortedList.Values);
        }
Ejemplo n.º 2
0
        public override IList <IEntity> Find(Vector3 position, int dimension)
        {
            var posX = position.X + xOffset;
            var posY = position.Y + yOffset;

            var xIndex = (int)Math.Floor(posX / areaSize);

            var yIndex = (int)Math.Floor(posY / areaSize);

            // x2 and y2 only required for complete exact range check

            /*var x2Index = (int) Math.Ceiling(posX / areaSize);
            *
            *  var y2Index = (int) Math.Ceiling(posY / areaSize);*/

            if (xIndex < 0 || yIndex < 0 || xIndex >= maxXAreaIndex || yIndex >= maxYAreaIndex)
            {
                return(null);
            }

            var gridEntity = entityAreas[xIndex][yIndex];

            sortedList.ClearSize();

            while (gridEntity != null)
            {
                var entityClientDistance = Vector3.DistanceSquared(gridEntity.Entity.Position, position);

                if (entityClientDistance <= gridEntity.Entity.RangeSquared &&
                    CanSeeOtherDimension(dimension, gridEntity.Entity.Dimension))
                {
                    var entity = gridEntity.Entity;
                    entity.LastStreamInRange = entityClientDistance;
                    sortedList.Add(entityClientDistance, entity);
                }

                gridEntity = gridEntity.Next;
            }

            return(sortedList.Values);
        }