public void AddInstancingOrder( VegetationDetailLevel level, List <VegetationSubjectEntity> gainedEntities, List <VegetationSubjectEntity> lostEntities) { PostChainedAction( () => _grass2RuntimeManager.AddInstancingOrderAsync(level, gainedEntities, lostEntities)); }
public List <VegetationSubjectEntity> GetEntiesFrom(IGeometry area, VegetationDetailLevel level) { var outPositions = new List <Vector2>(); if (level == VegetationDetailLevel.FULL) { var envelope = area.EnvelopeInternal; var gridPositionsStart = new IntVector2( Mathf.CeilToInt((float)envelope.MinX / _configuration.PositionsGridSize.x), Mathf.CeilToInt((float)envelope.MinY / _configuration.PositionsGridSize.y)); var afterGridingLength = new Vector2( (float)(envelope.MaxX - gridPositionsStart.X * _configuration.PositionsGridSize.x), (float)(envelope.MaxY - gridPositionsStart.Y * _configuration.PositionsGridSize.y)); var gridLength = new IntVector2( //ceil becouse there is point at length 0 !! Mathf.CeilToInt(afterGridingLength.x / _configuration.PositionsGridSize.x), Mathf.CeilToInt(afterGridingLength.y / _configuration.PositionsGridSize.y)); for (int x = 0; x < gridLength.X; x++) { for (int y = 0; y < gridLength.Y; y++) { var position = new Vector2( (0.5f + (gridPositionsStart.X + x)) * _configuration.PositionsGridSize.x, (0.5f + (gridPositionsStart.Y + y)) * _configuration.PositionsGridSize.y); outPositions.Add(position); } } } return(outPositions.Where(c => area.Contains(MyNetTopologySuiteUtils.ToGeometryEnvelope( MyNetTopologySuiteUtils.ToPointEnvelope(c)))).Select(c => new VegetationSubjectEntity( new DesignBodyLevel0Detail() { Pos2D = c, Radius = 0, Size = 0, SpeciesEnum = VegetationSpeciesEnum.Grass2SpotMarker })).ToList()); }
public async Task AddInstancingOrderAsync( VegetationDetailLevel level, List <VegetationSubjectEntity> gainedEntities, List <VegetationSubjectEntity> lostEntities) { foreach (var entity in gainedEntities) { Preconditions.Assert(entity.Detail.SpeciesEnum == VegetationSpeciesEnum.Grass2SpotMarker, $"Given entity is not of type spotMarker. It is {entity.Detail.SpeciesEnum}"); var position = entity.Position2D; var generationArea = MyRectangle.CenteredAt(position, _configuration.GroupSize); var grassBandInfo = await _grassGroupsGrower.GrowGrassBandAsync(generationArea); _entityToGrassBand[entity.Id] = grassBandInfo; } foreach (var entity in lostEntities) { var id = entity.Id; var bandInfo = _entityToGrassBand[id]; _entityToGrassBand.Remove(id); _grassGroupsGrower.RemoveGrassBand(bandInfo); } }
public void AddInstancingOrder( VegetationDetailLevel level, List <VegetationSubjectEntity> gainedEntities, List <VegetationSubjectEntity> lostEntities) { var gainedLists = new List <List <VegetationSubjectEntity> >(); var lostLists = new List <List <VegetationSubjectEntity> >(); for (int i = 0; i < _listenersWithFilters.Count; i++) { gainedLists.Add(new List <VegetationSubjectEntity>()); lostLists.Add(new List <VegetationSubjectEntity>()); } foreach (var entity in gainedEntities) { int i = 0; bool foundListener = false; foreach (var listenerWithFilter in _listenersWithFilters) { if (listenerWithFilter.Filter(entity)) { gainedLists[i].Add(entity); foundListener = true; break; } i++; } if (!foundListener) { Debug.LogError("E41. No listener accepted entity " + entity); } } foreach (var entity in lostEntities) { int i = 0; bool foundListener = false; foreach (var listenerWithFilter in _listenersWithFilters) { if (listenerWithFilter.Filter(entity)) { lostLists[i].Add(entity); foundListener = true; break; } i++; } if (!foundListener) { Debug.LogError("E42. No listener accepted entity " + entity); } } int k = 0; foreach (var listener in _listenersWithFilters.Select(c => c.ChangeListener)) { var gained = gainedLists[k]; var lost = lostLists[k]; if (gained.Any() || lost.Any()) { listener.AddInstancingOrder(level, gained, lost); } k++; } }
public List <VegetationSubjectEntity> GetEntiesFrom(IGeometry area, VegetationDetailLevel level) { return(_sources.SelectMany(c => c.GetEntiesFrom(area, level)).ToList()); }