Exemple #1
0
        protected override void onDraw(XnaDrawArgs e)
        {
            // Determine all of the cells in view
            ZRTSModel.Map map            = ((XnaUITestGame)Game).Model.GetScenario().GetGameWorld().GetMap();
            Point         upperLeftCell  = new Point(ScrollX / CellDimension, ScrollY / CellDimension);
            Point         lowerRightCell = new Point(Math.Min((ScrollX + DrawBox.Width) / CellDimension, map.GetWidth() - 1), Math.Min((ScrollY + DrawBox.Height) / CellDimension, map.GetHeight() - 1));
            Point         offset         = new Point(ScrollX % CellDimension, ScrollY % CellDimension);

            // Draw all of the tiles
            for (int x = upperLeftCell.X; x <= lowerRightCell.X; x++)
            {
                for (int y = upperLeftCell.Y; y <= lowerRightCell.Y; y++)
                {
                    CellComponent   cell   = map.GetCellAt(x, y);
                    Tile            tile   = cell.GetTile();
                    DrawTileVisitor drawer = new DrawTileVisitor(e.SpriteBatch, ((XnaUITestGame)Game).SpriteSheet, new Rectangle((x - upperLeftCell.X) * CellDimension - offset.X, (y - upperLeftCell.Y) * CellDimension - offset.Y, CellDimension, CellDimension));
                    tile.Accept(drawer);
                }
            }
        }
        /// <inheritdoc />
        public IObservable <Unit> Load(Tile tile)
        {
            var boundingBox = tile.BoundingBox;
            var zoomLevel   = ZoomHelper.GetZoomLevel(tile.RenderMode);

            var filterElementVisitor = new CompositeElementVisitor(
                new NodeVisitor(tile, _modelLoader, _objectPool),
                new WayVisitor(tile, _modelLoader, _objectPool),
                new RelationVisitor(tile, _modelLoader, _objectPool));

            _elevationProvider.SetNullPoint(tile.RelativeNullPoint);

            // download elevation data if necessary
            if (!_elevationProvider.HasElevation(tile.BoundingBox))
            {
                _elevationProvider.Download(tile.BoundingBox).Wait();
            }

            // prepare tile
            tile.Accept(tile, _modelLoader);

            var subject = new Subject <Unit>();

            _elementSourceProvider
            .Get(tile.BoundingBox)
            .SelectMany(e => e.Get(boundingBox, zoomLevel))
            .ObserveOn(Scheduler.ThreadPool)
            .SubscribeOn(Scheduler.ThreadPool)
            .Subscribe(element => element.Accept(filterElementVisitor),
                       () =>
            {
                tile.Canvas.Accept(tile, _modelLoader);
                subject.OnCompleted();
            });

            return(subject);
        }