Exemple #1
0
    public Game(int screenWidth, int screenHeight)
        : base(screenWidth, screenHeight, GraphicsMode.Default, "OpenTK Quick Start Sample")
    {
        touchDeltaCount = 5;
        touchXDeltas    = new double[touchDeltaCount];
        touchYDeltas    = new double[touchDeltaCount];

        pool = new MapPool(20, new int[] { screenWidth, screenHeight });

        screenDimensions = new int[] { screenWidth, screenHeight };

        GeocodingRequest req = new GeocodingRequest();

        req.Address = "215 Keenan Hall Notre Dame, IN 46556";
        req.Sensor  = false;

        var resp   = new GeocodingService().GetResponse(req);
        var result = resp.Results[0];

        var loc = result.Geometry.Location;

        setLL(loc.Latitude, loc.Longitude);

        VSync = VSyncMode.On;

        Mouse.ButtonDown   += new EventHandler <MouseButtonEventArgs>(handleTouchDown);
        Mouse.ButtonUp     += new EventHandler <MouseButtonEventArgs>(handleTouchUp);
        Mouse.WheelChanged += new EventHandler <MouseWheelEventArgs>(handleTouchZoom);
        Mouse.Move         += new EventHandler <MouseMoveEventArgs>(handleTouchMove);
    }
Exemple #2
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var mapModel = (Map)e.OldElement;
                MessagingCenter.Unsubscribe <Map, MapSpan>(this, MoveMessageName);
                ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged -= OnCollectionChanged;

                foreach (Pin pin in mapModel.Pins)
                {
                    pin.PropertyChanged -= PinOnPropertyChanged;
                }
            }

            if (e.NewElement != null)
            {
                var mapModel = (Map)e.NewElement;

                if (Control == null)
                {
                    MKMapView mapView = null;
#if __MOBILE__
                    if (FormsMaps.IsiOs9OrNewer)
                    {
                        // See if we've got an MKMapView available in the pool; if so, use it
                        mapView = MapPool.Get();
                    }
#endif
                    if (mapView == null)
                    {
                        // If this is iOS 8 or lower, or if there weren't any MKMapViews in the pool,
                        // create a new one
                        mapView = new MKMapView(RectangleF.Empty);
                    }

                    SetNativeControl(mapView);

                    mapView.GetViewForAnnotation = GetViewForAnnotation;
                    mapView.RegionChanged       += MkMapViewOnRegionChanged;
                }

                MessagingCenter.Subscribe <Map, MapSpan>(this, MoveMessageName, (s, a) => MoveToRegion(a), mapModel);
                if (mapModel.LastMoveToRegion != null)
                {
                    MoveToRegion(mapModel.LastMoveToRegion, false);
                }

                UpdateMapType();
                UpdateIsShowingUser();
                UpdateHasScrollEnabled();
                UpdateHasZoomEnabled();

                ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged += OnCollectionChanged;

                OnCollectionChanged(((Map)Element).Pins, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
Exemple #3
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                if (Element != null)
                {
                    var mapModel = (Map)Element;
                    MessagingCenter.Unsubscribe <Map, MapSpan>(this, MoveMessageName);
                    ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged -= OnPinCollectionChanged;
                    ((ObservableCollection <MapElement>)mapModel.MapElements).CollectionChanged -= OnMapElementCollectionChanged;
                    foreach (Pin pin in mapModel.Pins)
                    {
                        pin.PropertyChanged -= PinOnPropertyChanged;
                    }
                }

                var mkMapView = (MKMapView)Control;
                mkMapView.DidSelectAnnotationView -= MkMapViewOnAnnotationViewSelected;
                mkMapView.RegionChanged           -= MkMapViewOnRegionChanged;
                mkMapView.GetViewForAnnotation     = null;
                mkMapView.OverlayRenderer          = null;
                if (mkMapView.Delegate != null)
                {
                    mkMapView.Delegate.Dispose();
                    mkMapView.Delegate = null;
                }
                mkMapView.RemoveFromSuperview();
#if __MOBILE__
                mkMapView.RemoveGestureRecognizer(_mapClickedGestureRecognizer);
                _mapClickedGestureRecognizer.Dispose();
                _mapClickedGestureRecognizer = null;

                if (FormsMaps.IsiOs9OrNewer)
                {
                    // This renderer is done with the MKMapView; we can put it in the pool
                    // for other rendererers to use in the future
                    MapPool.Add(mkMapView);
                }
#endif
                // For iOS versions < 9, the MKMapView will be disposed in ViewRenderer's Dispose method

                if (_locationManager != null)
                {
                    _locationManager.Dispose();
                    _locationManager = null;
                }

                _lastTouchedView = null;
            }

            base.Dispose(disposing);
        }
Exemple #4
0
    void Awake()
    {
        partData         = new List <PartData>();
        mapPool          = new MapPool();
        specialBlockList = new List <SpecialBlock>();
        bgCount          = 0;
        isInitMap        = false;

        PhotonProtocol.Instance.GetRandomMapId((res) => GetRandomMapIdSuccessCallback(res), (err) => { });
    }
 public void SwitchToStage(string stageToSwitchTo)
 {
     try
     {
         currentPool             = poolManager.pools.Find(x => x.Stage == stageToSwitchTo);
         commManager.CurrentPool = currentPool;
         ShowTabPages(false);
         ShowTabPages(true);
         RemoveAllButtonsFromTabs();
         AddButtonsToTabs();
     }
     catch (Exception e)
     {
         MessageBox.Show($"Hijuesu, algo se rompio intentando cambiar de pool\r\nMandale esto al menso del Iojioji\r\n\r\n{e.Message}", "Error inesperado al cambiar de pool O:", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                if (Element != null)
                {
                    var mapModel = (Map)Element;
                    MessagingCenter.Unsubscribe <Map, MapSpan>(this, MoveMessageName);
                    ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged -= OnCollectionChanged;
                }

                var mkMapView = (MKMapView)Control;
                mkMapView.RegionChanged       -= MkMapViewOnRegionChanged;
                mkMapView.GetViewForAnnotation = null;
                mkMapView.Delegate.Dispose();
                mkMapView.Delegate = null;
                mkMapView.RemoveFromSuperview();
#if __MOBILE__
                if (FormsMaps.IsiOs9OrNewer)
                {
                    // This renderer is done with the MKMapView; we can put it in the pool
                    // for other rendererers to use in the future
                    MapPool.Add(mkMapView);
                }
#endif
                // For iOS versions < 9, the MKMapView will be disposed in ViewRenderer's Dispose method

                if (_locationManager != null)
                {
                    _locationManager.Dispose();
                    _locationManager = null;
                }
            }

            base.Dispose(disposing);
        }
    private static Path ReconstructPath(Dictionary <HexCell, PathNode> cameFrom, HexCell current)
    {
        List <PathNode> path = ListPool <PathNode> .GLGet();

        path.Add(new PathNode(current, cameFrom[current].costTo)); // Last Node
        current = cameFrom[current].location;

        while (cameFrom.ContainsKey(current))
        {
            PathNode node = cameFrom[current];
            path.Add(new PathNode(current, node.costTo));
            current = node.location;
        }
        path.Add(new PathNode(current, 0));               // Start Node

        path.Reverse();                                   // ! O(n)

        MapPool <HexCell, PathNode> .GLRestore(cameFrom); // Restore memory

        return(new Path(path));
    }
Exemple #8
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var mapModel = (Map)e.OldElement;

                MessagingCenter.Unsubscribe <Map, MapSpan>(this, MoveMessageName);

                ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged -= OnPinCollectionChanged;
                foreach (Pin pin in mapModel.Pins)
                {
                    pin.PropertyChanged -= PinOnPropertyChanged;
                }

                ((ObservableCollection <MapElement>)mapModel.MapElements).CollectionChanged -= OnMapElementCollectionChanged;
                foreach (MapElement mapElement in mapModel.MapElements)
                {
                    mapElement.PropertyChanged -= MapElementPropertyChanged;
                }
            }

            if (e.NewElement != null)
            {
                var mapModel = (Map)e.NewElement;

                if (Control == null)
                {
                    MKMapView mapView = null;
#if __MOBILE__
                    // See if we've got an MKMapView available in the pool; if so, use it
                    mapView = MapPool.Get();
#endif
                    if (mapView == null)
                    {
                        // If this is iOS 8 or lower, or if there weren't any MKMapViews in the pool,
                        // create a new one
                        mapView = new MKMapView(RectangleF.Empty);
                    }

                    SetNativeControl(mapView);

                    mapView.GetViewForAnnotation     = GetViewForAnnotation;
                    mapView.OverlayRenderer          = GetViewForOverlay;
                    mapView.DidSelectAnnotationView += MkMapViewOnAnnotationViewSelected;
                    mapView.RegionChanged           += MkMapViewOnRegionChanged;
#if __MOBILE__
                    mapView.AddGestureRecognizer(_mapClickedGestureRecognizer = new UITapGestureRecognizer(OnMapClicked));
#endif
                }

                MessagingCenter.Subscribe <Map, MapSpan>(this, MoveMessageName, (s, a) => MoveToRegion(a), mapModel);
                if (mapModel.LastMoveToRegion != null)
                {
                    MoveToRegion(mapModel.LastMoveToRegion, false);
                }

                UpdateTrafficEnabled();
                UpdateMapType();
                UpdateIsShowingUser();
                UpdateHasScrollEnabled();
                UpdateHasZoomEnabled();

                ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged += OnPinCollectionChanged;
                OnPinCollectionChanged(mapModel.Pins, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

                ((ObservableCollection <MapElement>)mapModel.MapElements).CollectionChanged += OnMapElementCollectionChanged;
                OnMapElementCollectionChanged(mapModel.MapElements, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
    public static Optional <Path> FindPath(MapPawn mapPawn)
    {
        HexCell start = mapPawn.Location;
        HexCell dest  = mapPawn.Destination;

        // For node n, cameFrom[n] is the node immediately preceding it on the cheapest path from start
        // to n currently known.
        Dictionary <HexCell, PathNode> cameFrom = MapPool <HexCell, PathNode> .GLGet();

        // For node n, gScore[n] is the cost of the cheapest path from start to n currently known.
        Dictionary <HexCell, int> gScore = MapPool <HexCell, int> .GLGet();

        gScore[start] = 0;

        // For node n, fScore[n] = gScore[n] + h(n). fScore[n] represents our current best guess as to
        // how short a path from start to finish can be if it goes through n.
        int startFScore = Heuristic(start, dest);

        // The set of discovered nodes that may need to be (re-)expanded.
        PriorityQueue <HexCell> openSet = ObjectPool <PriorityQueue <HexCell> > .GLGet();

        openSet.Add(start, startFScore);

        // The set of nodes for which a shortest path has already been found
        HashSet <HexCell> closedSet = HashSetPool <HexCell> .GLGet();

        while (!openSet.IsEmpty())
        {
            HexCell current = (HexCell)openSet.Poll();  // Explicit cast because we know this can never be null
            if (current == dest)
            {
                ObjectPool <PriorityQueue <HexCell> > .GLRestore(openSet);

                MapPool <HexCell, int> .GLRestore(gScore);

                HashSetPool <HexCell> .GLRestore(closedSet);

                return(ReconstructPath(cameFrom, current));
            }

            closedSet.Add(current);

            for (HexDirection dir = HexDirection.NE; dir <= HexDirection.NW; dir++)
            {
                HexCell neighbor = current.GetNeighbor(dir);

                if (neighbor == null || closedSet.Contains(neighbor))
                {
                    continue;                                                   // Dont waste time with already evaluated nodes
                }
                if (!mapPawn.CanTransverse(current, neighbor, dir))
                {
                    continue;                                                   // We cannot go there
                }
                int transversalCost  = mapPawn.TransversalCost(current, neighbor);
                int tentative_gScore = gScore[current] + transversalCost;

                int neighbor_gScore = gScore.ContainsKey(neighbor) ? gScore[neighbor] : int.MaxValue;
                if (tentative_gScore < neighbor_gScore)
                {
                    cameFrom[neighbor] = new PathNode(current, transversalCost);
                    gScore[neighbor]   = tentative_gScore;
                    int fScore = tentative_gScore + Heuristic(neighbor, dest);

                    if (!openSet.Update(neighbor, fScore))
                    {
                        openSet.Add(neighbor, fScore);
                    }
                }
            }
        }

        // Open set is empty but goal was never reached
        ObjectPool <PriorityQueue <HexCell> > .GLRestore(openSet);

        MapPool <HexCell, PathNode> .GLRestore(cameFrom);

        MapPool <HexCell, int> .GLRestore(gScore);

        HashSetPool <HexCell> .GLRestore(closedSet);

        return(null);
    }
        public static MapPoolSet Read(string fileName)
        {
            ISheet sheet  = null;
            var    set    = new MapPoolSet();
            var    result = new List <MapPool>();

            set.Pool = result;
            IWorkbook workbook = null;

            try
            {
                var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                if (fileName.IndexOf(".xlsx") > 0)
                {// 2007版本
                    workbook = new XSSFWorkbook(fs);
                }
                else if (fileName.IndexOf(".xls") > 0)
                { // 2003版本
                    workbook = new HSSFWorkbook(fs);
                }

                sheet = workbook.GetSheetAt(0);

                if (sheet != null)
                {
                    int startRow = sheet.FirstRowNum;
                    int rowCount = sheet.LastRowNum;
                    var head     = sheet.GetRow(startRow);
                    set.PoolName = head.GetCell(head.FirstCellNum).ToString();
                    for (int i = startRow + 1; i <= rowCount; ++i)
                    {
                        var row = sheet.GetRow(i);
                        if (row == null || row.GetCell(row.FirstCellNum).ToString().Equals(""))
                        {
                            continue;
                        }

                        //处理云选图的注释部分
                        if (!row.GetCell(row.FirstCellNum).ToString().StartsWith("http") && !row.GetCell(row.FirstCellNum).ToString().StartsWith("*"))
                        {
                            var pool = new MapPool
                            {
                                Map  = new List <Beatmap>(),
                                Type = row.GetCell(row.FirstCellNum).ToString()
                            };
                            result.Add(pool);
                        }
                        else
                        {
                            var raw = row.GetCell(row.FirstCellNum + 1).ToString();
                            var mc  = BEATMAP_NAME_REGEX.Match(raw);
                            if (mc.Success)
                            {
                                var link = row.GetCell(row.FirstCellNum).ToString();
                                var bid  = link.Substring(link.LastIndexOf("/") + 1);
                                var pool = result[result.Count - 1];
                                var maps = pool.Map;
                                var map  = new Beatmap
                                {
                                    SetId      = (mc.Groups["setId"].Value),
                                    Title      = (mc.Groups["title"].Value),
                                    Difficulty = (mc.Groups["difficulty"].Value),
                                    Mapper     = (mc.Groups["mapper"].Value),
                                    BeatmapId  = bid
                                };
                                maps.Add(map);
                            }
                        }
                    }
                }
                return(set);
            }
            catch (Exception ex)
            {
                Console.WriteLine("读取图池失败:" + ex.Message);
                return(null);
            }
        }